Remove CFGAS_FontMgr::EnumFontFromFiles.
It can't work under chrome and its sandbox process model.
It is only hit once under pdfium_test, and that occurs in
FPDFUnavailableSysFontInfoEmbedderTest where we don't want
any fonts to be found in the first place, so probing doesn't
impact success.
We've already adapted the subordinate CPDF-based font mgr to
cope with the chrome environment, so let CFGAS just piggy back
off of that.
Change-Id: I16ba3f52084e65b7ae229088b124d77c191900c5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/73335
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fgas/BUILD.gn b/xfa/fgas/BUILD.gn
index 17e60cd..7860fbd 100644
--- a/xfa/fgas/BUILD.gn
+++ b/xfa/fgas/BUILD.gn
@@ -38,13 +38,6 @@
"../:xfa_warnings",
]
visibility = [ "../../*" ]
-
- if (!is_win) {
- sources += [
- "font/cfgas_fontsource_enum_file.cpp",
- "font/cfgas_fontsource_enum_file.h",
- ]
- }
}
pdfium_unittest_source_set("unittests") {
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 485c1dd..8b2de13 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -23,10 +23,6 @@
#include "xfa/fgas/font/cfgas_gefont.h"
#include "xfa/fgas/font/fgas_fontutils.h"
-#if !defined(OS_WIN)
-#include "xfa/fgas/font/cfgas_fontsource_enum_file.h"
-#endif
-
namespace {
bool VerifyUnicode(const RetainPtr<CFGAS_GEFont>& pFont, wchar_t wcUnicode) {
@@ -608,8 +604,7 @@
CFX_FontDescriptor::~CFX_FontDescriptor() = default;
-CFGAS_FontMgr::CFGAS_FontMgr()
- : m_pFontSource(std::make_unique<CFGAS_FontSourceEnumFile>()) {}
+CFGAS_FontMgr::CFGAS_FontMgr() = default;
CFGAS_FontMgr::~CFGAS_FontMgr() = default;
@@ -632,19 +627,8 @@
return !m_InstalledFonts.empty();
}
-bool CFGAS_FontMgr::EnumFontsFromFiles() {
- m_pFontSource->GetNext();
- while (m_pFontSource->HasNext()) {
- RetainPtr<IFX_SeekableStream> stream = m_pFontSource->GetStream();
- if (stream)
- RegisterFaces(stream, nullptr);
- m_pFontSource->GetNext();
- }
- return !m_InstalledFonts.empty();
-}
-
bool CFGAS_FontMgr::EnumFonts() {
- return EnumFontsFromFontMapper() || EnumFontsFromFiles();
+ return EnumFontsFromFontMapper();
}
RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicodeImpl(
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 0d5daff..c91cc8c 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -21,7 +21,6 @@
#include "core/fxge/cfx_face.h"
#include "core/fxge/fx_freetype.h"
-class CFGAS_FontSourceEnumFile;
class CFGAS_GEFont;
class CFX_FontMapper;
class IFX_SeekableReadStream;
@@ -149,7 +148,6 @@
#if defined(OS_WIN)
std::deque<FX_FONTDESCRIPTOR> m_FontFaces;
#else
- std::unique_ptr<CFGAS_FontSourceEnumFile> m_pFontSource;
std::vector<std::unique_ptr<CFX_FontDescriptor>> m_InstalledFonts;
std::map<uint32_t, std::unique_ptr<std::vector<CFX_FontDescriptorInfo>>>
m_Hash2CandidateList;
diff --git a/xfa/fgas/font/cfgas_fontsource_enum_file.cpp b/xfa/fgas/font/cfgas_fontsource_enum_file.cpp
deleted file mode 100644
index eb57acf..0000000
--- a/xfa/fgas/font/cfgas_fontsource_enum_file.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-// 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/cfgas_fontsource_enum_file.h"
-
-#include <iterator>
-
-#include "build/build_config.h"
-
-namespace {
-
-constexpr char kFolderSeparator = '/';
-
-constexpr const char* kFontFolders[] = {
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
- "/usr/share/fonts",
- "/usr/share/X11/fonts/Type1",
- "/usr/share/X11/fonts/TTF",
- "/usr/local/share/fonts",
-#elif defined(OS_APPLE)
- "~/Library/Fonts",
- "/Library/Fonts",
- "/System/Library/Fonts",
-#elif defined(OS_ANDROID)
- "/system/fonts",
-#endif
-};
-
-} // namespace
-
-CFGAS_FontSourceEnumFile::CFGAS_FontSourceEnumFile()
- : m_FolderPaths(std::begin(kFontFolders), std::end(kFontFolders)) {}
-
-CFGAS_FontSourceEnumFile::~CFGAS_FontSourceEnumFile() = default;
-
-ByteString CFGAS_FontSourceEnumFile::GetNextFile() {
- FX_FolderHandle* pCurHandle =
- !m_FolderQueue.empty() ? m_FolderQueue.back().pFolderHandle : nullptr;
- if (!pCurHandle) {
- if (m_FolderPaths.empty())
- return ByteString();
- pCurHandle = FX_OpenFolder(m_FolderPaths.back().c_str());
- HandleParentPath hpp;
- hpp.pFolderHandle = pCurHandle;
- hpp.bsParentPath = m_FolderPaths.back();
- m_FolderQueue.push_back(hpp);
- }
- ByteString bsName;
- bool bFolder;
- 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() : ByteString();
- }
- pCurHandle = m_FolderQueue.back().pFolderHandle;
- continue;
- }
- if (bsName == "." || bsName == "..")
- continue;
- if (bFolder) {
- HandleParentPath hpp;
- hpp.bsParentPath =
- m_FolderQueue.back().bsParentPath + kFolderSeparator + bsName;
- hpp.pFolderHandle = FX_OpenFolder(hpp.bsParentPath.c_str());
- if (!hpp.pFolderHandle)
- continue;
- m_FolderQueue.push_back(hpp);
- pCurHandle = hpp.pFolderHandle;
- continue;
- }
- bsName = m_FolderQueue.back().bsParentPath + kFolderSeparator + bsName;
- break;
- }
- return bsName;
-}
-
-void CFGAS_FontSourceEnumFile::GetNext() {
- m_wsNext = WideString::FromUTF8(GetNextFile().AsStringView());
-}
-
-bool CFGAS_FontSourceEnumFile::HasNext() const {
- return !m_wsNext.IsEmpty();
-}
-
-RetainPtr<IFX_SeekableStream> CFGAS_FontSourceEnumFile::GetStream() const {
- ASSERT(HasNext());
- return IFX_SeekableStream::CreateFromFilename(m_wsNext.c_str(),
- FX_FILEMODE_ReadOnly);
-}
diff --git a/xfa/fgas/font/cfgas_fontsource_enum_file.h b/xfa/fgas/font/cfgas_fontsource_enum_file.h
deleted file mode 100644
index d7b0c6b..0000000
--- a/xfa/fgas/font/cfgas_fontsource_enum_file.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// 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_CFGAS_FONTSOURCE_ENUM_FILE_H_
-#define XFA_FGAS_FONT_CFGAS_FONTSOURCE_ENUM_FILE_H_
-
-#include <vector>
-
-#include "build/build_config.h"
-#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 defined(OS_WIN)
-#error "Not used on Windows"
-#endif
-
-class CFGAS_FontSourceEnumFile {
- public:
- CFGAS_FontSourceEnumFile();
- ~CFGAS_FontSourceEnumFile();
-
- void GetNext();
- bool HasNext() const;
- RetainPtr<IFX_SeekableStream> GetStream() const;
-
- private:
- struct HandleParentPath {
- HandleParentPath() = default;
- HandleParentPath(const HandleParentPath& x) {
- pFolderHandle = x.pFolderHandle;
- bsParentPath = x.bsParentPath;
- }
- FX_FolderHandle* pFolderHandle;
- ByteString bsParentPath;
- };
-
- ByteString GetNextFile();
-
- WideString m_wsNext;
- std::vector<HandleParentPath> m_FolderQueue;
- std::vector<ByteString> m_FolderPaths;
-};
-
-#endif // XFA_FGAS_FONT_CFGAS_FONTSOURCE_ENUM_FILE_H_