[Libreoffice-commits] core.git: vcl/inc vcl/quartz vcl/source vcl/unx vcl/win

Khaled Hosny khaledhosny at eglug.org
Wed Apr 25 20:55:36 UTC 2018


 vcl/inc/sallayout.hxx                    |   12 +--
 vcl/quartz/salgdi.cxx                    |    2 
 vcl/source/gdi/pdfwriter_impl.cxx        |    6 -
 vcl/source/gdi/sallayout.cxx             |  100 +++++++++----------------------
 vcl/source/outdev/font.cxx               |    2 
 vcl/source/outdev/text.cxx               |    2 
 vcl/source/outdev/textline.cxx           |    2 
 vcl/unx/generic/gdi/cairotextrender.cxx  |    2 
 vcl/unx/generic/print/genpspgraphics.cxx |    2 
 vcl/win/gdi/DWriteTextRenderer.cxx       |    2 
 vcl/win/gdi/winlayout.cxx                |    6 -
 11 files changed, 49 insertions(+), 89 deletions(-)

New commits:
commit 5441727c29fba37dff85e465ec55ead5942d8232
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Tue Apr 24 15:55:34 2018 +0200

    Simplify and rename SalLayout::GetNextGlyphs
    
    It is now always called with nLen == 1, so simplify and rename. The
    criteria for deciding how many glyphs to return was bogus anyway, good
    riddance.
    
    Change-Id: Iff578d124ab40a0dfa84469be8e0e9fc1b6b8c48
    Reviewed-on: https://gerrit.libreoffice.org/53406
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Khaled Hosny <khaledhosny at eglug.org>

diff --git a/vcl/inc/sallayout.hxx b/vcl/inc/sallayout.hxx
index 0ab317dae03f..170c2a2c380d 100644
--- a/vcl/inc/sallayout.hxx
+++ b/vcl/inc/sallayout.hxx
@@ -173,8 +173,8 @@ public:
     virtual bool    IsKashidaPosValid ( int /*nCharPos*/ ) const { return true; } // i60594
 
     // methods using glyph indexing
-    virtual int     GetNextGlyphs(int nLen, const GlyphItem** pGlyphs, Point& rPos, int&,
-                                  const PhysicalFontFace** pFallbackFonts = nullptr) const = 0;
+    virtual bool    GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int&,
+                                 const PhysicalFontFace** pFallbackFont = nullptr) const = 0;
     virtual bool    GetOutline( SalGraphics&, basegfx::B2DPolyPolygonVector& ) const;
     virtual bool    GetBoundRect( SalGraphics&, tools::Rectangle& ) const;
 
@@ -214,8 +214,8 @@ public:
     virtual sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const override;
     virtual DeviceCoordinate FillDXArray( DeviceCoordinate* pDXArray ) const override;
     virtual void    GetCaretPositions( int nArraySize, long* pCaretXArray ) const override;
-    virtual int     GetNextGlyphs(int nLen, const GlyphItem** pGlyphs, Point& rPos, int&,
-                                  const PhysicalFontFace** pFallbackFonts = nullptr) const override;
+    virtual bool    GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int&,
+                                 const PhysicalFontFace** pFallbackFont = nullptr) const override;
     virtual bool    GetOutline( SalGraphics&, basegfx::B2DPolyPolygonVector& ) const override;
     virtual bool    IsKashidaPosValid(int nCharPos) const override;
 
@@ -316,8 +316,8 @@ public:
     virtual void    GetCaretPositions( int nArraySize, long* pCaretXArray ) const override;
 
     // used by display layers
-    virtual int     GetNextGlyphs(int nLen, const GlyphItem** pGlyphs, Point& rPos, int&,
-                                  const PhysicalFontFace** pFallbackFonts = nullptr) const override;
+    virtual bool    GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int&,
+                                 const PhysicalFontFace** pFallbackFont = nullptr) const override;
 
 protected:
                     GenericSalLayout();
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 7ee45db62aef..ed0d4b78d9d1 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -418,7 +418,7 @@ void AquaSalGraphics::DrawTextLayout(const CommonSalLayout& rLayout)
     std::vector<CGPoint> aGlyphPos;
     std::vector<bool> aGlyphOrientation;
     int nStart = 0;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (rLayout.GetNextGlyph(&pGlyph, aPos, nStart))
     {
         CGPoint aGCPos = CGPointMake(aPos.X(), -aPos.Y());
 
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 3b7b2a84d3af..de4872342db7 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -6673,7 +6673,7 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool
     aGlyphs.reserve( nMaxGlyphs );
     // first get all the glyphs and register them; coordinates still in Pixel
     Point aPos;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nIndex, &pFallbackFont))
+    while (rLayout.GetNextGlyph(&pGlyph, aPos, nIndex, &pFallbackFont))
     {
         const auto* pFont = pFallbackFont ? pFallbackFont : pDevFont;
 
@@ -6791,7 +6791,7 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool
             Point aStartPt;
             sal_Int32 nWidth = 0;
             nIndex = 0;
-            while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nIndex))
+            while (rLayout.GetNextGlyph(&pGlyph, aPos, nIndex))
             {
                 if (!pGlyph->IsSpacing())
                 {
@@ -6886,7 +6886,7 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool
         aOffset.AdjustY(m_pReferenceDevice->mpFontInstance->mxFontMetric->GetAscent() );
 
     nIndex = 0;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nIndex))
+    while (rLayout.GetNextGlyph(&pGlyph, aPos, nIndex))
     {
         if (pGlyph->IsSpacing())
         {
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index 0eb3c98c61fa..c1ddd412ca70 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -641,7 +641,7 @@ bool SalLayout::GetOutline( SalGraphics& rSalGraphics,
     Point aPos;
     const GlyphItem* pGlyph;
     int nStart = 0;
-    while (GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (GetNextGlyph(&pGlyph, aPos, nStart))
     {
         // get outline of individual glyph, ignoring "empty" glyphs
         bool bSuccess = rSalGraphics.GetGlyphOutline(*pGlyph, aGlyphOutline);
@@ -673,7 +673,7 @@ bool SalLayout::GetBoundRect( SalGraphics& rSalGraphics, tools::Rectangle& rRect
     Point aPos;
     const GlyphItem* pGlyph;
     int nStart = 0;
-    while (GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (GetNextGlyph(&pGlyph, aPos, nStart))
     {
         // get bounding rectangle of individual glyph
         if (rSalGraphics.GetGlyphBoundRect(*pGlyph, aRectangle))
@@ -903,9 +903,9 @@ sal_Int32 GenericSalLayout::GetTextBreak( DeviceCoordinate nMaxWidth, DeviceCoor
     return -1;
 }
 
-int GenericSalLayout::GetNextGlyphs(int nLen, const GlyphItem** pGlyphs,
+bool GenericSalLayout::GetNextGlyph(const GlyphItem** pGlyph,
                                     Point& rPos, int& nStart,
-                                    const PhysicalFontFace** /*pFallbackFonts*/) const
+                                    const PhysicalFontFace** /*pFallbackFont*/) const
 {
     std::vector<GlyphItem>::const_iterator pGlyphIter = m_GlyphItems.begin();
     std::vector<GlyphItem>::const_iterator pGlyphIterEnd = m_GlyphItems.end();
@@ -921,53 +921,23 @@ int GenericSalLayout::GetNextGlyphs(int nLen, const GlyphItem** pGlyphs,
 
     // return zero if no more glyph found
     if( nStart >= static_cast<int>(m_GlyphItems.size()) )
-        return 0;
+        return false;
 
     if( pGlyphIter == pGlyphIterEnd )
-        return 0;
+        return false;
+
+    // update return data with glyph info
+    *pGlyph = &(*pGlyphIter);
+    ++nStart;
 
     // calculate absolute position in pixel units
     Point aRelativePos = pGlyphIter->maLinearPos;
 
-    // find more glyphs which can be merged into one drawing instruction
-    int nCount = 0;
-    long nYPos = pGlyphIter->maLinearPos.Y();
-    for(;;)
-    {
-        // update return data with glyph info
-        ++nCount;
-        *(pGlyphs++) = &(*pGlyphIter);
-
-        // break at end of glyph list
-        if( ++nStart >= static_cast<int>(m_GlyphItems.size()) )
-            break;
-        // break when enough glyphs
-        if( nCount >= nLen )
-            break;
-
-        long nGlyphAdvance = pGlyphIter[1].maLinearPos.X() - pGlyphIter->maLinearPos.X();
-        // stop when next x-position is unexpected
-        if( pGlyphIter->mnOrigWidth != nGlyphAdvance )
-            break;
-
-        // advance to next glyph
-        ++pGlyphIter;
-
-        // stop when next y-position is unexpected
-        if( nYPos != pGlyphIter->maLinearPos.Y() )
-            break;
-
-        // stop when no longer in string
-        int n = pGlyphIter->mnCharPos;
-        if( (n < mnMinCharPos) || (mnEndCharPos <= n) )
-            break;
-    }
-
     aRelativePos.setX( aRelativePos.X() / ( mnUnitsPerPixel) );
     aRelativePos.setY( aRelativePos.Y() / ( mnUnitsPerPixel) );
     rPos = GetDrawPosition( aRelativePos );
 
-    return nCount;
+    return true;
 }
 
 void GenericSalLayout::MoveGlyph( int nStart, long nNewXPos )
@@ -1157,7 +1127,7 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
     int nStartOld[ MAX_FALLBACK ];
     int nStartNew[ MAX_FALLBACK ];
     const GlyphItem* pGlyphs[MAX_FALLBACK];
-    int nValid[ MAX_FALLBACK ] = {0};
+    bool bValid[MAX_FALLBACK] = { false };
 
     Point aPos;
     int nLevel = 0, n;
@@ -1182,9 +1152,9 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
 
         // prepare merging components
         nStartNew[ nLevel ] = nStartOld[ nLevel ] = 0;
-        nValid[nLevel] = mpLayouts[n]->GetNextGlyphs(1, &pGlyphs[nLevel], aPos, nStartNew[nLevel]);
+        bValid[nLevel] = mpLayouts[n]->GetNextGlyph(&pGlyphs[nLevel], aPos, nStartNew[nLevel]);
 
-        if( (n > 0) && !nValid[ nLevel ] )
+        if( (n > 0) && !bValid[ nLevel ] )
         {
             // an empty fallback layout can be released
             mpLayouts[n].reset();
@@ -1212,7 +1182,7 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
     int nFirstValid = -1;
     for( n = 0; n < nLevel; ++n )
     {
-        if(nValid[n] > 0)
+        if(bValid[n])
         {
             nFirstValid = n;
             break;
@@ -1228,11 +1198,11 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
         rArgs.mnEndCharPos : rArgs.mnMinCharPos - 1;
     int nRunVisibleEndChar = pGlyphs[nFirstValid]->mnCharPos;
     // merge the fallback levels
-    while( nValid[nFirstValid] && (nLevel > 0))
+    while( bValid[nFirstValid] && (nLevel > 0))
     {
         // find best fallback level
         for( n = 0; n < nLevel; ++n )
-            if( nValid[n] && !maFallbackRuns[n].PosIsInAnyRun( nActiveCharPos ) )
+            if( bValid[n] && !maFallbackRuns[n].PosIsInAnyRun( nActiveCharPos ) )
                 // fallback level n wins when it requested no further fallback
                 break;
         int nFBLevel = n;
@@ -1261,9 +1231,9 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
             {
                 mpLayouts[0]->DropGlyph( nStartOld[0] );
                 nStartOld[0] = nStartNew[0];
-                nValid[nFirstValid] = mpLayouts[0]->GetNextGlyphs(1, &pGlyphs[nFirstValid], aPos, nStartNew[0]);
+                bValid[nFirstValid] = mpLayouts[0]->GetNextGlyph(&pGlyphs[nFirstValid], aPos, nStartNew[0]);
 
-                if( !nValid[nFirstValid] )
+                if( !bValid[nFirstValid] )
                    break;
             }
         }
@@ -1278,9 +1248,9 @@ void MultiSalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
             // proceed to next glyph
             nStartOld[n] = nStartNew[n];
             int nOrigCharPos = pGlyphs[n]->mnCharPos;
-            nValid[n] = mpLayouts[n]->GetNextGlyphs(1, &pGlyphs[n], aPos, nStartNew[n]);
+            bValid[n] = mpLayouts[n]->GetNextGlyph(&pGlyphs[n], aPos, nStartNew[n]);
             // break after last glyph of active layout
-            if( !nValid[n] )
+            if( !bValid[n] )
             {
                 // performance optimization (when a fallback layout is no longer needed)
                 if( n >= nLevel-1 )
@@ -1543,14 +1513,10 @@ void MultiSalLayout::GetCaretPositions( int nMaxIndex, long* pCaretXArray ) cons
     }
 }
 
-int MultiSalLayout::GetNextGlyphs(int nLen, const GlyphItem** pGlyphs,
+bool MultiSalLayout::GetNextGlyph(const GlyphItem** pGlyph,
                                   Point& rPos, int& nStart,
-                                  const PhysicalFontFace** pFallbackFonts) const
+                                  const PhysicalFontFace** pFallbackFont) const
 {
-    // for multi-level fallback only single glyphs should be used
-    if( mnLevel > 1 && nLen > 1 )
-        nLen = 1;
-
     // NOTE: nStart is tagged with current font index
     int nLevel = static_cast<unsigned>(nStart) >> GF_FONTSHIFT;
     nStart &= ~GF_FONTMASK;
@@ -1558,29 +1524,23 @@ int MultiSalLayout::GetNextGlyphs(int nLen, const GlyphItem** pGlyphs,
     {
         SalLayout& rLayout = *mpLayouts[ nLevel ];
         rLayout.InitFont();
-        int nRetVal = rLayout.GetNextGlyphs(nLen, pGlyphs, rPos, nStart);
-        if( nRetVal )
+        if (rLayout.GetNextGlyph(pGlyph, rPos, nStart))
         {
             int nFontTag = nLevel << GF_FONTSHIFT;
             nStart |= nFontTag;
-            for( int i = 0; i < nRetVal; ++i )
-            {
-                // FIXME: This cast is ugly!
-                const_cast<GlyphItem*>(pGlyphs[i])->mnFallbackLevel = nLevel;
-                if( pFallbackFonts )
-                {
-                    pFallbackFonts[ i ] =  mpFallbackFonts[ nLevel ];
-                }
-            }
+            // FIXME: This cast is ugly!
+            const_cast<GlyphItem*>(*pGlyph)->mnFallbackLevel = nLevel;
+            if (pFallbackFont)
+                *pFallbackFont = mpFallbackFonts[nLevel];
             rPos += maDrawBase;
             rPos += maDrawOffset;
-            return nRetVal;
+            return true;
         }
     }
 
     // #111016# reset to base level font when done
     mpLayouts[0]->InitFont();
-    return 0;
+    return false;
 }
 
 bool MultiSalLayout::GetOutline( SalGraphics& rGraphics,
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 94308054b03c..25f3feec001f 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -1258,7 +1258,7 @@ void OutputDevice::ImplDrawEmphasisMarks( SalLayout& rSalLayout )
     tools::Rectangle aRectangle;
     const GlyphItem* pGlyph;
     int nStart = 0;
-    while (rSalLayout.GetNextGlyphs(1, &pGlyph, aOutPoint, nStart))
+    while (rSalLayout.GetNextGlyph(&pGlyph, aOutPoint, nStart))
     {
         if (!mpGraphics->GetGlyphBoundRect(*pGlyph, aRectangle ) )
             continue;
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index a3547b1bb491..d794feb5ec42 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -2340,7 +2340,7 @@ SystemTextLayoutData OutputDevice::GetSysTextLayoutData(const Point& rStartPt, c
     Point aPos;
     const GlyphItem* pGlyph;
     int nStart = 0;
-    while (pLayout->GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (pLayout->GetNextGlyph(&pGlyph, aPos, nStart))
     {
         SystemGlyphData aSystemGlyph;
         aSystemGlyph.index = pGlyph->maGlyphId;
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index bff62fe6e660..22e7db6230a1 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -751,7 +751,7 @@ void OutputDevice::ImplDrawTextLines( SalLayout& rSalLayout, FontStrikeout eStri
         DeviceCoordinate nWidth = 0;
         const GlyphItem* pGlyph;
         int nStart = 0;
-        while (rSalLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
+        while (rSalLayout.GetNextGlyph(&pGlyph, aPos, nStart))
         {
             // calculate the boundaries of each word
             if (!pGlyph->IsSpacing())
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index 25317651a003..00532c8644b9 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -162,7 +162,7 @@ void CairoTextRender::DrawTextLayout(const CommonSalLayout& rLayout)
     Point aPos;
     const GlyphItem* pGlyph;
     int nStart = 0;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (rLayout.GetNextGlyph(&pGlyph, aPos, nStart))
     {
         cairo_glyph_t aGlyph;
         aGlyph.index = pGlyph->maGlyphId;
diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx
index 048904d561d4..402ac5788f08 100644
--- a/vcl/unx/generic/print/genpspgraphics.cxx
+++ b/vcl/unx/generic/print/genpspgraphics.cxx
@@ -570,7 +570,7 @@ void GenPspGraphics::DrawTextLayout(const CommonSalLayout& rLayout)
     const GlyphItem* pGlyph;
     Point aPos;
     int nStart = 0;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (rLayout.GetNextGlyph(&pGlyph, aPos, nStart))
     {
         sal_Int32 nAdvance = pGlyph->mnNewWidth / rLayout.GetUnitsPerPixel();
         m_pPrinterGfx->DrawGlyph(aPos, *pGlyph, nAdvance);
diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx b/vcl/win/gdi/DWriteTextRenderer.cxx
index 25530c00aa84..8006d3f7d0d5 100644
--- a/vcl/win/gdi/DWriteTextRenderer.cxx
+++ b/vcl/win/gdi/DWriteTextRenderer.cxx
@@ -294,7 +294,7 @@ bool D2DWriteTextOutRenderer::performRender(CommonSalLayout const & rLayout, Sal
         int nStart = 0;
         Point aPos(0, 0);
         const GlyphItem* pGlyph;
-        while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
+        while (rLayout.GetNextGlyph(&pGlyph, aPos, nStart))
         {
             UINT16 glyphIndices[] = { pGlyph->maGlyphId };
             FLOAT glyphAdvances[] = { pGlyph->mnNewWidth };
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index f7c407c78fe1..94eb47dddebb 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -274,7 +274,7 @@ bool ExTextOutRenderer::operator ()(CommonSalLayout const &rLayout,
     int nStart = 0;
     Point aPos(0, 0);
     const GlyphItem* pGlyph;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (rLayout.GetNextGlyph(&pGlyph, aPos, nStart))
     {
         WORD glyphWStr[] = { pGlyph->maGlyphId };
         if (hAltFont && pGlyph->IsVertical() == bUseAltFont)
@@ -351,7 +351,7 @@ bool WinSalGraphics::CacheGlyphs(const CommonSalLayout& rLayout)
     int nStart = 0;
     Point aPos(0, 0);
     const GlyphItem* pGlyph;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (rLayout.GetNextGlyph(&pGlyph, aPos, nStart))
     {
         if (!rFont.GetGlyphCache().IsGlyphCached(pGlyph->maGlyphId))
         {
@@ -382,7 +382,7 @@ bool WinSalGraphics::DrawCachedGlyphs(const CommonSalLayout& rLayout)
     int nStart = 0;
     Point aPos(0, 0);
     const GlyphItem* pGlyph;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
+    while (rLayout.GetNextGlyph(&pGlyph, aPos, nStart))
     {
         OpenGLGlyphDrawElement& rElement(rFont.GetGlyphCache().GetDrawElement(pGlyph->maGlyphId));
         OpenGLTexture& rTexture = rElement.maTexture;


More information about the Libreoffice-commits mailing list