[PATCH] Don’t shrink text from fallback fonts

Khaled Hosny (via Code Review) gerrit at gerrit.libreoffice.org
Sat Jun 15 05:36:19 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/4293

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/93/4293/1

Don’t shrink text from fallback fonts

This code is bogus in multiple ways:
* It scales text based on ascent or descent, but this makes no sense
  as those control line height and nothing else, if one is to scale two
  different fonts to “fit” together, cap or x height would be more
  appropriate. This results in some text being ridiculously shrunk.
* Not only that, but it is comparing apples to oranges; original font
  ascent/descent with the bounding box of the fallback glyphs, which
  results in different scale ratios depending on the shape of the glyphs
  at hand, which leads to all sorts of funny and irregular text.
* Even worse, the PDF export is completely broken in this case; it uses
  the scaled down glyph widths but the unscaled font size, resulting in
  cramped unreadable text.

Change-Id: Iaa6117ecfdad8388887d9a03b538e7327544ad5e
---
M include/vcl/outdev.hxx
M vcl/source/gdi/outdev3.cxx
2 files changed, 6 insertions(+), 66 deletions(-)



diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 306c9d4..93276bb 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -540,9 +540,9 @@
     // 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 SalLayout* getFallbackFontThatFits(ImplFontEntry &rFallbackFont,
+    SAL_DLLPRIVATE SalLayout* getFallbackFont(ImplFontEntry &rFallbackFont,
         FontSelectPattern &rFontSelData, int nFallbackLevel,
-        ImplLayoutArgs& rLayoutArgs, const ImplFontMetricData& rOrigMetric) const;
+        ImplLayoutArgs& rLayoutArgs) const;
 protected:
                         OutputDevice();
 
diff --git a/vcl/source/gdi/outdev3.cxx b/vcl/source/gdi/outdev3.cxx
index ec55ff1..b041869 100644
--- a/vcl/source/gdi/outdev3.cxx
+++ b/vcl/source/gdi/outdev3.cxx
@@ -5895,9 +5895,9 @@
     return pSalLayout;
 }
 
-SalLayout* OutputDevice::getFallbackFontThatFits(ImplFontEntry &rFallbackFont,
+SalLayout* OutputDevice::getFallbackFont(ImplFontEntry &rFallbackFont,
     FontSelectPattern &rFontSelData, int nFallbackLevel,
-    ImplLayoutArgs& rLayoutArgs, const ImplFontMetricData& rOrigMetric) const
+    ImplLayoutArgs& rLayoutArgs) const
 {
     rFallbackFont.mnSetFontFlags = mpGraphics->SetFont( &rFontSelData, nFallbackLevel );
 
@@ -5914,68 +5914,8 @@
         return NULL;
     }
 
-    Rectangle aBoundRect;
-    bool bHaveBounding = false;
-    Rectangle aRectangle;
-
     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
-    Point aPos;
-    for( int nStart = 0;;)
-    {
-        sal_GlyphId nLGlyph;
-        if( !pFallback->GetNextGlyphs( 1, &nLGlyph, aPos, nStart ) )
-            break;
-
-        sal_GlyphId nFontTag = nFallbackLevel << GF_FONTSHIFT;
-        nLGlyph |= nFontTag;
-
-        // get bounding rectangle of individual glyph
-        if( mpGraphics->GetGlyphBoundRect( nLGlyph, aRectangle ) )
-        {
-            // merge rectangle
-            aRectangle += aPos;
-            aBoundRect.Union( aRectangle );
-            bHaveBounding = true;
-        }
-    }
-
-    // Shrink it down if it won't fit
-    if (bHaveBounding)
-    {
-        long  nGlyphsAscent = -aBoundRect.Top();
-        float fScaleTop = nGlyphsAscent > rOrigMetric.mnAscent ?
-            rOrigMetric.mnAscent/(float)nGlyphsAscent : 1;
-        long  nGlyphsDescent = aBoundRect.Bottom();
-        float fScaleBottom = nGlyphsDescent > rOrigMetric.mnDescent ?
-            rOrigMetric.mnDescent/(float)nGlyphsDescent : 1;
-        float fScale = fScaleBottom < fScaleTop ? fScaleBottom : fScaleTop;
-        if (fScale < 1)
-        {
-            long nOrigHeight = rFontSelData.mnHeight;
-            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;
 }
 
@@ -6036,8 +5976,8 @@
         }
 
         // create and add glyph fallback layout to multilayout
-        SalLayout* pFallback = getFallbackFontThatFits(*pFallbackFont, aFontSelData,
-            nFallbackLevel, rLayoutArgs, aOrigMetric);
+        SalLayout* pFallback = getFallbackFont(*pFallbackFont, aFontSelData,
+            nFallbackLevel, rLayoutArgs);
         if (pFallback)
         {
             if( !pMultiSalLayout )

-- 
To view, visit https://gerrit.libreoffice.org/4293
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa6117ecfdad8388887d9a03b538e7327544ad5e
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Khaled Hosny <khaledhosny at eglug.org>



More information about the LibreOffice mailing list