Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: core/fxge/ge/cfx_fontmapper.cpp

Issue 2239703003: Refactoring cfx_fontmapper (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nit Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/fxge/include/cfx_fontmapper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "core/fxge/include/cfx_fontmapper.h" 7 #include "core/fxge/include/cfx_fontmapper.h"
8 8
9 #include "core/fxge/include/ifx_systemfontinfo.h" 9 #include "core/fxge/include/ifx_systemfontinfo.h"
10 #include "core/fxge/include/fx_font.h" 10 #include "core/fxge/include/fx_font.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 {932, 128}, {936, 134}, {949, 129}, {950, 136}, {1250, 238}, 154 {932, 128}, {936, 134}, {949, 129}, {950, 136}, {1250, 238},
155 {1251, 204}, {1252, 0}, {1253, 161}, {1254, 162}, {1255, 177}, 155 {1251, 204}, {1252, 0}, {1253, 161}, {1254, 162}, {1255, 177},
156 {1256, 178}, {1257, 186}, {1258, 163}, {1361, 130}, {10000, 77}, 156 {1256, 178}, {1257, 186}, {1258, 163}, {1361, 130}, {10000, 77},
157 {10001, 78}, {10002, 81}, {10003, 79}, {10004, 84}, {10005, 83}, 157 {10001, 78}, {10002, 81}, {10003, 79}, {10004, 84}, {10005, 83},
158 {10006, 85}, {10007, 89}, {10008, 80}, {10021, 87}, {10029, 88}, 158 {10006, 85}, {10007, 89}, {10008, 80}, {10021, 87}, {10029, 88},
159 {10081, 86}, 159 {10081, 86},
160 }; 160 };
161 161
162 int CompareFontFamilyString(const void* key, const void* element) { 162 int CompareFontFamilyString(const void* key, const void* element) {
163 CFX_ByteString str_key((const FX_CHAR*)key); 163 CFX_ByteString str_key((const FX_CHAR*)key);
164 if (str_key.Find(((AltFontFamily*)element)->m_pFontName) != -1) { 164 if (str_key.Find(((AltFontFamily*)element)->m_pFontName) != -1)
165 return 0; 165 return 0;
166 }
167 return FXSYS_stricmp((const FX_CHAR*)key, 166 return FXSYS_stricmp((const FX_CHAR*)key,
168 ((AltFontFamily*)element)->m_pFontName); 167 ((AltFontFamily*)element)->m_pFontName);
169 } 168 }
170 169
171 int CompareString(const void* key, const void* element) { 170 int CompareString(const void* key, const void* element) {
172 return FXSYS_stricmp((const FX_CHAR*)key, ((AltFontName*)element)->m_pName); 171 return FXSYS_stricmp((const FX_CHAR*)key, ((AltFontName*)element)->m_pName);
173 } 172 }
174 173
175 CFX_ByteString TT_NormalizeName(const FX_CHAR* family) { 174 CFX_ByteString TT_NormalizeName(const FX_CHAR* family) {
176 CFX_ByteString norm(family); 175 CFX_ByteString norm(family);
177 norm.Remove(' '); 176 norm.Remove(' ');
178 norm.Remove('-'); 177 norm.Remove('-');
179 norm.Remove(','); 178 norm.Remove(',');
180 int pos = norm.Find('+'); 179 int pos = norm.Find('+');
181 if (pos > 0) { 180 if (pos > 0)
182 norm = norm.Left(pos); 181 norm = norm.Left(pos);
183 }
184 norm.MakeLower(); 182 norm.MakeLower();
185 return norm; 183 return norm;
186 } 184 }
187 185
188 uint8_t GetCharsetFromCodePage(uint16_t codepage) { 186 uint8_t GetCharsetFromCodePage(uint16_t codepage) {
189 const CODEPAGE_MAP* pEnd = 187 const CODEPAGE_MAP* pEnd =
190 g_Codepage2CharsetTable + FX_ArraySize(g_Codepage2CharsetTable); 188 g_Codepage2CharsetTable + FX_ArraySize(g_Codepage2CharsetTable);
191 const CODEPAGE_MAP* pCharmap = 189 const CODEPAGE_MAP* pCharmap =
192 std::lower_bound(g_Codepage2CharsetTable, pEnd, codepage, 190 std::lower_bound(g_Codepage2CharsetTable, pEnd, codepage,
193 [](const CODEPAGE_MAP& charset, uint16_t page) { 191 [](const CODEPAGE_MAP& charset, uint16_t page) {
194 return charset.codepage < page; 192 return charset.codepage < page;
195 }); 193 });
196 if (pCharmap < pEnd && codepage == pCharmap->codepage) 194 if (pCharmap < pEnd && codepage == pCharmap->codepage)
197 return pCharmap->charset; 195 return pCharmap->charset;
198 return FXFONT_DEFAULT_CHARSET; 196 return FXFONT_DEFAULT_CHARSET;
199 } 197 }
200 198
201 CFX_ByteString GetFontFamily(CFX_ByteString fontName, int nStyle) { 199 CFX_ByteString GetFontFamily(CFX_ByteString fontName, int nStyle) {
202 if (fontName.Find("Script") >= 0) { 200 if (fontName.Find("Script") >= 0) {
203 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) { 201 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold)
204 fontName = "ScriptMTBold"; 202 fontName = "ScriptMTBold";
205 } else if (fontName.Find("Palace") >= 0) { 203 else if (fontName.Find("Palace") >= 0)
206 fontName = "PalaceScriptMT"; 204 fontName = "PalaceScriptMT";
207 } else if (fontName.Find("French") >= 0) { 205 else if (fontName.Find("French") >= 0)
208 fontName = "FrenchScriptMT"; 206 fontName = "FrenchScriptMT";
209 } else if (fontName.Find("FreeStyle") >= 0) { 207 else if (fontName.Find("FreeStyle") >= 0)
210 fontName = "FreeStyleScript"; 208 fontName = "FreeStyleScript";
211 }
212 return fontName; 209 return fontName;
213 } 210 }
214 AltFontFamily* found = (AltFontFamily*)FXSYS_bsearch( 211 AltFontFamily* found = (AltFontFamily*)FXSYS_bsearch(
215 fontName.c_str(), g_AltFontFamilies, 212 fontName.c_str(), g_AltFontFamilies,
216 sizeof g_AltFontFamilies / sizeof(AltFontFamily), sizeof(AltFontFamily), 213 sizeof g_AltFontFamilies / sizeof(AltFontFamily), sizeof(AltFontFamily),
217 CompareFontFamilyString); 214 CompareFontFamilyString);
218 return found ? CFX_ByteString(found->m_pFontFamily) : fontName; 215 return found ? CFX_ByteString(found->m_pFontFamily) : fontName;
219 } 216 }
220 217
221 CFX_ByteString ParseStyle(const FX_CHAR* pStyle, int iLen, int iIndex) { 218 CFX_ByteString ParseStyle(const FX_CHAR* pStyle, int iLen, int iIndex) {
222 CFX_ByteTextBuf buf; 219 CFX_ByteTextBuf buf;
223 if (!iLen || iLen <= iIndex) { 220 if (!iLen || iLen <= iIndex)
224 return buf.MakeString(); 221 return buf.MakeString();
225 }
226 while (iIndex < iLen) { 222 while (iIndex < iLen) {
227 if (pStyle[iIndex] == ',') { 223 if (pStyle[iIndex] == ',')
228 break; 224 break;
229 }
230 buf.AppendChar(pStyle[iIndex]); 225 buf.AppendChar(pStyle[iIndex]);
231 ++iIndex; 226 ++iIndex;
232 } 227 }
233 return buf.MakeString(); 228 return buf.MakeString();
234 } 229 }
235 230
236 int32_t GetStyleType(const CFX_ByteString& bsStyle, FX_BOOL bRevert) { 231 int32_t GetStyleType(const CFX_ByteString& bsStyle, FX_BOOL bRevert) {
237 int32_t iLen = bsStyle.GetLength(); 232 int32_t iLen = bsStyle.GetLength();
238 if (!iLen) { 233 if (!iLen)
239 return -1; 234 return -1;
240 }
241 int iSize = sizeof(g_FontStyles) / sizeof(FX_FontStyle); 235 int iSize = sizeof(g_FontStyles) / sizeof(FX_FontStyle);
242 const FX_FontStyle* pStyle = nullptr; 236 const FX_FontStyle* pStyle = nullptr;
243 for (int i = iSize - 1; i >= 0; --i) { 237 for (int i = iSize - 1; i >= 0; --i) {
244 pStyle = g_FontStyles + i; 238 pStyle = g_FontStyles + i;
245 if (!pStyle || pStyle->len > iLen) { 239 if (!pStyle || pStyle->len > iLen)
246 continue; 240 continue;
247 }
248 if (!bRevert) { 241 if (!bRevert) {
249 if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0) { 242 if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0)
250 return i; 243 return i;
251 }
252 } else { 244 } else {
253 if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0) { 245 if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0)
254 return i; 246 return i;
255 }
256 } 247 }
257 } 248 }
258 return -1; 249 return -1;
259 } 250 }
260 251
261 FX_BOOL CheckSupportThirdPartFont(CFX_ByteString name, int& PitchFamily) { 252 FX_BOOL CheckSupportThirdPartFont(CFX_ByteString name, int& PitchFamily) {
262 if (name == "MyriadPro") { 253 if (name == "MyriadPro") {
263 PitchFamily &= ~FXFONT_FF_ROMAN; 254 PitchFamily &= ~FXFONT_FF_ROMAN;
264 return TRUE; 255 return TRUE;
265 } 256 }
266 return FALSE; 257 return FALSE;
267 } 258 }
268 259
260 void UpdatePitchFamily(uint32_t flags, int& PitchFamily) {
261 if (flags & FXFONT_SERIF)
262 PitchFamily |= FXFONT_FF_ROMAN;
263 if (flags & FXFONT_SCRIPT)
264 PitchFamily |= FXFONT_FF_SCRIPT;
265 if (flags & FXFONT_FIXED_PITCH)
266 PitchFamily |= FXFONT_FF_FIXEDPITCH;
267 }
268
269 } // namespace 269 } // namespace
270 270
271 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) 271 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr)
272 : m_bListLoaded(FALSE), m_pFontMgr(mgr) { 272 : m_bListLoaded(FALSE), m_pFontMgr(mgr) {
273 m_MMFaces[0] = nullptr; 273 m_MMFaces[0] = nullptr;
274 m_MMFaces[1] = nullptr; 274 m_MMFaces[1] = nullptr;
275 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces)); 275 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces));
276 } 276 }
277 277
278 CFX_FontMapper::~CFX_FontMapper() { 278 CFX_FontMapper::~CFX_FontMapper() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 m_pFontInfo->EnumFontList(this); 355 m_pFontInfo->EnumFontList(this);
356 m_bListLoaded = TRUE; 356 m_bListLoaded = TRUE;
357 } 357 }
358 358
359 CFX_ByteString CFX_FontMapper::MatchInstalledFonts( 359 CFX_ByteString CFX_FontMapper::MatchInstalledFonts(
360 const CFX_ByteString& norm_name) { 360 const CFX_ByteString& norm_name) {
361 LoadInstalledFonts(); 361 LoadInstalledFonts();
362 int i; 362 int i;
363 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) { 363 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) {
364 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str()); 364 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str());
365 if (norm1 == norm_name) { 365 if (norm1 == norm_name)
366 break; 366 break;
367 }
368 } 367 }
369 if (i < 0) { 368 if (i < 0)
370 return CFX_ByteString(); 369 return CFX_ByteString();
371 }
372 CFX_ByteString match = m_InstalledTTFonts[i]; 370 CFX_ByteString match = m_InstalledTTFonts[i];
373 if (match[0] == ' ') { 371 if (match[0] == ' ')
374 match = m_InstalledTTFonts[i + 1]; 372 match = m_InstalledTTFonts[i + 1];
375 }
376 return match; 373 return match;
377 } 374 }
378 375
379 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, 376 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont,
380 int iBaseFont, 377 int iBaseFont,
381 int italic_angle, 378 int italic_angle,
382 int weight, 379 int weight,
383 int picthfamily) { 380 int picthfamily) {
384 if (iBaseFont < 12) { 381 if (iBaseFont < 12) {
385 if (m_FoxitFaces[iBaseFont]) { 382 if (m_FoxitFaces[iBaseFont])
386 return m_FoxitFaces[iBaseFont]; 383 return m_FoxitFaces[iBaseFont];
387 }
388 const uint8_t* pFontData = nullptr; 384 const uint8_t* pFontData = nullptr;
389 uint32_t size = 0; 385 uint32_t size = 0;
390 if (m_pFontMgr->GetBuiltinFont(iBaseFont, &pFontData, &size)) { 386 if (m_pFontMgr->GetBuiltinFont(iBaseFont, &pFontData, &size)) {
391 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 387 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
392 return m_FoxitFaces[iBaseFont]; 388 return m_FoxitFaces[iBaseFont];
393 } 389 }
394 } 390 }
395 pSubstFont->m_SubstFlags |= FXFONT_SUBST_MM; 391 pSubstFont->m_SubstFlags |= FXFONT_SUBST_MM;
396 pSubstFont->m_ItalicAngle = italic_angle; 392 pSubstFont->m_ItalicAngle = italic_angle;
397 if (weight) { 393 if (weight)
398 pSubstFont->m_Weight = weight; 394 pSubstFont->m_Weight = weight;
399 }
400 if (picthfamily & FXFONT_FF_ROMAN) { 395 if (picthfamily & FXFONT_FF_ROMAN) {
401 pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5; 396 pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5;
402 pSubstFont->m_Family = "Chrome Serif"; 397 pSubstFont->m_Family = "Chrome Serif";
403 if (m_MMFaces[1]) { 398 if (m_MMFaces[1])
404 return m_MMFaces[1]; 399 return m_MMFaces[1];
405 }
406 const uint8_t* pFontData = nullptr; 400 const uint8_t* pFontData = nullptr;
407 uint32_t size = 0; 401 uint32_t size = 0;
408 m_pFontMgr->GetBuiltinFont(14, &pFontData, &size); 402 m_pFontMgr->GetBuiltinFont(14, &pFontData, &size);
409 m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 403 m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
410 return m_MMFaces[1]; 404 return m_MMFaces[1];
411 } 405 }
412 pSubstFont->m_Family = "Chrome Sans"; 406 pSubstFont->m_Family = "Chrome Sans";
413 if (m_MMFaces[0]) { 407 if (m_MMFaces[0])
414 return m_MMFaces[0]; 408 return m_MMFaces[0];
415 }
416 const uint8_t* pFontData = nullptr; 409 const uint8_t* pFontData = nullptr;
417 uint32_t size = 0; 410 uint32_t size = 0;
418 m_pFontMgr->GetBuiltinFont(15, &pFontData, &size); 411 m_pFontMgr->GetBuiltinFont(15, &pFontData, &size);
419 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 412 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
420 return m_MMFaces[0]; 413 return m_MMFaces[0];
421 } 414 }
422 415
423 FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, 416 FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
424 FX_BOOL bTrueType, 417 FX_BOOL bTrueType,
425 uint32_t flags, 418 uint32_t flags,
426 int weight, 419 int weight,
427 int italic_angle, 420 int italic_angle,
428 int WindowCP, 421 int WindowCP,
429 CFX_SubstFont* pSubstFont) { 422 CFX_SubstFont* pSubstFont) {
430 if (!(flags & FXFONT_USEEXTERNATTR)) { 423 if (!(flags & FXFONT_USEEXTERNATTR)) {
431 weight = FXFONT_FW_NORMAL; 424 weight = FXFONT_FW_NORMAL;
432 italic_angle = 0; 425 italic_angle = 0;
433 } 426 }
434 CFX_ByteString SubstName = name; 427 CFX_ByteString SubstName = name;
435 SubstName.Remove(0x20); 428 SubstName.Remove(0x20);
436 if (bTrueType) { 429 if (bTrueType && name[0] == '@')
437 if (name[0] == '@') { 430 SubstName = name.Mid(1);
438 SubstName = name.Mid(1);
439 }
440 }
441 PDF_GetStandardFontName(&SubstName); 431 PDF_GetStandardFontName(&SubstName);
442 if (SubstName == "Symbol" && !bTrueType) { 432 if (SubstName == "Symbol" && !bTrueType) {
443 pSubstFont->m_Family = "Chrome Symbol"; 433 pSubstFont->m_Family = "Chrome Symbol";
444 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; 434 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET;
445 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; 435 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
446 if (m_FoxitFaces[12]) { 436 if (m_FoxitFaces[12])
447 return m_FoxitFaces[12]; 437 return m_FoxitFaces[12];
448 }
449 const uint8_t* pFontData = nullptr; 438 const uint8_t* pFontData = nullptr;
450 uint32_t size = 0; 439 uint32_t size = 0;
451 m_pFontMgr->GetBuiltinFont(12, &pFontData, &size); 440 m_pFontMgr->GetBuiltinFont(12, &pFontData, &size);
452 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 441 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
453 return m_FoxitFaces[12]; 442 return m_FoxitFaces[12];
454 } 443 }
455 if (SubstName == "ZapfDingbats") { 444 if (SubstName == "ZapfDingbats") {
456 pSubstFont->m_Family = "Chrome Dingbats"; 445 pSubstFont->m_Family = "Chrome Dingbats";
457 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; 446 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET;
458 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; 447 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
459 if (m_FoxitFaces[13]) { 448 if (m_FoxitFaces[13])
460 return m_FoxitFaces[13]; 449 return m_FoxitFaces[13];
461 }
462 const uint8_t* pFontData = nullptr; 450 const uint8_t* pFontData = nullptr;
463 uint32_t size = 0; 451 uint32_t size = 0;
464 m_pFontMgr->GetBuiltinFont(13, &pFontData, &size); 452 m_pFontMgr->GetBuiltinFont(13, &pFontData, &size);
465 m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 453 m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
466 return m_FoxitFaces[13]; 454 return m_FoxitFaces[13];
467 } 455 }
468 int iBaseFont = 0; 456 int iBaseFont = 0;
469 CFX_ByteString family, style; 457 CFX_ByteString family, style;
470 FX_BOOL bHasComma = FALSE; 458 FX_BOOL bHasComma = FALSE;
471 FX_BOOL bHasHypen = FALSE; 459 FX_BOOL bHasHypen = FALSE;
472 int find = SubstName.Find(",", 0); 460 int find = SubstName.Find(",", 0);
473 if (find >= 0) { 461 if (find >= 0) {
474 family = SubstName.Left(find); 462 family = SubstName.Left(find);
475 PDF_GetStandardFontName(&family); 463 PDF_GetStandardFontName(&family);
476 style = SubstName.Mid(find + 1); 464 style = SubstName.Mid(find + 1);
477 bHasComma = TRUE; 465 bHasComma = TRUE;
478 } else { 466 } else {
479 family = SubstName; 467 family = SubstName;
480 } 468 }
481 for (; iBaseFont < 12; iBaseFont++) 469 for (; iBaseFont < 12; iBaseFont++) {
482 if (family == CFX_ByteStringC(g_Base14FontNames[iBaseFont])) { 470 if (family == CFX_ByteStringC(g_Base14FontNames[iBaseFont]))
483 break; 471 break;
484 } 472 }
485 int PitchFamily = 0; 473 int PitchFamily = 0;
486 FX_BOOL bItalic = FALSE; 474 FX_BOOL bItalic = FALSE;
487 uint32_t nStyle = 0; 475 uint32_t nStyle = 0;
488 FX_BOOL bStyleAvail = FALSE; 476 FX_BOOL bStyleAvail = FALSE;
489 if (iBaseFont < 12) { 477 if (iBaseFont < 12) {
490 family = g_Base14FontNames[iBaseFont]; 478 if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2)
491 if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2) {
492 nStyle |= FX_FONT_STYLE_Bold; 479 nStyle |= FX_FONT_STYLE_Bold;
493 } 480 if ((iBaseFont % 4) / 2)
494 if ((iBaseFont % 4) / 2) {
495 nStyle |= FX_FONT_STYLE_Italic; 481 nStyle |= FX_FONT_STYLE_Italic;
496 } 482 if (iBaseFont < 4)
497 if (iBaseFont < 4) {
498 PitchFamily |= FXFONT_FF_FIXEDPITCH; 483 PitchFamily |= FXFONT_FF_FIXEDPITCH;
499 } 484 if (iBaseFont >= 8)
500 if (iBaseFont >= 8) {
501 PitchFamily |= FXFONT_FF_ROMAN; 485 PitchFamily |= FXFONT_FF_ROMAN;
502 }
503 } else { 486 } else {
504 if (!bHasComma) { 487 if (!bHasComma) {
505 find = family.ReverseFind('-'); 488 find = family.ReverseFind('-');
506 if (find >= 0) { 489 if (find >= 0) {
507 style = family.Mid(find + 1); 490 style = family.Mid(find + 1);
508 family = family.Left(find); 491 family = family.Left(find);
509 bHasHypen = TRUE; 492 bHasHypen = TRUE;
510 } 493 }
511 } 494 }
512 if (!bHasHypen) { 495 if (!bHasHypen) {
513 int nLen = family.GetLength(); 496 int nLen = family.GetLength();
514 int32_t nRet = GetStyleType(family, TRUE); 497 int32_t nRet = GetStyleType(family, TRUE);
515 if (nRet > -1) { 498 if (nRet > -1) {
516 family = family.Left(nLen - g_FontStyles[nRet].len); 499 family = family.Left(nLen - g_FontStyles[nRet].len);
517 if (nRet == 0) { 500 if (nRet == 0)
518 nStyle |= FX_FONT_STYLE_Bold; 501 nStyle |= FX_FONT_STYLE_Bold;
519 } 502 if (nRet == 1)
520 if (nRet == 1) {
521 nStyle |= FX_FONT_STYLE_Italic; 503 nStyle |= FX_FONT_STYLE_Italic;
522 } 504 if (nRet == 2)
523 if (nRet == 2) {
524 nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic); 505 nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic);
525 }
526 } 506 }
527 } 507 }
528 if (flags & FXFONT_SERIF) { 508 UpdatePitchFamily(flags, PitchFamily);
529 PitchFamily |= FXFONT_FF_ROMAN;
530 }
531 if (flags & FXFONT_SCRIPT) {
532 PitchFamily |= FXFONT_FF_SCRIPT;
533 }
534 if (flags & FXFONT_FIXED_PITCH) {
535 PitchFamily |= FXFONT_FF_FIXEDPITCH;
536 }
537 } 509 }
538 if (!style.IsEmpty()) { 510 if (!style.IsEmpty()) {
539 int nLen = style.GetLength(); 511 int nLen = style.GetLength();
540 const FX_CHAR* pStyle = style.c_str(); 512 const FX_CHAR* pStyle = style.c_str();
541 int i = 0; 513 int i = 0;
542 FX_BOOL bFirstItem = TRUE; 514 FX_BOOL bFirstItem = TRUE;
543 CFX_ByteString buf; 515 CFX_ByteString buf;
544 while (i < nLen) { 516 while (i < nLen) {
545 buf = ParseStyle(pStyle, nLen, i); 517 buf = ParseStyle(pStyle, nLen, i);
546 int32_t nRet = GetStyleType(buf, FALSE); 518 int32_t nRet = GetStyleType(buf, FALSE);
547 if ((i && !bStyleAvail) || (!i && nRet < 0)) { 519 if ((i && !bStyleAvail) || (!i && nRet < 0)) {
548 family = SubstName; 520 family = SubstName;
549 iBaseFont = 12; 521 iBaseFont = 12;
550 break; 522 break;
551 } else if (nRet >= 0) { 523 } else if (nRet >= 0) {
552 bStyleAvail = TRUE; 524 bStyleAvail = TRUE;
553 } 525 }
554 if (nRet == 0) { 526 if (nRet == 0) {
555 if (nStyle & FX_FONT_STYLE_Bold) { 527 if (nStyle & FX_FONT_STYLE_Bold)
556 nStyle |= FX_FONT_STYLE_BoldBold; 528 nStyle |= FX_FONT_STYLE_BoldBold;
557 } else { 529 else
558 nStyle |= FX_FONT_STYLE_Bold; 530 nStyle |= FX_FONT_STYLE_Bold;
559 }
560 bFirstItem = FALSE; 531 bFirstItem = FALSE;
561 } 532 }
562 if (nRet == 1) { 533 if (nRet == 1) {
563 if (bFirstItem) { 534 if (bFirstItem) {
564 nStyle |= FX_FONT_STYLE_Italic; 535 nStyle |= FX_FONT_STYLE_Italic;
565 } else { 536 } else {
566 family = SubstName; 537 family = SubstName;
567 iBaseFont = 12; 538 iBaseFont = 12;
568 } 539 }
569 break; 540 break;
570 } 541 }
571 if (nRet == 2) { 542 if (nRet == 2) {
572 nStyle |= FX_FONT_STYLE_Italic; 543 nStyle |= FX_FONT_STYLE_Italic;
573 if (nStyle & FX_FONT_STYLE_Bold) { 544 if (nStyle & FX_FONT_STYLE_Bold)
574 nStyle |= FX_FONT_STYLE_BoldBold; 545 nStyle |= FX_FONT_STYLE_BoldBold;
575 } else { 546 else
576 nStyle |= FX_FONT_STYLE_Bold; 547 nStyle |= FX_FONT_STYLE_Bold;
577 }
578 bFirstItem = FALSE; 548 bFirstItem = FALSE;
579 } 549 }
580 i += buf.GetLength() + 1; 550 i += buf.GetLength() + 1;
581 } 551 }
582 } 552 }
583 weight = weight ? weight : FXFONT_FW_NORMAL; 553 weight = weight ? weight : FXFONT_FW_NORMAL;
584 int old_weight = weight; 554 int old_weight = weight;
585 if (nStyle) { 555 if (nStyle) {
586 weight = 556 weight =
587 nStyle & FX_FONT_STYLE_BoldBold 557 nStyle & FX_FONT_STYLE_BoldBold
588 ? 900 558 ? 900
589 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); 559 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL);
590 } 560 }
591 if (nStyle & FX_FONT_STYLE_Italic) { 561 if (nStyle & FX_FONT_STYLE_Italic)
592 bItalic = TRUE; 562 bItalic = TRUE;
593 }
594 FX_BOOL bCJK = FALSE; 563 FX_BOOL bCJK = FALSE;
595 int iExact = 0; 564 int iExact = 0;
596 int Charset = FXFONT_ANSI_CHARSET; 565 int Charset = FXFONT_ANSI_CHARSET;
597 if (WindowCP) { 566 if (WindowCP)
598 Charset = GetCharsetFromCodePage(WindowCP); 567 Charset = GetCharsetFromCodePage(WindowCP);
599 } else if (iBaseFont == 12 && (flags & FXFONT_SYMBOLIC)) { 568 else if (iBaseFont == 12 && (flags & FXFONT_SYMBOLIC))
600 Charset = FXFONT_SYMBOL_CHARSET; 569 Charset = FXFONT_SYMBOL_CHARSET;
601 }
602 if (Charset == FXFONT_SHIFTJIS_CHARSET || Charset == FXFONT_GB2312_CHARSET || 570 if (Charset == FXFONT_SHIFTJIS_CHARSET || Charset == FXFONT_GB2312_CHARSET ||
603 Charset == FXFONT_HANGEUL_CHARSET || 571 Charset == FXFONT_HANGEUL_CHARSET ||
604 Charset == FXFONT_CHINESEBIG5_CHARSET) { 572 Charset == FXFONT_CHINESEBIG5_CHARSET) {
605 bCJK = TRUE; 573 bCJK = TRUE;
606 } 574 }
607 if (!m_pFontInfo) { 575 if (!m_pFontInfo) {
608 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; 576 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
609 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, 577 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight,
610 PitchFamily); 578 PitchFamily);
611 } 579 }
612 family = GetFontFamily(family, nStyle); 580 family = GetFontFamily(family, nStyle);
613 CFX_ByteString match = MatchInstalledFonts(TT_NormalizeName(family.c_str())); 581 CFX_ByteString match = MatchInstalledFonts(TT_NormalizeName(family.c_str()));
614 if (match.IsEmpty() && family != SubstName && 582 if (match.IsEmpty() && family != SubstName &&
615 (!bHasComma && (!bHasHypen || (bHasHypen && !bStyleAvail)))) { 583 (!bHasComma && (!bHasHypen || (bHasHypen && !bStyleAvail)))) {
616 match = MatchInstalledFonts(TT_NormalizeName(SubstName.c_str())); 584 match = MatchInstalledFonts(TT_NormalizeName(SubstName.c_str()));
617 } 585 }
618 if (match.IsEmpty() && iBaseFont >= 12) { 586 if (match.IsEmpty() && iBaseFont >= 12) {
619 if (!bCJK) { 587 if (!bCJK) {
620 if (!CheckSupportThirdPartFont(family, PitchFamily)) { 588 if (!CheckSupportThirdPartFont(family, PitchFamily)) {
621 if (italic_angle != 0) { 589 if (italic_angle != 0)
622 bItalic = TRUE; 590 bItalic = TRUE;
623 } else { 591 else
624 bItalic = FALSE; 592 bItalic = FALSE;
625 }
626 weight = old_weight; 593 weight = old_weight;
627 } 594 }
628 } else { 595 } else {
629 pSubstFont->m_bSubstCJK = true; 596 pSubstFont->m_bSubstCJK = true;
630 if (nStyle) { 597 if (nStyle)
631 pSubstFont->m_WeightCJK = weight; 598 pSubstFont->m_WeightCJK = weight;
632 } else { 599 else
633 pSubstFont->m_WeightCJK = FXFONT_FW_NORMAL; 600 pSubstFont->m_WeightCJK = FXFONT_FW_NORMAL;
634 } 601 if (nStyle & FX_FONT_STYLE_Italic)
635 if (nStyle & FX_FONT_STYLE_Italic) {
636 pSubstFont->m_bItalicCJK = true; 602 pSubstFont->m_bItalicCJK = true;
637 }
638 } 603 }
639 } else { 604 } else {
640 italic_angle = 0; 605 italic_angle = 0;
641 weight = 606 weight =
642 nStyle & FX_FONT_STYLE_BoldBold 607 nStyle & FX_FONT_STYLE_BoldBold
643 ? 900 608 ? 900
644 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); 609 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL);
645 } 610 }
646 if (!match.IsEmpty() || iBaseFont < 12) { 611 if (!match.IsEmpty() || iBaseFont < 12) {
647 if (!match.IsEmpty()) { 612 if (!match.IsEmpty())
648 family = match; 613 family = match;
649 }
650 if (iBaseFont < 12) { 614 if (iBaseFont < 12) {
651 if (nStyle && !(iBaseFont % 4)) { 615 if (nStyle && !(iBaseFont % 4)) {
652 if ((nStyle & 0x3) == 1) { 616 if ((nStyle & 0x3) == 1)
653 iBaseFont += 1; 617 iBaseFont += 1;
654 } 618 if ((nStyle & 0x3) == 2)
655 if ((nStyle & 0x3) == 2) {
656 iBaseFont += 3; 619 iBaseFont += 3;
657 } 620 if ((nStyle & 0x3) == 3)
658 if ((nStyle & 0x3) == 3) {
659 iBaseFont += 2; 621 iBaseFont += 2;
660 }
661 } 622 }
662 family = g_Base14FontNames[iBaseFont]; 623 family = g_Base14FontNames[iBaseFont];
663 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; 624 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
664 } 625 }
665 } else { 626 } else {
666 if (flags & FXFONT_ITALIC) { 627 if (flags & FXFONT_ITALIC)
667 bItalic = TRUE; 628 bItalic = TRUE;
668 }
669 } 629 }
670 iExact = !match.IsEmpty(); 630 iExact = !match.IsEmpty();
671 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, 631 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily,
672 family.c_str(), iExact); 632 family.c_str(), iExact);
673 if (iExact) { 633 if (iExact)
674 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; 634 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT;
675 }
676 if (!hFont) { 635 if (!hFont) {
677 #ifdef PDF_ENABLE_XFA 636 #ifdef PDF_ENABLE_XFA
678 if (flags & FXFONT_EXACTMATCH) { 637 if (flags & FXFONT_EXACTMATCH)
679 return nullptr; 638 return nullptr;
680 }
681 #endif // PDF_ENABLE_XFA 639 #endif // PDF_ENABLE_XFA
682 if (bCJK) { 640 if (bCJK) {
683 if (italic_angle != 0) { 641 if (italic_angle != 0)
684 bItalic = TRUE; 642 bItalic = TRUE;
685 } else { 643 else
686 bItalic = FALSE; 644 bItalic = FALSE;
687 }
688 weight = old_weight; 645 weight = old_weight;
689 } 646 }
690 if (!match.IsEmpty()) { 647 if (!match.IsEmpty()) {
691 hFont = m_pFontInfo->GetFont(match.c_str()); 648 hFont = m_pFontInfo->GetFont(match.c_str());
692 if (!hFont) { 649 if (!hFont) {
693 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, 650 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight,
694 PitchFamily); 651 PitchFamily);
695 } 652 }
696 } else { 653 } else {
697 if (Charset == FXFONT_SYMBOL_CHARSET) { 654 if (Charset == FXFONT_SYMBOL_CHARSET) {
698 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ 655 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \
699 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ 656 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_
700 if (SubstName == "Symbol") { 657 if (SubstName == "Symbol") {
701 pSubstFont->m_Family = "Chrome Symbol"; 658 pSubstFont->m_Family = "Chrome Symbol";
702 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; 659 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
703 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; 660 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET;
704 if (m_FoxitFaces[12]) { 661 if (m_FoxitFaces[12])
705 return m_FoxitFaces[12]; 662 return m_FoxitFaces[12];
706 }
707 const uint8_t* pFontData = nullptr; 663 const uint8_t* pFontData = nullptr;
708 uint32_t size = 0; 664 uint32_t size = 0;
709 m_pFontMgr->GetBuiltinFont(12, &pFontData, &size); 665 m_pFontMgr->GetBuiltinFont(12, &pFontData, &size);
710 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 666 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
711 return m_FoxitFaces[12]; 667 return m_FoxitFaces[12];
712 } 668 }
713 #endif 669 #endif
714 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; 670 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL;
715 return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMBOLIC, 671 return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMBOLIC,
716 weight, italic_angle, 0, pSubstFont); 672 weight, italic_angle, 0, pSubstFont);
(...skipping 14 matching lines...) Expand all
731 PitchFamily); 687 PitchFamily);
732 } 688 }
733 hFont = m_pFontInfo->GetFont(it->name.c_str()); 689 hFont = m_pFontInfo->GetFont(it->name.c_str());
734 } 690 }
735 } 691 }
736 pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont); 692 pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont);
737 if (!hFont) 693 if (!hFont)
738 return nullptr; 694 return nullptr;
739 695
740 m_pFontInfo->GetFaceName(hFont, SubstName); 696 m_pFontInfo->GetFaceName(hFont, SubstName);
741 if (Charset == FXFONT_DEFAULT_CHARSET) { 697 if (Charset == FXFONT_DEFAULT_CHARSET)
742 m_pFontInfo->GetFontCharset(hFont, Charset); 698 m_pFontInfo->GetFontCharset(hFont, Charset);
743 }
744 uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, kTableTTCF, nullptr, 0); 699 uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, kTableTTCF, nullptr, 0);
745 uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0); 700 uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0);
746 if (font_size == 0 && ttc_size == 0) { 701 if (font_size == 0 && ttc_size == 0) {
747 m_pFontInfo->DeleteFont(hFont); 702 m_pFontInfo->DeleteFont(hFont);
748 return nullptr; 703 return nullptr;
749 } 704 }
750 FXFT_Face face = nullptr; 705 FXFT_Face face = nullptr;
751 if (ttc_size) { 706 if (ttc_size)
752 uint8_t temp[1024]; 707 face = GetCachedTTCFace(hFont, kTableTTCF, ttc_size, font_size);
753 m_pFontInfo->GetFontData(hFont, kTableTTCF, temp, 1024); 708 else
754 uint32_t checksum = 0; 709 face = GetCachedFace(hFont, SubstName, weight, bItalic, font_size);
755 for (int i = 0; i < 256; i++) {
756 checksum += ((uint32_t*)temp)[i];
757 }
758 uint8_t* pFontData;
759 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum,
760 ttc_size - font_size, pFontData);
761 if (!face) {
762 pFontData = FX_Alloc(uint8_t, ttc_size);
763 m_pFontInfo->GetFontData(hFont, kTableTTCF, pFontData, ttc_size);
764 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData,
765 ttc_size, ttc_size - font_size);
766 }
767 } else {
768 uint8_t* pFontData;
769 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
770 if (!face) {
771 pFontData = FX_Alloc(uint8_t, font_size);
772 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
773 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData,
774 font_size,
775 m_pFontInfo->GetFaceIndex(hFont));
776 }
777 }
778 if (!face) { 710 if (!face) {
779 m_pFontInfo->DeleteFont(hFont); 711 m_pFontInfo->DeleteFont(hFont);
780 return nullptr; 712 return nullptr;
781 } 713 }
782 pSubstFont->m_Family = SubstName; 714 pSubstFont->m_Family = SubstName;
783 pSubstFont->m_Charset = Charset; 715 pSubstFont->m_Charset = Charset;
784 FX_BOOL bNeedUpdateWeight = FALSE; 716 FX_BOOL bNeedUpdateWeight = FALSE;
785 if (FXFT_Is_Face_Bold(face)) { 717 if (FXFT_Is_Face_Bold(face)) {
786 if (weight == FXFONT_FW_BOLD) { 718 if (weight == FXFONT_FW_BOLD)
787 bNeedUpdateWeight = FALSE; 719 bNeedUpdateWeight = FALSE;
788 } else { 720 else
789 bNeedUpdateWeight = TRUE; 721 bNeedUpdateWeight = TRUE;
790 }
791 } else { 722 } else {
792 if (weight == FXFONT_FW_NORMAL) { 723 if (weight == FXFONT_FW_NORMAL)
793 bNeedUpdateWeight = FALSE; 724 bNeedUpdateWeight = FALSE;
794 } else { 725 else
795 bNeedUpdateWeight = TRUE; 726 bNeedUpdateWeight = TRUE;
796 }
797 } 727 }
798 if (bNeedUpdateWeight) { 728 if (bNeedUpdateWeight)
799 pSubstFont->m_Weight = weight; 729 pSubstFont->m_Weight = weight;
800 }
801 if (bItalic && !FXFT_Is_Face_Italic(face)) { 730 if (bItalic && !FXFT_Is_Face_Italic(face)) {
802 if (italic_angle == 0) { 731 if (italic_angle == 0)
803 italic_angle = -12; 732 italic_angle = -12;
804 } else if (FXSYS_abs(italic_angle) < 5) { 733 else if (FXSYS_abs(italic_angle) < 5)
805 italic_angle = 0; 734 italic_angle = 0;
806 }
807 pSubstFont->m_ItalicAngle = italic_angle; 735 pSubstFont->m_ItalicAngle = italic_angle;
808 } 736 }
809 m_pFontInfo->DeleteFont(hFont); 737 m_pFontInfo->DeleteFont(hFont);
810 return face; 738 return face;
811 } 739 }
740
812 #ifdef PDF_ENABLE_XFA 741 #ifdef PDF_ENABLE_XFA
813 FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(uint32_t dwUnicode, 742 FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(uint32_t dwUnicode,
814 uint32_t flags, 743 uint32_t flags,
815 int weight, 744 int weight,
816 int italic_angle) { 745 int italic_angle) {
817 if (!m_pFontInfo) 746 if (!m_pFontInfo)
818 return nullptr; 747 return nullptr;
819 748
820 FX_BOOL bItalic = (flags & FXFONT_ITALIC) != 0; 749 FX_BOOL bItalic = (flags & FXFONT_ITALIC) != 0;
821 int PitchFamily = 0; 750 int PitchFamily = 0;
822 if (flags & FXFONT_SERIF) { 751 UpdatePitchFamily(flags, PitchFamily);
823 PitchFamily |= FXFONT_FF_ROMAN;
824 }
825 if (flags & FXFONT_SCRIPT) {
826 PitchFamily |= FXFONT_FF_SCRIPT;
827 }
828 if (flags & FXFONT_FIXED_PITCH) {
829 PitchFamily |= FXFONT_FF_FIXEDPITCH;
830 }
831 void* hFont = 752 void* hFont =
832 m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily); 753 m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily);
833 if (!hFont) 754 if (!hFont)
834 return nullptr; 755 return nullptr;
835 756
836 uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, nullptr, 0); 757 uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, nullptr, 0);
837 uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0); 758 uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0);
838 if (font_size == 0 && ttc_size == 0) { 759 if (font_size == 0 && ttc_size == 0) {
839 m_pFontInfo->DeleteFont(hFont); 760 m_pFontInfo->DeleteFont(hFont);
840 return nullptr; 761 return nullptr;
841 } 762 }
842 FXFT_Face face = nullptr; 763 FXFT_Face face = nullptr;
843 if (ttc_size) { 764 if (ttc_size) {
844 uint8_t temp[1024]; 765 face = GetCachedTTCFace(hFont, 0x74746366, ttc_size, font_size);
845 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024);
846 uint32_t checksum = 0;
847 for (int i = 0; i < 256; i++) {
848 checksum += ((uint32_t*)temp)[i];
849 }
850 uint8_t* pFontData;
851 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum,
852 ttc_size - font_size, pFontData);
853 if (!face) {
854 pFontData = FX_Alloc(uint8_t, ttc_size);
855 if (pFontData) {
856 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size);
857 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData,
858 ttc_size, ttc_size - font_size);
859 }
860 }
861 } else { 766 } else {
862 CFX_ByteString SubstName; 767 CFX_ByteString SubstName;
863 m_pFontInfo->GetFaceName(hFont, SubstName); 768 m_pFontInfo->GetFaceName(hFont, SubstName);
864 uint8_t* pFontData; 769 face = GetCachedFace(hFont, SubstName, weight, bItalic, font_size);
865 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
866 if (!face) {
867 pFontData = FX_Alloc(uint8_t, font_size);
868 if (!pFontData) {
869 m_pFontInfo->DeleteFont(hFont);
870 return nullptr;
871 }
872 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
873 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData,
874 font_size,
875 m_pFontInfo->GetFaceIndex(hFont));
876 }
877 } 770 }
878 m_pFontInfo->DeleteFont(hFont); 771 m_pFontInfo->DeleteFont(hFont);
879 return face; 772 return face;
880 } 773 }
881 #endif // PDF_ENABLE_XFA 774 #endif // PDF_ENABLE_XFA
882 775
883 int CFX_FontMapper::GetFaceSize() const { 776 int CFX_FontMapper::GetFaceSize() const {
884 return pdfium::CollectionSize<int>(m_FaceArray); 777 return pdfium::CollectionSize<int>(m_FaceArray);
885 } 778 }
886 779
887 FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const { 780 FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const {
888 for (size_t i = 0; i < MM_FACE_COUNT; ++i) { 781 for (size_t i = 0; i < MM_FACE_COUNT; ++i) {
889 if (m_MMFaces[i] == face) { 782 if (m_MMFaces[i] == face)
890 return TRUE; 783 return TRUE;
891 }
892 } 784 }
893 for (size_t i = 0; i < FOXIT_FACE_COUNT; ++i) { 785 for (size_t i = 0; i < FOXIT_FACE_COUNT; ++i) {
894 if (m_FoxitFaces[i] == face) { 786 if (m_FoxitFaces[i] == face)
895 return TRUE; 787 return TRUE;
896 }
897 } 788 }
898 return FALSE; 789 return FALSE;
899 } 790 }
900 791
792 FXFT_Face CFX_FontMapper::GetCachedTTCFace(void* hFont,
793 const uint32_t tableTTCF,
794 uint32_t ttc_size,
795 uint32_t font_size) {
796 FXFT_Face face;
797 uint8_t temp[1024];
798 m_pFontInfo->GetFontData(hFont, tableTTCF, temp, 1024);
799 uint32_t checksum = 0;
800 for (int i = 0; i < 256; i++)
801 checksum += ((uint32_t*)temp)[i];
802 uint8_t* pFontData;
803 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_size,
804 pFontData);
805 if (!face) {
806 pFontData = FX_Alloc(uint8_t, ttc_size);
807 m_pFontInfo->GetFontData(hFont, tableTTCF, pFontData, ttc_size);
808 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size,
809 ttc_size - font_size);
810 }
811 return face;
812 }
813
814 FXFT_Face CFX_FontMapper::GetCachedFace(void* hFont,
815 CFX_ByteString SubstName,
816 int weight,
817 FX_BOOL bItalic,
818 uint32_t font_size) {
819 FXFT_Face face;
820 uint8_t* pFontData;
821 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
822 if (!face) {
823 pFontData = FX_Alloc(uint8_t, font_size);
824 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
825 face =
826 m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData,
827 font_size, m_pFontInfo->GetFaceIndex(hFont));
828 }
829 return face;
830 }
831
901 int PDF_GetStandardFontName(CFX_ByteString* name) { 832 int PDF_GetStandardFontName(CFX_ByteString* name) {
902 AltFontName* found = static_cast<AltFontName*>( 833 AltFontName* found = static_cast<AltFontName*>(
903 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), 834 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
904 sizeof(AltFontName), CompareString)); 835 sizeof(AltFontName), CompareString));
905 if (!found) 836 if (!found)
906 return -1; 837 return -1;
907 838
908 *name = g_Base14FontNames[found->m_Index]; 839 *name = g_Base14FontNames[found->m_Index];
909 return found->m_Index; 840 return found->m_Index;
910 } 841 }
OLDNEW
« no previous file with comments | « no previous file | core/fxge/include/cfx_fontmapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698