12#include "build/build_config.h"
13#include "core/fxcrt/check.h"
14#include "core/fxcrt/compiler_specific.h"
15#include "core/fxcrt/fx_codepage.h"
16#include "core/fxcrt/stl_util.h"
17#include "core/fxge/cfx_folderfontinfo.h"
18#include "core/fxge/cfx_fontmgr.h"
19#include "core/fxge/cfx_gemodule.h"
20#include "core/fxge/fx_font.h"
21#include "core/fxge/systemfontinfo_iface.h"
23#if !BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS) && !defined(OS_ASMJS)
24#error "Included on the wrong platform"
29enum JpFontFamilyRowIndex : uint8_t {
36constexpr size_t kJpFontFamilyColumnCount = 5;
37using JpFontFamilyRow = std::array<
const char*, kJpFontFamilyColumnCount>;
38constexpr auto kJpFontTable = fxcrt::ToArray<
const JpFontFamilyRow>({
39 {{
"MS PGothic",
"TakaoPGothic",
"VL PGothic",
"IPAPGothic",
"VL Gothic"}},
40 {{
"MS Gothic",
"TakaoGothic",
"VL Gothic",
"IPAGothic",
"Kochi Gothic"}},
41 {{
"MS PMincho",
"TakaoPMincho",
"IPAPMincho",
"VL Gothic",
"Kochi Mincho"}},
42 {{
"MS Mincho",
"TakaoMincho",
"IPAMincho",
"VL Gothic",
"Kochi Mincho"}},
45const char*
const kGbFontList[] = {
46 "AR PL UMing CN Light",
47 "WenQuanYi Micro Hei",
51const char*
const kB5FontList[] = {
52 "AR PL UMing TW Light",
53 "WenQuanYi Micro Hei",
57const char*
const kHGFontList[] = {
61JpFontFamilyRowIndex GetJapanesePreference(
const ByteString& face,
64 if (face.Contains(
"Gothic") ||
65 face.Contains(
"\x83\x53\x83\x56\x83\x62\x83\x4e")) {
66 if (face.Contains(
"PGothic") ||
67 face.Contains(
"\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e")) {
68 return kJpFontPGothic;
72 if (face.Contains(
"Mincho") || face.Contains(
"\x96\xbe\x92\xa9")) {
73 if (face.Contains(
"PMincho") || face.Contains(
"\x82\x6f\x96\xbe\x92\xa9")) {
74 return kJpFontPMincho;
79 return kJpFontPGothic;
81 return kJpFontPMincho;
86 CFX_LinuxFontInfo() =
default;
87 ~CFX_LinuxFontInfo()
override =
default;
90 void* MapFont(
int weight,
96 bool ParseFontCfg(
const char** pUserPaths);
99void* CFX_LinuxFontInfo::MapFont(
int weight,
111 JpFontFamilyRowIndex index =
112 GetJapanesePreference(face, weight, pitch_family);
113 for (
const char* name : kJpFontTable[index]) {
114 auto it = m_FontList.find(name);
115 if (it != m_FontList.end())
116 return it->second.get();
121 for (
const char* name : kGbFontList) {
122 auto it = m_FontList.find(name);
123 if (it != m_FontList.end())
124 return it->second.get();
129 for (
const char* name : kB5FontList) {
130 auto it = m_FontList.find(name);
131 if (it != m_FontList.end())
132 return it->second.get();
137 for (
const char* name : kHGFontList) {
138 auto it = m_FontList.find(name);
139 if (it != m_FontList.end())
140 return it->second.get();
148 return FindFont(weight, bItalic, charset, pitch_family, face, !bCJK);
151bool CFX_LinuxFontInfo::ParseFontCfg(
const char** pUserPaths) {
157 for (
const char** pPath = pUserPaths; *pPath; ++pPath) {
174 auto pInfo =
std::make_unique<CFX_LinuxFontInfo>();
176 pInfo->AddPath(
"/usr/share/fonts");
177 pInfo->AddPath(
"/usr/share/X11/fonts/Type1");
178 pInfo->AddPath(
"/usr/share/X11/fonts/TTF");
179 pInfo->AddPath(
"/usr/local/share/fonts");
186std::unique_ptr<CFX_GEModule::PlatformIface>
fxcrt::ByteString ByteString
void * GetSubstFont(const ByteString &face)
void * FindFont(int weight, bool bItalic, FX_Charset charset, int pitch_family, const ByteString &family, bool bMatchName)
void AddPath(const ByteString &path)
static CFX_GEModule * Get()
const char ** GetUserFontPaths() const
#define UNSAFE_BUFFERS(...)
bool FontFamilyIsRoman(uint32_t family)