From f9e0498bb1ce2a52628065bc13389b4fc2768f42 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 3 Oct 2018 17:53:09 +0000 Subject: Simplify CFX_FontSourceEnum_File's file iterator. Break the methods down to their basic functionality, and built up from there. Change-Id: I691abaf08375425b59f2382cf95577c3917aca9d Reviewed-on: https://pdfium-review.googlesource.com/42972 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- xfa/fgas/font/cfgas_fontmgr.cpp | 30 ++++++++++++------------------ xfa/fgas/font/cfgas_fontmgr.h | 8 +++----- 2 files changed, 15 insertions(+), 23 deletions(-) (limited to 'xfa') diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index b2150f99b8..c8aed88547 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -634,20 +634,18 @@ ByteString CFX_FontSourceEnum_File::GetNextFile() { return bsName; } -bool CFX_FontSourceEnum_File::HasStartPosition() { +void CFX_FontSourceEnum_File::GetNext() { m_wsNext = GetNextFile().UTF8Decode(); - return !m_wsNext.IsEmpty(); } -std::pair> -CFX_FontSourceEnum_File::GetNext() { - if (m_wsNext.IsEmpty()) - return {false, nullptr}; +bool CFX_FontSourceEnum_File::HasNext() const { + return !m_wsNext.IsEmpty(); +} - auto stream = IFX_SeekableStream::CreateFromFilename(m_wsNext.c_str(), - FX_FILEMODE_ReadOnly); - m_wsNext = GetNextFile().UTF8Decode(); - return {true, stream}; +RetainPtr CFX_FontSourceEnum_File::GetStream() const { + ASSERT(HasNext()); + return IFX_SeekableStream::CreateFromFilename(m_wsNext.c_str(), + FX_FILEMODE_ReadOnly); } CFGAS_FontMgr::CFGAS_FontMgr() @@ -684,16 +682,12 @@ bool CFGAS_FontMgr::EnumFontsFromFontMapper() { bool CFGAS_FontMgr::EnumFontsFromFiles() { CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); - if (!m_pFontSource->HasStartPosition()) - return !m_InstalledFonts.empty(); - - bool has_next; - RetainPtr stream; - std::tie(has_next, stream) = m_pFontSource->GetNext(); - while (has_next) { + m_pFontSource->GetNext(); + while (m_pFontSource->HasNext()) { + RetainPtr stream = m_pFontSource->GetStream(); if (stream) RegisterFaces(stream, nullptr); - std::tie(has_next, stream) = m_pFontSource->GetNext(); + m_pFontSource->GetNext(); } return !m_InstalledFonts.empty(); } diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index bc2a7af2a7..3c63a1c636 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -11,7 +11,6 @@ #include #include #include -#include #include #include "core/fxcrt/fx_extension.h" @@ -98,10 +97,9 @@ class CFX_FontSourceEnum_File { CFX_FontSourceEnum_File(); ~CFX_FontSourceEnum_File(); - bool HasStartPosition(); - - // - std::pair> GetNext(); + void GetNext(); + bool HasNext() const; + RetainPtr GetStream() const; private: struct HandleParentPath { -- cgit v1.2.3