[Libreoffice-commits] .: Branch 'libreoffice-3-6' - vcl/inc vcl/source

Andras Timar timar at kemper.freedesktop.org
Sat Jul 14 09:56:39 PDT 2012


 vcl/inc/vcl/outdev.hxx     |    2 -
 vcl/source/gdi/outdev3.cxx |   73 ++++++++++++++++++++++++++++-----------------
 2 files changed, 47 insertions(+), 28 deletions(-)

New commits:
commit c5df4ffdab3a66508b6e259703b77979a2733401
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Jul 12 12:10:49 2012 +0100

    Related: fdo#45355 stale gdi font handles apparently still used
    
    When we do glyph fallback we check to see if the glyph is too large to fit the
    space available, and if it is we try and rescale it smaller.
    
    This worked wonderfully under Linux, but under Windows it seems that the
    SalLayout impl keeps an old unscaled gdi font handle which would give visually
    broken glyphs for me when the base font was smaller than the replacement font.
    
    So, now instead rather than just changing the font for the fallback level, we
    throw away the SalLayout using the old font, set the font for the fallback
    level, and recreate a new SalLayout using the new font.
    
    Hopefully this is the true reason behind the crashes of fdo#45355 although
    that remains unreproducible for me.
    
    Change-Id: I415b6e7a77777d4aa5e62079c52c6c18473c0ebd
    Signed-off-by: Andras Timar <atimar at suse.com>

diff --git a/vcl/inc/vcl/outdev.hxx b/vcl/inc/vcl/outdev.hxx
index dd10eda..295799b 100644
--- a/vcl/inc/vcl/outdev.hxx
+++ b/vcl/inc/vcl/outdev.hxx
@@ -561,7 +561,7 @@ public:
     // Helper for line geometry paint with support for graphic expansion (pattern and fat_to_area)
     void impPaintLineGeometryWithEvtlExpand(const LineInfo& rInfo, basegfx::B2DPolyPolygon aLinePolyPolygon);
 
-    SAL_DLLPRIVATE void forceFallbackFontToFit(SalLayout &rFallback, ImplFontEntry &rFallbackFont,
+    SAL_DLLPRIVATE SalLayout* getFallbackFontThatFits(ImplFontEntry &rFallbackFont,
         FontSelectPattern &rFontSelData, int nFallbackLevel,
         ImplLayoutArgs& rLayoutArgs, const ImplFontMetricData& rOrigMetric) const;
 protected:
diff --git a/vcl/source/gdi/outdev3.cxx b/vcl/source/gdi/outdev3.cxx
index 261f14a..1b4d993 100644
--- a/vcl/source/gdi/outdev3.cxx
+++ b/vcl/source/gdi/outdev3.cxx
@@ -6223,15 +6223,30 @@ SalLayout* OutputDevice::ImplLayout( const String& rOrigStr,
     return pSalLayout;
 }
 
-void OutputDevice::forceFallbackFontToFit(SalLayout &rFallback, ImplFontEntry &rFallbackFont,
+SalLayout* OutputDevice::getFallbackFontThatFits(ImplFontEntry &rFallbackFont,
     FontSelectPattern &rFontSelData, int nFallbackLevel,
     ImplLayoutArgs& rLayoutArgs, const ImplFontMetricData& rOrigMetric) const
 {
+    rFallbackFont.mnSetFontFlags = mpGraphics->SetFont( &rFontSelData, nFallbackLevel );
+
+    rLayoutArgs.ResetPos();
+    SalLayout* pFallback = mpGraphics->GetTextLayout( rLayoutArgs, nFallbackLevel );
+
+    if (!pFallback)
+        return NULL;
+
+    if (!pFallback->LayoutText(rLayoutArgs))
+    {
+        // there is no need for a font that couldn't resolve anything
+        pFallback->Release();
+        return NULL;
+    }
+
     Rectangle aBoundRect;
     bool bHaveBounding = false;
     Rectangle aRectangle;
 
-    rFallback.AdjustLayout( rLayoutArgs );
+    pFallback->AdjustLayout( rLayoutArgs );
 
     //All we care about here is getting the vertical bounds of this text and
     //make sure it will fit inside the available space
@@ -6239,7 +6254,7 @@ void OutputDevice::forceFallbackFontToFit(SalLayout &rFallback, ImplFontEntry &r
     for( int nStart = 0;;)
     {
         sal_GlyphId nLGlyph;
-        if( !rFallback.GetNextGlyphs( 1, &nLGlyph, aPos, nStart ) )
+        if( !pFallback->GetNextGlyphs( 1, &nLGlyph, aPos, nStart ) )
             break;
 
         sal_GlyphId nFontTag = nFallbackLevel << GF_FONTSHIFT;
@@ -6268,11 +6283,28 @@ void OutputDevice::forceFallbackFontToFit(SalLayout &rFallback, ImplFontEntry &r
         if (fScale < 1)
         {
             long nOrigHeight = rFontSelData.mnHeight;
-            rFontSelData.mnHeight = static_cast<int>(static_cast<float>(rFontSelData.mnHeight) * fScale);
+            long nNewHeight = static_cast<int>(static_cast<float>(rFontSelData.mnHeight) * fScale);
+
+            if (nNewHeight == nOrigHeight)
+                --nNewHeight;
+
+            pFallback->Release();
+
+            rFontSelData.mnHeight = nNewHeight;
             rFallbackFont.mnSetFontFlags = mpGraphics->SetFont( &rFontSelData, nFallbackLevel );
             rFontSelData.mnHeight = nOrigHeight;
+
+            rLayoutArgs.ResetPos();
+            pFallback = mpGraphics->GetTextLayout( rLayoutArgs, nFallbackLevel );
+            if (pFallback && !pFallback->LayoutText(rLayoutArgs))
+            {
+                pFallback->Release();
+                pFallback = NULL;
+            }
+            SAL_WARN_IF(pFallback, "vcl.gdi", "we couldn't layout text with a smaller point size that worked with a bigger one");
         }
     }
+    return pFallback;
 }
 
 // -----------------------------------------------------------------------
@@ -6333,30 +6365,17 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay
             }
         }
 
-        pFallbackFont->mnSetFontFlags = mpGraphics->SetFont( &aFontSelData, nFallbackLevel );
-
         // create and add glyph fallback layout to multilayout
-        rLayoutArgs.ResetPos();
-        SalLayout* pFallback = mpGraphics->GetTextLayout( rLayoutArgs, nFallbackLevel );
-        if( pFallback )
-        {
-            if( pFallback->LayoutText( rLayoutArgs ) )
-            {
-                forceFallbackFontToFit(*pFallback, *pFallbackFont, aFontSelData,
-                    nFallbackLevel, rLayoutArgs, aOrigMetric);
-
-                if( !pMultiSalLayout )
-                    pMultiSalLayout = new MultiSalLayout( *pSalLayout );
-                pMultiSalLayout->AddFallback( *pFallback,
-                    rLayoutArgs.maRuns, aFontSelData.mpFontData );
-                if (nFallbackLevel == MAX_FALLBACK-1)
-                    pMultiSalLayout->SetInComplete();
-            }
-            else
-            {
-                // there is no need for a font that couldn't resolve anything
-                pFallback->Release();
-            }
+        SalLayout* pFallback = getFallbackFontThatFits(*pFallbackFont, aFontSelData,
+            nFallbackLevel, rLayoutArgs, aOrigMetric);
+        if (pFallback)
+        {
+            if( !pMultiSalLayout )
+                pMultiSalLayout = new MultiSalLayout( *pSalLayout );
+            pMultiSalLayout->AddFallback( *pFallback,
+                rLayoutArgs.maRuns, aFontSelData.mpFontData );
+            if (nFallbackLevel == MAX_FALLBACK-1)
+                pMultiSalLayout->SetInComplete();
         }
 
         mpFontCache->Release( pFallbackFont );


More information about the Libreoffice-commits mailing list