vcl/source/font/LogicalFontInstance.cxx |    2 +-
 vcl/source/gdi/CommonSalLayout.cxx      |    2 ++
 vcl/source/outdev/font.cxx              |    6 +++++-
 vcl/source/outdev/text.cxx              |   26 +++++++++-----------------
 4 files changed, 17 insertions(+), 19 deletions(-)

New commits:
commit a21958db9111e27312c6ae52e2d5e3a9e8a39e08
Author:     Khaled Hosny <kha...@libreoffice.org>
AuthorDate: Tue Jul 18 17:13:33 2023 +0300
Commit:     خالد حسني <kha...@libreoffice.org>
CommitDate: Sun Jul 23 06:02:51 2023 +0200

    vcl: Use doubles in GetTextBreak()
    
    Change-Id: I88ee2434ba6ddb41cf1983afceebe1ae72be8d9f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154584
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@libreoffice.org>

diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index c02509718a60..8d4f557288c2 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -1456,14 +1456,10 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& 
rStr, tools::Long nTextWid
         // problem with rounding errors especially for small nCharExtras
         // TODO: remove when layout units have subpixel granularity
         tools::Long nSubPixelFactor = 64;
-        nTextWidth *= nSubPixelFactor;
-        DeviceCoordinate nTextPixelWidth = LogicWidthToDeviceCoordinate( 
nTextWidth );
-        DeviceCoordinate nExtraPixelWidth = 0;
+        double nTextPixelWidth = ImplLogicWidthToDeviceSubPixel(nTextWidth * 
nSubPixelFactor);
+        double nExtraPixelWidth = 0;
         if( nCharExtra != 0 )
-        {
-            nCharExtra *= nSubPixelFactor;
-            nExtraPixelWidth = LogicWidthToDeviceCoordinate( nCharExtra );
-        }
+            nExtraPixelWidth = ImplLogicWidthToDeviceSubPixel(nCharExtra * 
nSubPixelFactor);
         nRetVal = pSalLayout->GetTextBreak( nTextPixelWidth, nExtraPixelWidth, 
nSubPixelFactor );
     }
 
@@ -1490,14 +1486,10 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& 
rStr, tools::Long nTextWid
         // TODO: remove when layout units have subpixel granularity
         tools::Long nSubPixelFactor = 64;
 
-        nTextWidth *= nSubPixelFactor;
-        DeviceCoordinate nTextPixelWidth = LogicWidthToDeviceCoordinate( 
nTextWidth );
-        DeviceCoordinate nExtraPixelWidth = 0;
+        double nTextPixelWidth = ImplLogicWidthToDeviceSubPixel(nTextWidth * 
nSubPixelFactor);
+        double nExtraPixelWidth = 0;
         if( nCharExtra != 0 )
-        {
-            nCharExtra *= nSubPixelFactor;
-            nExtraPixelWidth = LogicWidthToDeviceCoordinate( nCharExtra );
-        }
+            nExtraPixelWidth = ImplLogicWidthToDeviceSubPixel(nCharExtra * 
nSubPixelFactor);
 
         // calculate un-hyphenated break position
         nRetVal = pSalLayout->GetTextBreak( nTextPixelWidth, nExtraPixelWidth, 
nSubPixelFactor );
@@ -1508,7 +1500,7 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& 
rStr, tools::Long nTextWid
         if( pHyphenLayout )
         {
             // calculate subpixel width of hyphenation character
-            tools::Long nHyphenPixelWidth = pHyphenLayout->GetTextWidth() * 
nSubPixelFactor;
+            double nHyphenPixelWidth = pHyphenLayout->GetTextWidth() * 
nSubPixelFactor;
 
             // calculate hyphenated break position
             nTextPixelWidth -= nHyphenPixelWidth;
@@ -1689,7 +1681,7 @@ void OutputDevice::ImplDrawText( OutputDevice& 
rTargetDevice, const tools::Recta
                                                 nIndex, nLineLen );
                         sal_Int32 lc_x1 = pCaretXArray[2*(nMnemonicPos - 
nIndex)];
                         sal_Int32 lc_x2 = pCaretXArray[2*(nMnemonicPos - 
nIndex)+1];
-                        nMnemonicWidth = 
rTargetDevice.LogicWidthToDeviceCoordinate( std::abs(lc_x1 - lc_x2) );
+                        nMnemonicWidth = 
rTargetDevice.ImplLogicWidthToDeviceSubPixel(std::abs(lc_x1 - lc_x2));
 
                         Point       aTempPos = rTargetDevice.LogicToPixel( 
aPos );
                         nMnemonicX = rTargetDevice.GetOutOffXPixel() + 
aTempPos.X() + rTargetDevice.ImplLogicWidthToDevicePixel( std::min( lc_x1, 
lc_x2 ) );
@@ -1757,7 +1749,7 @@ void OutputDevice::ImplDrawText( OutputDevice& 
rTargetDevice, const tools::Recta
             /*sal_Bool bRet =*/ _rLayout.GetCaretPositions( aStr, 
pCaretXArray.get(), 0, aStr.getLength() );
             tools::Long lc_x1 = pCaretXArray[2*nMnemonicPos];
             tools::Long lc_x2 = pCaretXArray[2*nMnemonicPos+1];
-            nMnemonicWidth = rTargetDevice.LogicWidthToDeviceCoordinate( 
std::abs(lc_x1 - lc_x2) );
+            nMnemonicWidth = 
rTargetDevice.ImplLogicWidthToDeviceSubPixel(std::abs(lc_x1 - lc_x2));
 
             Point aTempPos = rTargetDevice.LogicToPixel( aPos );
             nMnemonicX = rTargetDevice.GetOutOffXPixel() + aTempPos.X() + 
rTargetDevice.ImplLogicWidthToDevicePixel( std::min(lc_x1, lc_x2) );
commit 9d9e3b439883c3c315501f56bb613e080863db64
Author:     Khaled Hosny <kha...@libreoffice.org>
AuthorDate: Mon Jul 17 17:21:34 2023 +0300
Commit:     خالد حسني <kha...@libreoffice.org>
CommitDate: Sun Jul 23 06:02:43 2023 +0200

    tdf#156211: Don’t round Kashida width when doing subpixel positioning
    
    This improves our calculated positions for the inserted Kashida glyphs,
    which has the side effect of fixing this issue, and generally improves
    Kashida positions so that there is less rounding errors and visible gaps
    between them.
    
    Change-Id: If60126e77e59c2c1246298e2993609547d38c79c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154550
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@libreoffice.org>

diff --git a/vcl/source/font/LogicalFontInstance.cxx 
b/vcl/source/font/LogicalFontInstance.cxx
index 965fc91591c1..ec9740fd8812 100644
--- a/vcl/source/font/LogicalFontInstance.cxx
+++ b/vcl/source/font/LogicalFontInstance.cxx
@@ -106,7 +106,7 @@ double LogicalFontInstance::GetKashidaWidth() const
 {
     sal_GlyphId nGlyph = GetGlyphIndex(0x0640);
     if (nGlyph)
-        return std::ceil(GetGlyphWidth(nGlyph));
+        return GetGlyphWidth(nGlyph);
     return 0;
 }
 
diff --git a/vcl/source/gdi/CommonSalLayout.cxx 
b/vcl/source/gdi/CommonSalLayout.cxx
index 4e24b4979983..3324d492e3cf 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -757,6 +757,8 @@ void GenericSalLayout::ApplyDXArray(const double* pDXArray, 
const sal_Bool* pKas
     // Find Kashida glyph width and index.
     sal_GlyphId nKashidaIndex = GetFont().GetGlyphIndex(0x0640);
     double nKashidaWidth = GetFont().GetKashidaWidth();
+    if (!GetSubpixelPositioning())
+        nKashidaWidth = std::ceil(nKashidaWidth);
 
     if (nKashidaWidth <= 0)
     {
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 6525368964af..e8e3f9fefc18 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -1133,7 +1133,11 @@ tools::Long OutputDevice::GetMinKashida() const
     if (!ImplNewFont())
         return 0;
 
-    return ImplDevicePixelToLogicWidth( 
mpFontInstance->mxFontMetric->GetMinKashida() );
+    auto nKashidaWidth = mpFontInstance->mxFontMetric->GetMinKashida();
+    if (!mbMap)
+        nKashidaWidth = std::ceil(nKashidaWidth);
+
+    return ImplDevicePixelToLogicWidth(nKashidaWidth);
 }
 
 sal_Int32 OutputDevice::ValidateKashidas ( const OUString& rTxt,

Reply via email to