Chromium Code Reviews| 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/cfx_fontmapper.h" | 7 #include "core/fxge/cfx_fontmapper.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 if (!hFont) { | 341 if (!hFont) { |
| 342 int iExact; | 342 int iExact; |
| 343 hFont = m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, | 343 hFont = m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, |
| 344 name.c_str(), iExact); | 344 name.c_str(), iExact); |
| 345 if (!hFont) | 345 if (!hFont) |
| 346 return; | 346 return; |
| 347 } | 347 } |
| 348 | 348 |
| 349 CFX_ByteString new_name = GetPSNameFromTT(hFont); | 349 CFX_ByteString new_name = GetPSNameFromTT(hFont); |
| 350 if (!new_name.IsEmpty()) { | 350 if (!new_name.IsEmpty()) { |
| 351 new_name.Insert(0, ' '); | 351 m_InstalledTTFonts[TT_NormalizeName(new_name.c_str())] = name; |
|
dsinclair
2016/10/05 21:12:07
Should this name be new_name?
npm
2016/10/05 21:21:47
No. See comment below
| |
| 352 m_InstalledTTFonts.push_back(new_name); | |
| 353 } | 352 } |
| 354 m_pFontInfo->DeleteFont(hFont); | 353 m_pFontInfo->DeleteFont(hFont); |
| 355 } | 354 } |
| 356 m_InstalledTTFonts.push_back(name); | 355 m_InstalledTTFonts[TT_NormalizeName(name.c_str())] = name; |
| 357 m_LastFamily = name; | 356 m_LastFamily = name; |
| 358 } | 357 } |
| 359 | 358 |
| 360 void CFX_FontMapper::LoadInstalledFonts() { | 359 void CFX_FontMapper::LoadInstalledFonts() { |
| 361 if (!m_pFontInfo || m_bListLoaded) | 360 if (!m_pFontInfo || m_bListLoaded) |
| 362 return; | 361 return; |
| 363 | 362 |
| 364 m_pFontInfo->EnumFontList(this); | 363 m_pFontInfo->EnumFontList(this); |
| 365 m_bListLoaded = TRUE; | 364 m_bListLoaded = TRUE; |
| 366 } | 365 } |
| 367 | 366 |
| 368 CFX_ByteString CFX_FontMapper::MatchInstalledFonts( | 367 CFX_ByteString CFX_FontMapper::MatchInstalledFonts( |
| 369 const CFX_ByteString& norm_name) { | 368 const CFX_ByteString& norm_name) { |
| 370 LoadInstalledFonts(); | 369 LoadInstalledFonts(); |
| 371 int i; | 370 auto it = m_InstalledTTFonts.find(norm_name); |
| 372 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) { | 371 if (it == m_InstalledTTFonts.end()) |
|
Tom Sepez
2016/10/05 21:17:34
I worry about the order being significant as we mo
npm
2016/10/05 21:21:47
The order here is relevant in the sense that we ma
| |
| 373 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str()); | |
|
dsinclair
2016/10/05 21:12:07
Previously if TT_NormalizeName(new_name) matched n
npm
2016/10/05 21:21:47
On previous line 381, the index is increased by 1.
| |
| 374 if (norm1 == norm_name) | |
| 375 break; | |
| 376 } | |
| 377 if (i < 0) | |
| 378 return CFX_ByteString(); | 372 return CFX_ByteString(); |
| 379 CFX_ByteString match = m_InstalledTTFonts[i]; | 373 return it->second; |
| 380 if (match[0] == ' ') | |
| 381 match = m_InstalledTTFonts[i + 1]; | |
| 382 return match; | |
| 383 } | 374 } |
| 384 | 375 |
| 385 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, | 376 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, |
| 386 int iBaseFont, | 377 int iBaseFont, |
| 387 int italic_angle, | 378 int italic_angle, |
| 388 int weight, | 379 int weight, |
| 389 int picthfamily) { | 380 int picthfamily) { |
| 390 if (iBaseFont < kExternalFontIndex) { | 381 if (iBaseFont < kExternalFontIndex) { |
| 391 if (m_FoxitFaces[iBaseFont]) | 382 if (m_FoxitFaces[iBaseFont]) |
| 392 return m_FoxitFaces[iBaseFont]; | 383 return m_FoxitFaces[iBaseFont]; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 int PDF_GetStandardFontName(CFX_ByteString* name) { | 816 int PDF_GetStandardFontName(CFX_ByteString* name) { |
| 826 AltFontName* found = static_cast<AltFontName*>( | 817 AltFontName* found = static_cast<AltFontName*>( |
| 827 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 818 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
| 828 sizeof(AltFontName), CompareString)); | 819 sizeof(AltFontName), CompareString)); |
| 829 if (!found) | 820 if (!found) |
| 830 return -1; | 821 return -1; |
| 831 | 822 |
| 832 *name = g_Base14FontNames[found->m_Index]; | 823 *name = g_Base14FontNames[found->m_Index]; |
| 833 return found->m_Index; | 824 return found->m_Index; |
| 834 } | 825 } |
| OLD | NEW |