diff options
-rw-r--r-- | vcl/inc/impfontmetricdata.hxx | 5 | ||||
-rw-r--r-- | vcl/inc/sft.hxx | 4 | ||||
-rw-r--r-- | vcl/qt5/Qt5Graphics_Text.cxx | 8 | ||||
-rw-r--r-- | vcl/quartz/ctfonts.cxx | 18 | ||||
-rw-r--r-- | vcl/source/font/fontmetric.cxx | 22 | ||||
-rw-r--r-- | vcl/source/fontsubset/sft.cxx | 30 | ||||
-rw-r--r-- | vcl/unx/generic/glyphs/freetype_glyphcache.cxx | 10 | ||||
-rw-r--r-- | vcl/win/gdi/salfont.cxx | 10 |
8 files changed, 40 insertions, 67 deletions
diff --git a/vcl/inc/impfontmetricdata.hxx b/vcl/inc/impfontmetricdata.hxx index 73beb59722db..6250c9155436 100644 --- a/vcl/inc/impfontmetricdata.hxx +++ b/vcl/inc/impfontmetricdata.hxx @@ -32,6 +32,7 @@ typedef tools::SvRef<ImplFontMetricData> ImplFontMetricDataRef; class OutputDevice; class FontSelectPattern; +class LogicalFontInstance; class VCL_DLLPUBLIC ImplFontMetricData : public FontAttributes, public SvRefBase { @@ -92,9 +93,7 @@ public: void ImplInitTextLineSize( const OutputDevice* pDev ); void ImplInitAboveTextLineSize(); void ImplInitFlags( const OutputDevice* pDev ); - void ImplCalcLineSpacing(const std::vector<uint8_t>& rHhea, - const std::vector<uint8_t>& rOS_2, - int nUPEM); + void ImplCalcLineSpacing(LogicalFontInstance *pFontInstance); private: bool ShouldUseWinMetrics(const vcl::TTGlobalFontInfo& rInfo); diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx index fbf570b27adb..aa81dcd151cb 100644 --- a/vcl/inc/sft.hxx +++ b/vcl/inc/sft.hxx @@ -419,8 +419,8 @@ namespace vcl * @ingroup sft * */ - void GetTTFontMetrics(const std::vector<uint8_t>& hhea, - const std::vector<uint8_t>& os2, + void GetTTFontMetrics(const uint8_t *pHhea, size_t nHhea, + const uint8_t *pOs2, size_t nOs2, TTGlobalFontInfo *info); /** diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx index 38723f3dd623..85b51b82b1eb 100644 --- a/vcl/qt5/Qt5Graphics_Text.cxx +++ b/vcl/qt5/Qt5Graphics_Text.cxx @@ -59,13 +59,7 @@ void Qt5Graphics::GetFontMetric(ImplFontMetricDataRef& rFMD, int nFallbackLevel) QRawFont aRawFont(QRawFont::fromFont(*m_pTextStyle[nFallbackLevel])); Qt5FontFace::fillAttributesFromQFont(*m_pTextStyle[nFallbackLevel], *rFMD); - QByteArray aHheaTable = aRawFont.fontTable("hhea"); - std::vector<uint8_t> rHhea(aHheaTable.data(), aHheaTable.data() + aHheaTable.size()); - - QByteArray aOs2Table = aRawFont.fontTable("OS/2"); - std::vector<uint8_t> rOS2(aOs2Table.data(), aOs2Table.data() + aOs2Table.size()); - - rFMD->ImplCalcLineSpacing(rHhea, rOS2, aRawFont.unitsPerEm()); + rFMD->ImplCalcLineSpacing(m_pTextStyle[nFallbackLevel].get()); rFMD->SetSlant(0); rFMD->SetWidth(aRawFont.averageCharWidth()); diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx index 06a25965653f..252720a0aa4e 100644 --- a/vcl/quartz/ctfonts.cxx +++ b/vcl/quartz/ctfonts.cxx @@ -110,24 +110,8 @@ void CoreTextStyle::GetFontMetric( ImplFontMetricDataRef const & rxFontMetric ) // get the matching CoreText font handle // TODO: is it worth it to cache the CTFontRef in SetFont() and reuse it here? CTFontRef aCTFontRef = static_cast<CTFontRef>(CFDictionaryGetValue( mpStyleDict, kCTFontAttributeName )); - const CoreTextFontFace* mpFontData = static_cast<const CoreTextFontFace*>(GetFontFace()); - int nBufSize = 0; - - nBufSize = mpFontData->GetFontTable("hhea", nullptr); - uint8_t* pHheaBuf = new uint8_t[nBufSize]; - nBufSize = mpFontData->GetFontTable("hhea", pHheaBuf); - std::vector<uint8_t> rHhea(pHheaBuf, pHheaBuf + nBufSize); - - nBufSize = mpFontData->GetFontTable("OS/2", nullptr); - uint8_t* pOS2Buf = new uint8_t[nBufSize]; - nBufSize = mpFontData->GetFontTable("OS/2", pOS2Buf); - std::vector<uint8_t> rOS2(pOS2Buf, pOS2Buf + nBufSize); - - rxFontMetric->ImplCalcLineSpacing(rHhea, rOS2, CTFontGetUnitsPerEm(aCTFontRef)); - - delete[] pHheaBuf; - delete[] pOS2Buf; + rxFontMetric->ImplCalcLineSpacing(this); // since ImplFontMetricData::mnWidth is only used for stretching/squeezing fonts // setting this width to the pixel height of the fontsize is good enough diff --git a/vcl/source/font/fontmetric.cxx b/vcl/source/font/fontmetric.cxx index 47f91569e995..72a5a77cc6fe 100644 --- a/vcl/source/font/fontmetric.cxx +++ b/vcl/source/font/fontmetric.cxx @@ -24,6 +24,7 @@ #include <vcl/outdev.hxx> #include <sal/log.hxx> +#include <fontinstance.hxx> #include <fontselect.hxx> #include <impfontmetricdata.hxx> #include <sft.hxx> @@ -319,17 +320,28 @@ bool ImplFontMetricData::ShouldUseWinMetrics(const vcl::TTGlobalFontInfo& rInfo) * - Use Win metrics if available. * - Unless USE_TYPO_METRICS flag is set, in which case use Typo metrics. */ -void ImplFontMetricData::ImplCalcLineSpacing(const std::vector<uint8_t>& rHheaData, - const std::vector<uint8_t>& rOS2Data, int nUPEM) +void ImplFontMetricData::ImplCalcLineSpacing(LogicalFontInstance *pFontInstance) { mnAscent = mnDescent = mnExtLeading = mnIntLeading = 0; - double fScale = static_cast<double>(mnHeight) / nUPEM; - double fAscent = 0, fDescent = 0, fExtLeading = 0; + hb_font_t* pHbFont = pFontInstance->GetHbFont(); + hb_face_t* pHbFace = hb_font_get_face(pHbFont); + + hb_blob_t* pHhea = hb_face_reference_table(pHbFace, HB_TAG('h', 'h', 'e', 'a')); + hb_blob_t* pOS2 = hb_face_reference_table(pHbFace, HB_TAG('O', 'S', '/', '2')); vcl::TTGlobalFontInfo rInfo; memset(&rInfo, 0, sizeof(vcl::TTGlobalFontInfo)); - GetTTFontMetrics(rHheaData, rOS2Data, &rInfo); + GetTTFontMetrics(reinterpret_cast<const uint8_t*>(hb_blob_get_data(pHhea, nullptr)), hb_blob_get_length(pHhea), + reinterpret_cast<const uint8_t*>(hb_blob_get_data(pOS2, nullptr)), hb_blob_get_length(pOS2), + &rInfo); + + hb_blob_destroy(pHhea); + hb_blob_destroy(pOS2); + + double nUPEM = hb_face_get_upem(pHbFace); + double fScale = mnHeight / nUPEM; + double fAscent = 0, fDescent = 0, fExtLeading = 0; // Try hhea table first. // tdf#107605: Some fonts have weird values here, so check that ascender is diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index a7f2161309cc..47e4f7a8d7f4 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -2354,8 +2354,8 @@ std::unique_ptr<sal_uInt16[]> GetTTSimpleGlyphMetrics(TrueTypeFont const *ttf, c } // TODO, clean up table parsing and re-use it elsewhere in this file. -void GetTTFontMetrics(const std::vector<uint8_t>& hhea, - const std::vector<uint8_t>& os2, +void GetTTFontMetrics(const uint8_t *pHhea, size_t nHhea, + const uint8_t *pOs2, size_t nOs2, TTGlobalFontInfo *info) { /* There are 3 different versions of OS/2 table: original (68 bytes long), @@ -2365,20 +2365,20 @@ void GetTTFontMetrics(const std::vector<uint8_t>& hhea, * FIXME: horribly outdated comment and horrible code that uses hard-coded * offsets to read the table. */ - if (os2.size() >= 76 + 2) + if (nOs2 >= 76 + 2) { - info->fsSelection = GetUInt16(os2.data(), 62); - info->typoAscender = GetInt16(os2.data(), 68); - info->typoDescender = GetInt16(os2.data(), 70); - info->typoLineGap = GetInt16(os2.data(), 72); - info->winAscent = GetUInt16(os2.data(), 74); - info->winDescent = GetUInt16(os2.data(), 76); - } - - if (hhea.size() >= 8 + 2) { - info->ascender = GetInt16(hhea.data(), 4); - info->descender = GetInt16(hhea.data(), 6); - info->linegap = GetInt16(hhea.data(), 8); + info->fsSelection = GetUInt16(pOs2, 62); + info->typoAscender = GetInt16(pOs2, 68); + info->typoDescender = GetInt16(pOs2, 70); + info->typoLineGap = GetInt16(pOs2, 72); + info->winAscent = GetUInt16(pOs2, 74); + info->winDescent = GetUInt16(pOs2, 76); + } + + if (nHhea >= 8 + 2) { + info->ascender = GetInt16(pHhea, 4); + info->descender = GetInt16(pHhea, 6); + info->linegap = GetInt16(pHhea, 8); } } diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx index 86b7213e7ad7..5ed232cf4ebd 100644 --- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx +++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx @@ -532,15 +532,7 @@ void FreetypeFont::GetFontMetric(ImplFontMetricDataRef const & rxTo) const FT_Activate_Size( maSizeFT ); - sal_uLong nHhea = 0; - const uint8_t* pHheaBuf = mpFontInfo->GetTable("hhea", &nHhea); - const std::vector<uint8_t> rHhea(pHheaBuf, pHheaBuf + nHhea); - - sal_uLong nOS2 = 0; - const uint8_t* pOS2Buf = mpFontInfo->GetTable("OS/2", &nOS2); - const std::vector<uint8_t> rOS2(pOS2Buf, pOS2Buf + nOS2); - - rxTo->ImplCalcLineSpacing(rHhea, rOS2, maFaceFT->units_per_EM); + rxTo->ImplCalcLineSpacing(mpFontInstance.get()); rxTo->SetSlant( 0 ); rxTo->SetWidth( mnWidth ); diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index 8a83a29d567b..343e3f8b6208 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -950,12 +950,8 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int nFa if( GetTextFaceW( getHDC(), SAL_N_ELEMENTS(aFaceName), aFaceName ) ) rxFontMetric->SetFamilyName(o3tl::toU(aFaceName)); - const DWORD nHheaTag = CalcTag("hhea"); - const DWORD nOS2Tag = CalcTag("OS/2"); - const RawFontData aHheaRawData(getHDC(), nHheaTag); - const RawFontData aOS2RawData(getHDC(), nOS2Tag); - rxFontMetric->SetMinKashida(pFontInstance->GetKashidaWidth()); + rxFontMetric->ImplCalcLineSpacing(pFontInstance.get()); // get the font metric OUTLINETEXTMETRICW aOutlineMetric; @@ -977,10 +973,6 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int nFa // transformation dependent font metrics rxFontMetric->SetWidth(static_cast<int>(pFontInstance->GetScale() * aWinMetric.tmAveCharWidth)); - - const std::vector<uint8_t> rHhea(aHheaRawData.get(), aHheaRawData.get() + aHheaRawData.size()); - const std::vector<uint8_t> rOS2(aOS2RawData.get(), aOS2RawData.get() + aOS2RawData.size()); - rxFontMetric->ImplCalcLineSpacing(rHhea, rOS2, aOutlineMetric.otmEMSquare); } FontCharMapRef WinSalGraphics::GetFontCharMap() const |