OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fx_fpf.h" | 7 #include "fx_fpf.h" |
8 #if _FX_OS_ == _FX_ANDROID_ | 8 #if _FX_OS_ == _FX_ANDROID_ |
9 #define FPF_SKIAMATCHWEIGHT_NAME1» 62 | 9 #define FPF_SKIAMATCHWEIGHT_NAME1 62 |
10 #define FPF_SKIAMATCHWEIGHT_NAME2» 60 | 10 #define FPF_SKIAMATCHWEIGHT_NAME2 60 |
11 #define FPF_SKIAMATCHWEIGHT_1» » 16 | 11 #define FPF_SKIAMATCHWEIGHT_1 16 |
12 #define FPF_SKIAMATCHWEIGHT_2» » 8 | 12 #define FPF_SKIAMATCHWEIGHT_2 8 |
13 #include "fpf_skiafontmgr.h" | 13 #include "fpf_skiafontmgr.h" |
14 #include "fpf_skiafont.h" | 14 #include "fpf_skiafont.h" |
15 #ifdef __cplusplus | 15 #ifdef __cplusplus |
16 extern "C" { | 16 extern "C" { |
17 #endif | 17 #endif |
18 static unsigned long FPF_SkiaStream_Read(FXFT_Stream stream, unsigned long offse
t, unsigned char* buffer, unsigned long count) | 18 static unsigned long FPF_SkiaStream_Read(FXFT_Stream stream, |
19 { | 19 unsigned long offset, |
20 IFX_FileRead *pFileRead = (IFX_FileRead*)stream->descriptor.pointer; | 20 unsigned char* buffer, |
21 if (!pFileRead) { | 21 unsigned long count) { |
22 return 0; | 22 IFX_FileRead* pFileRead = (IFX_FileRead*)stream->descriptor.pointer; |
23 } | 23 if (!pFileRead) { |
24 if (count > 0) { | 24 return 0; |
25 if (pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count) !=
count) { | 25 } |
26 return 0; | 26 if (count > 0) { |
27 } | 27 if (pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count) != |
28 } | 28 count) { |
29 return count; | 29 return 0; |
30 } | 30 } |
31 static void FPF_SkiaStream_Close(FXFT_Stream stream) | 31 } |
32 { | 32 return count; |
33 } | 33 } |
| 34 static void FPF_SkiaStream_Close(FXFT_Stream stream) {} |
34 #ifdef __cplusplus | 35 #ifdef __cplusplus |
35 }; | 36 }; |
36 #endif | 37 #endif |
37 typedef struct _FPF_SKIAFONTMAP { | 38 typedef struct _FPF_SKIAFONTMAP { |
38 FX_DWORD» dwFamily; | 39 FX_DWORD dwFamily; |
39 FX_DWORD» dwSubSt; | 40 FX_DWORD dwSubSt; |
40 } FPF_SKIAFONTMAP, *FPF_LPSKIAFONTMAP; | 41 } FPF_SKIAFONTMAP, *FPF_LPSKIAFONTMAP; |
41 typedef FPF_SKIAFONTMAP const * FPF_LPCSKIAFONTMAP; | 42 typedef FPF_SKIAFONTMAP const* FPF_LPCSKIAFONTMAP; |
42 static const FPF_SKIAFONTMAP g_SkiaFontmap[] = { | 43 static const FPF_SKIAFONTMAP g_SkiaFontmap[] = { |
43 {0x58c5083,»» 0xc8d2e345}, | 44 {0x58c5083, 0xc8d2e345}, {0x5dfade2, 0xe1633081}, |
44 {0x5dfade2,»» 0xe1633081}, | 45 {0x684317d, 0xe1633081}, {0x14ee2d13, 0xc8d2e345}, |
45 {0x684317d,»» 0xe1633081}, | 46 {0x3918fe2d, 0xbbeeec72}, {0x3b98b31c, 0xe1633081}, |
46 {0x14ee2d13,» 0xc8d2e345}, | 47 {0x3d49f40e, 0xe1633081}, {0x432c41c5, 0xe1633081}, |
47 {0x3918fe2d,» 0xbbeeec72}, | 48 {0x491b6ad0, 0xe1633081}, {0x5612cab1, 0x59b9f8f1}, |
48 {0x3b98b31c,» 0xe1633081}, | 49 {0x779ce19d, 0xc8d2e345}, {0x7cc9510b, 0x59b9f8f1}, |
49 {0x3d49f40e,» 0xe1633081}, | 50 {0x83746053, 0xbbeeec72}, {0xaaa60c03, 0xbbeeec72}, |
50 {0x432c41c5,» 0xe1633081}, | 51 {0xbf85ff26, 0xe1633081}, {0xc04fe601, 0xbbeeec72}, |
51 {0x491b6ad0,» 0xe1633081}, | 52 {0xca3812d5, 0x59b9f8f1}, {0xca383e15, 0x59b9f8f1}, |
52 {0x5612cab1,» 0x59b9f8f1}, | 53 {0xcad5eaf6, 0x59b9f8f1}, {0xcb7a04c8, 0xc8d2e345}, |
53 {0x779ce19d,» 0xc8d2e345}, | 54 {0xfb4ce0de, 0xe1633081}, |
54 {0x7cc9510b,» 0x59b9f8f1}, | |
55 {0x83746053,» 0xbbeeec72}, | |
56 {0xaaa60c03,» 0xbbeeec72}, | |
57 {0xbf85ff26,» 0xe1633081}, | |
58 {0xc04fe601,» 0xbbeeec72}, | |
59 {0xca3812d5,» 0x59b9f8f1}, | |
60 {0xca383e15,» 0x59b9f8f1}, | |
61 {0xcad5eaf6,» 0x59b9f8f1}, | |
62 {0xcb7a04c8,» 0xc8d2e345}, | |
63 {0xfb4ce0de,» 0xe1633081}, | |
64 }; | 55 }; |
65 FX_DWORD FPF_SkiaGetSubstFont(FX_DWORD dwHash) | 56 FX_DWORD FPF_SkiaGetSubstFont(FX_DWORD dwHash) { |
66 { | 57 int32_t iStart = 0; |
67 int32_t iStart = 0; | 58 int32_t iEnd = sizeof(g_SkiaFontmap) / sizeof(FPF_SKIAFONTMAP); |
68 int32_t iEnd = sizeof(g_SkiaFontmap) / sizeof(FPF_SKIAFONTMAP); | 59 while (iStart <= iEnd) { |
69 while (iStart <= iEnd) { | 60 int32_t iMid = (iStart + iEnd) / 2; |
70 int32_t iMid = (iStart + iEnd) / 2; | 61 FPF_LPCSKIAFONTMAP pItem = &g_SkiaFontmap[iMid]; |
71 FPF_LPCSKIAFONTMAP pItem = &g_SkiaFontmap[iMid]; | 62 if (dwHash < pItem->dwFamily) { |
72 if (dwHash < pItem->dwFamily) { | 63 iEnd = iMid - 1; |
73 iEnd = iMid - 1; | 64 } else if (dwHash > pItem->dwFamily) { |
74 } else if (dwHash > pItem->dwFamily) { | 65 iStart = iMid + 1; |
75 iStart = iMid + 1; | 66 } else { |
76 } else { | 67 return pItem->dwSubSt; |
77 return pItem->dwSubSt; | 68 } |
78 } | 69 } |
79 } | 70 return 0; |
| 71 } |
| 72 static const FPF_SKIAFONTMAP g_SkiaSansFontMap[] = { |
| 73 {0x58c5083, 0xd5b8d10f}, {0x14ee2d13, 0xd5b8d10f}, |
| 74 {0x779ce19d, 0xd5b8d10f}, {0xcb7a04c8, 0xd5b8d10f}, |
| 75 {0xfb4ce0de, 0xd5b8d10f}, |
| 76 }; |
| 77 FX_DWORD FPF_SkiaGetSansFont(FX_DWORD dwHash) { |
| 78 int32_t iStart = 0; |
| 79 int32_t iEnd = sizeof(g_SkiaSansFontMap) / sizeof(FPF_SKIAFONTMAP); |
| 80 while (iStart <= iEnd) { |
| 81 int32_t iMid = (iStart + iEnd) / 2; |
| 82 FPF_LPCSKIAFONTMAP pItem = &g_SkiaSansFontMap[iMid]; |
| 83 if (dwHash < pItem->dwFamily) { |
| 84 iEnd = iMid - 1; |
| 85 } else if (dwHash > pItem->dwFamily) { |
| 86 iStart = iMid + 1; |
| 87 } else { |
| 88 return pItem->dwSubSt; |
| 89 } |
| 90 } |
| 91 return 0; |
| 92 } |
| 93 static uint32_t FPF_GetHashCode_StringA(const FX_CHAR* pStr, |
| 94 int32_t iLength, |
| 95 FX_BOOL bIgnoreCase = FALSE) { |
| 96 if (!pStr) { |
80 return 0; | 97 return 0; |
81 } | 98 } |
82 static const FPF_SKIAFONTMAP g_SkiaSansFontMap[] = { | 99 if (iLength < 0) { |
83 {0x58c5083,»» 0xd5b8d10f}, | 100 iLength = FXSYS_strlen(pStr); |
84 {0x14ee2d13,» 0xd5b8d10f}, | 101 } |
85 {0x779ce19d,» 0xd5b8d10f}, | 102 const FX_CHAR* pStrEnd = pStr + iLength; |
86 {0xcb7a04c8,» 0xd5b8d10f}, | 103 uint32_t uHashCode = 0; |
87 {0xfb4ce0de,» 0xd5b8d10f}, | 104 if (bIgnoreCase) { |
| 105 while (pStr < pStrEnd) { |
| 106 uHashCode = 31 * uHashCode + FXSYS_tolower(*pStr++); |
| 107 } |
| 108 } else { |
| 109 while (pStr < pStrEnd) { |
| 110 uHashCode = 31 * uHashCode + *pStr++; |
| 111 } |
| 112 } |
| 113 return uHashCode; |
| 114 } |
| 115 enum FPF_SKIACHARSET { |
| 116 FPF_SKIACHARSET_Ansi = 1 << 0, |
| 117 FPF_SKIACHARSET_Default = 1 << 1, |
| 118 FPF_SKIACHARSET_Symbol = 1 << 2, |
| 119 FPF_SKIACHARSET_ShiftJIS = 1 << 3, |
| 120 FPF_SKIACHARSET_Korean = 1 << 4, |
| 121 FPF_SKIACHARSET_Johab = 1 << 5, |
| 122 FPF_SKIACHARSET_GB2312 = 1 << 6, |
| 123 FPF_SKIACHARSET_BIG5 = 1 << 7, |
| 124 FPF_SKIACHARSET_Greek = 1 << 8, |
| 125 FPF_SKIACHARSET_Turkish = 1 << 9, |
| 126 FPF_SKIACHARSET_Vietnamese = 1 << 10, |
| 127 FPF_SKIACHARSET_Hebrew = 1 << 11, |
| 128 FPF_SKIACHARSET_Arabic = 1 << 12, |
| 129 FPF_SKIACHARSET_Baltic = 1 << 13, |
| 130 FPF_SKIACHARSET_Cyrillic = 1 << 14, |
| 131 FPF_SKIACHARSET_Thai = 1 << 15, |
| 132 FPF_SKIACHARSET_EeasternEuropean = 1 << 16, |
| 133 FPF_SKIACHARSET_PC = 1 << 17, |
| 134 FPF_SKIACHARSET_OEM = 1 << 18, |
88 }; | 135 }; |
89 FX_DWORD FPF_SkiaGetSansFont(FX_DWORD dwHash) | 136 static FX_DWORD FPF_SkiaGetCharset(uint8_t uCharset) { |
90 { | 137 switch (uCharset) { |
91 int32_t iStart = 0; | 138 case FXFONT_ANSI_CHARSET: |
92 int32_t iEnd = sizeof(g_SkiaSansFontMap) / sizeof(FPF_SKIAFONTMAP); | 139 return FPF_SKIACHARSET_Ansi; |
93 while (iStart <= iEnd) { | 140 case FXFONT_DEFAULT_CHARSET: |
94 int32_t iMid = (iStart + iEnd) / 2; | 141 return FPF_SKIACHARSET_Default; |
95 FPF_LPCSKIAFONTMAP pItem = &g_SkiaSansFontMap[iMid]; | 142 case FXFONT_SYMBOL_CHARSET: |
96 if (dwHash < pItem->dwFamily) { | 143 return FPF_SKIACHARSET_Symbol; |
97 iEnd = iMid - 1; | 144 case FXFONT_SHIFTJIS_CHARSET: |
98 } else if (dwHash > pItem->dwFamily) { | 145 return FPF_SKIACHARSET_ShiftJIS; |
99 iStart = iMid + 1; | 146 case FXFONT_HANGEUL_CHARSET: |
100 } else { | 147 return FPF_SKIACHARSET_Korean; |
101 return pItem->dwSubSt; | 148 case FXFONT_GB2312_CHARSET: |
102 } | 149 return FPF_SKIACHARSET_GB2312; |
103 } | 150 case FXFONT_CHINESEBIG5_CHARSET: |
104 return 0; | 151 return FPF_SKIACHARSET_BIG5; |
105 } | 152 case FXFONT_GREEK_CHARSET: |
106 static uint32_t FPF_GetHashCode_StringA(const FX_CHAR* pStr, int32_t iLength, FX
_BOOL bIgnoreCase = FALSE) | 153 return FPF_SKIACHARSET_Greek; |
107 { | 154 case FXFONT_TURKISH_CHARSET: |
108 if (!pStr) { | 155 return FPF_SKIACHARSET_Turkish; |
109 return 0; | 156 case FXFONT_HEBREW_CHARSET: |
110 } | 157 return FPF_SKIACHARSET_Hebrew; |
111 if (iLength < 0) { | 158 case FXFONT_ARABIC_CHARSET: |
112 iLength = FXSYS_strlen(pStr); | 159 return FPF_SKIACHARSET_Arabic; |
113 } | 160 case FXFONT_BALTIC_CHARSET: |
114 const FX_CHAR* pStrEnd = pStr + iLength; | 161 return FPF_SKIACHARSET_Baltic; |
115 uint32_t uHashCode = 0; | 162 case FXFONT_RUSSIAN_CHARSET: |
116 if (bIgnoreCase) { | 163 return FPF_SKIACHARSET_Cyrillic; |
117 while (pStr < pStrEnd) { | 164 case FXFONT_THAI_CHARSET: |
118 uHashCode = 31 * uHashCode + FXSYS_tolower(*pStr++); | 165 return FPF_SKIACHARSET_Thai; |
119 } | 166 case FXFONT_EASTEUROPE_CHARSET: |
| 167 return FPF_SKIACHARSET_EeasternEuropean; |
| 168 } |
| 169 return FPF_SKIACHARSET_Default; |
| 170 } |
| 171 static FX_DWORD FPF_SKIANormalizeFontName(const CFX_ByteStringC& bsfamily) { |
| 172 FX_DWORD dwHash = 0; |
| 173 int32_t iLength = bsfamily.GetLength(); |
| 174 const FX_CHAR* pBuffer = bsfamily.GetCStr(); |
| 175 for (int32_t i = 0; i < iLength; i++) { |
| 176 FX_CHAR ch = pBuffer[i]; |
| 177 if (ch == ' ' || ch == '-' || ch == ',') { |
| 178 continue; |
| 179 } |
| 180 dwHash = 31 * dwHash + FXSYS_tolower(ch); |
| 181 } |
| 182 return dwHash; |
| 183 } |
| 184 static FX_DWORD FPF_SKIAGetFamilyHash(const CFX_ByteStringC& bsFamily, |
| 185 FX_DWORD dwStyle, |
| 186 uint8_t uCharset) { |
| 187 CFX_ByteString bsFont(bsFamily); |
| 188 if (dwStyle & FXFONT_BOLD) { |
| 189 bsFont += "Bold"; |
| 190 } |
| 191 if (dwStyle & FXFONT_ITALIC) { |
| 192 bsFont += "Italic"; |
| 193 } |
| 194 if (dwStyle & FXFONT_SERIF) { |
| 195 bsFont += "Serif"; |
| 196 } |
| 197 bsFont += uCharset; |
| 198 return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength(), TRUE); |
| 199 } |
| 200 static FX_BOOL FPF_SkiaIsCJK(uint8_t uCharset) { |
| 201 return (uCharset == FXFONT_GB2312_CHARSET) || |
| 202 (uCharset == FXFONT_CHINESEBIG5_CHARSET) || |
| 203 (uCharset == FXFONT_HANGEUL_CHARSET) || |
| 204 (uCharset == FXFONT_SHIFTJIS_CHARSET); |
| 205 } |
| 206 static FX_BOOL FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename) { |
| 207 CFX_ByteString bsName = bsFacename; |
| 208 bsName.MakeLower(); |
| 209 return bsName.Find("symbol") > -1; |
| 210 } |
| 211 static FX_BOOL FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename) { |
| 212 CFX_ByteString bsName = bsFacename; |
| 213 bsName.MakeLower(); |
| 214 return bsName.Find("arabic") > -1; |
| 215 } |
| 216 CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() : m_bLoaded(FALSE), m_FTLibrary(NULL) {} |
| 217 CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() { |
| 218 void* pkey = NULL; |
| 219 CFPF_SkiaFont* pValue = NULL; |
| 220 FX_POSITION pos = m_FamilyFonts.GetStartPosition(); |
| 221 while (pos) { |
| 222 m_FamilyFonts.GetNextAssoc(pos, pkey, (void*&)pValue); |
| 223 if (pValue) { |
| 224 pValue->Release(); |
| 225 } |
| 226 } |
| 227 m_FamilyFonts.RemoveAll(); |
| 228 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) { |
| 229 CFPF_SkiaFontDescriptor* pFont = |
| 230 (CFPF_SkiaFontDescriptor*)m_FontFaces.ElementAt(i); |
| 231 delete pFont; |
| 232 } |
| 233 m_FontFaces.RemoveAll(); |
| 234 if (m_FTLibrary) { |
| 235 FXFT_Done_FreeType(m_FTLibrary); |
| 236 } |
| 237 } |
| 238 FX_BOOL CFPF_SkiaFontMgr::InitFTLibrary() { |
| 239 if (m_FTLibrary == NULL) { |
| 240 FXFT_Init_FreeType(&m_FTLibrary); |
| 241 } |
| 242 return m_FTLibrary != NULL; |
| 243 } |
| 244 void CFPF_SkiaFontMgr::LoadSystemFonts() { |
| 245 if (m_bLoaded) { |
| 246 return; |
| 247 } |
| 248 ScanPath(FX_BSTRC("/system/fonts")); |
| 249 OutputSystemFonts(); |
| 250 m_bLoaded = TRUE; |
| 251 } |
| 252 void CFPF_SkiaFontMgr::LoadPrivateFont(IFX_FileRead* pFontFile) {} |
| 253 void CFPF_SkiaFontMgr::LoadPrivateFont(const CFX_ByteStringC& bsFileName) {} |
| 254 void CFPF_SkiaFontMgr::LoadPrivateFont(void* pBuffer, size_t szBuffer) {} |
| 255 IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname, |
| 256 uint8_t uCharset, |
| 257 FX_DWORD dwStyle, |
| 258 FX_DWORD dwMatch) { |
| 259 FX_DWORD dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset); |
| 260 IFPF_Font* pFont = NULL; |
| 261 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
| 262 if (pFont) { |
| 263 return pFont->Retain(); |
| 264 } |
| 265 } |
| 266 FX_DWORD dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname); |
| 267 FX_DWORD dwSubst = FPF_SkiaGetSubstFont(dwFaceName); |
| 268 FX_DWORD dwSubstSans = FPF_SkiaGetSansFont(dwFaceName); |
| 269 FX_BOOL bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname); |
| 270 if (uCharset != FXFONT_ARABIC_CHARSET && FPF_SkiaMaybeArabic(bsFamilyname)) { |
| 271 uCharset = FXFONT_ARABIC_CHARSET; |
| 272 } else if (uCharset == FXFONT_ANSI_CHARSET && |
| 273 (dwMatch & FPF_MATCHFONT_REPLACEANSI)) { |
| 274 uCharset = FXFONT_DEFAULT_CHARSET; |
| 275 } |
| 276 int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 + |
| 277 FPF_SKIAMATCHWEIGHT_2 * 2; |
| 278 int32_t nItem = -1; |
| 279 int32_t nMax = -1; |
| 280 int32_t nGlyphNum = 0; |
| 281 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) { |
| 282 CFPF_SkiaPathFont* pFontDes = (CFPF_SkiaPathFont*)m_FontFaces.ElementAt(i); |
| 283 if (!(pFontDes->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) { |
| 284 continue; |
| 285 } |
| 286 int32_t nFind = 0; |
| 287 FX_DWORD dwSysFontName = FPF_SKIANormalizeFontName(pFontDes->m_pFamily); |
| 288 if (dwFaceName == dwSysFontName) { |
| 289 nFind += FPF_SKIAMATCHWEIGHT_NAME1; |
| 290 } |
| 291 FX_BOOL bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1); |
| 292 if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) { |
| 293 nFind += FPF_SKIAMATCHWEIGHT_1; |
| 294 } |
| 295 if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC)) { |
| 296 nFind += FPF_SKIAMATCHWEIGHT_1; |
| 297 } |
| 298 if ((dwStyle & FXFONT_FIXED_PITCH) == |
| 299 (pFontDes->m_dwStyle & FXFONT_FIXED_PITCH)) { |
| 300 nFind += FPF_SKIAMATCHWEIGHT_2; |
| 301 } |
| 302 if ((dwStyle & FXFONT_SERIF) == (pFontDes->m_dwStyle & FXFONT_SERIF)) { |
| 303 nFind += FPF_SKIAMATCHWEIGHT_1; |
| 304 } |
| 305 if ((dwStyle & FXFONT_SCRIPT) == (pFontDes->m_dwStyle & FXFONT_SCRIPT)) { |
| 306 nFind += FPF_SKIAMATCHWEIGHT_2; |
| 307 } |
| 308 if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) { |
| 309 nFind += FPF_SKIAMATCHWEIGHT_NAME2; |
| 310 bMatchedName = TRUE; |
| 311 } |
| 312 if (uCharset == FXFONT_DEFAULT_CHARSET || bMaybeSymbol) { |
| 313 if (nFind > nMax && bMatchedName) { |
| 314 nMax = nFind; |
| 315 nItem = i; |
| 316 } |
| 317 } else if (FPF_SkiaIsCJK(uCharset)) { |
| 318 if (bMatchedName || pFontDes->m_iGlyphNum > nGlyphNum) { |
| 319 nItem = i; |
| 320 nGlyphNum = pFontDes->m_iGlyphNum; |
| 321 } |
| 322 } else if (nFind > nMax) { |
| 323 nMax = nFind; |
| 324 nItem = i; |
| 325 } |
| 326 if (nExpectVal <= nFind) { |
| 327 nItem = i; |
| 328 break; |
| 329 } |
| 330 } |
| 331 if (nItem > -1) { |
| 332 CFPF_SkiaFontDescriptor* pFontDes = |
| 333 (CFPF_SkiaFontDescriptor*)m_FontFaces.ElementAt(nItem); |
| 334 CFPF_SkiaFont* pFont = new CFPF_SkiaFont; |
| 335 if (pFont->InitFont(this, pFontDes, bsFamilyname, dwStyle, uCharset)) { |
| 336 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 337 return pFont->Retain(); |
| 338 } |
| 339 pFont->Release(); |
| 340 } |
| 341 return NULL; |
| 342 } |
| 343 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_FileRead* pFileRead, |
| 344 int32_t iFaceIndex) { |
| 345 if (!pFileRead) { |
| 346 return NULL; |
| 347 } |
| 348 if (pFileRead->GetSize() == 0) { |
| 349 return NULL; |
| 350 } |
| 351 if (iFaceIndex < 0) { |
| 352 return NULL; |
| 353 } |
| 354 FXFT_StreamRec streamRec; |
| 355 FXSYS_memset(&streamRec, 0, sizeof(FXFT_StreamRec)); |
| 356 streamRec.size = pFileRead->GetSize(); |
| 357 streamRec.descriptor.pointer = pFileRead; |
| 358 streamRec.read = FPF_SkiaStream_Read; |
| 359 streamRec.close = FPF_SkiaStream_Close; |
| 360 FXFT_Open_Args args; |
| 361 args.flags = FT_OPEN_STREAM; |
| 362 args.stream = &streamRec; |
| 363 FXFT_Face face; |
| 364 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 365 return NULL; |
| 366 } |
| 367 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 368 return face; |
| 369 } |
| 370 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const CFX_ByteStringC& bsFile, |
| 371 int32_t iFaceIndex) { |
| 372 if (bsFile.IsEmpty()) { |
| 373 return NULL; |
| 374 } |
| 375 if (iFaceIndex < 0) { |
| 376 return NULL; |
| 377 } |
| 378 FXFT_Open_Args args; |
| 379 args.flags = FT_OPEN_PATHNAME; |
| 380 args.pathname = (FT_String*)bsFile.GetCStr(); |
| 381 FXFT_Face face; |
| 382 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 383 return FALSE; |
| 384 } |
| 385 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 386 return face; |
| 387 } |
| 388 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, |
| 389 size_t szBuffer, |
| 390 int32_t iFaceIndex) { |
| 391 if (!pBuffer || szBuffer < 1) { |
| 392 return NULL; |
| 393 } |
| 394 if (iFaceIndex < 0) { |
| 395 return NULL; |
| 396 } |
| 397 FXFT_Open_Args args; |
| 398 args.flags = FT_OPEN_MEMORY; |
| 399 args.memory_base = pBuffer; |
| 400 args.memory_size = szBuffer; |
| 401 FXFT_Face face; |
| 402 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 403 return FALSE; |
| 404 } |
| 405 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 406 return face; |
| 407 } |
| 408 void CFPF_SkiaFontMgr::ScanPath(const CFX_ByteStringC& path) { |
| 409 void* handle = FX_OpenFolder(path.GetCStr()); |
| 410 if (!handle) { |
| 411 return; |
| 412 } |
| 413 CFX_ByteString filename; |
| 414 FX_BOOL bFolder = FALSE; |
| 415 while (FX_GetNextFile(handle, filename, bFolder)) { |
| 416 if (bFolder) { |
| 417 if (filename == FX_BSTRC(".") || filename == FX_BSTRC("..")) { |
| 418 continue; |
| 419 } |
120 } else { | 420 } else { |
121 while (pStr < pStrEnd) { | 421 CFX_ByteString ext = filename.Right(4); |
122 uHashCode = 31 * uHashCode + *pStr ++; | 422 ext.MakeLower(); |
123 } | 423 if (ext != FX_BSTRC(".ttf") && ext != FX_BSTRC(".ttc")) { |
124 } | 424 continue; |
125 return uHashCode; | 425 } |
126 } | 426 } |
127 enum FPF_SKIACHARSET { | 427 CFX_ByteString fullpath = path; |
128 FPF_SKIACHARSET_Ansi = 1 << 0, | 428 fullpath += "/"; |
129 FPF_SKIACHARSET_Default = 1 << 1, | 429 fullpath += filename; |
130 FPF_SKIACHARSET_Symbol = 1 << 2, | 430 if (bFolder) { |
131 FPF_SKIACHARSET_ShiftJIS = 1 << 3, | 431 ScanPath(fullpath); |
132 FPF_SKIACHARSET_Korean = 1 << 4, | 432 } else { |
133 FPF_SKIACHARSET_Johab = 1 << 5, | 433 ScanFile(fullpath); |
134 FPF_SKIACHARSET_GB2312 = 1 << 6, | 434 } |
135 FPF_SKIACHARSET_BIG5 = 1 << 7, | 435 } |
136 FPF_SKIACHARSET_Greek = 1 << 8, | 436 FX_CloseFolder(handle); |
137 FPF_SKIACHARSET_Turkish = 1 << 9, | 437 } |
138 FPF_SKIACHARSET_Vietnamese = 1 << 10, | 438 void CFPF_SkiaFontMgr::ScanFile(const CFX_ByteStringC& file) { |
139 FPF_SKIACHARSET_Hebrew = 1 << 11, | 439 FXFT_Face face = GetFontFace(file); |
140 FPF_SKIACHARSET_Arabic = 1 << 12, | 440 if (face) { |
141 FPF_SKIACHARSET_Baltic = 1 << 13, | 441 CFPF_SkiaPathFont* pFontDesc = new CFPF_SkiaPathFont; |
142 FPF_SKIACHARSET_Cyrillic = 1 << 14, | 442 pFontDesc->SetPath(file.GetCStr()); |
143 FPF_SKIACHARSET_Thai = 1 << 15, | 443 ReportFace(face, pFontDesc); |
144 FPF_SKIACHARSET_EeasternEuropean = 1 << 16, | 444 m_FontFaces.Add(pFontDesc); |
145 FPF_SKIACHARSET_PC = 1 << 17, | 445 FXFT_Done_Face(face); |
146 FPF_SKIACHARSET_OEM = 1 << 18, | 446 } |
147 }; | 447 } |
148 static FX_DWORD FPF_SkiaGetCharset(uint8_t uCharset) | 448 static const FX_DWORD g_FPFSkiaFontCharsets[] = { |
149 { | |
150 switch (uCharset) { | |
151 case FXFONT_ANSI_CHARSET: | |
152 return FPF_SKIACHARSET_Ansi; | |
153 case FXFONT_DEFAULT_CHARSET: | |
154 return FPF_SKIACHARSET_Default; | |
155 case FXFONT_SYMBOL_CHARSET: | |
156 return FPF_SKIACHARSET_Symbol; | |
157 case FXFONT_SHIFTJIS_CHARSET: | |
158 return FPF_SKIACHARSET_ShiftJIS; | |
159 case FXFONT_HANGEUL_CHARSET: | |
160 return FPF_SKIACHARSET_Korean; | |
161 case FXFONT_GB2312_CHARSET: | |
162 return FPF_SKIACHARSET_GB2312; | |
163 case FXFONT_CHINESEBIG5_CHARSET: | |
164 return FPF_SKIACHARSET_BIG5; | |
165 case FXFONT_GREEK_CHARSET: | |
166 return FPF_SKIACHARSET_Greek; | |
167 case FXFONT_TURKISH_CHARSET: | |
168 return FPF_SKIACHARSET_Turkish; | |
169 case FXFONT_HEBREW_CHARSET: | |
170 return FPF_SKIACHARSET_Hebrew; | |
171 case FXFONT_ARABIC_CHARSET: | |
172 return FPF_SKIACHARSET_Arabic; | |
173 case FXFONT_BALTIC_CHARSET: | |
174 return FPF_SKIACHARSET_Baltic; | |
175 case FXFONT_RUSSIAN_CHARSET: | |
176 return FPF_SKIACHARSET_Cyrillic; | |
177 case FXFONT_THAI_CHARSET: | |
178 return FPF_SKIACHARSET_Thai; | |
179 case FXFONT_EASTEUROPE_CHARSET: | |
180 return FPF_SKIACHARSET_EeasternEuropean; | |
181 } | |
182 return FPF_SKIACHARSET_Default; | |
183 } | |
184 static FX_DWORD FPF_SKIANormalizeFontName(const CFX_ByteStringC& bsfamily) | |
185 { | |
186 FX_DWORD dwHash = 0; | |
187 int32_t iLength = bsfamily.GetLength(); | |
188 const FX_CHAR* pBuffer = bsfamily.GetCStr(); | |
189 for (int32_t i = 0; i < iLength; i++) { | |
190 FX_CHAR ch = pBuffer[i]; | |
191 if (ch == ' ' || ch == '-' || ch == ',') { | |
192 continue; | |
193 } | |
194 dwHash = 31 * dwHash + FXSYS_tolower(ch); | |
195 } | |
196 return dwHash; | |
197 } | |
198 static FX_DWORD FPF_SKIAGetFamilyHash(const CFX_ByteStringC& bsFamily, FX_DWORD
dwStyle, uint8_t uCharset) | |
199 { | |
200 CFX_ByteString bsFont(bsFamily); | |
201 if (dwStyle & FXFONT_BOLD) { | |
202 bsFont += "Bold"; | |
203 } | |
204 if (dwStyle & FXFONT_ITALIC) { | |
205 bsFont += "Italic"; | |
206 } | |
207 if (dwStyle & FXFONT_SERIF) { | |
208 bsFont += "Serif"; | |
209 } | |
210 bsFont += uCharset; | |
211 return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength(), TRUE); | |
212 } | |
213 static FX_BOOL FPF_SkiaIsCJK(uint8_t uCharset) | |
214 { | |
215 return (uCharset == FXFONT_GB2312_CHARSET) || (uCharset == FXFONT_CHINESEBIG
5_CHARSET) | |
216 || (uCharset == FXFONT_HANGEUL_CHARSET) || (uCharset == FXFONT_SHIFTJ
IS_CHARSET); | |
217 } | |
218 static FX_BOOL FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename) | |
219 { | |
220 CFX_ByteString bsName = bsFacename; | |
221 bsName.MakeLower(); | |
222 return bsName.Find("symbol") > -1; | |
223 } | |
224 static FX_BOOL FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename) | |
225 { | |
226 CFX_ByteString bsName = bsFacename; | |
227 bsName.MakeLower(); | |
228 return bsName.Find("arabic") > -1; | |
229 } | |
230 CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() | |
231 : m_bLoaded(FALSE), m_FTLibrary(NULL) | |
232 { | |
233 } | |
234 CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() | |
235 { | |
236 void *pkey = NULL; | |
237 CFPF_SkiaFont *pValue = NULL; | |
238 FX_POSITION pos = m_FamilyFonts.GetStartPosition(); | |
239 while (pos) { | |
240 m_FamilyFonts.GetNextAssoc(pos, pkey, (void*&)pValue); | |
241 if (pValue) { | |
242 pValue->Release(); | |
243 } | |
244 } | |
245 m_FamilyFonts.RemoveAll(); | |
246 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) { | |
247 CFPF_SkiaFontDescriptor *pFont = (CFPF_SkiaFontDescriptor*)m_FontFaces.E
lementAt(i); | |
248 delete pFont; | |
249 } | |
250 m_FontFaces.RemoveAll(); | |
251 if (m_FTLibrary) { | |
252 FXFT_Done_FreeType(m_FTLibrary); | |
253 } | |
254 } | |
255 FX_BOOL CFPF_SkiaFontMgr::InitFTLibrary() | |
256 { | |
257 if (m_FTLibrary == NULL) { | |
258 FXFT_Init_FreeType(&m_FTLibrary); | |
259 } | |
260 return m_FTLibrary != NULL; | |
261 } | |
262 void CFPF_SkiaFontMgr::LoadSystemFonts() | |
263 { | |
264 if (m_bLoaded) { | |
265 return; | |
266 } | |
267 ScanPath(FX_BSTRC("/system/fonts")); | |
268 OutputSystemFonts(); | |
269 m_bLoaded = TRUE; | |
270 } | |
271 void CFPF_SkiaFontMgr::LoadPrivateFont(IFX_FileRead* pFontFile) | |
272 { | |
273 } | |
274 void CFPF_SkiaFontMgr::LoadPrivateFont(const CFX_ByteStringC& bsFileName) | |
275 { | |
276 } | |
277 void CFPF_SkiaFontMgr::LoadPrivateFont(void* pBuffer, size_t szBuffer) | |
278 { | |
279 } | |
280 IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname, uin
t8_t uCharset, FX_DWORD dwStyle, FX_DWORD dwMatch) | |
281 { | |
282 FX_DWORD dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset); | |
283 IFPF_Font *pFont = NULL; | |
284 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | |
285 if (pFont) { | |
286 return pFont->Retain(); | |
287 } | |
288 } | |
289 FX_DWORD dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname); | |
290 FX_DWORD dwSubst = FPF_SkiaGetSubstFont(dwFaceName); | |
291 FX_DWORD dwSubstSans = FPF_SkiaGetSansFont(dwFaceName); | |
292 FX_BOOL bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname); | |
293 if (uCharset != FXFONT_ARABIC_CHARSET && FPF_SkiaMaybeArabic(bsFamilyname))
{ | |
294 uCharset = FXFONT_ARABIC_CHARSET; | |
295 } else if (uCharset == FXFONT_ANSI_CHARSET && (dwMatch & FPF_MATCHFONT_REPLA
CEANSI)) { | |
296 uCharset = FXFONT_DEFAULT_CHARSET; | |
297 } | |
298 int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 +
FPF_SKIAMATCHWEIGHT_2 * 2; | |
299 int32_t nItem = -1; | |
300 int32_t nMax = -1; | |
301 int32_t nGlyphNum = 0; | |
302 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) { | |
303 CFPF_SkiaPathFont *pFontDes = (CFPF_SkiaPathFont*)m_FontFaces.ElementAt(
i); | |
304 if(!(pFontDes->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) { | |
305 continue; | |
306 } | |
307 int32_t nFind = 0; | |
308 FX_DWORD dwSysFontName = FPF_SKIANormalizeFontName(pFontDes->m_pFamily); | |
309 if (dwFaceName == dwSysFontName) { | |
310 nFind += FPF_SKIAMATCHWEIGHT_NAME1; | |
311 } | |
312 FX_BOOL bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1); | |
313 if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) { | |
314 nFind += FPF_SKIAMATCHWEIGHT_1; | |
315 } | |
316 if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC))
{ | |
317 nFind += FPF_SKIAMATCHWEIGHT_1; | |
318 } | |
319 if ((dwStyle & FXFONT_FIXED_PITCH) == (pFontDes->m_dwStyle & FXFONT_FIXE
D_PITCH)) { | |
320 nFind += FPF_SKIAMATCHWEIGHT_2; | |
321 } | |
322 if ((dwStyle & FXFONT_SERIF) == (pFontDes->m_dwStyle & FXFONT_SERIF)) { | |
323 nFind += FPF_SKIAMATCHWEIGHT_1; | |
324 } | |
325 if ((dwStyle & FXFONT_SCRIPT) == (pFontDes->m_dwStyle & FXFONT_SCRIPT))
{ | |
326 nFind += FPF_SKIAMATCHWEIGHT_2; | |
327 } | |
328 if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) { | |
329 nFind += FPF_SKIAMATCHWEIGHT_NAME2; | |
330 bMatchedName = TRUE; | |
331 } | |
332 if (uCharset == FXFONT_DEFAULT_CHARSET || bMaybeSymbol) { | |
333 if (nFind > nMax && bMatchedName) { | |
334 nMax = nFind; | |
335 nItem = i; | |
336 } | |
337 } else if (FPF_SkiaIsCJK(uCharset)) { | |
338 if (bMatchedName || pFontDes->m_iGlyphNum > nGlyphNum) { | |
339 nItem = i; | |
340 nGlyphNum = pFontDes->m_iGlyphNum; | |
341 } | |
342 } else if (nFind > nMax) { | |
343 nMax = nFind; | |
344 nItem = i; | |
345 } | |
346 if (nExpectVal <= nFind) { | |
347 nItem = i; | |
348 break; | |
349 } | |
350 } | |
351 if (nItem > -1) { | |
352 CFPF_SkiaFontDescriptor *pFontDes = (CFPF_SkiaFontDescriptor*)m_FontFace
s.ElementAt(nItem); | |
353 CFPF_SkiaFont *pFont = new CFPF_SkiaFont; | |
354 if (pFont->InitFont(this, pFontDes, bsFamilyname, dwStyle, uCharset)) { | |
355 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); | |
356 return pFont->Retain(); | |
357 } | |
358 pFont->Release(); | |
359 } | |
360 return NULL; | |
361 } | |
362 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_FileRead *pFileRead, int32_t iFaceIn
dex) | |
363 { | |
364 if (!pFileRead) { | |
365 return NULL; | |
366 } | |
367 if (pFileRead->GetSize() == 0) { | |
368 return NULL; | |
369 } | |
370 if (iFaceIndex < 0) { | |
371 return NULL; | |
372 } | |
373 FXFT_StreamRec streamRec; | |
374 FXSYS_memset(&streamRec, 0, sizeof(FXFT_StreamRec)); | |
375 streamRec.size = pFileRead->GetSize(); | |
376 streamRec.descriptor.pointer = pFileRead; | |
377 streamRec.read = FPF_SkiaStream_Read; | |
378 streamRec.close = FPF_SkiaStream_Close; | |
379 FXFT_Open_Args args; | |
380 args.flags = FT_OPEN_STREAM; | |
381 args.stream = &streamRec; | |
382 FXFT_Face face; | |
383 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | |
384 return NULL; | |
385 } | |
386 FXFT_Set_Pixel_Sizes(face, 0, 64); | |
387 return face; | |
388 } | |
389 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const CFX_ByteStringC& bsFile, int32_t i
FaceIndex ) | |
390 { | |
391 if (bsFile.IsEmpty()) { | |
392 return NULL; | |
393 } | |
394 if (iFaceIndex < 0) { | |
395 return NULL; | |
396 } | |
397 FXFT_Open_Args args; | |
398 args.flags = FT_OPEN_PATHNAME; | |
399 args.pathname = (FT_String*)bsFile.GetCStr(); | |
400 FXFT_Face face; | |
401 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | |
402 return FALSE; | |
403 } | |
404 FXFT_Set_Pixel_Sizes(face, 0, 64); | |
405 return face; | |
406 } | |
407 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, size_t szBuffer,
int32_t iFaceIndex ) | |
408 { | |
409 if (!pBuffer || szBuffer < 1) { | |
410 return NULL; | |
411 } | |
412 if (iFaceIndex < 0) { | |
413 return NULL; | |
414 } | |
415 FXFT_Open_Args args; | |
416 args.flags = FT_OPEN_MEMORY; | |
417 args.memory_base = pBuffer; | |
418 args.memory_size = szBuffer; | |
419 FXFT_Face face; | |
420 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | |
421 return FALSE; | |
422 } | |
423 FXFT_Set_Pixel_Sizes(face, 0, 64); | |
424 return face; | |
425 } | |
426 void CFPF_SkiaFontMgr::ScanPath(const CFX_ByteStringC& path) | |
427 { | |
428 void *handle = FX_OpenFolder(path.GetCStr()); | |
429 if (!handle) { | |
430 return; | |
431 } | |
432 CFX_ByteString filename; | |
433 FX_BOOL bFolder = FALSE; | |
434 while (FX_GetNextFile(handle, filename, bFolder)) { | |
435 if (bFolder) { | |
436 if (filename == FX_BSTRC(".") || filename == FX_BSTRC("..")) { | |
437 continue; | |
438 } | |
439 } else { | |
440 CFX_ByteString ext = filename.Right(4); | |
441 ext.MakeLower(); | |
442 if (ext != FX_BSTRC(".ttf") && ext != FX_BSTRC(".ttc")) { | |
443 continue; | |
444 } | |
445 } | |
446 CFX_ByteString fullpath = path; | |
447 fullpath += "/"; | |
448 fullpath += filename; | |
449 if (bFolder) { | |
450 ScanPath(fullpath); | |
451 } else { | |
452 ScanFile(fullpath); | |
453 } | |
454 } | |
455 FX_CloseFolder(handle); | |
456 } | |
457 void CFPF_SkiaFontMgr::ScanFile(const CFX_ByteStringC& file) | |
458 { | |
459 FXFT_Face face = GetFontFace(file); | |
460 if (face) { | |
461 CFPF_SkiaPathFont *pFontDesc = new CFPF_SkiaPathFont; | |
462 pFontDesc->SetPath(file.GetCStr()); | |
463 ReportFace(face, pFontDesc); | |
464 m_FontFaces.Add(pFontDesc); | |
465 FXFT_Done_Face(face); | |
466 } | |
467 } | |
468 static const FX_DWORD g_FPFSkiaFontCharsets [] = { | |
469 FPF_SKIACHARSET_Ansi, | 449 FPF_SKIACHARSET_Ansi, |
470 FPF_SKIACHARSET_EeasternEuropean, | 450 FPF_SKIACHARSET_EeasternEuropean, |
471 FPF_SKIACHARSET_Cyrillic, | 451 FPF_SKIACHARSET_Cyrillic, |
472 FPF_SKIACHARSET_Greek, | 452 FPF_SKIACHARSET_Greek, |
473 FPF_SKIACHARSET_Turkish, | 453 FPF_SKIACHARSET_Turkish, |
474 FPF_SKIACHARSET_Hebrew, | 454 FPF_SKIACHARSET_Hebrew, |
475 FPF_SKIACHARSET_Arabic, | 455 FPF_SKIACHARSET_Arabic, |
476 FPF_SKIACHARSET_Baltic, | 456 FPF_SKIACHARSET_Baltic, |
477 0, | 457 0, |
478 0, | 458 0, |
(...skipping 13 matching lines...) Expand all Loading... |
492 0, | 472 0, |
493 0, | 473 0, |
494 0, | 474 0, |
495 0, | 475 0, |
496 0, | 476 0, |
497 0, | 477 0, |
498 0, | 478 0, |
499 FPF_SKIACHARSET_OEM, | 479 FPF_SKIACHARSET_OEM, |
500 FPF_SKIACHARSET_Symbol, | 480 FPF_SKIACHARSET_Symbol, |
501 }; | 481 }; |
502 static FX_DWORD FPF_SkiaGetFaceCharset(TT_OS2 *pOS2) | 482 static FX_DWORD FPF_SkiaGetFaceCharset(TT_OS2* pOS2) { |
503 { | 483 FX_DWORD dwCharset = 0; |
504 FX_DWORD dwCharset = 0; | 484 if (pOS2) { |
505 if (pOS2) { | 485 for (int32_t i = 0; i < 32; i++) { |
506 for (int32_t i = 0; i < 32; i++) { | 486 if (pOS2->ulCodePageRange1 & (1 << i)) { |
507 if (pOS2->ulCodePageRange1 & (1 << i)) { | 487 dwCharset |= g_FPFSkiaFontCharsets[i]; |
508 dwCharset |= g_FPFSkiaFontCharsets[i]; | 488 } |
509 } | |
510 } | |
511 } | 489 } |
512 dwCharset |= FPF_SKIACHARSET_Default; | 490 } |
513 return dwCharset; | 491 dwCharset |= FPF_SKIACHARSET_Default; |
| 492 return dwCharset; |
514 } | 493 } |
515 void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, CFPF_SkiaFontDescriptor *pFont
Desc) | 494 void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, |
516 { | 495 CFPF_SkiaFontDescriptor* pFontDesc) { |
517 if (!face || !pFontDesc) { | 496 if (!face || !pFontDesc) { |
518 return; | 497 return; |
| 498 } |
| 499 pFontDesc->SetFamily(FXFT_Get_Face_Family_Name(face)); |
| 500 if (FXFT_Is_Face_Bold(face)) { |
| 501 pFontDesc->m_dwStyle |= FXFONT_BOLD; |
| 502 } |
| 503 if (FXFT_Is_Face_Italic(face)) { |
| 504 pFontDesc->m_dwStyle |= FXFONT_ITALIC; |
| 505 } |
| 506 if (FT_IS_FIXED_WIDTH(face)) { |
| 507 pFontDesc->m_dwStyle |= FXFONT_FIXED_PITCH; |
| 508 } |
| 509 TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2); |
| 510 if (pOS2) { |
| 511 if (pOS2->ulCodePageRange1 & (1 << 31)) { |
| 512 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; |
519 } | 513 } |
520 pFontDesc->SetFamily(FXFT_Get_Face_Family_Name(face)); | 514 if (pOS2->panose[0] == 2) { |
521 if (FXFT_Is_Face_Bold(face))» { | 515 uint8_t uSerif = pOS2->panose[1]; |
522 pFontDesc->m_dwStyle |= FXFONT_BOLD; | 516 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) { |
| 517 pFontDesc->m_dwStyle |= FXFONT_SERIF; |
| 518 } |
523 } | 519 } |
524 if (FXFT_Is_Face_Italic(face))» { | 520 } |
525 pFontDesc->m_dwStyle |= FXFONT_ITALIC; | 521 if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) { |
526 } | 522 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; |
527 if (FT_IS_FIXED_WIDTH(face))» { | 523 } |
528 pFontDesc->m_dwStyle |= FXFONT_FIXED_PITCH; | 524 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); |
529 } | 525 pFontDesc->m_iFaceIndex = face->face_index; |
530 TT_OS2 *pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2); | 526 pFontDesc->m_iGlyphNum = face->num_glyphs; |
531 if (pOS2) { | |
532 if (pOS2->ulCodePageRange1 & (1 << 31)) { | |
533 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; | |
534 } | |
535 if (pOS2->panose[0] == 2) { | |
536 uint8_t uSerif = pOS2->panose[1]; | |
537 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) { | |
538 pFontDesc->m_dwStyle |= FXFONT_SERIF; | |
539 } | |
540 } | |
541 } | |
542 if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) { | |
543 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; | |
544 } | |
545 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); | |
546 pFontDesc->m_iFaceIndex = face->face_index; | |
547 pFontDesc->m_iGlyphNum = face->num_glyphs; | |
548 } | 527 } |
549 void CFPF_SkiaFontMgr::OutputSystemFonts() | 528 void CFPF_SkiaFontMgr::OutputSystemFonts() {} |
550 { | |
551 } | |
552 #endif | 529 #endif |
OLD | NEW |