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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 void* hFont = m_pFontInfo->GetFont(name.c_str()); | 340 void* hFont = m_pFontInfo->GetFont(name.c_str()); |
| 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()) { |
|
Tom Sepez
2016/10/06 15:58:03
nit: no {}
| |
| 351 new_name.Insert(0, ' '); | 351 m_LocalizedTTFonts.push_back(std::make_pair(new_name, name)); |
| 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.push_back(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 int i; |
| 372 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) { | 371 for (i = pdfium::CollectionSize<int>(m_InstalledTTFonts) - 1; i >= 0; i--) { |
| 373 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str()); | 372 CFX_ByteString norm1 = TT_NormalizeName(m_InstalledTTFonts[i].c_str()); |
| 374 if (norm1 == norm_name) | 373 if (norm1 == norm_name) |
| 375 break; | 374 break; |
|
Tom Sepez
2016/10/06 15:58:03
nit: just return m_InstalledTTFonts[i] here?
| |
| 376 } | 375 } |
| 377 if (i < 0) | 376 if (i >= 0) |
| 378 return CFX_ByteString(); | 377 return m_InstalledTTFonts[i]; |
| 379 CFX_ByteString match = m_InstalledTTFonts[i]; | 378 for (i = pdfium::CollectionSize<int>(m_LocalizedTTFonts) - 1; i >= 0; i--) { |
| 380 if (match[0] == ' ') | 379 CFX_ByteString norm1 = |
| 381 match = m_InstalledTTFonts[i + 1]; | 380 TT_NormalizeName(m_LocalizedTTFonts[i].first.c_str()); |
| 382 return match; | 381 if (norm1 == norm_name) |
| 382 break; | |
|
Tom Sepez
2016/10/06 15:58:03
nit: same idea here.
| |
| 383 } | |
| 384 if (i >= 0) | |
| 385 return m_LocalizedTTFonts[i].second; | |
| 386 return CFX_ByteString(); | |
| 383 } | 387 } |
| 384 | 388 |
| 385 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, | 389 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, |
| 386 int iBaseFont, | 390 int iBaseFont, |
| 387 int italic_angle, | 391 int italic_angle, |
| 388 int weight, | 392 int weight, |
| 389 int picthfamily) { | 393 int picthfamily) { |
| 390 if (iBaseFont < kExternalFontIndex) { | 394 if (iBaseFont < kExternalFontIndex) { |
| 391 if (m_FoxitFaces[iBaseFont]) | 395 if (m_FoxitFaces[iBaseFont]) |
| 392 return m_FoxitFaces[iBaseFont]; | 396 return m_FoxitFaces[iBaseFont]; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 int PDF_GetStandardFontName(CFX_ByteString* name) { | 829 int PDF_GetStandardFontName(CFX_ByteString* name) { |
| 826 AltFontName* found = static_cast<AltFontName*>( | 830 AltFontName* found = static_cast<AltFontName*>( |
| 827 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), | 831 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), |
| 828 sizeof(AltFontName), CompareString)); | 832 sizeof(AltFontName), CompareString)); |
| 829 if (!found) | 833 if (!found) |
| 830 return -1; | 834 return -1; |
| 831 | 835 |
| 832 *name = g_Base14FontNames[found->m_Index]; | 836 *name = g_Base14FontNames[found->m_Index]; |
| 833 return found->m_Index; | 837 return found->m_Index; |
| 834 } | 838 } |
| OLD | NEW |