Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: xfa/fgas/font/fgas_stdfontmgr.cpp

Issue 2227883002: Use smart pointers for class owned pointers in xfa/fxfa (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fgas/font/fgas_stdfontmgr.h ('k') | xfa/fwl/theme/cfwl_widgettp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "xfa/fgas/crt/fgas_codepage.h" 14 #include "xfa/fgas/crt/fgas_codepage.h"
15 #include "xfa/fgas/font/fgas_fontutils.h" 15 #include "xfa/fgas/font/fgas_fontutils.h"
16 #include "xfa/fgas/font/fgas_gefont.h" 16 #include "xfa/fgas/font/fgas_gefont.h"
17 17
18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
19 19
20 IFGAS_FontMgr* IFGAS_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { 20 std::unique_ptr<IFGAS_FontMgr> IFGAS_FontMgr::Create(
21 return new CFGAS_StdFontMgrImp(pEnumerator); 21 FX_LPEnumAllFonts pEnumerator) {
22 return std::unique_ptr<IFGAS_FontMgr>(new CFGAS_StdFontMgrImp(pEnumerator));
22 } 23 }
23 24
24 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) 25 CFGAS_StdFontMgrImp::CFGAS_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator)
25 : m_pEnumerator(pEnumerator), 26 : m_pEnumerator(pEnumerator),
26 m_FontFaces(100), 27 m_FontFaces(100),
27 m_CPFonts(8), 28 m_CPFonts(8),
28 m_FamilyFonts(16), 29 m_FamilyFonts(16),
29 m_UnicodeFonts(16), 30 m_UnicodeFonts(16),
30 m_BufferFonts(4), 31 m_BufferFonts(4),
31 m_StreamFonts(4), 32 m_StreamFonts(4),
32 m_DeriveFonts(4) { 33 m_DeriveFonts(4) {
33 if (m_pEnumerator) { 34 if (m_pEnumerator) {
34 m_pEnumerator(m_FontFaces, nullptr, 0xFEFF); 35 m_pEnumerator(m_FontFaces, nullptr, 0xFEFF);
35 } 36 }
36 } 37 }
37 38
38 CFGAS_StdFontMgrImp::~CFGAS_StdFontMgrImp() { 39 CFGAS_StdFontMgrImp::~CFGAS_StdFontMgrImp() {
39 m_FontFaces.RemoveAll(FALSE); 40 m_FontFaces.RemoveAll(FALSE);
40 m_CPFonts.RemoveAll(); 41 m_CPFonts.RemoveAll();
41 m_FamilyFonts.RemoveAll(); 42 m_FamilyFonts.RemoveAll();
42 m_UnicodeFonts.RemoveAll(); 43 m_UnicodeFonts.RemoveAll();
43 m_BufferFonts.RemoveAll(); 44 m_BufferFonts.RemoveAll();
44 m_StreamFonts.RemoveAll(); 45 m_StreamFonts.RemoveAll();
45 m_DeriveFonts.RemoveAll(); 46 m_DeriveFonts.RemoveAll();
46 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) 47 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--)
47 m_Fonts[i]->Release(); 48 m_Fonts[i]->Release();
48 } 49 }
49 50
50 void CFGAS_StdFontMgrImp::Release() {
51 delete this;
52 }
53
54 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage( 51 CFGAS_GEFont* CFGAS_StdFontMgrImp::GetDefFontByCodePage(
55 uint16_t wCodePage, 52 uint16_t wCodePage,
56 uint32_t dwFontStyles, 53 uint32_t dwFontStyles,
57 const FX_WCHAR* pszFontFamily) { 54 const FX_WCHAR* pszFontFamily) {
58 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); 55 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
59 CFGAS_GEFont* pFont = nullptr; 56 CFGAS_GEFont* pFont = nullptr;
60 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { 57 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
61 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr; 58 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : nullptr;
62 } 59 }
63 FX_FONTDESCRIPTOR const* pFD = 60 FX_FONTDESCRIPTOR const* pFD =
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 return (FX_POSITION)-1; 554 return (FX_POSITION)-1;
558 } 555 }
559 556
560 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { 557 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) {
561 IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC()); 558 IFX_FileAccess* pAccess = FX_CreateDefaultFileAccess(m_wsNext.AsStringC());
562 m_wsNext = GetNextFile().UTF8Decode(); 559 m_wsNext = GetNextFile().UTF8Decode();
563 pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr; 560 pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr;
564 return pAccess; 561 return pAccess;
565 } 562 }
566 563
567 IFGAS_FontMgr* IFGAS_FontMgr::Create(CFX_FontSourceEnum_File* pFontEnum) { 564 std::unique_ptr<IFGAS_FontMgr> IFGAS_FontMgr::Create(
565 CFX_FontSourceEnum_File* pFontEnum) {
568 if (!pFontEnum) 566 if (!pFontEnum)
569 return nullptr; 567 return nullptr;
570 568
571 std::unique_ptr<CFGAS_FontMgrImp> pFontMgr(new CFGAS_FontMgrImp(pFontEnum)); 569 std::unique_ptr<CFGAS_FontMgrImp> pFontMgr(new CFGAS_FontMgrImp(pFontEnum));
572 if (!pFontMgr->EnumFonts()) 570 if (!pFontMgr->EnumFonts())
573 return nullptr; 571 return nullptr;
574 return pFontMgr.release(); 572 return std::move(pFontMgr);
575 } 573 }
576 574
577 CFGAS_FontMgrImp::CFGAS_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum) 575 CFGAS_FontMgrImp::CFGAS_FontMgrImp(CFX_FontSourceEnum_File* pFontEnum)
578 : m_pFontSource(pFontEnum) {} 576 : m_pFontSource(pFontEnum) {}
579 577
580 CFGAS_FontMgrImp::~CFGAS_FontMgrImp() {} 578 CFGAS_FontMgrImp::~CFGAS_FontMgrImp() {
579 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) {
580 delete m_InstalledFonts[i];
581 }
582 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
583 while (pos) {
584 uint32_t dwHash;
585 CFX_FontDescriptorInfos* pDescs;
586 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
587 delete pDescs;
588 }
589 pos = m_Hash2Fonts.GetStartPosition();
590 while (pos) {
591 uint32_t dwHash;
592 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts;
593 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts);
594 delete pFonts;
595 }
596 m_Hash2Fonts.RemoveAll();
597 pos = m_IFXFont2FileRead.GetStartPosition();
598 while (pos) {
599 CFGAS_GEFont* pFont;
600 IFX_FileRead* pFileRead;
601 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
602 pFileRead->Release();
603 }
604 }
581 605
582 FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFontMapper() { 606 FX_BOOL CFGAS_FontMgrImp::EnumFontsFromFontMapper() {
583 CFX_FontMapper* pFontMapper = 607 CFX_FontMapper* pFontMapper =
584 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper(); 608 CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper();
585 if (!pFontMapper) 609 if (!pFontMapper)
586 return FALSE; 610 return FALSE;
587 611
588 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); 612 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
589 if (!pSystemFontInfo) 613 if (!pSystemFontInfo)
590 return FALSE; 614 return FALSE;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 return FALSE; 651 return FALSE;
628 return TRUE; 652 return TRUE;
629 } 653 }
630 654
631 FX_BOOL CFGAS_FontMgrImp::EnumFonts() { 655 FX_BOOL CFGAS_FontMgrImp::EnumFonts() {
632 if (EnumFontsFromFontMapper()) 656 if (EnumFontsFromFontMapper())
633 return TRUE; 657 return TRUE;
634 return EnumFontsFromFiles(); 658 return EnumFontsFromFiles();
635 } 659 }
636 660
637 void CFGAS_FontMgrImp::Release() {
638 for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++) {
639 delete m_InstalledFonts[i];
640 }
641 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
642 while (pos) {
643 uint32_t dwHash;
644 CFX_FontDescriptorInfos* pDescs;
645 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
646 delete pDescs;
647 }
648 pos = m_Hash2Fonts.GetStartPosition();
649 while (pos) {
650 uint32_t dwHash;
651 CFX_ArrayTemplate<CFGAS_GEFont*>* pFonts;
652 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts);
653 delete pFonts;
654 }
655 m_Hash2Fonts.RemoveAll();
656 pos = m_IFXFont2FileRead.GetStartPosition();
657 while (pos) {
658 CFGAS_GEFont* pFont;
659 IFX_FileRead* pFileRead;
660 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
661 pFileRead->Release();
662 }
663 delete this;
664 }
665
666 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage( 661 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCodePage(
667 uint16_t wCodePage, 662 uint16_t wCodePage,
668 uint32_t dwFontStyles, 663 uint32_t dwFontStyles,
669 const FX_WCHAR* pszFontFamily) { 664 const FX_WCHAR* pszFontFamily) {
670 return nullptr; 665 return nullptr;
671 } 666 }
672 667
673 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCharset( 668 CFGAS_GEFont* CFGAS_FontMgrImp::GetDefFontByCharset(
674 uint8_t nCharset, 669 uint8_t nCharset,
675 uint32_t dwFontStyles, 670 uint32_t dwFontStyles,
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 1386
1392 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1, 1387 int32_t CFGAS_FontMgrImp::IsPartName(const CFX_WideString& Name1,
1393 const CFX_WideString& Name2) { 1388 const CFX_WideString& Name2) {
1394 if (Name1.Find(Name2.c_str()) != -1) { 1389 if (Name1.Find(Name2.c_str()) != -1) {
1395 return 1; 1390 return 1;
1396 } 1391 }
1397 return 0; 1392 return 0;
1398 } 1393 }
1399 1394
1400 #endif 1395 #endif
OLDNEW
« no previous file with comments | « xfa/fgas/font/fgas_stdfontmgr.h ('k') | xfa/fwl/theme/cfwl_widgettp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698