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

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

Issue 2562563002: Properly ref count IFX_FileAccess. (Closed)
Patch Set: Created 4 years 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
« core/fxcrt/fx_extension.cpp ('K') | « xfa/fgas/font/cfgas_fontmgr.h ('k') | no next file » | 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/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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 return bsName; 559 return bsName;
560 } 560 }
561 561
562 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() { 562 FX_POSITION CFX_FontSourceEnum_File::GetStartPosition() {
563 m_wsNext = GetNextFile().UTF8Decode(); 563 m_wsNext = GetNextFile().UTF8Decode();
564 if (m_wsNext.GetLength() == 0) 564 if (m_wsNext.GetLength() == 0)
565 return (FX_POSITION)0; 565 return (FX_POSITION)0;
566 return (FX_POSITION)-1; 566 return (FX_POSITION)-1;
567 } 567 }
568 568
569 IFX_FileAccess* CFX_FontSourceEnum_File::GetNext(FX_POSITION& pos) { 569 CFX_RetainPtr<IFX_FileAccess> CFX_FontSourceEnum_File::GetNext(
570 IFX_FileAccess* pAccess = IFX_FileAccess::CreateDefault(m_wsNext.AsStringC()); 570 FX_POSITION& pos) {
dsinclair 2016/12/07 23:05:03 Can this be a * instead of an &?
Tom Sepez 2016/12/07 23:26:55 It could, but this goes far beyond this -- the FX
571 CFX_RetainPtr<IFX_FileAccess> pAccess =
572 IFX_FileAccess::CreateDefault(m_wsNext.AsStringC());
571 m_wsNext = GetNextFile().UTF8Decode(); 573 m_wsNext = GetNextFile().UTF8Decode();
572 pos = m_wsNext.GetLength() != 0 ? pAccess : nullptr; 574 pos = m_wsNext.GetLength() != 0 ? pAccess.Get() : nullptr;
573 return pAccess; 575 return pAccess;
574 } 576 }
575 577
576 std::unique_ptr<CFGAS_FontMgr> CFGAS_FontMgr::Create( 578 std::unique_ptr<CFGAS_FontMgr> CFGAS_FontMgr::Create(
577 CFX_FontSourceEnum_File* pFontEnum) { 579 CFX_FontSourceEnum_File* pFontEnum) {
578 if (!pFontEnum) 580 if (!pFontEnum)
579 return nullptr; 581 return nullptr;
580 582
581 auto pFontMgr = pdfium::MakeUnique<CFGAS_FontMgr>(pFontEnum); 583 auto pFontMgr = pdfium::MakeUnique<CFGAS_FontMgr>(pFontEnum);
582 if (!pFontMgr->EnumFonts()) 584 if (!pFontMgr->EnumFonts())
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 CFX_WideString wsFaceName = 631 CFX_WideString wsFaceName =
630 CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str()); 632 CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str());
631 RegisterFaces(pFontStream, &wsFaceName); 633 RegisterFaces(pFontStream, &wsFaceName);
632 } 634 }
633 return m_InstalledFonts.GetSize() != 0; 635 return m_InstalledFonts.GetSize() != 0;
634 } 636 }
635 637
636 bool CFGAS_FontMgr::EnumFontsFromFiles() { 638 bool CFGAS_FontMgr::EnumFontsFromFiles() {
637 CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); 639 CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary();
638 FX_POSITION pos = m_pFontSource->GetStartPosition(); 640 FX_POSITION pos = m_pFontSource->GetStartPosition();
639 IFX_FileAccess* pFontSource = nullptr;
640 CFX_RetainPtr<IFX_SeekableReadStream> pFontStream;
641 while (pos) { 641 while (pos) {
642 pFontSource = m_pFontSource->GetNext(pos); 642 CFX_RetainPtr<IFX_FileAccess> pFontSource = m_pFontSource->GetNext(pos);
643 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); 643 CFX_RetainPtr<IFX_SeekableReadStream> pFontStream =
644 if (!pFontStream) { 644 pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly);
645 pFontSource->Release(); 645 if (pFontStream)
646 continue; 646 RegisterFaces(pFontStream, nullptr);
647 }
648 RegisterFaces(pFontStream, nullptr);
649 pFontSource->Release();
650 } 647 }
651 return m_InstalledFonts.GetSize() != 0; 648 return m_InstalledFonts.GetSize() != 0;
652 } 649 }
653 650
654 bool CFGAS_FontMgr::EnumFonts() { 651 bool CFGAS_FontMgr::EnumFonts() {
655 if (EnumFontsFromFontMapper()) 652 if (EnumFontsFromFontMapper())
656 return true; 653 return true;
657 return EnumFontsFromFiles(); 654 return EnumFontsFromFiles();
658 } 655 }
659 656
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 } 1185 }
1189 1186
1190 int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1, 1187 int32_t CFGAS_FontMgr::IsPartName(const CFX_WideString& Name1,
1191 const CFX_WideString& Name2) { 1188 const CFX_WideString& Name2) {
1192 if (Name1.Find(Name2.c_str()) != -1) 1189 if (Name1.Find(Name2.c_str()) != -1)
1193 return 1; 1190 return 1;
1194 return 0; 1191 return 0;
1195 } 1192 }
1196 1193
1197 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 1194 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
OLDNEW
« core/fxcrt/fx_extension.cpp ('K') | « xfa/fgas/font/cfgas_fontmgr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698