Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 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 "xfa/fgas/font/cfgas_fontmgr.h" | 7 #include "xfa/fgas/font/cfgas_fontmgr.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 return nullptr; | 568 return nullptr; |
| 569 return pFontMgr; | 569 return pFontMgr; |
| 570 } | 570 } |
| 571 | 571 |
| 572 CFGAS_FontMgr::CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum) | 572 CFGAS_FontMgr::CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum) |
| 573 : m_pFontSource(pFontEnum) {} | 573 : m_pFontSource(pFontEnum) {} |
| 574 | 574 |
| 575 CFGAS_FontMgr::~CFGAS_FontMgr() { | 575 CFGAS_FontMgr::~CFGAS_FontMgr() { |
| 576 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) | 576 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) |
| 577 delete m_InstalledFonts[i]; | 577 delete m_InstalledFonts[i]; |
| 578 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 578 for (auto& pair : m_Hash2CandidateList) |
|
Tom Sepez
2017/01/05 21:31:46
NOTE: hang on, I'm going to make this unique_ptr.
| |
| 579 while (pos) { | 579 delete pair.second; |
| 580 uint32_t dwHash; | |
| 581 CFX_FontDescriptorInfos* pDescs; | |
| 582 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | |
| 583 delete pDescs; | |
| 584 } | |
| 585 m_Hash2Fonts.clear(); | 580 m_Hash2Fonts.clear(); |
| 586 } | 581 } |
| 587 | 582 |
| 588 bool CFGAS_FontMgr::EnumFontsFromFontMapper() { | 583 bool CFGAS_FontMgr::EnumFontsFromFontMapper() { |
| 589 CFX_FontMapper* pFontMapper = | 584 CFX_FontMapper* pFontMapper = |
| 590 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); | 585 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); |
| 591 if (!pFontMapper) | 586 if (!pFontMapper) |
| 592 return false; | 587 return false; |
| 593 | 588 |
| 594 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 589 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 uint32_t dwFontStyles, | 633 uint32_t dwFontStyles, |
| 639 const FX_WCHAR* pszFontFamily) { | 634 const FX_WCHAR* pszFontFamily) { |
| 640 CFX_ByteString bsHash; | 635 CFX_ByteString bsHash; |
| 641 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 636 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
| 642 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 637 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
| 643 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | 638 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 644 std::vector<CFX_RetainPtr<CFGAS_GEFont>>* pFontArray = &m_Hash2Fonts[dwHash]; | 639 std::vector<CFX_RetainPtr<CFGAS_GEFont>>* pFontArray = &m_Hash2Fonts[dwHash]; |
| 645 if (!pFontArray->empty()) | 640 if (!pFontArray->empty()) |
| 646 return (*pFontArray)[0]; | 641 return (*pFontArray)[0]; |
| 647 | 642 |
| 648 CFX_FontDescriptorInfos* sortedFonts = nullptr; | 643 CFX_FontDescriptorInfos* sortedFonts = m_Hash2CandidateList[dwHash]; |
| 649 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { | 644 if (!sortedFonts) { |
| 650 sortedFonts = new CFX_FontDescriptorInfos; | 645 sortedFonts = new CFX_FontDescriptorInfos; |
| 651 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, | 646 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, |
| 652 CFX_WideString(pszFontFamily), 0); | 647 CFX_WideString(pszFontFamily), 0); |
| 653 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); | 648 m_Hash2CandidateList[dwHash] = sortedFonts; |
| 654 } | 649 } |
| 655 if (sortedFonts->GetSize() == 0) | 650 if (sortedFonts->GetSize() == 0) |
| 656 return nullptr; | 651 return nullptr; |
| 657 | 652 |
| 658 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; | 653 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; |
| 659 CFX_RetainPtr<CFGAS_GEFont> pFont = | 654 CFX_RetainPtr<CFGAS_GEFont> pFont = |
| 660 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); | 655 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); |
| 661 if (!pFont) | 656 if (!pFont) |
| 662 return nullptr; | 657 return nullptr; |
| 663 | 658 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 681 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); | 676 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); |
| 682 else | 677 else |
| 683 bsHash.Format("%d, %d", wCodePage, dwFontStyles); | 678 bsHash.Format("%d, %d", wCodePage, dwFontStyles); |
| 684 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); | 679 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); |
| 685 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); | 680 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); |
| 686 std::vector<CFX_RetainPtr<CFGAS_GEFont>>* pFonts = &m_Hash2Fonts[dwHash]; | 681 std::vector<CFX_RetainPtr<CFGAS_GEFont>>* pFonts = &m_Hash2Fonts[dwHash]; |
| 687 for (size_t i = 0; i < pFonts->size(); ++i) { | 682 for (size_t i = 0; i < pFonts->size(); ++i) { |
| 688 if (VerifyUnicode((*pFonts)[i], wUnicode)) | 683 if (VerifyUnicode((*pFonts)[i], wUnicode)) |
| 689 return (*pFonts)[i]; | 684 return (*pFonts)[i]; |
| 690 } | 685 } |
| 691 CFX_FontDescriptorInfos* sortedFonts = nullptr; | 686 CFX_FontDescriptorInfos* sortedFonts = m_Hash2CandidateList[dwHash]; |
| 692 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { | 687 if (!sortedFonts) { |
| 693 sortedFonts = new CFX_FontDescriptorInfos; | 688 sortedFonts = new CFX_FontDescriptorInfos; |
| 694 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, | 689 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, |
| 695 CFX_WideString(pszFontFamily), wUnicode); | 690 CFX_WideString(pszFontFamily), wUnicode); |
| 696 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); | 691 m_Hash2CandidateList[dwHash] = sortedFonts; |
| 697 } | 692 } |
| 698 for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { | 693 for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { |
| 699 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; | 694 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; |
| 700 if (!VerifyUnicode(pDesc, wUnicode)) | 695 if (!VerifyUnicode(pDesc, wUnicode)) |
| 701 continue; | 696 continue; |
| 702 CFX_RetainPtr<CFGAS_GEFont> pFont = | 697 CFX_RetainPtr<CFGAS_GEFont> pFont = |
| 703 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); | 698 LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); |
| 704 if (!pFont) | 699 if (!pFont) |
| 705 continue; | 700 continue; |
| 706 pFont->SetLogicalFontStyle(dwFontStyles); | 701 pFont->SetLogicalFontStyle(dwFontStyles); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1150 } | 1145 } |
| 1151 | 1146 |
| 1152 int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1, | 1147 int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1, |
| 1153 const CFX_WideString& Name2) { | 1148 const CFX_WideString& Name2) { |
| 1154 if (Name1.Find(Name2.c_str()) != -1) | 1149 if (Name1.Find(Name2.c_str()) != -1) |
| 1155 return 1; | 1150 return 1; |
| 1156 return 0; | 1151 return 0; |
| 1157 } | 1152 } |
| 1158 | 1153 |
| 1159 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1154 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| OLD | NEW |