OLD | NEW |
---|---|
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 <memory> | |
10 #include <utility> | |
11 #include <vector> | |
12 | |
9 #include "core/fxge/include/ifx_systemfontinfo.h" | 13 #include "core/fxge/include/ifx_systemfontinfo.h" |
10 #include "core/fxge/include/fx_font.h" | 14 #include "core/fxge/include/fx_font.h" |
11 | 15 |
12 #include "third_party/base/stl_util.h" | 16 #include "third_party/base/stl_util.h" |
13 | 17 |
14 #define FX_FONT_STYLE_None 0x00 | 18 #define FX_FONT_STYLE_None 0x00 |
15 #define FX_FONT_STYLE_Bold 0x01 | 19 #define FX_FONT_STYLE_Bold 0x01 |
16 #define FX_FONT_STYLE_Italic 0x02 | 20 #define FX_FONT_STYLE_Italic 0x02 |
17 #define FX_FONT_STYLE_BoldBold 0x04 | 21 #define FX_FONT_STYLE_BoldBold 0x04 |
18 | 22 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 {932, 128}, {936, 134}, {949, 129}, {950, 136}, {1250, 238}, | 158 {932, 128}, {936, 134}, {949, 129}, {950, 136}, {1250, 238}, |
155 {1251, 204}, {1252, 0}, {1253, 161}, {1254, 162}, {1255, 177}, | 159 {1251, 204}, {1252, 0}, {1253, 161}, {1254, 162}, {1255, 177}, |
156 {1256, 178}, {1257, 186}, {1258, 163}, {1361, 130}, {10000, 77}, | 160 {1256, 178}, {1257, 186}, {1258, 163}, {1361, 130}, {10000, 77}, |
157 {10001, 78}, {10002, 81}, {10003, 79}, {10004, 84}, {10005, 83}, | 161 {10001, 78}, {10002, 81}, {10003, 79}, {10004, 84}, {10005, 83}, |
158 {10006, 85}, {10007, 89}, {10008, 80}, {10021, 87}, {10029, 88}, | 162 {10006, 85}, {10007, 89}, {10008, 80}, {10021, 87}, {10029, 88}, |
159 {10081, 86}, | 163 {10081, 86}, |
160 }; | 164 }; |
161 | 165 |
162 int CompareFontFamilyString(const void* key, const void* element) { | 166 int CompareFontFamilyString(const void* key, const void* element) { |
163 CFX_ByteString str_key((const FX_CHAR*)key); | 167 CFX_ByteString str_key((const FX_CHAR*)key); |
164 if (str_key.Find(((AltFontFamily*)element)->m_pFontName) != -1) | 168 const AltFontFamily* family = reinterpret_cast<const AltFontFamily*>(element); |
169 if (str_key.Find(family->m_pFontName) != -1) | |
165 return 0; | 170 return 0; |
166 return FXSYS_stricmp((const FX_CHAR*)key, | 171 return FXSYS_stricmp(reinterpret_cast<const FX_CHAR*>(key), |
167 ((AltFontFamily*)element)->m_pFontName); | 172 family->m_pFontName); |
168 } | 173 } |
169 | 174 |
170 int CompareString(const void* key, const void* element) { | 175 int CompareString(const void* key, const void* element) { |
171 return FXSYS_stricmp((const FX_CHAR*)key, ((AltFontName*)element)->m_pName); | 176 return FXSYS_stricmp(reinterpret_cast<const FX_CHAR*>(key), |
177 reinterpret_cast<const AltFontName*>(element)->m_pName); | |
172 } | 178 } |
173 | 179 |
174 CFX_ByteString TT_NormalizeName(const FX_CHAR* family) { | 180 CFX_ByteString TT_NormalizeName(const FX_CHAR* family) { |
175 CFX_ByteString norm(family); | 181 CFX_ByteString norm(family); |
176 norm.Remove(' '); | 182 norm.Remove(' '); |
177 norm.Remove('-'); | 183 norm.Remove('-'); |
178 norm.Remove(','); | 184 norm.Remove(','); |
179 int pos = norm.Find('+'); | 185 int pos = norm.Find('+'); |
180 if (pos > 0) | 186 if (pos > 0) |
181 norm = norm.Left(pos); | 187 norm = norm.Left(pos); |
(...skipping 19 matching lines...) Expand all Loading... | |
201 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) | 207 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) |
202 fontName = "ScriptMTBold"; | 208 fontName = "ScriptMTBold"; |
203 else if (fontName.Find("Palace") >= 0) | 209 else if (fontName.Find("Palace") >= 0) |
204 fontName = "PalaceScriptMT"; | 210 fontName = "PalaceScriptMT"; |
205 else if (fontName.Find("French") >= 0) | 211 else if (fontName.Find("French") >= 0) |
206 fontName = "FrenchScriptMT"; | 212 fontName = "FrenchScriptMT"; |
207 else if (fontName.Find("FreeStyle") >= 0) | 213 else if (fontName.Find("FreeStyle") >= 0) |
208 fontName = "FreeStyleScript"; | 214 fontName = "FreeStyleScript"; |
209 return fontName; | 215 return fontName; |
210 } | 216 } |
211 AltFontFamily* found = (AltFontFamily*)FXSYS_bsearch( | 217 AltFontFamily* found = reinterpret_cast<AltFontFamily*>(FXSYS_bsearch( |
212 fontName.c_str(), g_AltFontFamilies, | 218 fontName.c_str(), g_AltFontFamilies, FX_ArraySize(g_AltFontFamilies), |
213 sizeof g_AltFontFamilies / sizeof(AltFontFamily), sizeof(AltFontFamily), | 219 sizeof(AltFontFamily), CompareFontFamilyString)); |
214 CompareFontFamilyString); | |
215 return found ? CFX_ByteString(found->m_pFontFamily) : fontName; | 220 return found ? CFX_ByteString(found->m_pFontFamily) : fontName; |
216 } | 221 } |
217 | 222 |
218 CFX_ByteString ParseStyle(const FX_CHAR* pStyle, int iLen, int iIndex) { | 223 CFX_ByteString ParseStyle(const FX_CHAR* pStyle, int iLen, int iIndex) { |
219 CFX_ByteTextBuf buf; | 224 CFX_ByteTextBuf buf; |
220 if (!iLen || iLen <= iIndex) | 225 if (!iLen || iLen <= iIndex) |
221 return buf.MakeString(); | 226 return buf.MakeString(); |
222 while (iIndex < iLen) { | 227 while (iIndex < iLen) { |
223 if (pStyle[iIndex] == ',') | 228 if (pStyle[iIndex] == ',') |
224 break; | 229 break; |
225 buf.AppendChar(pStyle[iIndex]); | 230 buf.AppendChar(pStyle[iIndex]); |
226 ++iIndex; | 231 ++iIndex; |
227 } | 232 } |
228 return buf.MakeString(); | 233 return buf.MakeString(); |
229 } | 234 } |
230 | 235 |
231 int32_t GetStyleType(const CFX_ByteString& bsStyle, FX_BOOL bRevert) { | 236 int32_t GetStyleType(const CFX_ByteString& bsStyle, bool bReverse) { |
232 int32_t iLen = bsStyle.GetLength(); | 237 int32_t iLen = bsStyle.GetLength(); |
233 if (!iLen) | 238 if (!iLen) |
234 return -1; | 239 return -1; |
235 int iSize = sizeof(g_FontStyles) / sizeof(FX_FontStyle); | 240 int iSize = FX_ArraySize(g_FontStyles); |
236 const FX_FontStyle* pStyle = nullptr; | 241 const FX_FontStyle* pStyle = nullptr; |
237 for (int i = iSize - 1; i >= 0; --i) { | 242 for (int i = iSize - 1; i >= 0; --i) { |
238 pStyle = g_FontStyles + i; | 243 pStyle = g_FontStyles + i; |
239 if (!pStyle || pStyle->len > iLen) | 244 if (!pStyle || pStyle->len > iLen) |
240 continue; | 245 continue; |
241 if (!bRevert) { | 246 |
242 if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0) | 247 if (bReverse) { |
248 if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0) | |
243 return i; | 249 return i; |
244 } else { | 250 } else { |
245 if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0) | 251 if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0) |
246 return i; | 252 return i; |
247 } | 253 } |
248 } | 254 } |
249 return -1; | 255 return -1; |
250 } | 256 } |
251 | 257 |
252 FX_BOOL CheckSupportThirdPartFont(CFX_ByteString name, int& PitchFamily) { | 258 FX_BOOL CheckSupportThirdPartFont(CFX_ByteString name, int& PitchFamily) { |
253 if (name == "MyriadPro") { | 259 if (name == "MyriadPro") { |
254 PitchFamily &= ~FXFONT_FF_ROMAN; | 260 PitchFamily &= ~FXFONT_FF_ROMAN; |
255 return TRUE; | 261 return TRUE; |
256 } | 262 } |
257 return FALSE; | 263 return FALSE; |
258 } | 264 } |
259 | 265 |
260 void UpdatePitchFamily(uint32_t flags, int& PitchFamily) { | 266 void UpdatePitchFamily(uint32_t flags, int& PitchFamily) { |
261 if (flags & FXFONT_SERIF) | 267 if (flags & FXFONT_SERIF) |
262 PitchFamily |= FXFONT_FF_ROMAN; | 268 PitchFamily |= FXFONT_FF_ROMAN; |
263 if (flags & FXFONT_SCRIPT) | 269 if (flags & FXFONT_SCRIPT) |
264 PitchFamily |= FXFONT_FF_SCRIPT; | 270 PitchFamily |= FXFONT_FF_SCRIPT; |
265 if (flags & FXFONT_FIXED_PITCH) | 271 if (flags & FXFONT_FIXED_PITCH) |
266 PitchFamily |= FXFONT_FF_FIXEDPITCH; | 272 PitchFamily |= FXFONT_FF_FIXEDPITCH; |
267 } | 273 } |
268 | 274 |
275 const int kExternalFontIndex = 12; | |
npm
2016/08/25 17:43:30
Do we have any conventions on the placement of var
Lei Zhang
2016/08/25 18:41:37
Oh, I can move it to the top if that's what you me
npm
2016/08/25 19:01:50
My understanding is there's 14 base fonts: first 1
| |
276 | |
269 } // namespace | 277 } // namespace |
270 | 278 |
271 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) | 279 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) |
272 : m_bListLoaded(FALSE), m_pFontMgr(mgr) { | 280 : m_bListLoaded(FALSE), m_pFontMgr(mgr) { |
273 m_MMFaces[0] = nullptr; | 281 m_MMFaces[0] = nullptr; |
274 m_MMFaces[1] = nullptr; | 282 m_MMFaces[1] = nullptr; |
275 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces)); | 283 FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces)); |
276 } | 284 } |
277 | 285 |
278 CFX_FontMapper::~CFX_FontMapper() { | 286 CFX_FontMapper::~CFX_FontMapper() { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 if (match[0] == ' ') | 379 if (match[0] == ' ') |
372 match = m_InstalledTTFonts[i + 1]; | 380 match = m_InstalledTTFonts[i + 1]; |
373 return match; | 381 return match; |
374 } | 382 } |
375 | 383 |
376 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, | 384 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, |
377 int iBaseFont, | 385 int iBaseFont, |
378 int italic_angle, | 386 int italic_angle, |
379 int weight, | 387 int weight, |
380 int picthfamily) { | 388 int picthfamily) { |
381 if (iBaseFont < 12) { | 389 if (iBaseFont < kExternalFontIndex) { |
382 if (m_FoxitFaces[iBaseFont]) | 390 if (m_FoxitFaces[iBaseFont]) |
383 return m_FoxitFaces[iBaseFont]; | 391 return m_FoxitFaces[iBaseFont]; |
384 const uint8_t* pFontData = nullptr; | 392 const uint8_t* pFontData = nullptr; |
385 uint32_t size = 0; | 393 uint32_t size = 0; |
386 if (m_pFontMgr->GetBuiltinFont(iBaseFont, &pFontData, &size)) { | 394 if (m_pFontMgr->GetBuiltinFont(iBaseFont, &pFontData, &size)) { |
387 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 395 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
388 return m_FoxitFaces[iBaseFont]; | 396 return m_FoxitFaces[iBaseFont]; |
389 } | 397 } |
390 } | 398 } |
391 pSubstFont->m_SubstFlags |= FXFONT_SUBST_MM; | 399 pSubstFont->m_SubstFlags |= FXFONT_SUBST_MM; |
392 pSubstFont->m_ItalicAngle = italic_angle; | 400 pSubstFont->m_ItalicAngle = italic_angle; |
393 if (weight) | 401 if (weight) |
394 pSubstFont->m_Weight = weight; | 402 pSubstFont->m_Weight = weight; |
395 if (picthfamily & FXFONT_FF_ROMAN) { | 403 if (picthfamily & FXFONT_FF_ROMAN) { |
396 pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5; | 404 pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5; |
397 pSubstFont->m_Family = "Chrome Serif"; | 405 pSubstFont->m_Family = "Chrome Serif"; |
398 if (m_MMFaces[1]) | 406 if (m_MMFaces[1]) |
399 return m_MMFaces[1]; | 407 return m_MMFaces[1]; |
400 const uint8_t* pFontData = nullptr; | 408 const uint8_t* pFontData = nullptr; |
401 uint32_t size = 0; | 409 uint32_t size = 0; |
402 m_pFontMgr->GetBuiltinFont(14, &pFontData, &size); | 410 m_pFontMgr->GetBuiltinFont(14, &pFontData, &size); |
npm
2016/08/25 17:43:30
Replace 14 with kExternalFontIndex + 2
Lei Zhang
2016/08/25 18:41:37
I haven't looked, so I don't know if the index pas
| |
403 m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 411 m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
404 return m_MMFaces[1]; | 412 return m_MMFaces[1]; |
405 } | 413 } |
406 pSubstFont->m_Family = "Chrome Sans"; | 414 pSubstFont->m_Family = "Chrome Sans"; |
407 if (m_MMFaces[0]) | 415 if (m_MMFaces[0]) |
408 return m_MMFaces[0]; | 416 return m_MMFaces[0]; |
409 const uint8_t* pFontData = nullptr; | 417 const uint8_t* pFontData = nullptr; |
410 uint32_t size = 0; | 418 uint32_t size = 0; |
411 m_pFontMgr->GetBuiltinFont(15, &pFontData, &size); | 419 m_pFontMgr->GetBuiltinFont(15, &pFontData, &size); |
npm
2016/08/25 17:43:30
kExternalFontIndex + 3
| |
412 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 420 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
413 return m_MMFaces[0]; | 421 return m_MMFaces[0]; |
414 } | 422 } |
415 | 423 |
416 FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, | 424 FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, |
417 FX_BOOL bTrueType, | 425 FX_BOOL bTrueType, |
418 uint32_t flags, | 426 uint32_t flags, |
419 int weight, | 427 int weight, |
420 int italic_angle, | 428 int italic_angle, |
421 int WindowCP, | 429 int WindowCP, |
422 CFX_SubstFont* pSubstFont) { | 430 CFX_SubstFont* pSubstFont) { |
423 if (!(flags & FXFONT_USEEXTERNATTR)) { | 431 if (!(flags & FXFONT_USEEXTERNATTR)) { |
424 weight = FXFONT_FW_NORMAL; | 432 weight = FXFONT_FW_NORMAL; |
425 italic_angle = 0; | 433 italic_angle = 0; |
426 } | 434 } |
427 CFX_ByteString SubstName = name; | 435 CFX_ByteString SubstName = name; |
428 SubstName.Remove(0x20); | 436 SubstName.Remove(' '); |
429 if (bTrueType && name[0] == '@') | 437 if (bTrueType && name[0] == '@') |
430 SubstName = name.Mid(1); | 438 SubstName = name.Mid(1); |
431 PDF_GetStandardFontName(&SubstName); | 439 PDF_GetStandardFontName(&SubstName); |
432 if (SubstName == "Symbol" && !bTrueType) { | 440 if (SubstName == "Symbol" && !bTrueType) { |
433 pSubstFont->m_Family = "Chrome Symbol"; | 441 pSubstFont->m_Family = "Chrome Symbol"; |
434 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; | 442 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; |
435 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 443 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
436 if (m_FoxitFaces[12]) | 444 if (m_FoxitFaces[12]) |
npm
2016/08/25 17:43:30
kExternalFontIndex for this and the 12's just belo
| |
437 return m_FoxitFaces[12]; | 445 return m_FoxitFaces[12]; |
438 const uint8_t* pFontData = nullptr; | 446 const uint8_t* pFontData = nullptr; |
439 uint32_t size = 0; | 447 uint32_t size = 0; |
440 m_pFontMgr->GetBuiltinFont(12, &pFontData, &size); | 448 m_pFontMgr->GetBuiltinFont(12, &pFontData, &size); |
441 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 449 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
442 return m_FoxitFaces[12]; | 450 return m_FoxitFaces[12]; |
443 } | 451 } |
444 if (SubstName == "ZapfDingbats") { | 452 if (SubstName == "ZapfDingbats") { |
445 pSubstFont->m_Family = "Chrome Dingbats"; | 453 pSubstFont->m_Family = "Chrome Dingbats"; |
446 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; | 454 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; |
447 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 455 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
448 if (m_FoxitFaces[13]) | 456 if (m_FoxitFaces[13]) |
npm
2016/08/25 17:43:30
Similarly, kExternalFontIndex+1 here
| |
449 return m_FoxitFaces[13]; | 457 return m_FoxitFaces[13]; |
450 const uint8_t* pFontData = nullptr; | 458 const uint8_t* pFontData = nullptr; |
451 uint32_t size = 0; | 459 uint32_t size = 0; |
452 m_pFontMgr->GetBuiltinFont(13, &pFontData, &size); | 460 m_pFontMgr->GetBuiltinFont(13, &pFontData, &size); |
453 m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 461 m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
454 return m_FoxitFaces[13]; | 462 return m_FoxitFaces[13]; |
455 } | 463 } |
456 int iBaseFont = 0; | 464 int iBaseFont = 0; |
457 CFX_ByteString family, style; | 465 CFX_ByteString family; |
458 FX_BOOL bHasComma = FALSE; | 466 CFX_ByteString style; |
459 FX_BOOL bHasHypen = FALSE; | 467 bool bHasComma = false; |
468 bool bHasHyphen = false; | |
460 int find = SubstName.Find(",", 0); | 469 int find = SubstName.Find(",", 0); |
461 if (find >= 0) { | 470 if (find >= 0) { |
462 family = SubstName.Left(find); | 471 family = SubstName.Left(find); |
463 PDF_GetStandardFontName(&family); | 472 PDF_GetStandardFontName(&family); |
464 style = SubstName.Mid(find + 1); | 473 style = SubstName.Mid(find + 1); |
465 bHasComma = TRUE; | 474 bHasComma = true; |
466 } else { | 475 } else { |
467 family = SubstName; | 476 family = SubstName; |
468 } | 477 } |
469 for (; iBaseFont < 12; iBaseFont++) { | 478 for (; iBaseFont < kExternalFontIndex; iBaseFont++) { |
470 if (family == CFX_ByteStringC(g_Base14FontNames[iBaseFont])) | 479 if (family == CFX_ByteStringC(g_Base14FontNames[iBaseFont])) |
471 break; | 480 break; |
472 } | 481 } |
473 int PitchFamily = 0; | 482 int PitchFamily = 0; |
474 FX_BOOL bItalic = FALSE; | 483 bool bItalic = false; |
475 uint32_t nStyle = 0; | 484 uint32_t nStyle = 0; |
476 FX_BOOL bStyleAvail = FALSE; | 485 bool bStyleAvail = false; |
477 if (iBaseFont < 12) { | 486 if (iBaseFont < kExternalFontIndex) { |
478 if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2) | 487 if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2) |
479 nStyle |= FX_FONT_STYLE_Bold; | 488 nStyle |= FX_FONT_STYLE_Bold; |
480 if ((iBaseFont % 4) / 2) | 489 if ((iBaseFont % 4) / 2) |
481 nStyle |= FX_FONT_STYLE_Italic; | 490 nStyle |= FX_FONT_STYLE_Italic; |
482 if (iBaseFont < 4) | 491 if (iBaseFont < 4) |
483 PitchFamily |= FXFONT_FF_FIXEDPITCH; | 492 PitchFamily |= FXFONT_FF_FIXEDPITCH; |
484 if (iBaseFont >= 8) | 493 if (iBaseFont >= 8) |
485 PitchFamily |= FXFONT_FF_ROMAN; | 494 PitchFamily |= FXFONT_FF_ROMAN; |
486 } else { | 495 } else { |
487 if (!bHasComma) { | 496 if (!bHasComma) { |
488 find = family.ReverseFind('-'); | 497 find = family.ReverseFind('-'); |
489 if (find >= 0) { | 498 if (find >= 0) { |
490 style = family.Mid(find + 1); | 499 style = family.Mid(find + 1); |
491 family = family.Left(find); | 500 family = family.Left(find); |
492 bHasHypen = TRUE; | 501 bHasHyphen = true; |
493 } | 502 } |
494 } | 503 } |
495 if (!bHasHypen) { | 504 if (!bHasHyphen) { |
496 int nLen = family.GetLength(); | 505 int nLen = family.GetLength(); |
497 int32_t nRet = GetStyleType(family, TRUE); | 506 int32_t nRet = GetStyleType(family, true); |
498 if (nRet > -1) { | 507 if (nRet > -1) { |
499 family = family.Left(nLen - g_FontStyles[nRet].len); | 508 family = family.Left(nLen - g_FontStyles[nRet].len); |
500 if (nRet == 0) | 509 if (nRet == 0) |
501 nStyle |= FX_FONT_STYLE_Bold; | 510 nStyle |= FX_FONT_STYLE_Bold; |
502 if (nRet == 1) | 511 else if (nRet == 1) |
503 nStyle |= FX_FONT_STYLE_Italic; | 512 nStyle |= FX_FONT_STYLE_Italic; |
504 if (nRet == 2) | 513 else if (nRet == 2) |
505 nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic); | 514 nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic); |
506 } | 515 } |
507 } | 516 } |
508 UpdatePitchFamily(flags, PitchFamily); | 517 UpdatePitchFamily(flags, PitchFamily); |
509 } | 518 } |
510 if (!style.IsEmpty()) { | 519 if (!style.IsEmpty()) { |
511 int nLen = style.GetLength(); | 520 int nLen = style.GetLength(); |
512 const FX_CHAR* pStyle = style.c_str(); | 521 const FX_CHAR* pStyle = style.c_str(); |
513 int i = 0; | 522 int i = 0; |
514 FX_BOOL bFirstItem = TRUE; | 523 bool bFirstItem = true; |
515 CFX_ByteString buf; | 524 CFX_ByteString buf; |
516 while (i < nLen) { | 525 while (i < nLen) { |
517 buf = ParseStyle(pStyle, nLen, i); | 526 buf = ParseStyle(pStyle, nLen, i); |
518 int32_t nRet = GetStyleType(buf, FALSE); | 527 int32_t nRet = GetStyleType(buf, false); |
519 if ((i && !bStyleAvail) || (!i && nRet < 0)) { | 528 if ((i && !bStyleAvail) || (!i && nRet < 0)) { |
520 family = SubstName; | 529 family = SubstName; |
521 iBaseFont = 12; | 530 iBaseFont = kExternalFontIndex; |
522 break; | 531 break; |
523 } else if (nRet >= 0) { | 532 } |
524 bStyleAvail = TRUE; | 533 if (nRet >= 0) { |
534 bStyleAvail = true; | |
535 } | |
536 if (nRet == 1) { | |
537 if (bFirstItem) { | |
538 nStyle |= FX_FONT_STYLE_Italic; | |
539 } else { | |
540 family = SubstName; | |
541 iBaseFont = kExternalFontIndex; | |
542 } | |
543 break; | |
525 } | 544 } |
526 if (nRet == 0) { | 545 if (nRet == 0) { |
527 if (nStyle & FX_FONT_STYLE_Bold) | 546 if (nStyle & FX_FONT_STYLE_Bold) |
528 nStyle |= FX_FONT_STYLE_BoldBold; | 547 nStyle |= FX_FONT_STYLE_BoldBold; |
529 else | 548 else |
530 nStyle |= FX_FONT_STYLE_Bold; | 549 nStyle |= FX_FONT_STYLE_Bold; |
531 bFirstItem = FALSE; | 550 bFirstItem = false; |
532 } | 551 } else if (nRet == 2) { |
533 if (nRet == 1) { | |
534 if (bFirstItem) { | |
535 nStyle |= FX_FONT_STYLE_Italic; | |
536 } else { | |
537 family = SubstName; | |
538 iBaseFont = 12; | |
539 } | |
540 break; | |
541 } | |
542 if (nRet == 2) { | |
543 nStyle |= FX_FONT_STYLE_Italic; | 552 nStyle |= FX_FONT_STYLE_Italic; |
544 if (nStyle & FX_FONT_STYLE_Bold) | 553 if (nStyle & FX_FONT_STYLE_Bold) |
545 nStyle |= FX_FONT_STYLE_BoldBold; | 554 nStyle |= FX_FONT_STYLE_BoldBold; |
546 else | 555 else |
547 nStyle |= FX_FONT_STYLE_Bold; | 556 nStyle |= FX_FONT_STYLE_Bold; |
548 bFirstItem = FALSE; | 557 bFirstItem = false; |
549 } | 558 } |
550 i += buf.GetLength() + 1; | 559 i += buf.GetLength() + 1; |
551 } | 560 } |
552 } | 561 } |
553 weight = weight ? weight : FXFONT_FW_NORMAL; | 562 weight = weight ? weight : FXFONT_FW_NORMAL; |
554 int old_weight = weight; | 563 int old_weight = weight; |
555 if (nStyle) { | 564 if (nStyle) { |
556 weight = | 565 weight = |
557 nStyle & FX_FONT_STYLE_BoldBold | 566 nStyle & FX_FONT_STYLE_BoldBold |
558 ? 900 | 567 ? 900 |
559 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); | 568 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); |
560 } | 569 } |
561 if (nStyle & FX_FONT_STYLE_Italic) | 570 if (nStyle & FX_FONT_STYLE_Italic) |
562 bItalic = TRUE; | 571 bItalic = true; |
563 FX_BOOL bCJK = FALSE; | |
564 int iExact = 0; | 572 int iExact = 0; |
565 int Charset = FXFONT_ANSI_CHARSET; | 573 int Charset = FXFONT_ANSI_CHARSET; |
566 if (WindowCP) | 574 if (WindowCP) |
567 Charset = GetCharsetFromCodePage(WindowCP); | 575 Charset = GetCharsetFromCodePage(WindowCP); |
568 else if (iBaseFont == 12 && (flags & FXFONT_SYMBOLIC)) | 576 else if (iBaseFont == kExternalFontIndex && (flags & FXFONT_SYMBOLIC)) |
569 Charset = FXFONT_SYMBOL_CHARSET; | 577 Charset = FXFONT_SYMBOL_CHARSET; |
570 if (Charset == FXFONT_SHIFTJIS_CHARSET || Charset == FXFONT_GB2312_CHARSET || | 578 bool bCJK = |
571 Charset == FXFONT_HANGEUL_CHARSET || | 579 (Charset == FXFONT_SHIFTJIS_CHARSET || Charset == FXFONT_GB2312_CHARSET || |
572 Charset == FXFONT_CHINESEBIG5_CHARSET) { | 580 Charset == FXFONT_HANGEUL_CHARSET || |
573 bCJK = TRUE; | 581 Charset == FXFONT_CHINESEBIG5_CHARSET); |
574 } | |
575 if (!m_pFontInfo) { | 582 if (!m_pFontInfo) { |
576 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 583 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
577 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, | 584 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, |
578 PitchFamily); | 585 PitchFamily); |
579 } | 586 } |
580 family = GetFontFamily(family, nStyle); | 587 family = GetFontFamily(family, nStyle); |
581 CFX_ByteString match = MatchInstalledFonts(TT_NormalizeName(family.c_str())); | 588 CFX_ByteString match = MatchInstalledFonts(TT_NormalizeName(family.c_str())); |
582 if (match.IsEmpty() && family != SubstName && | 589 if (match.IsEmpty() && family != SubstName && |
583 (!bHasComma && (!bHasHypen || (bHasHypen && !bStyleAvail)))) { | 590 (!bHasComma && (!bHasHyphen || (bHasHyphen && !bStyleAvail)))) { |
584 match = MatchInstalledFonts(TT_NormalizeName(SubstName.c_str())); | 591 match = MatchInstalledFonts(TT_NormalizeName(SubstName.c_str())); |
585 } | 592 } |
586 if (match.IsEmpty() && iBaseFont >= 12) { | 593 if (match.IsEmpty() && iBaseFont >= kExternalFontIndex) { |
587 if (!bCJK) { | 594 if (!bCJK) { |
588 if (!CheckSupportThirdPartFont(family, PitchFamily)) { | 595 if (!CheckSupportThirdPartFont(family, PitchFamily)) { |
589 if (italic_angle != 0) | 596 bItalic = italic_angle != 0; |
590 bItalic = TRUE; | |
591 else | |
592 bItalic = FALSE; | |
593 weight = old_weight; | 597 weight = old_weight; |
594 } | 598 } |
595 } else { | 599 } else { |
596 pSubstFont->m_bSubstCJK = true; | 600 pSubstFont->m_bSubstCJK = true; |
597 if (nStyle) | 601 if (nStyle) |
598 pSubstFont->m_WeightCJK = weight; | 602 pSubstFont->m_WeightCJK = nStyle ? weight : FXFONT_FW_NORMAL; |
599 else | |
600 pSubstFont->m_WeightCJK = FXFONT_FW_NORMAL; | |
601 if (nStyle & FX_FONT_STYLE_Italic) | 603 if (nStyle & FX_FONT_STYLE_Italic) |
602 pSubstFont->m_bItalicCJK = true; | 604 pSubstFont->m_bItalicCJK = true; |
603 } | 605 } |
604 } else { | 606 } else { |
605 italic_angle = 0; | 607 italic_angle = 0; |
606 weight = | 608 weight = |
607 nStyle & FX_FONT_STYLE_BoldBold | 609 nStyle & FX_FONT_STYLE_BoldBold |
608 ? 900 | 610 ? 900 |
609 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); | 611 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); |
610 } | 612 } |
611 if (!match.IsEmpty() || iBaseFont < 12) { | 613 if (!match.IsEmpty() || iBaseFont < kExternalFontIndex) { |
612 if (!match.IsEmpty()) | 614 if (!match.IsEmpty()) |
613 family = match; | 615 family = match; |
614 if (iBaseFont < 12) { | 616 if (iBaseFont < kExternalFontIndex) { |
615 if (nStyle && !(iBaseFont % 4)) { | 617 if (nStyle && !(iBaseFont % 4)) { |
616 if ((nStyle & 0x3) == 1) | 618 if ((nStyle & 0x3) == 1) |
617 iBaseFont += 1; | 619 iBaseFont += 1; |
618 if ((nStyle & 0x3) == 2) | 620 if ((nStyle & 0x3) == 2) |
619 iBaseFont += 3; | 621 iBaseFont += 3; |
620 if ((nStyle & 0x3) == 3) | 622 if ((nStyle & 0x3) == 3) |
621 iBaseFont += 2; | 623 iBaseFont += 2; |
622 } | 624 } |
623 family = g_Base14FontNames[iBaseFont]; | 625 family = g_Base14FontNames[iBaseFont]; |
624 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 626 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
625 } | 627 } |
626 } else { | 628 } else { |
627 if (flags & FXFONT_ITALIC) | 629 if (flags & FXFONT_ITALIC) |
628 bItalic = TRUE; | 630 bItalic = true; |
629 } | 631 } |
630 iExact = !match.IsEmpty(); | 632 iExact = !match.IsEmpty(); |
631 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, | 633 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, |
632 family.c_str(), iExact); | 634 family.c_str(), iExact); |
633 if (iExact) | 635 if (iExact) |
634 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; | 636 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT; |
635 if (!hFont) { | 637 if (!hFont) { |
636 #ifdef PDF_ENABLE_XFA | 638 #ifdef PDF_ENABLE_XFA |
637 if (flags & FXFONT_EXACTMATCH) | 639 if (flags & FXFONT_EXACTMATCH) |
638 return nullptr; | 640 return nullptr; |
639 #endif // PDF_ENABLE_XFA | 641 #endif // PDF_ENABLE_XFA |
640 if (bCJK) { | 642 if (bCJK) { |
641 if (italic_angle != 0) | 643 bItalic = italic_angle != 0; |
642 bItalic = TRUE; | |
643 else | |
644 bItalic = FALSE; | |
645 weight = old_weight; | 644 weight = old_weight; |
646 } | 645 } |
647 if (!match.IsEmpty()) { | 646 if (!match.IsEmpty()) { |
648 hFont = m_pFontInfo->GetFont(match.c_str()); | 647 hFont = m_pFontInfo->GetFont(match.c_str()); |
649 if (!hFont) { | 648 if (!hFont) { |
650 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, | 649 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, |
651 PitchFamily); | 650 PitchFamily); |
652 } | 651 } |
653 } else { | 652 } else { |
654 if (Charset == FXFONT_SYMBOL_CHARSET) { | 653 if (Charset == FXFONT_SYMBOL_CHARSET) { |
655 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ | 654 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ |
656 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ | 655 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ |
657 if (SubstName == "Symbol") { | 656 if (SubstName == "Symbol") { |
658 pSubstFont->m_Family = "Chrome Symbol"; | 657 pSubstFont->m_Family = "Chrome Symbol"; |
659 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 658 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
660 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; | 659 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; |
661 if (m_FoxitFaces[12]) | 660 if (m_FoxitFaces[12]) |
npm
2016/08/25 17:43:30
kExternalFontIndex here and below
| |
662 return m_FoxitFaces[12]; | 661 return m_FoxitFaces[12]; |
663 const uint8_t* pFontData = nullptr; | 662 const uint8_t* pFontData = nullptr; |
664 uint32_t size = 0; | 663 uint32_t size = 0; |
665 m_pFontMgr->GetBuiltinFont(12, &pFontData, &size); | 664 m_pFontMgr->GetBuiltinFont(12, &pFontData, &size); |
666 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 665 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
667 return m_FoxitFaces[12]; | 666 return m_FoxitFaces[12]; |
668 } | 667 } |
669 #endif | 668 #endif |
670 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; | 669 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; |
671 return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMBOLIC, | 670 return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMBOLIC, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 if (ttc_size) | 704 if (ttc_size) |
706 face = GetCachedTTCFace(hFont, kTableTTCF, ttc_size, font_size); | 705 face = GetCachedTTCFace(hFont, kTableTTCF, ttc_size, font_size); |
707 else | 706 else |
708 face = GetCachedFace(hFont, SubstName, weight, bItalic, font_size); | 707 face = GetCachedFace(hFont, SubstName, weight, bItalic, font_size); |
709 if (!face) { | 708 if (!face) { |
710 m_pFontInfo->DeleteFont(hFont); | 709 m_pFontInfo->DeleteFont(hFont); |
711 return nullptr; | 710 return nullptr; |
712 } | 711 } |
713 pSubstFont->m_Family = SubstName; | 712 pSubstFont->m_Family = SubstName; |
714 pSubstFont->m_Charset = Charset; | 713 pSubstFont->m_Charset = Charset; |
715 FX_BOOL bNeedUpdateWeight = FALSE; | 714 bool bNeedUpdateWeight = false; |
716 if (FXFT_Is_Face_Bold(face)) { | 715 if (FXFT_Is_Face_Bold(face)) |
717 if (weight == FXFONT_FW_BOLD) | 716 bNeedUpdateWeight = weight != FXFONT_FW_BOLD; |
718 bNeedUpdateWeight = FALSE; | 717 else |
719 else | 718 bNeedUpdateWeight = weight != FXFONT_FW_NORMAL; |
720 bNeedUpdateWeight = TRUE; | |
721 } else { | |
722 if (weight == FXFONT_FW_NORMAL) | |
723 bNeedUpdateWeight = FALSE; | |
724 else | |
725 bNeedUpdateWeight = TRUE; | |
726 } | |
727 if (bNeedUpdateWeight) | 719 if (bNeedUpdateWeight) |
728 pSubstFont->m_Weight = weight; | 720 pSubstFont->m_Weight = weight; |
729 if (bItalic && !FXFT_Is_Face_Italic(face)) { | 721 if (bItalic && !FXFT_Is_Face_Italic(face)) { |
730 if (italic_angle == 0) | 722 if (italic_angle == 0) |
731 italic_angle = -12; | 723 italic_angle = -12; |
732 else if (FXSYS_abs(italic_angle) < 5) | 724 else if (FXSYS_abs(italic_angle) < 5) |
733 italic_angle = 0; | 725 italic_angle = 0; |
734 pSubstFont->m_ItalicAngle = italic_angle; | 726 pSubstFont->m_ItalicAngle = italic_angle; |
735 } | 727 } |
736 m_pFontInfo->DeleteFont(hFont); | 728 m_pFontInfo->DeleteFont(hFont); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 return TRUE; | 778 return TRUE; |
787 } | 779 } |
788 return FALSE; | 780 return FALSE; |
789 } | 781 } |
790 | 782 |
791 FXFT_Face CFX_FontMapper::GetCachedTTCFace(void* hFont, | 783 FXFT_Face CFX_FontMapper::GetCachedTTCFace(void* hFont, |
792 const uint32_t tableTTCF, | 784 const uint32_t tableTTCF, |
793 uint32_t ttc_size, | 785 uint32_t ttc_size, |
794 uint32_t font_size) { | 786 uint32_t font_size) { |
795 FXFT_Face face; | 787 FXFT_Face face; |
796 uint8_t temp[1024]; | 788 uint8_t buffer[1024]; |
797 m_pFontInfo->GetFontData(hFont, tableTTCF, temp, 1024); | 789 m_pFontInfo->GetFontData(hFont, tableTTCF, buffer, FX_ArraySize(buffer)); |
790 uint32_t* pBuffer = reinterpret_cast<uint32_t*>(&buffer); | |
npm
2016/08/25 17:43:30
Is this the same as
uint32_t* pBuffer = reinterpre
Lei Zhang
2016/08/25 18:41:37
Done.
| |
798 uint32_t checksum = 0; | 791 uint32_t checksum = 0; |
799 for (int i = 0; i < 256; i++) | 792 for (int i = 0; i < 256; i++) |
800 checksum += ((uint32_t*)temp)[i]; | 793 checksum += pBuffer[i]; |
801 uint8_t* pFontData; | 794 uint8_t* pFontData; |
802 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_size, | 795 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_size, |
803 pFontData); | 796 pFontData); |
804 if (!face) { | 797 if (!face) { |
805 pFontData = FX_Alloc(uint8_t, ttc_size); | 798 pFontData = FX_Alloc(uint8_t, ttc_size); |
806 m_pFontInfo->GetFontData(hFont, tableTTCF, pFontData, ttc_size); | 799 m_pFontInfo->GetFontData(hFont, tableTTCF, pFontData, ttc_size); |
807 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size, | 800 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size, |
808 ttc_size - font_size); | 801 ttc_size - font_size); |
809 } | 802 } |
810 return face; | 803 return face; |
(...skipping 20 matching lines...) Expand all Loading... | |
831 int PDF_GetStandardFontName(CFX_ByteString* name) { | 824 int PDF_GetStandardFontName(CFX_ByteString* name) { |
832 AltFontName* found = static_cast<AltFontName*>( | 825 AltFontName* found = static_cast<AltFontName*>( |
833 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 826 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
834 sizeof(AltFontName), CompareString)); | 827 sizeof(AltFontName), CompareString)); |
835 if (!found) | 828 if (!found) |
836 return -1; | 829 return -1; |
837 | 830 |
838 *name = g_Base14FontNames[found->m_Index]; | 831 *name = g_Base14FontNames[found->m_Index]; |
839 return found->m_Index; | 832 return found->m_Index; |
840 } | 833 } |
OLD | NEW |