summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKhaled Hosny <khaledhosny@eglug.org>2017-10-03 19:59:58 +0200
committerCaolán McNamara <caolanm@redhat.com>2017-10-04 16:59:40 +0200
commit538ea38afafb3d69cf5f492f783ca97caefce384 (patch)
tree96d475e1f932e2596706c3de2f3dd0e640268239
parent23f9a6c6c311725ec1b42a1ff4442023a0355ec0 (diff)
tdf#107605: Fix line height cslculation for broken fonts
Change-Id: I06368dd15d7898dda61bc07b0f96bf82b00733b9 Reviewed-on: https://gerrit.libreoffice.org/43095 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Khaled Hosny <khaledhosny@eglug.org> (cherry picked from commit 9bc39be417a4c436cbe18391fc87e5e835551b07) Reviewed-on: https://gerrit.libreoffice.org/43108 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--vcl/source/font/fontmetric.cxx14
1 files changed, 9 insertions, 5 deletions
diff --git a/vcl/source/font/fontmetric.cxx b/vcl/source/font/fontmetric.cxx
index 7371c1dc7c74..35a9f97d4128 100644
--- a/vcl/source/font/fontmetric.cxx
+++ b/vcl/source/font/fontmetric.cxx
@@ -419,15 +419,18 @@ void ImplFontMetricData::ImplCalcLineSpacing(const std::vector<uint8_t>& rHheaDa
GetTTFontMterics(rHheaData, rOS2Data, &rInfo);
// Try hhea table first.
- if (rInfo.ascender || rInfo.descender)
+ // tdf#107605: Some fonts have weird values here, so check that ascender is
+ // +ve and descender is -ve as they normally should.
+ if (rInfo.ascender >= 0 && rInfo.descender <= 0)
{
- fAscent = rInfo.ascender * fScale;
+ fAscent = rInfo.ascender * fScale;
fDescent = -rInfo.descender * fScale;
- fExtLeading = rInfo.linegap * fScale;
+ fExtLeading = rInfo.linegap * fScale;
}
// But if OS/2 is present, prefer it.
- if (rInfo.winAscent || rInfo.winDescent || rInfo.typoAscender || rInfo.typoDescender)
+ if (rInfo.winAscent || rInfo.winDescent ||
+ rInfo.typoAscender || rInfo.typoDescender)
{
if (fAscent == 0 && fDescent == 0)
{
@@ -437,7 +440,8 @@ void ImplFontMetricData::ImplCalcLineSpacing(const std::vector<uint8_t>& rHheaDa
}
const uint16_t kUseTypoMetricsMask = 1 << 7;
- if (rInfo.fsSelection & kUseTypoMetricsMask)
+ if (rInfo.fsSelection & kUseTypoMetricsMask &&
+ rInfo.typoAscender >= 0 && rInfo.typoDescender <= 0)
{
fAscent = rInfo.typoAscender * fScale;
fDescent = -rInfo.typoDescender * fScale;