From fc11fd4d0bb458824bc0a78768171af23f038fd0 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Fri, 7 Aug 2020 15:31:28 -0400 Subject: [PATCH] Allow CoreText axis hidden value to be CFNumber. Parts of CoreText use 'structured' CFDictionaries to pass information. Because of the lack of explicit structure and very dynamic types, this requires that every entry be checked for existence and type before use. If the existence or type does not match expectations the code generally returns a failure or default value. In this case kCTFontVariationAxisHiddenKey is documented to be a CFBooleanRef, but on macOS 11 Big Sur Beta 4 it can be a CFNumberRef instead. Handle this case when it happens. Bug: chromium:1113444 Change-Id: Id1ae31104e674d65eaa67166d2442ab4f63989cd Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308764 Commit-Queue: Ben Wagner Reviewed-by: Mike Klein --- src/ports/SkTypeface_mac_ct.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ports/SkTypeface_mac_ct.cpp b/src/ports/SkTypeface_mac_ct.cpp index 143dbe85a6..8be4142424 100644 --- a/src/ports/SkTypeface_mac_ct.cpp +++ b/src/ports/SkTypeface_mac_ct.cpp @@ -1298,11 +1298,17 @@ int SkTypeface_Mac::onGetVariationDesignParameters(SkFontParameters::Variation:: if (kCTFontVariationAxisHiddenKeyPtr) { CFTypeRef hidden = CFDictionaryGetValue(axisInfoDict,*kCTFontVariationAxisHiddenKeyPtr); if (hidden) { + // At least macOS 11 Big Sur Beta 4 uses CFNumberRef instead of CFBooleanRef. + // https://crbug.com/1113444 CFBooleanRef hiddenBoolean; - if (!SkCFDynamicCast(hidden, &hiddenBoolean, "Variation hidden")) { + int hiddenInt; + if (SkCFDynamicCast(hidden, &hiddenBoolean, nullptr)) { + skAxis.setHidden(CFBooleanGetValue(hiddenBoolean)); + } else if (SkCFNumberDynamicCast(hidden, &hiddenInt, nullptr, "Axis hidden")) { + skAxis.setHidden(hiddenInt); + } else { return -1; } - skAxis.setHidden(CFBooleanGetValue(hiddenBoolean)); } } }