summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn7
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp85
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.h27
-rw-r--r--xfa/fgas/font/cfx_fontsourceenum_file.cpp92
-rw-r--r--xfa/fgas/font/cfx_fontsourceenum_file.h48
5 files changed, 151 insertions, 108 deletions
diff --git a/BUILD.gn b/BUILD.gn
index d3ea24dc64..d0ad6a02b3 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1889,6 +1889,13 @@ if (pdf_enable_xfa) {
":pdfium_core_config",
":xfa_warnings",
]
+
+ if (!is_win) {
+ sources += [
+ "xfa/fgas/font/cfx_fontsourceenum_file.cpp",
+ "xfa/fgas/font/cfx_fontsourceenum_file.h",
+ ]
+ }
}
jumbo_static_library("xfa_fwl") {
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index c8aed88547..8a51941627 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -23,6 +23,10 @@
#include "xfa/fgas/font/cfgas_gefont.h"
#include "xfa/fgas/font/fgas_fontutils.h"
+#if _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_
+#include "xfa/fgas/font/cfx_fontsourceenum_file.h"
+#endif
+
#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
namespace {
@@ -198,17 +202,6 @@ const FX_FONTDESCRIPTOR* CFGAS_FontMgr::FindFont(const wchar_t* pszFontFamily,
namespace {
-constexpr const char* g_FontFolders[] = {
-#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
- "/usr/share/fonts", "/usr/share/X11/fonts/Type1",
- "/usr/share/X11/fonts/TTF", "/usr/local/share/fonts",
-#elif _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
- "~/Library/Fonts", "/Library/Fonts", "/System/Library/Fonts",
-#elif _FX_PLATFORM_ == _FX_PLATFORM_ANDROID_
- "/system/fonts",
-#endif
-};
-
const uint16_t g_CodePages[] = {FX_CODEPAGE_MSWin_WesternEuropean,
FX_CODEPAGE_MSWin_EasternEuropean,
FX_CODEPAGE_MSWin_Cyrillic,
@@ -295,8 +288,6 @@ inline uint16_t GetUInt16(const uint8_t* p) {
return static_cast<uint16_t>(p[0] << 8 | p[1]);
}
-constexpr wchar_t kFolderSeparator = L'/';
-
extern "C" {
unsigned long ftStreamRead(FXFT_Stream stream,
@@ -580,74 +571,6 @@ CFX_FontDescriptor::CFX_FontDescriptor()
CFX_FontDescriptor::~CFX_FontDescriptor() {}
-CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() {
- for (size_t i = 0; i < FX_ArraySize(g_FontFolders); ++i)
- m_FolderPaths.push_back(g_FontFolders[i]);
-}
-
-CFX_FontSourceEnum_File::~CFX_FontSourceEnum_File() {}
-
-ByteString CFX_FontSourceEnum_File::GetNextFile() {
- FX_FileHandle* pCurHandle =
- !m_FolderQueue.empty() ? m_FolderQueue.back().pFileHandle : nullptr;
- if (!pCurHandle) {
- if (m_FolderPaths.empty())
- return "";
- pCurHandle = FX_OpenFolder(m_FolderPaths.back().c_str());
- HandleParentPath hpp;
- hpp.pFileHandle = pCurHandle;
- hpp.bsParentPath = m_FolderPaths.back();
- m_FolderQueue.push_back(hpp);
- }
- ByteString bsName;
- bool bFolder;
- ByteString bsFolderSeparator = WideString(kFolderSeparator).ToDefANSI();
- while (true) {
- if (!FX_GetNextFile(pCurHandle, &bsName, &bFolder)) {
- FX_CloseFolder(pCurHandle);
- if (!m_FolderQueue.empty())
- m_FolderQueue.pop_back();
- if (m_FolderQueue.empty()) {
- if (!m_FolderPaths.empty())
- m_FolderPaths.pop_back();
- return !m_FolderPaths.empty() ? GetNextFile() : "";
- }
- pCurHandle = m_FolderQueue.back().pFileHandle;
- continue;
- }
- if (bsName == "." || bsName == "..")
- continue;
- if (bFolder) {
- HandleParentPath hpp;
- hpp.bsParentPath =
- m_FolderQueue.back().bsParentPath + bsFolderSeparator + bsName;
- hpp.pFileHandle = FX_OpenFolder(hpp.bsParentPath.c_str());
- if (!hpp.pFileHandle)
- continue;
- m_FolderQueue.push_back(hpp);
- pCurHandle = hpp.pFileHandle;
- continue;
- }
- bsName = m_FolderQueue.back().bsParentPath + bsFolderSeparator + bsName;
- break;
- }
- return bsName;
-}
-
-void CFX_FontSourceEnum_File::GetNext() {
- m_wsNext = GetNextFile().UTF8Decode();
-}
-
-bool CFX_FontSourceEnum_File::HasNext() const {
- return !m_wsNext.IsEmpty();
-}
-
-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()
: m_pFontSource(pdfium::MakeUnique<CFX_FontSourceEnum_File>()) {}
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 3c63a1c636..0fd46c451e 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -92,33 +92,6 @@ class CFX_FontDescriptorInfo {
}
};
-class CFX_FontSourceEnum_File {
- public:
- CFX_FontSourceEnum_File();
- ~CFX_FontSourceEnum_File();
-
- void GetNext();
- bool HasNext() const;
- RetainPtr<IFX_SeekableStream> GetStream() const;
-
- private:
- struct HandleParentPath {
- HandleParentPath() = default;
- HandleParentPath(const HandleParentPath& x) {
- pFileHandle = x.pFileHandle;
- bsParentPath = x.bsParentPath;
- }
- FX_FileHandle* pFileHandle;
- ByteString bsParentPath;
- };
-
- ByteString GetNextFile();
-
- WideString m_wsNext;
- std::vector<HandleParentPath> m_FolderQueue;
- std::vector<ByteString> m_FolderPaths;
-};
-
#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
class CFGAS_FontMgr final : public Observable<CFGAS_FontMgr> {
diff --git a/xfa/fgas/font/cfx_fontsourceenum_file.cpp b/xfa/fgas/font/cfx_fontsourceenum_file.cpp
new file mode 100644
index 0000000000..c92fba5eea
--- /dev/null
+++ b/xfa/fgas/font/cfx_fontsourceenum_file.cpp
@@ -0,0 +1,92 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fgas/font/cfx_fontsourceenum_file.h"
+
+namespace {
+
+constexpr wchar_t kFolderSeparator = L'/';
+
+constexpr const char* g_FontFolders[] = {
+#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+ "/usr/share/fonts", "/usr/share/X11/fonts/Type1",
+ "/usr/share/X11/fonts/TTF", "/usr/local/share/fonts",
+#elif _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
+ "~/Library/Fonts", "/Library/Fonts", "/System/Library/Fonts",
+#elif _FX_PLATFORM_ == _FX_PLATFORM_ANDROID_
+ "/system/fonts",
+#endif
+};
+
+} // namespace
+
+CFX_FontSourceEnum_File::CFX_FontSourceEnum_File() {
+ for (size_t i = 0; i < FX_ArraySize(g_FontFolders); ++i)
+ m_FolderPaths.push_back(g_FontFolders[i]);
+}
+
+CFX_FontSourceEnum_File::~CFX_FontSourceEnum_File() {}
+
+ByteString CFX_FontSourceEnum_File::GetNextFile() {
+ FX_FileHandle* pCurHandle =
+ !m_FolderQueue.empty() ? m_FolderQueue.back().pFileHandle : nullptr;
+ if (!pCurHandle) {
+ if (m_FolderPaths.empty())
+ return "";
+ pCurHandle = FX_OpenFolder(m_FolderPaths.back().c_str());
+ HandleParentPath hpp;
+ hpp.pFileHandle = pCurHandle;
+ hpp.bsParentPath = m_FolderPaths.back();
+ m_FolderQueue.push_back(hpp);
+ }
+ ByteString bsName;
+ bool bFolder;
+ ByteString bsFolderSeparator = WideString(kFolderSeparator).ToDefANSI();
+ while (true) {
+ if (!FX_GetNextFile(pCurHandle, &bsName, &bFolder)) {
+ FX_CloseFolder(pCurHandle);
+ if (!m_FolderQueue.empty())
+ m_FolderQueue.pop_back();
+ if (m_FolderQueue.empty()) {
+ if (!m_FolderPaths.empty())
+ m_FolderPaths.pop_back();
+ return !m_FolderPaths.empty() ? GetNextFile() : "";
+ }
+ pCurHandle = m_FolderQueue.back().pFileHandle;
+ continue;
+ }
+ if (bsName == "." || bsName == "..")
+ continue;
+ if (bFolder) {
+ HandleParentPath hpp;
+ hpp.bsParentPath =
+ m_FolderQueue.back().bsParentPath + bsFolderSeparator + bsName;
+ hpp.pFileHandle = FX_OpenFolder(hpp.bsParentPath.c_str());
+ if (!hpp.pFileHandle)
+ continue;
+ m_FolderQueue.push_back(hpp);
+ pCurHandle = hpp.pFileHandle;
+ continue;
+ }
+ bsName = m_FolderQueue.back().bsParentPath + bsFolderSeparator + bsName;
+ break;
+ }
+ return bsName;
+}
+
+void CFX_FontSourceEnum_File::GetNext() {
+ m_wsNext = GetNextFile().UTF8Decode();
+}
+
+bool CFX_FontSourceEnum_File::HasNext() const {
+ return !m_wsNext.IsEmpty();
+}
+
+RetainPtr<IFX_SeekableStream> CFX_FontSourceEnum_File::GetStream() const {
+ ASSERT(HasNext());
+ return IFX_SeekableStream::CreateFromFilename(m_wsNext.c_str(),
+ FX_FILEMODE_ReadOnly);
+}
diff --git a/xfa/fgas/font/cfx_fontsourceenum_file.h b/xfa/fgas/font/cfx_fontsourceenum_file.h
new file mode 100644
index 0000000000..ce3f961723
--- /dev/null
+++ b/xfa/fgas/font/cfx_fontsourceenum_file.h
@@ -0,0 +1,48 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef XFA_FGAS_FONT_CFX_FONTSOURCEENUM_FILE_H_
+#define XFA_FGAS_FONT_CFX_FONTSOURCEENUM_FILE_H_
+
+#include <vector>
+
+#include "core/fxcrt/fx_stream.h"
+#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/retain_ptr.h"
+
+#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
+#error "Not used on Windows"
+#endif
+
+class CFX_FontSourceEnum_File {
+ public:
+ CFX_FontSourceEnum_File();
+ ~CFX_FontSourceEnum_File();
+
+ void GetNext();
+ bool HasNext() const;
+ RetainPtr<IFX_SeekableStream> GetStream() const;
+
+ private:
+ struct HandleParentPath {
+ HandleParentPath() = default;
+ HandleParentPath(const HandleParentPath& x) {
+ pFileHandle = x.pFileHandle;
+ bsParentPath = x.bsParentPath;
+ }
+ FX_FileHandle* pFileHandle;
+ ByteString bsParentPath;
+ };
+
+ ByteString GetNextFile();
+
+ WideString m_wsNext;
+ std::vector<HandleParentPath> m_FolderQueue;
+ std::vector<ByteString> m_FolderPaths;
+};
+
+#endif // XFA_FGAS_FONT_CFX_FONTSOURCEENUM_FILE_H_