summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-03 17:53:09 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-03 17:53:09 +0000
commitf9e0498bb1ce2a52628065bc13389b4fc2768f42 (patch)
treeca32a8eec12a42538fa5a5e1f86268c67a394ebc /xfa
parenta1c846c4cf3f8c08edfffa1cc6b60860c011000b (diff)
downloadpdfium-f9e0498bb1ce2a52628065bc13389b4fc2768f42.tar.xz
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 <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp30
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.h8
2 files changed, 15 insertions, 23 deletions
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<bool, RetainPtr<IFX_SeekableStream>>
-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<IFX_SeekableStream> 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<IFX_SeekableStream> stream;
- std::tie(has_next, stream) = m_pFontSource->GetNext();
- while (has_next) {
+ m_pFontSource->GetNext();
+ while (m_pFontSource->HasNext()) {
+ RetainPtr<IFX_SeekableStream> 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 <map>
#include <memory>
#include <set>
-#include <utility>
#include <vector>
#include "core/fxcrt/fx_extension.h"
@@ -98,10 +97,9 @@ class CFX_FontSourceEnum_File {
CFX_FontSourceEnum_File();
~CFX_FontSourceEnum_File();
- bool HasStartPosition();
-
- // <next exists, stream for next>
- std::pair<bool, RetainPtr<IFX_SeekableStream>> GetNext();
+ void GetNext();
+ bool HasNext() const;
+ RetainPtr<IFX_SeekableStream> GetStream() const;
private:
struct HandleParentPath {