summaryrefslogtreecommitdiffstats
path: root/vcl
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2013-06-15 14:24:21 +0200
committerCaolán McNamara <caolanm@redhat.com>2013-07-01 12:23:04 +0000
commit92ffe57f6bf40ec0f19e2abed24721137c569063 (patch)
tree9038228d1e944cf5170b05f642b240224b80aa6b /vcl
parentTranslate German comments. (diff)
downloadcore-92ffe57f6bf40ec0f19e2abed24721137c569063.tar.gz
core-92ffe57f6bf40ec0f19e2abed24721137c569063.zip
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 Reviewed-on: https://gerrit.libreoffice.org/4293 Reviewed-by: Bosdonnat Cedric <cedric.bosdonnat@free.fr> Tested-by: Bosdonnat Cedric <cedric.bosdonnat@free.fr> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/gdi/outdev3.cxx72
1 files changed, 4 insertions, 68 deletions
diff --git a/vcl/source/gdi/outdev3.cxx b/vcl/source/gdi/outdev3.cxx
index 38f1f2543cf0..999f703ebf7c 100644
--- a/vcl/source/gdi/outdev3.cxx
+++ b/vcl/source/gdi/outdev3.cxx
@@ -5877,9 +5877,9 @@ SalLayout* OutputDevice::ImplLayout( const OUString& rOrigStr, sal_Int32 nMinInd
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 );
@@ -5896,68 +5896,8 @@ SalLayout* OutputDevice::getFallbackFontThatFits(ImplFontEntry &rFallbackFont,
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;
}
@@ -5980,10 +5920,6 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay
FontSelectPattern aFontSelData = mpFontEntry->maFontSelData;
- ImplFontMetricData aOrigMetric( aFontSelData );
- // TODO: use cached metric in fontentry
- mpGraphics->GetFontMetric( &aOrigMetric );
-
// when device specific font substitution may have been performed for
// the originally selected font then make sure that a fallback to that
// font is performed first
@@ -6018,8 +5954,8 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay
}
// 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 )