11#include "build/build_config.h"
12#include "core/fxcrt/fx_codepage.h"
13#include "core/fxge/cfx_folderfontinfo.h"
14#include "core/fxge/cfx_fontmgr.h"
15#include "core/fxge/cfx_gemodule.h"
16#include "core/fxge/fx_font.h"
17#include "core/fxge/systemfontinfo_iface.h"
18#include "third_party/base/check.h"
20#if !BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS) && !defined(OS_FUCHSIA) &&
22#error "Included on the wrong platform"
27enum JpFontFamily : uint8_t {
35const char*
const kLinuxJpFontList[][JpFontFamily::kCount] = {
36 {
"TakaoPGothic",
"VL PGothic",
"IPAPGothic",
"VL Gothic"},
37 {
"TakaoGothic",
"VL Gothic",
"IPAGothic",
"Kochi Gothic"},
38 {
"TakaoPMincho",
"IPAPMincho",
"VL Gothic",
"Kochi Mincho"},
39 {
"TakaoMincho",
"IPAMincho",
"VL Gothic",
"Kochi Mincho"},
42const char*
const kLinuxGbFontList[] = {
43 "AR PL UMing CN Light",
44 "WenQuanYi Micro Hei",
48const char*
const kLinuxB5FontList[] = {
49 "AR PL UMing TW Light",
50 "WenQuanYi Micro Hei",
54const char*
const kLinuxHGFontList[] = {
58JpFontFamily GetJapanesePreference(
const ByteString& face,
61 if (face.Contains(
"Gothic") ||
62 face.Contains(
"\x83\x53\x83\x56\x83\x62\x83\x4e")) {
63 if (face.Contains(
"PGothic") ||
64 face.Contains(
"\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e")) {
65 return kJpFontPGothic;
69 if (face.Contains(
"Mincho") || face.Contains(
"\x96\xbe\x92\xa9")) {
70 if (face.Contains(
"PMincho") || face.Contains(
"\x82\x6f\x96\xbe\x92\xa9")) {
71 return kJpFontPMincho;
76 return kJpFontPGothic;
78 return kJpFontPMincho;
83 CFX_LinuxFontInfo() =
default;
84 ~CFX_LinuxFontInfo()
override =
default;
87 void* MapFont(
int weight,
91 const ByteString& face)
override;
93 bool ParseFontCfg(
const char** pUserPaths);
96void* CFX_LinuxFontInfo::MapFont(
int weight,
100 const ByteString& face) {
108 JpFontFamily index = GetJapanesePreference(face, weight, pitch_family);
109 DCHECK(index < std::size(kLinuxJpFontList));
110 for (
const char* name : kLinuxJpFontList[index]) {
111 auto it = m_FontList.find(name);
112 if (it != m_FontList.end())
113 return it->second.get();
118 for (
const char* name : kLinuxGbFontList) {
119 auto it = m_FontList.find(name);
120 if (it != m_FontList.end())
121 return it->second.get();
126 for (
const char* name : kLinuxB5FontList) {
127 auto it = m_FontList.find(name);
128 if (it != m_FontList.end())
129 return it->second.get();
134 for (
const char* name : kLinuxHGFontList) {
135 auto it = m_FontList.find(name);
136 if (it != m_FontList.end())
137 return it->second.get();
145 return FindFont(weight, bItalic, charset, pitch_family, face, !bCJK);
148bool CFX_LinuxFontInfo::ParseFontCfg(
const char** pUserPaths) {
152 for (
const char** pPath = pUserPaths; *pPath; ++pPath)
167 auto pInfo =
std::make_unique<CFX_LinuxFontInfo>();
169 pInfo->AddPath(
"/usr/share/fonts");
170 pInfo->AddPath(
"/usr/share/X11/fonts/Type1");
171 pInfo->AddPath(
"/usr/share/X11/fonts/TTF");
172 pInfo->AddPath(
"/usr/local/share/fonts");
179std::unique_ptr<CFX_GEModule::PlatformIface>
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
bool FontFamilyIsRoman(uint32_t family)