| 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/fgas_stdfontmgr.h" | 7 #include "xfa/fgas/font/fgas_stdfontmgr.h" | 
| 8 | 8 | 
| 9 #include "core/fxcrt/include/fx_stream.h" | 9 #include "core/fxcrt/include/fx_stream.h" | 
| 10 #include "core/fxge/include/cfx_fontmapper.h" | 10 #include "core/fxge/include/cfx_fontmapper.h" | 
| 11 #include "core/fxge/include/cfx_fontmgr.h" | 11 #include "core/fxge/include/cfx_fontmgr.h" | 
| 12 #include "core/fxge/include/cfx_gemodule.h" | 12 #include "core/fxge/include/cfx_gemodule.h" | 
| 13 #include "core/fxge/include/ifx_systemfontinfo.h" | 13 #include "core/fxge/include/ifx_systemfontinfo.h" | 
| 14 #include "core/fxge/include/fx_ge.h" | 14 #include "core/fxge/include/fx_ge.h" | 
| 15 #include "xfa/fgas/crt/fgas_codepage.h" | 15 #include "xfa/fgas/crt/fgas_codepage.h" | 
| 16 #include "xfa/fgas/font/fgas_fontutils.h" | 16 #include "xfa/fgas/font/fgas_fontutils.h" | 
| 17 #include "xfa/fgas/font/fgas_gefont.h" | 17 #include "xfa/fgas/font/fgas_gefont.h" | 
| 18 | 18 | 
| 19 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 19 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 
| 20 | 20 | 
| 21 IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { | 21 std::unique_ptr<IFGAS_FontMgr> IFGAS_FontMgr::Create( | 
| 22   return new CFGAS_StdFontMgrImp(pEnumerator); | 22     FX_LPEnumAllFonts pEnumerator) { | 
|  | 23   return std::unique_ptr<IFGAS_FontMgr>(new CFGAS_StdFontMgrImp(pEnumerator)); | 
| 23 } | 24 } | 
| 24 | 25 | 
| 25 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) | 26 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) | 
| 26     : m_pEnumerator(pEnumerator), | 27     : m_pEnumerator(pEnumerator), | 
| 27       m_FontFaces(100), | 28       m_FontFaces(100), | 
| 28       m_CPFonts(8), | 29       m_CPFonts(8), | 
| 29       m_FamilyFonts(16), | 30       m_FamilyFonts(16), | 
| 30       m_UnicodeFonts(16), | 31       m_UnicodeFonts(16), | 
| 31       m_BufferFonts(4), | 32       m_BufferFonts(4), | 
| 32       m_StreamFonts(4), | 33       m_StreamFonts(4), | 
| 33       m_DeriveFonts(4) { | 34       m_DeriveFonts(4) { | 
| 34   if (m_pEnumerator) { | 35   if (m_pEnumerator) { | 
| 35     m_pEnumerator(m_FontFaces, nullptr, 0xFEFF); | 36     m_pEnumerator(m_FontFaces, nullptr, 0xFEFF); | 
| 36   } | 37   } | 
| 37 } | 38 } | 
| 38 | 39 | 
| 39 CFGAS_StdFontMgrImp::~CFGAS_StdFontMgrImp() { | 40 CFGAS_StdFontMgrImp::~CFGAS_StdFontMgrImp() { | 
| 40   m_FontFaces.RemoveAll(FALSE); | 41   m_FontFaces.RemoveAll(FALSE); | 
| 41   m_CPFonts.RemoveAll(); | 42   m_CPFonts.RemoveAll(); | 
| 42   m_FamilyFonts.RemoveAll(); | 43   m_FamilyFonts.RemoveAll(); | 
| 43   m_UnicodeFonts.RemoveAll(); | 44   m_UnicodeFonts.RemoveAll(); | 
| 44   m_BufferFonts.RemoveAll(); | 45   m_BufferFonts.RemoveAll(); | 
| 45   m_StreamFonts.RemoveAll(); | 46   m_StreamFonts.RemoveAll(); | 
| 46   m_DeriveFonts.RemoveAll(); | 47   m_DeriveFonts.RemoveAll(); | 
| 47   for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) | 48   for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) | 
| 48     m_Fonts[i]->Release(); | 49     m_Fonts[i]->Release(); | 
| 49 } | 50 } | 
| 50 | 51 | 
| 51 void CFGAS_StdFontMgrImp::Release() { |  | 
| 52   delete this; |  | 
| 53 } |  | 
| 54 |  | 
| 55 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage( | 52 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage( | 
| 56     uint16_t wCodePage, | 53     uint16_t wCodePage, | 
| 57     uint32_t dwFontStyles, | 54     uint32_t dwFontStyles, | 
| 58     const FX_WCHAR* pszFontFamily) { | 55     const FX_WCHAR* pszFontFamily) { | 
| 59   uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 56   uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); | 
| 60   CFGAS_GEFont* pFont = nullptr; | 57   CFGAS_GEFont* pFont = nullptr; | 
| 61   if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 58   if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { | 
| 62     return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; | 59     return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; | 
| 63   } | 60   } | 
| 64   FX_FONTDESCRIPTOR const* pFD = | 61   FX_FONTDESCRIPTOR const* pFD = | 
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 558   return (FX_POSITION)-1; | 555   return (FX_POSITION)-1; | 
| 559 } | 556 } | 
| 560 | 557 | 
| 561 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { | 558 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { | 
| 562   IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); | 559   IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); | 
| 563   m_wsNext = GetNextFile().UTF8Decode(); | 560   m_wsNext = GetNextFile().UTF8Decode(); | 
| 564   pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr; | 561   pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr; | 
| 565   return pAccess; | 562   return pAccess; | 
| 566 } | 563 } | 
| 567 | 564 | 
| 568 IFGAS_FontMgr* IFGAS_FontMgr::Create(CFX_FontSourceEnum_File* pFontEnum) { | 565 std::unique_ptr<IFGAS_FontMgr> IFGAS_FontMgr::Create( | 
|  | 566     CFX_FontSourceEnum_File* pFontEnum) { | 
| 569   if (!pFontEnum) | 567   if (!pFontEnum) | 
| 570     return nullptr; | 568     return nullptr; | 
| 571 | 569 | 
| 572   std::unique_ptr<CFGAS_FontMgrImp> pFontMgr(new CFGAS_FontMgrImp(pFontEnum)); | 570   std::unique_ptr<CFGAS_FontMgrImp> pFontMgr(new CFGAS_FontMgrImp(pFontEnum)); | 
| 573   if (!pFontMgr->EnumFonts()) | 571   if (!pFontMgr->EnumFonts()) | 
| 574     return nullptr; | 572     return nullptr; | 
| 575   return pFontMgr.release(); | 573   return std::move(pFontMgr); | 
| 576 } | 574 } | 
| 577 | 575 | 
| 578 CFGAS_FontMgrImp::CFGAS_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum) | 576 CFGAS_FontMgrImp::CFGAS_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum) | 
| 579     : m_pFontSource(pFontEnum) {} | 577     : m_pFontSource(pFontEnum) {} | 
| 580 | 578 | 
| 581 CFGAS_FontMgrImp::~CFGAS_FontMgrImp() {} | 579 CFGAS_FontMgrImp::~CFGAS_FontMgrImp() { | 
|  | 580   for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) { | 
|  | 581     delete m_InstalledFonts[i]; | 
|  | 582   } | 
|  | 583   FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); | 
|  | 584   while (pos) { | 
|  | 585     uint32_t dwHash; | 
|  | 586     CFX_FontDescriptorInfos* pDescs; | 
|  | 587     m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); | 
|  | 588     delete pDescs; | 
|  | 589   } | 
|  | 590   pos = m_Hash2Fonts.GetStartPosition(); | 
|  | 591   while (pos) { | 
|  | 592     uint32_t dwHash; | 
|  | 593     CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; | 
|  | 594     m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); | 
|  | 595     delete pFonts; | 
|  | 596   } | 
|  | 597   m_Hash2Fonts.RemoveAll(); | 
|  | 598   pos = m_IFXFont2FileRead.GetStartPosition(); | 
|  | 599   while (pos) { | 
|  | 600     CFGAS_GEFont* pFont; | 
|  | 601     IFX_FileRead* pFileRead; | 
|  | 602     m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); | 
|  | 603     pFileRead->Release(); | 
|  | 604   } | 
|  | 605 } | 
| 582 | 606 | 
| 583 FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFontMapper() { | 607 FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFontMapper() { | 
| 584   CFX_FontMapper* pFontMapper = | 608   CFX_FontMapper* pFontMapper = | 
| 585       CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); | 609       CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); | 
| 586   if (!pFontMapper) | 610   if (!pFontMapper) | 
| 587     return FALSE; | 611     return FALSE; | 
| 588 | 612 | 
| 589   IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 613   IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); | 
| 590   if (!pSystemFontInfo) | 614   if (!pSystemFontInfo) | 
| 591     return FALSE; | 615     return FALSE; | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 628     return FALSE; | 652     return FALSE; | 
| 629   return TRUE; | 653   return TRUE; | 
| 630 } | 654 } | 
| 631 | 655 | 
| 632 FX_BOOL CFGAS_FontMgrImp::EnumFonts() { | 656 FX_BOOL CFGAS_FontMgrImp::EnumFonts() { | 
| 633   if (EnumFontsFromFontMapper()) | 657   if (EnumFontsFromFontMapper()) | 
| 634     return TRUE; | 658     return TRUE; | 
| 635   return EnumFontsFromFiles(); | 659   return EnumFontsFromFiles(); | 
| 636 } | 660 } | 
| 637 | 661 | 
| 638 void CFGAS_FontMgrImp::Release() { |  | 
| 639   for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) { |  | 
| 640     delete m_InstalledFonts[i]; |  | 
| 641   } |  | 
| 642   FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); |  | 
| 643   while (pos) { |  | 
| 644     uint32_t dwHash; |  | 
| 645     CFX_FontDescriptorInfos* pDescs; |  | 
| 646     m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); |  | 
| 647     delete pDescs; |  | 
| 648   } |  | 
| 649   pos = m_Hash2Fonts.GetStartPosition(); |  | 
| 650   while (pos) { |  | 
| 651     uint32_t dwHash; |  | 
| 652     CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts; |  | 
| 653     m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); |  | 
| 654     delete pFonts; |  | 
| 655   } |  | 
| 656   m_Hash2Fonts.RemoveAll(); |  | 
| 657   pos = m_IFXFont2FileRead.GetStartPosition(); |  | 
| 658   while (pos) { |  | 
| 659     CFGAS_GEFont* pFont; |  | 
| 660     IFX_FileRead* pFileRead; |  | 
| 661     m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); |  | 
| 662     pFileRead->Release(); |  | 
| 663   } |  | 
| 664   delete this; |  | 
| 665 } |  | 
| 666 |  | 
| 667 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( | 662 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( | 
| 668     uint16_t wCodePage, | 663     uint16_t wCodePage, | 
| 669     uint32_t dwFontStyles, | 664     uint32_t dwFontStyles, | 
| 670     const FX_WCHAR* pszFontFamily) { | 665     const FX_WCHAR* pszFontFamily) { | 
| 671   return nullptr; | 666   return nullptr; | 
| 672 } | 667 } | 
| 673 | 668 | 
| 674 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCharset( | 669 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCharset( | 
| 675     uint8_t nCharset, | 670     uint8_t nCharset, | 
| 676     uint32_t dwFontStyles, | 671     uint32_t dwFontStyles, | 
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1392 | 1387 | 
| 1393 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1388 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 
| 1394                                      const CFX_WideString& Name2) { | 1389                                      const CFX_WideString& Name2) { | 
| 1395   if (Name1.Find(Name2.c_str()) != -1) { | 1390   if (Name1.Find(Name2.c_str()) != -1) { | 
| 1396     return 1; | 1391     return 1; | 
| 1397   } | 1392   } | 
| 1398   return 0; | 1393   return 0; | 
| 1399 } | 1394 } | 
| 1400 | 1395 | 
| 1401 #endif | 1396 #endif | 
| OLD | NEW | 
|---|