#include "core/fxge/cfx_fontmapper.h"
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <utility>
#include "build/build_config.h"
#include "core/fxcrt/check_op.h"
#include "core/fxcrt/containers/adapters.h"
#include "core/fxcrt/containers/contains.h"
#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/unowned_ptr_exclusion.h"
#include "core/fxge/cfx_fontmgr.h"
#include "core/fxge/cfx_substfont.h"
#include "core/fxge/fx_font.h"
#include "core/fxge/systemfontinfo_iface.h"
namespace {
static_assert …;
constexpr std::array<const char*, CFX_FontMapper::kNumStandardFonts>
kBase14FontNames = …;
struct AltFontName { … };
constexpr AltFontName kAltFontNames[] = …;
struct AltFontFamily { … };
constexpr AltFontFamily kAltFontFamilies[] = …;
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || defined(OS_ASMJS)
const char kNarrowFamily[] = …;
#elif BUILDFLAG(IS_ANDROID)
const char kNarrowFamily[] = "RobotoCondensed";
#else
const char kNarrowFamily[] = "ArialNarrow";
#endif
ByteString TT_NormalizeName(ByteString norm) { … }
const char* GetFontFamily(uint32_t nStyle, const ByteString& fontname) { … }
ByteString ParseStyle(const ByteString& bsStyle, size_t iStart) { … }
struct FX_FontStyle { … };
constexpr FX_FontStyle kFontStyles[] = …;
const FX_FontStyle* GetStyleType(ByteStringView font_name,
bool reverse_search) { … }
bool ParseStyles(const ByteString& style_str,
bool* is_style_available,
int* weight,
uint32_t* style) { … }
bool CheckSupportThirdPartFont(const ByteString& name, int* pitch_family) { … }
uint32_t GetStyleFromBaseFont(int base_font) { … }
int GetPitchFamilyFromBaseFont(int base_font) { … }
int GetPitchFamilyFromFlags(uint32_t flags) { … }
int AdjustBaseFontForStyle(int base_font, uint32_t style) { … }
FX_Charset GetCharset(FX_CodePage code_page, int base_font, uint32_t flags) { … }
bool IsStrUpper(const ByteString& str) { … }
void RemoveSubsettedFontPrefix(ByteString* subst_name) { … }
ByteString GetSubstName(const ByteString& name, bool is_truetype) { … }
bool IsNarrowFontName(const ByteString& name) { … }
class ScopedFontDeleter { … };
}
CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) : … { … }
CFX_FontMapper::~CFX_FontMapper() = default;
void CFX_FontMapper::SetSystemFontInfo(
std::unique_ptr<SystemFontInfoIface> pFontInfo) { … }
std::unique_ptr<SystemFontInfoIface> CFX_FontMapper::TakeSystemFontInfo() { … }
uint32_t CFX_FontMapper::GetChecksumFromTT(void* font_handle) { … }
ByteString CFX_FontMapper::GetPSNameFromTT(void* font_handle) { … }
void CFX_FontMapper::AddInstalledFont(const ByteString& name,
FX_Charset charset) { … }
void CFX_FontMapper::LoadInstalledFonts() { … }
ByteString CFX_FontMapper::MatchInstalledFonts(const ByteString& norm_name) { … }
RetainPtr<CFX_Face> CFX_FontMapper::UseInternalSubst(
int base_font,
int weight,
int italic_angle,
int pitch_family,
CFX_SubstFont* subst_font) { … }
RetainPtr<CFX_Face> CFX_FontMapper::UseExternalSubst(
void* font_handle,
ByteString face_name,
int weight,
bool is_italic,
int italic_angle,
FX_Charset charset,
CFX_SubstFont* subst_font) { … }
RetainPtr<CFX_Face> CFX_FontMapper::FindSubstFont(const ByteString& name,
bool is_truetype,
uint32_t flags,
int weight,
int italic_angle,
FX_CodePage code_page,
CFX_SubstFont* subst_font) { … }
size_t CFX_FontMapper::GetFaceSize() const { … }
ByteString CFX_FontMapper::GetFaceName(size_t index) const { … }
bool CFX_FontMapper::HasInstalledFont(ByteStringView name) const { … }
bool CFX_FontMapper::HasLocalizedFont(ByteStringView name) const { … }
#if BUILDFLAG(IS_WIN)
std::optional<ByteString> CFX_FontMapper::InstalledFontNameStartingWith(
const ByteString& name) const {
for (const auto& thisname : m_InstalledTTFonts) {
if (thisname.First(name.GetLength()) == name)
return thisname;
}
return std::nullopt;
}
std::optional<ByteString> CFX_FontMapper::LocalizedFontNameStartingWith(
const ByteString& name) const {
for (const auto& thispair : m_LocalizedTTFonts) {
if (thispair.first.First(name.GetLength()) == name)
return thispair.second;
}
return std::nullopt;
}
#endif
#ifdef PDF_ENABLE_XFA
FixedSizeDataVector<uint8_t> CFX_FontMapper::RawBytesForIndex(size_t index) { … }
#endif
RetainPtr<CFX_Face> CFX_FontMapper::GetCachedTTCFace(void* font_handle,
size_t ttc_size,
size_t data_size) { … }
RetainPtr<CFX_Face> CFX_FontMapper::GetCachedFace(void* font_handle,
ByteString subst_name,
int weight,
bool is_italic,
size_t data_size) { … }
std::optional<CFX_FontMapper::StandardFont> CFX_FontMapper::GetStandardFontName(
ByteString* name) { … }
bool CFX_FontMapper::IsStandardFontName(const ByteString& name) { … }
bool CFX_FontMapper::IsSymbolicFont(StandardFont font) { … }
bool CFX_FontMapper::IsFixedFont(StandardFont font) { … }