diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2020-09-07 23:59:13 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2020-09-11 19:42:09 +0200 |
commit | e9b9044f7b7b44b45dd582885cad0b0a7d44f88b (patch) | |
tree | 418fe0bb1bf0c4caa56cd03eb52cbd31f7704003 /vcl | |
parent | 4f09fb9f64951340d140badb00b336dd99c68f2b (diff) |
tdf#125234 Qt5 set glpyh font bounding box
Not sure if this is strictly needed, and obviously it will be
"wrong" for a sub font containing just some of the glyphs, but
since other backends also do this, follow suit.
Change-Id: Ib83542b685b38d800d09b7a19780f9ac619c7ad0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102487
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/sft.hxx | 16 | ||||
-rw-r--r-- | vcl/qt5/Qt5Graphics_Text.cxx | 7 | ||||
-rw-r--r-- | vcl/source/fontsubset/sft.cxx | 26 |
3 files changed, 39 insertions, 10 deletions
diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx index 2aef3a67d2e5..89853335db54 100644 --- a/vcl/inc/sft.hxx +++ b/vcl/inc/sft.hxx @@ -675,6 +675,22 @@ class TrueTypeFont; VCL_DLLPUBLIC void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info); /** + * Returns part of the head table info, normally collected by GetTTGlobalFontInfo. + * + * Just implemented separate, because this info not available via Qt API. + * + * @param ttf pointer to a AbstractTrueTypeFont structure + * @param xMin global glyph bounding box min X + * @param yMin global glyph bounding box min Y + * @param xMax global glyph bounding box max X + * @param yMax global glyph bounding box max Y + * @param macStyle encoded Mac style flags of the font + * @return true, if table data could be decoded + * @ingroup sft + */ + VCL_DLLPUBLIC bool GetTTGlobalFontHeadInfo(AbstractTrueTypeFont *ttf, int& xMin, int& yMin, int& xMax, int& yMax, sal_uInt16& macStyle); + +/** * Returns fonts metrics. * @see TTGlobalFontInfo * diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx index a42d35ae6391..c533ad1d599a 100644 --- a/vcl/qt5/Qt5Graphics_Text.cxx +++ b/vcl/qt5/Qt5Graphics_Text.cxx @@ -238,6 +238,12 @@ bool Qt5Graphics::CreateFontSubset(const OUString& rToFile, const PhysicalFontFa rInfo.m_nAscent = aRawFont.ascent(); rInfo.m_nDescent = aRawFont.descent(); + Qt5TrueTypeFont aTTF(aRawFont); + int nXmin, nYmin, nXmax, nYmax; + sal_uInt16 nMacStyleFlags; + if (GetTTGlobalFontHeadInfo(&aTTF, nXmin, nYmin, nXmax, nYmax, nMacStyleFlags)) + rInfo.m_aFontBBox = tools::Rectangle(Point(nXmin, nYmin), Point(nXmax, nYmax)); + sal_uInt16 aShortIDs[nGlyphCount + 1]; sal_uInt8 aTempEncs[nGlyphCount + 1]; @@ -278,7 +284,6 @@ bool Qt5Graphics::CreateFontSubset(const OUString& rToFile, const PhysicalFontFa pGlyphWidths[i] = pGlyphMetrics[i]; // write subset into destination file - Qt5TrueTypeFont aTTF(aRawFont); vcl::SFErrCodes nRC = vcl::CreateTTFromTTGlyphs(&aTTF, aToFile.getStr(), aShortIDs, aTempEncs, nGlyphCount); return (nRC == vcl::SFErrCodes::Ok); diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index 30a6e37d1745..6eabe8480608 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -2364,6 +2364,22 @@ void GetTTFontMetrics(const uint8_t *pHhea, size_t nHhea, } } +bool GetTTGlobalFontHeadInfo(AbstractTrueTypeFont *ttf, int& xMin, int& yMin, int& xMax, int& yMax, sal_uInt16& macStyle) +{ + sal_uInt32 table_size; + const sal_uInt8* table = ttf->table(O_head, table_size); + if (table_size < 46) + return false; + + const int UPEm = ttf->unitsPerEm(); + xMin = XUnits(UPEm, GetInt16(table, HEAD_xMin_offset)); + yMin = XUnits(UPEm, GetInt16(table, HEAD_yMin_offset)); + xMax = XUnits(UPEm, GetInt16(table, HEAD_xMax_offset)); + yMax = XUnits(UPEm, GetInt16(table, HEAD_yMax_offset)); + macStyle = GetUInt16(table, HEAD_macStyle_offset); + return true; +} + void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info) { int UPEm = ttf->unitsPerEm(); @@ -2406,15 +2422,7 @@ void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info) info->italicAngle = GetInt32(table, POST_italicAngle_offset); } - table = ttf->table(O_head, table_size); /* 'head' tables is always there */ - if (table_size >= 46) - { - info->xMin = XUnits(UPEm, GetInt16(table, HEAD_xMin_offset)); - info->yMin = XUnits(UPEm, GetInt16(table, HEAD_yMin_offset)); - info->xMax = XUnits(UPEm, GetInt16(table, HEAD_xMax_offset)); - info->yMax = XUnits(UPEm, GetInt16(table, HEAD_yMax_offset)); - info->macStyle = GetUInt16(table, HEAD_macStyle_offset); - } + GetTTGlobalFontHeadInfo(ttf, info->xMin, info->yMin, info->xMax, info->yMax, info->macStyle); table = ttf->table(O_hhea, table_size); if (table_size >= 10) |