Bug 1732629 - [gfx/2d] Get non-localized variation axis names from CoreGraphics in ScaledFontMac, so that we set up the CGFont correctly with variation values. r=jrmuizel

Differential Revision: https://phabricator.services.mozilla.com/D129576
This commit is contained in:
Jonathan Kew 2021-10-27 14:15:12 +00:00
Родитель 6bd50dc8fd
Коммит e29954ec04
3 изменённых файлов: 40 добавлений и 21 удалений

Просмотреть файл

@ -94,7 +94,6 @@ static CTFontRef CreateCTFontFromCGFontWithVariations(CGFontRef aCGFont,
// CreateCTFontFromCGFontWithVariations in ScaledFontMac.cpp
// CreateCTFontFromCGFontWithVariations in cairo-quartz-font.c
// ctfont_create_exact_copy in SkFontHost_mac.cpp
CTFontRef ctFont;
if (nsCocoaFeatures::OnSierraExactly() ||
(aInstalledFont && nsCocoaFeatures::OnHighSierraOrLater())) {
@ -476,18 +475,28 @@ ScaledFontMac::InstanceData::InstanceData(
}
static CFDictionaryRef CreateVariationDictionaryOrNull(
CGFontRef aCGFont, CFArrayRef& aAxesCache, uint32_t aVariationCount,
const FontVariation* aVariations) {
if (!aAxesCache) {
CGFontRef aCGFont, CFArrayRef& aCGAxesCache, CFArrayRef& aCTAxesCache,
uint32_t aVariationCount, const FontVariation* aVariations) {
if (!aCGAxesCache) {
aCGAxesCache = CGFontCopyVariationAxes(aCGFont);
if (!aCGAxesCache) {
return nullptr;
}
}
if (!aCTAxesCache) {
AutoRelease<CTFontRef> ctFont(
CTFontCreateWithGraphicsFont(aCGFont, 0, nullptr, nullptr));
aAxesCache = CTFontCopyVariationAxes(ctFont);
if (!aAxesCache) {
aCTAxesCache = CTFontCopyVariationAxes(ctFont);
if (!aCTAxesCache) {
return nullptr;
}
}
CFIndex axisCount = CFArrayGetCount(aAxesCache);
CFIndex axisCount = CFArrayGetCount(aCTAxesCache);
if (CFArrayGetCount(aCGAxesCache) != axisCount) {
return nullptr;
}
AutoRelease<CFMutableDictionaryRef> dict(CFDictionaryCreateMutable(
kCFAllocatorDefault, axisCount, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));
@ -499,7 +508,7 @@ static CFDictionaryRef CreateVariationDictionaryOrNull(
for (CFIndex i = 0; i < axisCount; ++i) {
// We sanity-check the axis info found in the CTFont, and bail out
// (returning null) if it doesn't have the expected types.
CFTypeRef axisInfo = CFArrayGetValueAtIndex(aAxesCache, i);
CFTypeRef axisInfo = CFArrayGetValueAtIndex(aCTAxesCache, i);
if (CFDictionaryGetTypeID() != CFGetTypeID(axisInfo)) {
return nullptr;
}
@ -516,8 +525,12 @@ static CFDictionaryRef CreateVariationDictionaryOrNull(
return nullptr;
}
CFTypeRef axisName =
CFDictionaryGetValue(axis, kCTFontVariationAxisNameKey);
axisInfo = CFArrayGetValueAtIndex(aCGAxesCache, i);
if (CFDictionaryGetTypeID() != CFGetTypeID(axisInfo)) {
return nullptr;
}
CFTypeRef axisName = CFDictionaryGetValue(
static_cast<CFDictionaryRef>(axisInfo), kCGFontVariationAxisName);
if (!axisName || CFGetTypeID(axisName) != CFStringGetTypeID()) {
return nullptr;
}
@ -656,15 +669,15 @@ static CFDictionaryRef CreateVariationTagDictionaryOrNull(
/* static */
CGFontRef UnscaledFontMac::CreateCGFontWithVariations(
CGFontRef aFont, CFArrayRef& aAxesCache, uint32_t aVariationCount,
const FontVariation* aVariations) {
CGFontRef aFont, CFArrayRef& aCGAxesCache, CFArrayRef& aCTAxesCache,
uint32_t aVariationCount, const FontVariation* aVariations) {
if (!aVariationCount) {
return nullptr;
}
MOZ_ASSERT(aVariations);
AutoRelease<CFDictionaryRef> varDict(CreateVariationDictionaryOrNull(
aFont, aAxesCache, aVariationCount, aVariations));
aFont, aCGAxesCache, aCTAxesCache, aVariationCount, aVariations));
if (!varDict) {
return nullptr;
}
@ -684,7 +697,6 @@ already_AddRefed<ScaledFont> UnscaledFontMac::CreateScaledFont(
}
const ScaledFontMac::InstanceData& instanceData =
*reinterpret_cast<const ScaledFontMac::InstanceData*>(aInstanceData);
RefPtr<ScaledFontMac> scaledFont;
if (mFontDesc) {
AutoRelease<CTFontRef> font(
@ -710,7 +722,7 @@ already_AddRefed<ScaledFont> UnscaledFontMac::CreateScaledFont(
CGFontRef fontRef = mFont;
if (aNumVariations > 0) {
CGFontRef varFont = CreateCGFontWithVariations(
mFont, mAxesCache, aNumVariations, aVariations);
mFont, mCGAxesCache, mCTAxesCache, aNumVariations, aVariations);
if (varFont) {
fontRef = varFont;
}

Просмотреть файл

@ -34,8 +34,11 @@ class UnscaledFontMac final : public UnscaledFont {
}
virtual ~UnscaledFontMac() {
if (mAxesCache) {
CFRelease(mAxesCache);
if (mCTAxesCache) {
CFRelease(mCTAxesCache);
}
if (mCGAxesCache) {
CFRelease(mCGAxesCache);
}
if (mFontDesc) {
CFRelease(mFontDesc);
@ -64,13 +67,15 @@ class UnscaledFontMac final : public UnscaledFont {
const FontVariation* aVariations, uint32_t aNumVariations) override;
static CGFontRef CreateCGFontWithVariations(CGFontRef aFont,
CFArrayRef& aAxesCache,
CFArrayRef& aCGAxesCache,
CFArrayRef& aCTAxesCache,
uint32_t aVariationCount,
const FontVariation* aVariations);
bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
CFArrayRef& AxesCache() { return mAxesCache; }
CFArrayRef& CGAxesCache() { return mCGAxesCache; }
CFArrayRef& CTAxesCache() { return mCTAxesCache; }
static already_AddRefed<UnscaledFont> CreateFromFontDescriptor(
const uint8_t* aData, uint32_t aDataLength, uint32_t aIndex);
@ -78,7 +83,8 @@ class UnscaledFontMac final : public UnscaledFont {
private:
CTFontDescriptorRef mFontDesc = nullptr;
CGFontRef mFont = nullptr;
CFArrayRef mAxesCache = nullptr; // Cached array of variation axis details
CFArrayRef mCGAxesCache = nullptr; // Cached arrays of variation axis details
CFArrayRef mCTAxesCache = nullptr;
bool mIsDataFont;
};

Просмотреть файл

@ -104,7 +104,8 @@ gfxMacFont::gfxMacFont(const RefPtr<UnscaledFontMac>& aUnscaledFont,
}
mCGFont = UnscaledFontMac::CreateCGFontWithVariations(
baseFont, aUnscaledFont->AxesCache(), vars.Length(), vars.Elements());
baseFont, aUnscaledFont->CGAxesCache(), aUnscaledFont->CTAxesCache(),
vars.Length(), vars.Elements());
if (!mCGFont) {
::CFRetain(baseFont);
mCGFont = baseFont;