diff options
author | Khaled Hosny <khaled@aliftype.com> | 2022-09-02 01:47:23 +0200 |
---|---|---|
committer | خالد حسني <khaled@aliftype.com> | 2022-09-02 10:09:35 +0200 |
commit | 30a8f7e97d41d60098dbd14118d4f56c5557c06d (patch) | |
tree | dbc74a47ed0bf8f78f66ef78fae2b73912c24690 | |
parent | d8326fc81f7225047178e1b8a7605d32109fa08c (diff) |
vcl: set hb_font_t variations from CTFont
Without this we will be using the interpolated outlines (done by core
text) but apply OpenType features from the default instance.
Change-Id: I7a39b5483ba0f35b440841ffa07f587ad966bbf6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139248
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@aliftype.com>
-rw-r--r-- | vcl/inc/quartz/salgdi.h | 2 | ||||
-rw-r--r-- | vcl/quartz/ctfonts.cxx | 46 | ||||
-rw-r--r-- | vcl/unx/generic/glyphs/freetype_glyphcache.cxx | 4 |
3 files changed, 49 insertions, 3 deletions
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h index 569a14a6d3fc..29739adf33eb 100644 --- a/vcl/inc/quartz/salgdi.h +++ b/vcl/inc/quartz/salgdi.h @@ -107,6 +107,8 @@ private: hb_font_t* ImplInitHbFont() override; bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const override; + void SetFontVariationsOnHBFont(hb_font_t*) const; + /// CoreText text style object CFMutableDictionaryRef mpStyleDict; }; diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx index 7985905cc404..e5db219c3f8d 100644 --- a/vcl/quartz/ctfonts.cxx +++ b/vcl/quartz/ctfonts.cxx @@ -251,11 +251,55 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU return pBlob; } +void CoreTextStyle::SetFontVariationsOnHBFont(hb_font_t* pHbFont) const +{ + + CTFontRef aCTFontRef = static_cast<CTFontRef>(CFDictionaryGetValue( mpStyleDict, kCTFontAttributeName )); + + CFArrayRef pAxes = CTFontCopyVariationAxes(aCTFontRef); + if (!pAxes) + return; + + CFDictionaryRef pVariations = CTFontCopyVariation(aCTFontRef); + std::vector<hb_variation_t> aHBVariations; + if (pVariations) + { + CFIndex nAxes = CFArrayGetCount(pAxes); + for (CFIndex i = 0; i < nAxes; ++i) + { + auto pAxis = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(pAxes, i)); + if (pAxis) + { + hb_tag_t nTag; + auto pTag = static_cast<CFNumberRef>(CFDictionaryGetValue(pAxis, kCTFontVariationAxisIdentifierKey)); + if (!pTag) + continue; + CFNumberGetValue(pTag, kCFNumberIntType, &nTag); + + float fValue; + auto pValue = static_cast<CFNumberRef>(CFDictionaryGetValue(pVariations, pTag)); + if (!pValue) + continue; + CFNumberGetValue(pValue, kCFNumberFloatType, &fValue); + + aHBVariations.push_back({ nTag, fValue }); + } + } + CFRelease(pVariations); + } + CFRelease(pAxes); + + if (!aHBVariations.empty()) + hb_font_set_variations(pHbFont, aHBVariations.data(), aHBVariations.size()); +} + hb_font_t* CoreTextStyle::ImplInitHbFont() { hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, GetFontFace(), nullptr); + hb_font_t* pHBFont = InitHbFont(pHbFace); + SetFontVariationsOnHBFont(pHBFont); - return InitHbFont(pHbFace); + return pHBFont; } rtl::Reference<LogicalFontInstance> CoreTextFontFace::CreateFontInstance(const vcl::font::FontSelectPattern& rFSD) const diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx index a995a0fe1f2b..693d7a646436 100644 --- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx +++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx @@ -212,7 +212,7 @@ FT_FaceRec_* FreetypeFontInfo::GetFaceFT() return maFaceFT; } -void FreetypeFont::SetFontVariationsOnHBFont(hb_font_t* pHbFace) const +void FreetypeFont::SetFontVariationsOnHBFont(hb_font_t* pHbFont) const { sal_uInt32 nFaceVariation = mxFontInfo->GetFontFaceVariation(); if (!(maFaceFT && nFaceVariation)) @@ -231,7 +231,7 @@ void FreetypeFont::SetFontVariationsOnHBFont(hb_font_t* pHbFace) const aVariations[i].tag = pFtMMVar->axis[i].tag; aVariations[i].value = instance->coords[i] / 65536.0; } - hb_font_set_variations(pHbFace, aVariations.data(), aVariations.size()); + hb_font_set_variations(pHbFont, aVariations.data(), aVariations.size()); } dlFT_Done_MM_Var(aLibFT, pFtMMVar); } |