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