9#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
25static void add_opsz_attr(CFMutableDictionaryRef attr,
double opsz) {
26 SkUniqueCFRef<CFNumberRef> opszValueNumber(
27 CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &opsz));
29 CFStringRef SkCTFontOpticalSizeAttribute = CFSTR(
"NSCTFontOpticalSizeAttribute");
30 CFDictionarySetValue(attr, SkCTFontOpticalSizeAttribute, opszValueNumber.get());
34static void add_notrak_attr(CFMutableDictionaryRef attr) {
36 SkUniqueCFRef<CFNumberRef> unscaledTrackingNumber(
37 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &zero));
38 CFStringRef SkCTFontUnscaledTrackingAttribute = CFSTR(
"NSCTFontUnscaledTrackingAttribute");
39 CFDictionarySetValue(attr, SkCTFontUnscaledTrackingAttribute, unscaledTrackingNumber.get());
42SkUniqueCFRef<CTFontRef> SkCTFontCreateExactCopy(CTFontRef baseFont, CGFloat textSize,
43 OpszVariation opszVariation)
45 SkUniqueCFRef<CFMutableDictionaryRef> attr(
46 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
47 &kCFTypeDictionaryKeyCallBacks,
48 &kCFTypeDictionaryValueCallBacks));
50 if (opszVariation.isSet) {
51 add_opsz_attr(attr.get(), opszVariation.value);
62 CFStringRef SkCTFontOpticalSizeAttribute = CFSTR(
"NSCTFontOpticalSizeAttribute");
63 SkUniqueCFRef<CFTypeRef> opsz(CTFontCopyAttribute(baseFont, SkCTFontOpticalSizeAttribute));
66 CFGetTypeID(opsz.get()) != CFNumberGetTypeID() ||
67 !CFNumberGetValue(
static_cast<CFNumberRef
>(opsz.get()),kCFNumberDoubleType,&opsz_val) ||
70 opsz_val = CTFontGetSize(baseFont);
72 add_opsz_attr(attr.get(), opsz_val);
74 add_notrak_attr(attr.get());
76 SkUniqueCFRef<CTFontDescriptorRef>
desc(CTFontDescriptorCreateWithAttributes(attr.get()));
78 return SkUniqueCFRef<CTFontRef>(
79 CTFontCreateCopyWithAttributes(baseFont, textSize,
nullptr,
desc.get()));