1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2020 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/core/SkTypes.h" 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ci#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ci#include "include/core/SkData.h" 13cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 14cb93a386Sopenharmony_ci#include "include/private/SkOnce.h" 15cb93a386Sopenharmony_ci#include "src/sfnt/SkOTTable_OS_2.h" 16cb93a386Sopenharmony_ci#include "src/sfnt/SkSFNTHeader.h" 17cb93a386Sopenharmony_ci#include "src/utils/mac/SkCTFont.h" 18cb93a386Sopenharmony_ci#include "src/utils/mac/SkUniqueCFRef.h" 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ci#ifdef SK_BUILD_FOR_MAC 21cb93a386Sopenharmony_ci#import <ApplicationServices/ApplicationServices.h> 22cb93a386Sopenharmony_ci#endif 23cb93a386Sopenharmony_ci 24cb93a386Sopenharmony_ci#ifdef SK_BUILD_FOR_IOS 25cb93a386Sopenharmony_ci#include <CoreText/CoreText.h> 26cb93a386Sopenharmony_ci#include <CoreText/CTFontManager.h> 27cb93a386Sopenharmony_ci#include <CoreGraphics/CoreGraphics.h> 28cb93a386Sopenharmony_ci#include <CoreFoundation/CoreFoundation.h> 29cb93a386Sopenharmony_ci#endif 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ci#include <dlfcn.h> 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_cistatic constexpr CGBitmapInfo kBitmapInfoRGB = ((CGBitmapInfo)kCGImageAlphaNoneSkipFirst | 34cb93a386Sopenharmony_ci kCGBitmapByteOrder32Host); 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ci/** Drawn in FontForge, reduced with fonttools ttx, converted by xxd -i, 37cb93a386Sopenharmony_ci * this TrueType font contains a glyph of the spider. 38cb93a386Sopenharmony_ci * 39cb93a386Sopenharmony_ci * To re-forge the original bytes of the TrueType font file, 40cb93a386Sopenharmony_ci * remove all ',|( +0x)' from this definition, 41cb93a386Sopenharmony_ci * copy the data to the clipboard, 42cb93a386Sopenharmony_ci * run 'pbpaste | xxd -p -r - spider.ttf'. 43cb93a386Sopenharmony_ci */ 44cb93a386Sopenharmony_cistatic constexpr const uint8_t kSpiderSymbol_ttf[] = { 45cb93a386Sopenharmony_ci 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x80, 0x00, 0x03, 0x00, 0x40, 46cb93a386Sopenharmony_ci 0x47, 0x44, 0x45, 0x46, 0x00, 0x14, 0x00, 0x14, 0x00, 0x00, 0x07, 0xa8, 47cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x18, 0x4f, 0x53, 0x2f, 0x32, 0x8a, 0xf4, 0xfb, 0xdb, 48cb93a386Sopenharmony_ci 0x00, 0x00, 0x01, 0x48, 0x00, 0x00, 0x00, 0x60, 0x63, 0x6d, 0x61, 0x70, 49cb93a386Sopenharmony_ci 0xe0, 0x7f, 0x10, 0x7e, 0x00, 0x00, 0x01, 0xb8, 0x00, 0x00, 0x00, 0x54, 50cb93a386Sopenharmony_ci 0x67, 0x61, 0x73, 0x70, 0xff, 0xff, 0x00, 0x03, 0x00, 0x00, 0x07, 0xa0, 51cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x08, 0x67, 0x6c, 0x79, 0x66, 0x97, 0x0b, 0x6a, 0xf6, 52cb93a386Sopenharmony_ci 0x00, 0x00, 0x02, 0x18, 0x00, 0x00, 0x03, 0x40, 0x68, 0x65, 0x61, 0x64, 53cb93a386Sopenharmony_ci 0x0f, 0xa2, 0x24, 0x1a, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x36, 54cb93a386Sopenharmony_ci 0x68, 0x68, 0x65, 0x61, 0x0e, 0xd3, 0x07, 0x3f, 0x00, 0x00, 0x01, 0x04, 55cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x24, 0x68, 0x6d, 0x74, 0x78, 0x10, 0x03, 0x00, 0x44, 56cb93a386Sopenharmony_ci 0x00, 0x00, 0x01, 0xa8, 0x00, 0x00, 0x00, 0x0e, 0x6c, 0x6f, 0x63, 0x61, 57cb93a386Sopenharmony_ci 0x01, 0xb4, 0x00, 0x28, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x0a, 58cb93a386Sopenharmony_ci 0x6d, 0x61, 0x78, 0x70, 0x00, 0x4a, 0x01, 0x4d, 0x00, 0x00, 0x01, 0x28, 59cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0xc3, 0xe5, 0x39, 0xd4, 60cb93a386Sopenharmony_ci 0x00, 0x00, 0x05, 0x58, 0x00, 0x00, 0x02, 0x28, 0x70, 0x6f, 0x73, 0x74, 61cb93a386Sopenharmony_ci 0xff, 0x03, 0x00, 0x67, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x20, 62cb93a386Sopenharmony_ci 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0b, 0x0f, 0x08, 0x1d, 63cb93a386Sopenharmony_ci 0x5f, 0x0f, 0x3c, 0xf5, 0x00, 0x0b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 64cb93a386Sopenharmony_ci 0xd1, 0x97, 0xa8, 0x5a, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xe8, 0x32, 0x33, 65cb93a386Sopenharmony_ci 0x00, 0x03, 0xff, 0x3b, 0x08, 0x00, 0x05, 0x55, 0x00, 0x00, 0x00, 0x08, 66cb93a386Sopenharmony_ci 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 67cb93a386Sopenharmony_ci 0x05, 0x55, 0xff, 0x3b, 0x01, 0x79, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00, 68cb93a386Sopenharmony_ci 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 69cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 70cb93a386Sopenharmony_ci 0x00, 0x04, 0x01, 0x1c, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 71cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x2e, 72cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x01, 0x90, 0x00, 0x05, 73cb93a386Sopenharmony_ci 0x00, 0x00, 0x05, 0x33, 0x05, 0x99, 0x00, 0x00, 0x01, 0x1e, 0x05, 0x33, 74cb93a386Sopenharmony_ci 0x05, 0x99, 0x00, 0x00, 0x03, 0xd7, 0x00, 0x66, 0x02, 0x12, 0x00, 0x00, 75cb93a386Sopenharmony_ci 0x05, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 76cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 77cb93a386Sopenharmony_ci 0x00, 0x00, 0x73, 0x6b, 0x69, 0x61, 0x00, 0xc0, 0x00, 0x00, 0xf0, 0x21, 78cb93a386Sopenharmony_ci 0x06, 0x66, 0xfe, 0x66, 0x01, 0x79, 0x05, 0x55, 0x00, 0xc5, 0x80, 0x00, 79cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 80cb93a386Sopenharmony_ci 0x00, 0x20, 0x00, 0x01, 0x08, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 81cb93a386Sopenharmony_ci 0x08, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 82cb93a386Sopenharmony_ci 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x48, 83cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x0e, 0x00, 0x08, 0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 84cb93a386Sopenharmony_ci 0x00, 0x09, 0x00, 0x0d, 0x00, 0x1d, 0x00, 0x21, 0xf0, 0x21, 0xff, 0xff, 85cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0d, 0x00, 0x1d, 0x00, 0x21, 86cb93a386Sopenharmony_ci 0xf0, 0x21, 0xff, 0xff, 0x00, 0x01, 0xff, 0xf9, 0xff, 0xf5, 0xff, 0xe4, 87cb93a386Sopenharmony_ci 0xff, 0xe2, 0x0f, 0xe2, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 88cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 89cb93a386Sopenharmony_ci 0x00, 0x14, 0x00, 0x14, 0x01, 0xa0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x44, 90cb93a386Sopenharmony_ci 0x00, 0x00, 0x02, 0x64, 0x05, 0x55, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 91cb93a386Sopenharmony_ci 0x33, 0x11, 0x21, 0x11, 0x25, 0x21, 0x11, 0x21, 0x44, 0x02, 0x20, 0xfe, 92cb93a386Sopenharmony_ci 0x24, 0x01, 0x98, 0xfe, 0x68, 0x05, 0x55, 0xfa, 0xab, 0x44, 0x04, 0xcd, 93cb93a386Sopenharmony_ci 0x00, 0x04, 0x00, 0x03, 0xff, 0x3b, 0x08, 0x00, 0x05, 0x4c, 0x00, 0x15, 94cb93a386Sopenharmony_ci 0x00, 0x1d, 0x00, 0x25, 0x01, 0x1b, 0x00, 0x00, 0x01, 0x36, 0x37, 0x36, 95cb93a386Sopenharmony_ci 0x27, 0x26, 0x07, 0x06, 0x06, 0x23, 0x22, 0x27, 0x26, 0x27, 0x26, 0x07, 96cb93a386Sopenharmony_ci 0x06, 0x17, 0x16, 0x17, 0x16, 0x32, 0x37, 0x32, 0x35, 0x34, 0x23, 0x22, 97cb93a386Sopenharmony_ci 0x15, 0x14, 0x27, 0x32, 0x35, 0x34, 0x23, 0x22, 0x15, 0x14, 0x03, 0x32, 98cb93a386Sopenharmony_ci 0x17, 0x30, 0x17, 0x31, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x33, 99cb93a386Sopenharmony_ci 0x32, 0x33, 0x16, 0x33, 0x32, 0x17, 0x16, 0x07, 0x06, 0x23, 0x22, 0x27, 100cb93a386Sopenharmony_ci 0x26, 0x27, 0x26, 0x23, 0x22, 0x07, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 101cb93a386Sopenharmony_ci 0x1f, 0x02, 0x37, 0x36, 0x37, 0x36, 0x33, 0x32, 0x17, 0x17, 0x16, 0x33, 102cb93a386Sopenharmony_ci 0x16, 0x17, 0x16, 0x07, 0x06, 0x23, 0x22, 0x27, 0x27, 0x26, 0x23, 0x22, 103cb93a386Sopenharmony_ci 0x07, 0x06, 0x07, 0x06, 0x17, 0x16, 0x17, 0x16, 0x33, 0x32, 0x33, 0x32, 104cb93a386Sopenharmony_ci 0x37, 0x36, 0x37, 0x36, 0x17, 0x16, 0x1f, 0x02, 0x16, 0x17, 0x16, 0x15, 105cb93a386Sopenharmony_ci 0x14, 0x23, 0x22, 0x27, 0x27, 0x26, 0x27, 0x27, 0x26, 0x27, 0x26, 0x07, 106cb93a386Sopenharmony_ci 0x06, 0x07, 0x06, 0x17, 0x16, 0x17, 0x16, 0x15, 0x14, 0x07, 0x06, 0x07, 107cb93a386Sopenharmony_ci 0x06, 0x23, 0x22, 0x27, 0x26, 0x07, 0x06, 0x07, 0x06, 0x15, 0x14, 0x17, 108cb93a386Sopenharmony_ci 0x16, 0x17, 0x16, 0x15, 0x14, 0x07, 0x06, 0x23, 0x22, 0x27, 0x26, 0x27, 109cb93a386Sopenharmony_ci 0x26, 0x35, 0x34, 0x37, 0x36, 0x37, 0x36, 0x37, 0x34, 0x27, 0x26, 0x07, 110cb93a386Sopenharmony_ci 0x06, 0x07, 0x06, 0x0f, 0x02, 0x06, 0x23, 0x22, 0x27, 0x26, 0x35, 0x34, 111cb93a386Sopenharmony_ci 0x37, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x27, 0x26, 0x27, 112cb93a386Sopenharmony_ci 0x26, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x07, 0x06, 0x23, 0x22, 113cb93a386Sopenharmony_ci 0x27, 0x26, 0x35, 0x34, 0x37, 0x36, 0x37, 0x37, 0x36, 0x37, 0x37, 0x36, 114cb93a386Sopenharmony_ci 0x37, 0x36, 0x37, 0x36, 0x35, 0x34, 0x27, 0x26, 0x27, 0x26, 0x27, 0x26, 115cb93a386Sopenharmony_ci 0x23, 0x22, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x27, 0x26, 0x27, 0x26, 116cb93a386Sopenharmony_ci 0x27, 0x26, 0x35, 0x34, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x33, 0x32, 117cb93a386Sopenharmony_ci 0x17, 0x16, 0x33, 0x32, 0x37, 0x36, 0x35, 0x34, 0x37, 0x36, 0x37, 0x36, 118cb93a386Sopenharmony_ci 0x33, 0x04, 0xf5, 0x23, 0x13, 0x11, 0x14, 0x16, 0x1d, 0x1b, 0x4c, 0x1f, 119cb93a386Sopenharmony_ci 0x0e, 0x2d, 0x23, 0x14, 0x2c, 0x13, 0x18, 0x25, 0x2c, 0x10, 0x3c, 0x71, 120cb93a386Sopenharmony_ci 0x1d, 0x5c, 0x5c, 0x3f, 0xae, 0x5c, 0x5c, 0x3f, 0x6a, 0x27, 0x31, 0x5b, 121cb93a386Sopenharmony_ci 0x09, 0x27, 0x36, 0x03, 0x0a, 0x26, 0x35, 0x2e, 0x09, 0x08, 0xc6, 0x13, 122cb93a386Sopenharmony_ci 0x81, 0x17, 0x20, 0x18, 0x21, 0x1e, 0x04, 0x04, 0x15, 0x5c, 0x22, 0x26, 123cb93a386Sopenharmony_ci 0x48, 0x56, 0x3b, 0x10, 0x21, 0x01, 0x0c, 0x06, 0x06, 0x0f, 0x31, 0x44, 124cb93a386Sopenharmony_ci 0x3c, 0x52, 0x4a, 0x1d, 0x11, 0x3f, 0xb4, 0x71, 0x01, 0x26, 0x06, 0x0d, 125cb93a386Sopenharmony_ci 0x15, 0x1a, 0x2a, 0x13, 0x53, 0xaa, 0x42, 0x1d, 0x0a, 0x33, 0x20, 0x21, 126cb93a386Sopenharmony_ci 0x2b, 0x01, 0x02, 0x3e, 0x21, 0x09, 0x02, 0x02, 0x0f, 0x2d, 0x4b, 0x0a, 127cb93a386Sopenharmony_ci 0x22, 0x15, 0x20, 0x1f, 0x72, 0x8b, 0x2d, 0x2f, 0x1d, 0x1f, 0x0e, 0x25, 128cb93a386Sopenharmony_ci 0x3f, 0x4d, 0x1b, 0x63, 0x2a, 0x2c, 0x14, 0x22, 0x18, 0x1c, 0x0f, 0x08, 129cb93a386Sopenharmony_ci 0x2a, 0x08, 0x08, 0x0d, 0x3b, 0x4c, 0x52, 0x74, 0x27, 0x71, 0x2e, 0x01, 130cb93a386Sopenharmony_ci 0x0c, 0x10, 0x15, 0x0d, 0x06, 0x0d, 0x05, 0x01, 0x06, 0x2c, 0x28, 0x14, 131cb93a386Sopenharmony_ci 0x1b, 0x05, 0x04, 0x10, 0x06, 0x12, 0x08, 0x0a, 0x16, 0x27, 0x03, 0x0d, 132cb93a386Sopenharmony_ci 0x30, 0x4c, 0x4c, 0x4b, 0x1f, 0x0b, 0x22, 0x26, 0x0d, 0x15, 0x0d, 0x2d, 133cb93a386Sopenharmony_ci 0x68, 0x34, 0x14, 0x3c, 0x25, 0x12, 0x04, 0x10, 0x18, 0x0b, 0x09, 0x30, 134cb93a386Sopenharmony_ci 0x2b, 0x44, 0x66, 0x14, 0x47, 0x47, 0x59, 0x73, 0x25, 0x05, 0x03, 0x1f, 135cb93a386Sopenharmony_ci 0x01, 0x08, 0x3f, 0x48, 0x4b, 0x4b, 0x76, 0x2f, 0x49, 0x2d, 0x22, 0x24, 136cb93a386Sopenharmony_ci 0x0c, 0x15, 0x08, 0x0e, 0x33, 0x03, 0x44, 0x4c, 0x10, 0x46, 0x13, 0x1f, 137cb93a386Sopenharmony_ci 0x27, 0x1b, 0x1d, 0x13, 0x02, 0x24, 0x08, 0x02, 0x42, 0x0e, 0x4d, 0x3c, 138cb93a386Sopenharmony_ci 0x19, 0x1b, 0x40, 0x2b, 0x2b, 0x1e, 0x16, 0x11, 0x04, 0x1f, 0x11, 0x04, 139cb93a386Sopenharmony_ci 0x18, 0x11, 0x35, 0x01, 0xa3, 0x13, 0x24, 0x1f, 0x0b, 0x0c, 0x19, 0x19, 140cb93a386Sopenharmony_ci 0x18, 0x13, 0x0f, 0x0c, 0x1a, 0x18, 0x1f, 0x19, 0x1e, 0x07, 0x1a, 0xc3, 141cb93a386Sopenharmony_ci 0x54, 0x51, 0x54, 0x51, 0x04, 0x53, 0x51, 0x54, 0x50, 0x02, 0x48, 0x1a, 142cb93a386Sopenharmony_ci 0x31, 0x18, 0x55, 0x74, 0x04, 0x0e, 0x09, 0x0d, 0x06, 0x10, 0x16, 0x1b, 143cb93a386Sopenharmony_ci 0x24, 0x01, 0x04, 0x0b, 0x04, 0x10, 0x3f, 0x0a, 0x41, 0x02, 0x41, 0x20, 144cb93a386Sopenharmony_ci 0x06, 0x12, 0x16, 0x21, 0x17, 0x2a, 0x1e, 0x15, 0x40, 0x27, 0x11, 0x0e, 145cb93a386Sopenharmony_ci 0x1e, 0x11, 0x15, 0x1f, 0x43, 0x13, 0x1a, 0x10, 0x15, 0x1b, 0x04, 0x09, 146cb93a386Sopenharmony_ci 0x4d, 0x2a, 0x0f, 0x19, 0x0a, 0x0a, 0x03, 0x05, 0x15, 0x3c, 0x64, 0x21, 147cb93a386Sopenharmony_ci 0x4b, 0x2e, 0x21, 0x28, 0x13, 0x47, 0x44, 0x19, 0x3f, 0x11, 0x18, 0x0b, 148cb93a386Sopenharmony_ci 0x0a, 0x07, 0x18, 0x0d, 0x07, 0x24, 0x2c, 0x2b, 0x21, 0x32, 0x10, 0x48, 149cb93a386Sopenharmony_ci 0x2a, 0x2d, 0x1e, 0x1a, 0x01, 0x0c, 0x43, 0x59, 0x28, 0x4e, 0x1c, 0x0d, 150cb93a386Sopenharmony_ci 0x5d, 0x24, 0x14, 0x0a, 0x05, 0x1f, 0x24, 0x32, 0x46, 0x3e, 0x5f, 0x3e, 151cb93a386Sopenharmony_ci 0x44, 0x1a, 0x30, 0x15, 0x0d, 0x07, 0x18, 0x2b, 0x03, 0x0d, 0x1a, 0x28, 152cb93a386Sopenharmony_ci 0x28, 0x57, 0xb2, 0x29, 0x27, 0x40, 0x2c, 0x23, 0x16, 0x63, 0x58, 0x1a, 153cb93a386Sopenharmony_ci 0x0a, 0x18, 0x11, 0x23, 0x08, 0x1b, 0x29, 0x05, 0x04, 0x0b, 0x15, 0x0d, 154cb93a386Sopenharmony_ci 0x14, 0x0b, 0x2a, 0x29, 0x5a, 0x62, 0x01, 0x19, 0x1e, 0x05, 0x05, 0x26, 155cb93a386Sopenharmony_ci 0x42, 0x42, 0x2a, 0x2a, 0x3f, 0x0d, 0x0f, 0x09, 0x05, 0x07, 0x01, 0x0b, 156cb93a386Sopenharmony_ci 0x25, 0x3e, 0x0d, 0x17, 0x11, 0x01, 0x03, 0x0d, 0x13, 0x20, 0x19, 0x11, 157cb93a386Sopenharmony_ci 0x03, 0x02, 0x01, 0x04, 0x11, 0x04, 0x05, 0x1b, 0x3d, 0x10, 0x29, 0x20, 158cb93a386Sopenharmony_ci 0x04, 0x04, 0x0a, 0x07, 0x04, 0x1f, 0x15, 0x20, 0x3e, 0x0f, 0x2a, 0x1e, 159cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x1b, 0x01, 0x4a, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 160cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 161cb93a386Sopenharmony_ci 0x00, 0x01, 0x00, 0x0c, 0x00, 0x1b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 162cb93a386Sopenharmony_ci 0x00, 0x02, 0x00, 0x07, 0x00, 0x27, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 163cb93a386Sopenharmony_ci 0x00, 0x03, 0x00, 0x0c, 0x00, 0x1b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 164cb93a386Sopenharmony_ci 0x00, 0x04, 0x00, 0x0c, 0x00, 0x1b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 165cb93a386Sopenharmony_ci 0x00, 0x05, 0x00, 0x02, 0x00, 0x2e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 166cb93a386Sopenharmony_ci 0x00, 0x06, 0x00, 0x0c, 0x00, 0x1b, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 167cb93a386Sopenharmony_ci 0x00, 0x0d, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 168cb93a386Sopenharmony_ci 0x00, 0x0e, 0x00, 0x1a, 0x00, 0x30, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 169cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x36, 0x00, 0x4a, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 170cb93a386Sopenharmony_ci 0x00, 0x01, 0x00, 0x18, 0x00, 0x80, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 171cb93a386Sopenharmony_ci 0x00, 0x02, 0x00, 0x0e, 0x00, 0x98, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 172cb93a386Sopenharmony_ci 0x00, 0x03, 0x00, 0x18, 0x00, 0x80, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 173cb93a386Sopenharmony_ci 0x00, 0x04, 0x00, 0x18, 0x00, 0x80, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 174cb93a386Sopenharmony_ci 0x00, 0x05, 0x00, 0x04, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 175cb93a386Sopenharmony_ci 0x00, 0x06, 0x00, 0x18, 0x00, 0x80, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 176cb93a386Sopenharmony_ci 0x00, 0x0d, 0x00, 0x36, 0x00, 0x4a, 0x00, 0x03, 0x00, 0x00, 0x04, 0x09, 177cb93a386Sopenharmony_ci 0x00, 0x0e, 0x00, 0x34, 0x00, 0xaa, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 178cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x36, 0x00, 0x4a, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 179cb93a386Sopenharmony_ci 0x00, 0x01, 0x00, 0x18, 0x00, 0x80, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 180cb93a386Sopenharmony_ci 0x00, 0x02, 0x00, 0x0e, 0x00, 0x98, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 181cb93a386Sopenharmony_ci 0x00, 0x03, 0x00, 0x18, 0x00, 0x80, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 182cb93a386Sopenharmony_ci 0x00, 0x04, 0x00, 0x18, 0x00, 0x80, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 183cb93a386Sopenharmony_ci 0x00, 0x05, 0x00, 0x04, 0x00, 0xa6, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 184cb93a386Sopenharmony_ci 0x00, 0x06, 0x00, 0x18, 0x00, 0x80, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 185cb93a386Sopenharmony_ci 0x00, 0x0d, 0x00, 0x36, 0x00, 0x4a, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 186cb93a386Sopenharmony_ci 0x00, 0x0e, 0x00, 0x34, 0x00, 0xaa, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 187cb93a386Sopenharmony_ci 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x32, 0x30, 0x31, 0x35, 188cb93a386Sopenharmony_ci 0x2c, 0x20, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x53, 0x70, 0x69, 189cb93a386Sopenharmony_ci 0x64, 0x65, 0x72, 0x53, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x52, 0x65, 0x67, 190cb93a386Sopenharmony_ci 0x75, 0x6c, 0x61, 0x72, 0x56, 0x31, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 191cb93a386Sopenharmony_ci 0x2f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x73, 0x2e, 0x73, 0x69, 0x6c, 192cb93a386Sopenharmony_ci 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x4f, 0x46, 0x4c, 0x00, 0x43, 0x00, 0x6f, 193cb93a386Sopenharmony_ci 0x00, 0x70, 0x00, 0x79, 0x00, 0x72, 0x00, 0x69, 0x00, 0x67, 0x00, 0x68, 194cb93a386Sopenharmony_ci 0x00, 0x74, 0x00, 0x20, 0x00, 0x28, 0x00, 0x63, 0x00, 0x29, 0x00, 0x20, 195cb93a386Sopenharmony_ci 0x00, 0x32, 0x00, 0x30, 0x00, 0x31, 0x00, 0x35, 0x00, 0x2c, 0x00, 0x20, 196cb93a386Sopenharmony_ci 0x00, 0x47, 0x00, 0x6f, 0x00, 0x6f, 0x00, 0x67, 0x00, 0x6c, 0x00, 0x65, 197cb93a386Sopenharmony_ci 0x00, 0x2e, 0x00, 0x53, 0x00, 0x70, 0x00, 0x69, 0x00, 0x64, 0x00, 0x65, 198cb93a386Sopenharmony_ci 0x00, 0x72, 0x00, 0x53, 0x00, 0x79, 0x00, 0x6d, 0x00, 0x62, 0x00, 0x6f, 199cb93a386Sopenharmony_ci 0x00, 0x6c, 0x00, 0x52, 0x00, 0x65, 0x00, 0x67, 0x00, 0x75, 0x00, 0x6c, 200cb93a386Sopenharmony_ci 0x00, 0x61, 0x00, 0x72, 0x00, 0x56, 0x00, 0x31, 0x00, 0x68, 0x00, 0x74, 201cb93a386Sopenharmony_ci 0x00, 0x74, 0x00, 0x70, 0x00, 0x3a, 0x00, 0x2f, 0x00, 0x2f, 0x00, 0x73, 202cb93a386Sopenharmony_ci 0x00, 0x63, 0x00, 0x72, 0x00, 0x69, 0x00, 0x70, 0x00, 0x74, 0x00, 0x73, 203cb93a386Sopenharmony_ci 0x00, 0x2e, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6c, 0x00, 0x2e, 0x00, 0x6f, 204cb93a386Sopenharmony_ci 0x00, 0x72, 0x00, 0x67, 0x00, 0x2f, 0x00, 0x4f, 0x00, 0x46, 0x00, 0x4c, 205cb93a386Sopenharmony_ci 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x66, 206cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 207cb93a386Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 208cb93a386Sopenharmony_ci 0xff, 0xff, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 209cb93a386Sopenharmony_ci 0x00, 0x0c, 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 210cb93a386Sopenharmony_ci 0x00, 0x02, 0x00, 0x00 211cb93a386Sopenharmony_ci}; 212cb93a386Sopenharmony_ci 213cb93a386Sopenharmony_ci/** 214cb93a386Sopenharmony_ci * There does not appear to be a publicly accessible API for determining if lcd 215cb93a386Sopenharmony_ci * font smoothing will be applied if we request it. The main issue is that if 216cb93a386Sopenharmony_ci * smoothing is applied a gamma of 2.0 will be used, if not a gamma of 1.0. 217cb93a386Sopenharmony_ci */ 218cb93a386Sopenharmony_ciSkCTFontSmoothBehavior SkCTFontGetSmoothBehavior() { 219cb93a386Sopenharmony_ci static SkCTFontSmoothBehavior gSmoothBehavior = []{ 220cb93a386Sopenharmony_ci uint32_t noSmoothBitmap[16][16] = {}; 221cb93a386Sopenharmony_ci uint32_t smoothBitmap[16][16] = {}; 222cb93a386Sopenharmony_ci 223cb93a386Sopenharmony_ci SkUniqueCFRef<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB()); 224cb93a386Sopenharmony_ci SkUniqueCFRef<CGContextRef> noSmoothContext( 225cb93a386Sopenharmony_ci CGBitmapContextCreate(&noSmoothBitmap, 16, 16, 8, 16*4, 226cb93a386Sopenharmony_ci colorspace.get(), kBitmapInfoRGB)); 227cb93a386Sopenharmony_ci SkUniqueCFRef<CGContextRef> smoothContext( 228cb93a386Sopenharmony_ci CGBitmapContextCreate(&smoothBitmap, 16, 16, 8, 16*4, 229cb93a386Sopenharmony_ci colorspace.get(), kBitmapInfoRGB)); 230cb93a386Sopenharmony_ci 231cb93a386Sopenharmony_ci SkUniqueCFRef<CFDataRef> data(CFDataCreateWithBytesNoCopy( 232cb93a386Sopenharmony_ci kCFAllocatorDefault, kSpiderSymbol_ttf, SK_ARRAY_COUNT(kSpiderSymbol_ttf), 233cb93a386Sopenharmony_ci kCFAllocatorNull)); 234cb93a386Sopenharmony_ci SkUniqueCFRef<CTFontDescriptorRef> desc( 235cb93a386Sopenharmony_ci CTFontManagerCreateFontDescriptorFromData(data.get())); 236cb93a386Sopenharmony_ci SkUniqueCFRef<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc.get(), 16, nullptr)); 237cb93a386Sopenharmony_ci SkASSERT(ctFont); 238cb93a386Sopenharmony_ci 239cb93a386Sopenharmony_ci CGContextSetShouldSmoothFonts(noSmoothContext.get(), false); 240cb93a386Sopenharmony_ci CGContextSetShouldAntialias(noSmoothContext.get(), true); 241cb93a386Sopenharmony_ci CGContextSetTextDrawingMode(noSmoothContext.get(), kCGTextFill); 242cb93a386Sopenharmony_ci CGContextSetGrayFillColor(noSmoothContext.get(), 1, 1); 243cb93a386Sopenharmony_ci 244cb93a386Sopenharmony_ci CGContextSetShouldSmoothFonts(smoothContext.get(), true); 245cb93a386Sopenharmony_ci CGContextSetShouldAntialias(smoothContext.get(), true); 246cb93a386Sopenharmony_ci CGContextSetTextDrawingMode(smoothContext.get(), kCGTextFill); 247cb93a386Sopenharmony_ci CGContextSetGrayFillColor(smoothContext.get(), 1, 1); 248cb93a386Sopenharmony_ci 249cb93a386Sopenharmony_ci CGPoint point = CGPointMake(0, 3); 250cb93a386Sopenharmony_ci CGGlyph spiderGlyph = 3; 251cb93a386Sopenharmony_ci CTFontDrawGlyphs(ctFont.get(), &spiderGlyph, &point, 1, noSmoothContext.get()); 252cb93a386Sopenharmony_ci CTFontDrawGlyphs(ctFont.get(), &spiderGlyph, &point, 1, smoothContext.get()); 253cb93a386Sopenharmony_ci 254cb93a386Sopenharmony_ci // For debugging. 255cb93a386Sopenharmony_ci //SkUniqueCFRef<CGImageRef> image(CGBitmapContextCreateImage(noSmoothContext())); 256cb93a386Sopenharmony_ci //SkUniqueCFRef<CGImageRef> image(CGBitmapContextCreateImage(smoothContext())); 257cb93a386Sopenharmony_ci 258cb93a386Sopenharmony_ci SkCTFontSmoothBehavior smoothBehavior = SkCTFontSmoothBehavior::none; 259cb93a386Sopenharmony_ci for (int x = 0; x < 16; ++x) { 260cb93a386Sopenharmony_ci for (int y = 0; y < 16; ++y) { 261cb93a386Sopenharmony_ci uint32_t smoothPixel = smoothBitmap[x][y]; 262cb93a386Sopenharmony_ci uint32_t r = (smoothPixel >> 16) & 0xFF; 263cb93a386Sopenharmony_ci uint32_t g = (smoothPixel >> 8) & 0xFF; 264cb93a386Sopenharmony_ci uint32_t b = (smoothPixel >> 0) & 0xFF; 265cb93a386Sopenharmony_ci if (r != g || r != b) { 266cb93a386Sopenharmony_ci return SkCTFontSmoothBehavior::subpixel; 267cb93a386Sopenharmony_ci } 268cb93a386Sopenharmony_ci if (noSmoothBitmap[x][y] != smoothPixel) { 269cb93a386Sopenharmony_ci smoothBehavior = SkCTFontSmoothBehavior::some; 270cb93a386Sopenharmony_ci } 271cb93a386Sopenharmony_ci } 272cb93a386Sopenharmony_ci } 273cb93a386Sopenharmony_ci return smoothBehavior; 274cb93a386Sopenharmony_ci }(); 275cb93a386Sopenharmony_ci return gSmoothBehavior; 276cb93a386Sopenharmony_ci} 277cb93a386Sopenharmony_ci 278cb93a386Sopenharmony_ciSkCTFontWeightMapping& SkCTFontGetNSFontWeightMapping() { 279cb93a386Sopenharmony_ci // In the event something goes wrong finding the real values, use this mapping. 280cb93a386Sopenharmony_ci static constexpr CGFloat defaultNSFontWeights[] = 281cb93a386Sopenharmony_ci { -1.00, -0.80, -0.60, -0.40, 0.00, 0.23, 0.30, 0.40, 0.56, 0.62, 1.00 }; 282cb93a386Sopenharmony_ci 283cb93a386Sopenharmony_ci // Declarations in <AppKit/AppKit.h> on macOS, <UIKit/UIKit.h> on iOS 284cb93a386Sopenharmony_ci#ifdef SK_BUILD_FOR_MAC 285cb93a386Sopenharmony_ci# define SK_KIT_FONT_WEIGHT_PREFIX "NS" 286cb93a386Sopenharmony_ci#endif 287cb93a386Sopenharmony_ci#ifdef SK_BUILD_FOR_IOS 288cb93a386Sopenharmony_ci# define SK_KIT_FONT_WEIGHT_PREFIX "UI" 289cb93a386Sopenharmony_ci#endif 290cb93a386Sopenharmony_ci static constexpr const char* nsFontWeightNames[] = { 291cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightUltraLight", 292cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightThin", 293cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightLight", 294cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightRegular", 295cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightMedium", 296cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightSemibold", 297cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightBold", 298cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightHeavy", 299cb93a386Sopenharmony_ci SK_KIT_FONT_WEIGHT_PREFIX "FontWeightBlack", 300cb93a386Sopenharmony_ci }; 301cb93a386Sopenharmony_ci static_assert(SK_ARRAY_COUNT(nsFontWeightNames) == 9, ""); 302cb93a386Sopenharmony_ci 303cb93a386Sopenharmony_ci static CGFloat nsFontWeights[11]; 304cb93a386Sopenharmony_ci static const CGFloat (*selectedNSFontWeights)[11] = &defaultNSFontWeights; 305cb93a386Sopenharmony_ci static SkOnce once; 306cb93a386Sopenharmony_ci once([&] { 307cb93a386Sopenharmony_ci size_t i = 0; 308cb93a386Sopenharmony_ci nsFontWeights[i++] = -1.00; 309cb93a386Sopenharmony_ci for (const char* nsFontWeightName : nsFontWeightNames) { 310cb93a386Sopenharmony_ci void* nsFontWeightValuePtr = dlsym(RTLD_DEFAULT, nsFontWeightName); 311cb93a386Sopenharmony_ci if (nsFontWeightValuePtr) { 312cb93a386Sopenharmony_ci nsFontWeights[i++] = *(static_cast<CGFloat*>(nsFontWeightValuePtr)); 313cb93a386Sopenharmony_ci } else { 314cb93a386Sopenharmony_ci return; 315cb93a386Sopenharmony_ci } 316cb93a386Sopenharmony_ci } 317cb93a386Sopenharmony_ci nsFontWeights[i++] = 1.00; 318cb93a386Sopenharmony_ci selectedNSFontWeights = &nsFontWeights; 319cb93a386Sopenharmony_ci }); 320cb93a386Sopenharmony_ci return *selectedNSFontWeights; 321cb93a386Sopenharmony_ci} 322cb93a386Sopenharmony_ci 323cb93a386Sopenharmony_ciSkCTFontWeightMapping& SkCTFontGetDataFontWeightMapping() { 324cb93a386Sopenharmony_ci // In the event something goes wrong finding the real values, use this mapping. 325cb93a386Sopenharmony_ci // These were the values from macOS 10.13 to 10.15. 326cb93a386Sopenharmony_ci static constexpr CGFloat defaultDataFontWeights[] = 327cb93a386Sopenharmony_ci { -1.00, -0.70, -0.50, -0.23, 0.00, 0.20, 0.30, 0.40, 0.60, 0.80, 1.00 }; 328cb93a386Sopenharmony_ci 329cb93a386Sopenharmony_ci static const CGFloat (*selectedDataFontWeights)[11] = &defaultDataFontWeights; 330cb93a386Sopenharmony_ci static CGFloat dataFontWeights[11]; 331cb93a386Sopenharmony_ci static SkOnce once; 332cb93a386Sopenharmony_ci once([&] { 333cb93a386Sopenharmony_ci constexpr size_t dataSize = SK_ARRAY_COUNT(kSpiderSymbol_ttf); 334cb93a386Sopenharmony_ci sk_sp<SkData> data = SkData::MakeWithCopy(kSpiderSymbol_ttf, dataSize); 335cb93a386Sopenharmony_ci const SkSFNTHeader* sfntHeader = reinterpret_cast<const SkSFNTHeader*>(data->data()); 336cb93a386Sopenharmony_ci const SkSFNTHeader::TableDirectoryEntry* tableEntry = 337cb93a386Sopenharmony_ci SkTAfter<const SkSFNTHeader::TableDirectoryEntry>(sfntHeader); 338cb93a386Sopenharmony_ci const SkSFNTHeader::TableDirectoryEntry* os2TableEntry = nullptr; 339cb93a386Sopenharmony_ci int numTables = SkEndian_SwapBE16(sfntHeader->numTables); 340cb93a386Sopenharmony_ci for (int tableEntryIndex = 0; tableEntryIndex < numTables; ++tableEntryIndex) { 341cb93a386Sopenharmony_ci if (SkOTTableOS2::TAG == tableEntry[tableEntryIndex].tag) { 342cb93a386Sopenharmony_ci os2TableEntry = tableEntry + tableEntryIndex; 343cb93a386Sopenharmony_ci break; 344cb93a386Sopenharmony_ci } 345cb93a386Sopenharmony_ci } 346cb93a386Sopenharmony_ci if (!os2TableEntry) { 347cb93a386Sopenharmony_ci return; 348cb93a386Sopenharmony_ci } 349cb93a386Sopenharmony_ci size_t os2TableOffset = SkEndian_SwapBE32(os2TableEntry->offset); 350cb93a386Sopenharmony_ci SkOTTableOS2_V0* os2Table = SkTAddOffset<SkOTTableOS2_V0>(data->writable_data(), 351cb93a386Sopenharmony_ci os2TableOffset); 352cb93a386Sopenharmony_ci 353cb93a386Sopenharmony_ci for (int i = 0; i < 11; ++i) { 354cb93a386Sopenharmony_ci os2Table->usWeightClass.value = SkEndian_SwapBE16(i * 100); 355cb93a386Sopenharmony_ci 356cb93a386Sopenharmony_ci // On macOS 10.14 and earlier it appears that the CFDataGetBytePtr is used somehow in 357cb93a386Sopenharmony_ci // font caching. Creating a slightly modified font with data at the same address seems 358cb93a386Sopenharmony_ci // to in some ways act like a font previously created at that address. As a result, 359cb93a386Sopenharmony_ci // always make a copy of the data. 360cb93a386Sopenharmony_ci SkUniqueCFRef<CFDataRef> cfData( 361cb93a386Sopenharmony_ci CFDataCreate(kCFAllocatorDefault, (const UInt8 *)data->data(), data->size())); 362cb93a386Sopenharmony_ci if (!cfData) { 363cb93a386Sopenharmony_ci return; 364cb93a386Sopenharmony_ci } 365cb93a386Sopenharmony_ci SkUniqueCFRef<CTFontDescriptorRef> desc( 366cb93a386Sopenharmony_ci CTFontManagerCreateFontDescriptorFromData(cfData.get())); 367cb93a386Sopenharmony_ci if (!desc) { 368cb93a386Sopenharmony_ci return; 369cb93a386Sopenharmony_ci } 370cb93a386Sopenharmony_ci 371cb93a386Sopenharmony_ci // On macOS 10.14 and earlier, the CTFontDescriptorRef returned from 372cb93a386Sopenharmony_ci // CTFontManagerCreateFontDescriptorFromData is incomplete and does not have the 373cb93a386Sopenharmony_ci // correct traits. It is necessary to create the CTFont and then get the descriptor 374cb93a386Sopenharmony_ci // off of it. 375cb93a386Sopenharmony_ci SkUniqueCFRef<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc.get(), 9, nullptr)); 376cb93a386Sopenharmony_ci if (!ctFont) { 377cb93a386Sopenharmony_ci return; 378cb93a386Sopenharmony_ci } 379cb93a386Sopenharmony_ci SkUniqueCFRef<CTFontDescriptorRef> desc2(CTFontCopyFontDescriptor(ctFont.get())); 380cb93a386Sopenharmony_ci if (!desc2) { 381cb93a386Sopenharmony_ci return; 382cb93a386Sopenharmony_ci } 383cb93a386Sopenharmony_ci 384cb93a386Sopenharmony_ci SkUniqueCFRef<CFTypeRef> traitsRef( 385cb93a386Sopenharmony_ci CTFontDescriptorCopyAttribute(desc2.get(), kCTFontTraitsAttribute)); 386cb93a386Sopenharmony_ci if (!traitsRef || CFGetTypeID(traitsRef.get()) != CFDictionaryGetTypeID()) { 387cb93a386Sopenharmony_ci return; 388cb93a386Sopenharmony_ci } 389cb93a386Sopenharmony_ci CFDictionaryRef fontTraitsDict = static_cast<CFDictionaryRef>(traitsRef.get()); 390cb93a386Sopenharmony_ci 391cb93a386Sopenharmony_ci CFTypeRef weightRef; 392cb93a386Sopenharmony_ci if (!CFDictionaryGetValueIfPresent(fontTraitsDict, kCTFontWeightTrait, &weightRef) || 393cb93a386Sopenharmony_ci !weightRef || 394cb93a386Sopenharmony_ci CFGetTypeID(weightRef) != CFNumberGetTypeID()) 395cb93a386Sopenharmony_ci { 396cb93a386Sopenharmony_ci return; 397cb93a386Sopenharmony_ci } 398cb93a386Sopenharmony_ci CGFloat weight; 399cb93a386Sopenharmony_ci CFNumberRef weightNumber = static_cast<CFNumberRef>(weightRef); 400cb93a386Sopenharmony_ci if (!CFNumberIsFloatType(weightNumber) || 401cb93a386Sopenharmony_ci !CFNumberGetValue(weightNumber, kCFNumberCGFloatType, &weight)) 402cb93a386Sopenharmony_ci { 403cb93a386Sopenharmony_ci return; 404cb93a386Sopenharmony_ci } 405cb93a386Sopenharmony_ci 406cb93a386Sopenharmony_ci dataFontWeights[i] = weight; 407cb93a386Sopenharmony_ci } 408cb93a386Sopenharmony_ci selectedDataFontWeights = &dataFontWeights; 409cb93a386Sopenharmony_ci }); 410cb93a386Sopenharmony_ci return *selectedDataFontWeights; 411cb93a386Sopenharmony_ci} 412cb93a386Sopenharmony_ci 413cb93a386Sopenharmony_ci#endif 414