Make Android font manager respect `m_pUserFontPaths` During PDFium initialization, the caller can passes in an FPDF_LIBRARY_CONFIG with `m_pUserFontPaths` set. Plumb these paths from CAndroidPlatform to CFX_AndroidFontInfo to CFPF_SkiaFontMgr. Then have CFPF_SkiaFontMgr scan those directories. Rename CFPF_SkiaFontMgr::LoadSystemFonts() to LoadFonts() to better reflect its new role. Bug: 350526066 Change-Id: I97de0beca0058b6cce4fe6a66225e37f105347ca Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/121530 Reviewed-by: Tom Sepez <tsepez@google.com> Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp index 7c88f48..23bbb97 100644 --- a/core/fxge/android/cfpf_skiafontmgr.cpp +++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -11,6 +11,7 @@ #include <iterator> #include <utility> +#include "core/fxcrt/compiler_specific.h" #include "core/fxcrt/containers/adapters.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" @@ -235,12 +236,23 @@ return true; } -void CFPF_SkiaFontMgr::LoadSystemFonts() { - if (loaded_system_fonts_) { +void CFPF_SkiaFontMgr::LoadFonts(const char** user_paths) { + if (loaded_fonts_) { return; } + ScanPath("/system/fonts"); - loaded_system_fonts_ = true; + + if (user_paths) { + // SAFETY: nullptr-terminated array required from caller. + UNSAFE_BUFFERS({ + for (const char** path = user_paths; *path; ++path) { + ScanPath(*path); + } + }); + } + + loaded_fonts_ = true; } CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(ByteStringView family_name,
diff --git a/core/fxge/android/cfpf_skiafontmgr.h b/core/fxge/android/cfpf_skiafontmgr.h index 53ea58b..3958b52 100644 --- a/core/fxge/android/cfpf_skiafontmgr.h +++ b/core/fxge/android/cfpf_skiafontmgr.h
@@ -25,13 +25,13 @@ CFPF_SkiaFontMgr(); ~CFPF_SkiaFontMgr(); - void LoadSystemFonts(); + void LoadFonts(const char** user_paths); CFPF_SkiaFont* CreateFont(ByteStringView family_name, FX_Charset charset, uint32_t style); bool InitFTLibrary(); - RetainPtr<CFX_Face> GetFontFace(ByteStringView filename, int32_t face_index); + RetainPtr<CFX_Face> GetFontFace(ByteStringView path, int32_t face_index); private: void ScanPath(const ByteString& path); @@ -39,7 +39,7 @@ std::unique_ptr<CFPF_SkiaPathFont> ReportFace(RetainPtr<CFX_Face> face, const ByteString& file); - bool loaded_system_fonts_ = false; + bool loaded_fonts_ = false; ScopedFXFTLibraryRec ft_library_; std::vector<std::unique_ptr<CFPF_SkiaPathFont>> font_faces_; // Key is a hash based on CreateFont() parameters.
diff --git a/core/fxge/android/cfx_androidfontinfo.cpp b/core/fxge/android/cfx_androidfontinfo.cpp index 2799dcd..0154b92 100644 --- a/core/fxge/android/cfx_androidfontinfo.cpp +++ b/core/fxge/android/cfx_androidfontinfo.cpp
@@ -16,12 +16,14 @@ CFX_AndroidFontInfo::~CFX_AndroidFontInfo() = default; -bool CFX_AndroidFontInfo::Init(CFPF_SkiaFontMgr* pFontMgr) { - if (!pFontMgr) +bool CFX_AndroidFontInfo::Init(CFPF_SkiaFontMgr* pFontMgr, + const char** user_paths) { + if (!pFontMgr) { return false; + } - pFontMgr->LoadSystemFonts(); m_pFontMgr = pFontMgr; + m_pFontMgr->LoadFonts(user_paths); return true; }
diff --git a/core/fxge/android/cfx_androidfontinfo.h b/core/fxge/android/cfx_androidfontinfo.h index 3886f70..647e89b 100644 --- a/core/fxge/android/cfx_androidfontinfo.h +++ b/core/fxge/android/cfx_androidfontinfo.h
@@ -21,7 +21,7 @@ CFX_AndroidFontInfo(); ~CFX_AndroidFontInfo() override; - bool Init(CFPF_SkiaFontMgr* pFontMgr); + bool Init(CFPF_SkiaFontMgr* pFontMgr, const char** user_paths); // SystemFontInfoIface: bool EnumFontList(CFX_FontMapper* pMapper) override;
diff --git a/core/fxge/android/fx_android_impl.cpp b/core/fxge/android/fx_android_impl.cpp index 12783f5..7883e89 100644 --- a/core/fxge/android/fx_android_impl.cpp +++ b/core/fxge/android/fx_android_impl.cpp
@@ -29,7 +29,7 @@ return nullptr; auto pFontInfo = std::make_unique<CFX_AndroidFontInfo>(); - pFontInfo->Init(pFontMgr); + pFontInfo->Init(pFontMgr, CFX_GEModule::Get()->GetUserFontPaths()); return pFontInfo; }