diff options
author | Khaled Hosny <khaled@aliftype.com> | 2022-10-29 11:57:33 +0200 |
---|---|---|
committer | خالد حسني <khaled@aliftype.com> | 2022-10-29 13:50:28 +0200 |
commit | 8ca507a619313ead970ad03a71416dcebea91405 (patch) | |
tree | 44885500293d0e8ec9fc0b791a1dffce2cb33bb6 | |
parent | 37d6dbd1b8f90604d58a782f7af0af1d5c8c1f89 (diff) |
vcl: simplify how CoreTextFont stores CTFontRef
We create CFMutableDictionaryRef, store two items in it and only even
access one of them. Simplify the whole thing and skip the middleman.
Change-Id: Iefc6b2c2664b0ea92e231195390ce8cd0d8d9778
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142011
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@aliftype.com>
-rw-r--r-- | vcl/inc/quartz/salgdi.h | 5 | ||||
-rw-r--r-- | vcl/quartz/ctfonts.cxx | 39 | ||||
-rw-r--r-- | vcl/quartz/salgdi.cxx | 9 | ||||
-rw-r--r-- | vcl/skia/osx/gdiimpl.cxx | 4 |
4 files changed, 17 insertions, 40 deletions
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h index 8e54fa65aa53..a0e00c6c2af2 100644 --- a/vcl/inc/quartz/salgdi.h +++ b/vcl/inc/quartz/salgdi.h @@ -88,7 +88,7 @@ public: void GetFontMetric( ImplFontMetricDataRef const & ); bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override; - CFMutableDictionaryRef GetStyleDict( void ) const { return mpStyleDict; } + CTFontRef GetCTFont() const { return mpCTFont; } /// <1.0: font is squeezed, >1.0 font is stretched, else 1.0 float mfFontStretch; @@ -105,8 +105,7 @@ private: void SetFontVariationsOnHBFont(hb_font_t*) const; - /// CoreText text style object - CFMutableDictionaryRef mpStyleDict; + CTFontRef mpCTFont; }; // TODO: move into cross-platform headers diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx index 25a7efe46e2a..81ab7a6ad2dc 100644 --- a/vcl/quartz/ctfonts.cxx +++ b/vcl/quartz/ctfonts.cxx @@ -46,7 +46,7 @@ CoreTextFont::CoreTextFont(const CoreTextFontFace& rPFF, const vcl::font::FontSe , mfFontStretch( 1.0 ) , mfFontRotation( 0.0 ) , mbFauxBold(false) - , mpStyleDict( nullptr ) + , mpCTFont(nullptr) { double fScaledFontHeight = rFSP.mfExactHeight; @@ -63,15 +63,6 @@ CoreTextFont::CoreTextFont(const CoreTextFontFace& rPFF, const vcl::font::FontSe aMatrix = CGAffineTransformConcat(aMatrix, CGAffineTransformMakeScale(mfFontStretch, 1.0F)); } - // create the style object for CoreText font attributes - static const CFIndex nMaxDictSize = 16; // TODO: does this really suffice? - mpStyleDict = CFDictionaryCreateMutable( nullptr, nMaxDictSize, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks ); - - CFBooleanRef pCFVertBool = rFSP.mbVertical ? kCFBooleanTrue : kCFBooleanFalse; - CFDictionarySetValue( mpStyleDict, kCTVerticalFormsAttributeName, pCFVertBool ); - // fake bold if ( (rFSP.GetWeight() >= WEIGHT_BOLD) && ((rPFF.GetWeight() < WEIGHT_SEMIBOLD) && @@ -89,30 +80,24 @@ CoreTextFont::CoreTextFont(const CoreTextFontFace& rPFF, const vcl::font::FontSe } CTFontDescriptorRef pFontDesc = rPFF.GetFontDescriptorRef(); - CTFontRef pNewCTFont = CTFontCreateWithFontDescriptor( pFontDesc, fScaledFontHeight, &aMatrix ); - CFDictionarySetValue( mpStyleDict, kCTFontAttributeName, pNewCTFont ); - CFRelease( pNewCTFont); + mpCTFont = CTFontCreateWithFontDescriptor( pFontDesc, fScaledFontHeight, &aMatrix ); } CoreTextFont::~CoreTextFont() { - if( mpStyleDict ) - CFRelease( mpStyleDict ); + if (mpCTFont) + CFRelease(mpCTFont); } void CoreTextFont::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 )); - rxFontMetric->ImplCalcLineSpacing(this); rxFontMetric->ImplInitBaselines(this); // since ImplFontMetricData::mnWidth is only used for stretching/squeezing fonts // setting this width to the pixel height of the fontsize is good enough // it also makes the calculation of the stretch factor simple - rxFontMetric->SetWidth( lrint( CTFontGetSize( aCTFontRef ) * mfFontStretch) ); + rxFontMetric->SetWidth( lrint( CTFontGetSize(mpCTFont) * mfFontStretch) ); rxFontMetric->SetMinKashida(GetKashidaWidth()); } @@ -120,12 +105,11 @@ void CoreTextFont::GetFontMetric( ImplFontMetricDataRef const & rxFontMetric ) bool CoreTextFont::ImplGetGlyphBoundRect(sal_GlyphId nId, tools::Rectangle& rRect, bool bVertical) const { CGGlyph nCGGlyph = nId; - CTFontRef aCTFontRef = static_cast<CTFontRef>(CFDictionaryGetValue( mpStyleDict, kCTFontAttributeName )); SAL_WNODEPRECATED_DECLARATIONS_PUSH //TODO: 10.11 kCTFontDefaultOrientation const CTFontOrientation aFontOrientation = kCTFontDefaultOrientation; // TODO: horz/vert SAL_WNODEPRECATED_DECLARATIONS_POP - CGRect aCGRect = CTFontGetBoundingRectsForGlyphs(aCTFontRef, aFontOrientation, &nCGGlyph, nullptr, 1); + CGRect aCGRect = CTFontGetBoundingRectsForGlyphs(mpCTFont, aFontOrientation, &nCGGlyph, nullptr, 1); // Apply font rotation to non-vertical glyphs. if (mfFontRotation && !bVertical) @@ -200,12 +184,11 @@ bool CoreTextFont::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& rRe rResult.clear(); CGGlyph nCGGlyph = nId; - CTFontRef pCTFont = static_cast<CTFontRef>(CFDictionaryGetValue( mpStyleDict, kCTFontAttributeName )); SAL_WNODEPRECATED_DECLARATIONS_PUSH const CTFontOrientation aFontOrientation = kCTFontDefaultOrientation; SAL_WNODEPRECATED_DECLARATIONS_POP - CGRect aCGRect = CTFontGetBoundingRectsForGlyphs(pCTFont, aFontOrientation, &nCGGlyph, nullptr, 1); + CGRect aCGRect = CTFontGetBoundingRectsForGlyphs(mpCTFont, aFontOrientation, &nCGGlyph, nullptr, 1); if (!CGRectIsNull(aCGRect) && CGRectIsEmpty(aCGRect)) { @@ -214,7 +197,7 @@ bool CoreTextFont::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& rRe return true; } - CGPathRef xPath = CTFontCreatePathForGlyph( pCTFont, nCGGlyph, nullptr ); + CGPathRef xPath = CTFontCreatePathForGlyph(mpCTFont, nCGGlyph, nullptr); if (!xPath) { return false; @@ -287,13 +270,11 @@ hb_blob_t* CoreTextFontFace::GetHbTable(hb_tag_t nTag) const void CoreTextFont::SetFontVariationsOnHBFont(hb_font_t* pHbFont) const { - CTFontRef aCTFontRef = static_cast<CTFontRef>(CFDictionaryGetValue( mpStyleDict, kCTFontAttributeName )); - - CFArrayRef pAxes = CTFontCopyVariationAxes(aCTFontRef); + CFArrayRef pAxes = CTFontCopyVariationAxes(mpCTFont); if (!pAxes) return; - CFDictionaryRef pVariations = CTFontCopyVariation(aCTFontRef); + CFDictionaryRef pVariations = CTFontCopyVariation(mpCTFont); std::vector<hb_variation_t> aHBVariations; if (pVariations) { diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx index d0d6d517d2e7..a9f879dfea90 100644 --- a/vcl/quartz/salgdi.cxx +++ b/vcl/quartz/salgdi.cxx @@ -85,11 +85,10 @@ bool CoreTextGlyphFallbackSubstititution::FindFontSubstitute(vcl::font::FontSele { bool bFound = false; CoreTextFont* pFont = static_cast<CoreTextFont*>(pLogicalFont); - CTFontRef pCTFont = static_cast<CTFontRef>(CFDictionaryGetValue(pFont->GetStyleDict(), kCTFontAttributeName)); CFStringRef pStr = CreateCFString(rMissingChars); if (pStr) { - CTFontRef pFallback = CTFontCreateForString(pCTFont, pStr, CFRangeMake(0, CFStringGetLength(pStr))); + CTFontRef pFallback = CTFontCreateForString(pFont->GetCTFont(), pStr, CFRangeMake(0, CFStringGetLength(pStr))); if (pFallback) { bFound = true; @@ -325,7 +324,7 @@ void AquaGraphicsBackend::drawTextLayout(const GenericSalLayout& rLayout, bool b return; } - CTFontRef pFont = static_cast<CTFontRef>(CFDictionaryGetValue(rFont.GetStyleDict(), kCTFontAttributeName)); + CTFontRef pCTFont = rFont.GetCTFont(); CGAffineTransform aRotMatrix = CGAffineTransformMakeRotation(-rFont.mfFontRotation); DevicePoint aPos; @@ -347,7 +346,7 @@ void AquaGraphicsBackend::drawTextLayout(const GenericSalLayout& rLayout, bool b { bUprightGlyph = true; // Adjust the position of upright (vertical) glyphs. - aGCPos.y -= CTFontGetAscent(pFont) - CTFontGetDescent(pFont); + aGCPos.y -= CTFontGetAscent(pCTFont) - CTFontGetDescent(pCTFont); } else { @@ -424,7 +423,7 @@ void AquaGraphicsBackend::drawTextLayout(const GenericSalLayout& rLayout, bool b { CGContextRotateCTM(mrShared.maContextHolder.get(), rFont.mfFontRotation); } - CTFontDrawGlyphs(pFont, &aGlyphIds[nStartIndex], &aGlyphPos[nStartIndex], nLen, mrShared.maContextHolder.get()); + CTFontDrawGlyphs(pCTFont, &aGlyphIds[nStartIndex], &aGlyphPos[nStartIndex], nLen, mrShared.maContextHolder.get()); mrShared.maContextHolder.restoreState(); aIt = aNext; diff --git a/vcl/skia/osx/gdiimpl.cxx b/vcl/skia/osx/gdiimpl.cxx index 604c297c6fdd..e87adba1a460 100644 --- a/vcl/skia/osx/gdiimpl.cxx +++ b/vcl/skia/osx/gdiimpl.cxx @@ -301,9 +301,7 @@ void AquaSkiaSalGraphicsImpl::drawTextLayout(const GenericSalLayout& rLayout, } } - CTFontRef pFont - = static_cast<CTFontRef>(CFDictionaryGetValue(rFont.GetStyleDict(), kCTFontAttributeName)); - sk_sp<SkTypeface> typeface = SkMakeTypefaceFromCTFont(pFont); + sk_sp<SkTypeface> typeface = SkMakeTypefaceFromCTFont(rFont.GetCTFont()); SkFont font(typeface); font.setSize(nHeight); // font.setScaleX(rFont.mfFontStretch); TODO |