7#include "public/fpdf_sysfontinfo.h"
13#include "core/fxcrt/fx_codepage.h"
14#include "core/fxcrt/stl_util.h"
15#include "core/fxcrt/unowned_ptr.h"
16#include "core/fxge/cfx_font.h"
17#include "core/fxge/cfx_fontmapper.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"
22#include "third_party/base/numerics/safe_conversions.h"
25#include "xfa/fgas/font/cfgas_fontmgr.h"
26#include "xfa/fgas/font/cfgas_gemodule.h"
30 "Charset must match");
32 "Charset must match");
34 "Charset must match");
37 "Charset must match");
39 "Charset must match");
42 "Charset must match");
45 "Charset must match");
48 "Charset must match");
51 "Charset must match");
54 "Charset must match");
57 "Charset must match");
60 "Charset must match");
62 "Charset must match");
65 "Charset must match");
66static_assert(offsetof(CFX_Font::CharsetFontMap, charset) ==
67 offsetof(FPDF_CharsetFontMap, charset),
68 "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
69static_assert(offsetof(CFX_Font::CharsetFontMap, fontname) ==
70 offsetof(FPDF_CharsetFontMap, fontname),
71 "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
73 "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
80 m_pInfo->Release(m_pInfo);
84 if (m_pInfo->EnumFonts) {
85 m_pInfo->EnumFonts(m_pInfo, pMapper);
95 const ByteString& face)
override {
96 if (!m_pInfo->MapFont)
100 return m_pInfo->MapFont(m_pInfo, weight, bItalic,
static_cast<
int>(charset),
101 pitch_family, face.c_str(), &iExact);
104 void*
GetFont(
const ByteString& family)
override {
105 if (!m_pInfo->GetFont)
107 return m_pInfo->GetFont(m_pInfo, family.c_str());
112 pdfium::span<uint8_t> buffer)
override {
113 if (!m_pInfo->GetFontData)
115 return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer.data(),
116 fxcrt::CollectionSize<
unsigned long>(buffer));
120 if (!m_pInfo->GetFaceName)
122 unsigned long size = m_pInfo->GetFaceName(m_pInfo, hFont,
nullptr, 0);
125 char* buffer = FX_Alloc(
char, size);
126 size = m_pInfo->GetFaceName(m_pInfo, hFont, buffer, size);
127 *name
= ByteString(buffer, size);
133 if (!m_pInfo->GetFontCharset)
136 *charset = FX_GetCharsetFromInt(m_pInfo->GetFontCharset(m_pInfo, hFont));
141 if (m_pInfo->DeleteFont)
142 m_pInfo->DeleteFont(m_pInfo, hFont);
162 std::make_unique<CFX_ExternalFontInfo>(pFontInfoExt));
165 CFGAS_GEModule::Get()->GetFontMgr()->EnumFonts();
173struct FPDF_SYSFONTINFO_DEFAULT
final :
public FPDF_SYSFONTINFO {
178 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
179 pDefault->m_pFontInfo.ClearAndDelete();
183 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
184 pDefault->m_pFontInfo->EnumFontList(
static_cast<
CFX_FontMapper*>(pMapper));
189 FPDF_BOOL use_italic,
194 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
195 return pDefault->m_pFontInfo->MapFont(weight, !!use_italic,
197 pitch_family, family);
201 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
202 return pDefault->m_pFontInfo->GetFont(family);
208 unsigned char* buffer,
209 unsigned long buf_size) {
210 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
211 return pdfium::base::checked_cast<
unsigned long>(
212 pDefault->m_pFontInfo->GetFontData(hFont, table, {buffer, buf_size}));
218 unsigned long buf_size) {
220 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
221 if (!pDefault->m_pFontInfo->GetFaceName(hFont, &name))
224 const unsigned long copy_length =
225 pdfium::base::checked_cast<
unsigned long>(name.GetLength() + 1);
226 if (copy_length <= buf_size)
227 strncpy(buffer, name
.c_str(), copy_length *
sizeof(ByteString::CharType));
234 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
235 if (!pDefault->m_pFontInfo->GetFontCharset(hFont, &charset))
237 return static_cast<
int>(charset);
241 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
242 pDefault->m_pFontInfo->DeleteFont(hFont);
246 std::unique_ptr<SystemFontInfoIface> pFontInfo =
247 CFX_GEModule::Get()->GetPlatform()->CreateDefaultSystemFontInfo();
251 FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt =
252 FX_Alloc(FPDF_SYSFONTINFO_DEFAULT, 1);
262 pFontInfoExt->m_pFontInfo = pFontInfo.release();
268 FX_Free(
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pFontInfo));
void * GetFont(const ByteString &family) override
bool GetFontCharset(void *hFont, FX_Charset *charset) override
size_t GetFontData(void *hFont, uint32_t table, pdfium::span< uint8_t > buffer) override
CFX_ExternalFontInfo(FPDF_SYSFONTINFO *pInfo)
bool EnumFontList(CFX_FontMapper *pMapper) override
void DeleteFont(void *hFont) override
bool GetFaceName(void *hFont, ByteString *name) override
void * MapFont(int weight, bool bItalic, FX_Charset charset, int pitch_family, const ByteString &face) override
~CFX_ExternalFontInfo() override
void AddInstalledFont(const ByteString &name, FX_Charset charset)
CFX_FontMapper * GetBuiltinMapper() const
static const CharsetFontMap kDefaultTTFMap[]
static CFX_GEModule * Get()
CFX_FontMgr * GetFontMgr() const
const char * c_str() const
ByteString & operator=(ByteString &&that) noexcept
static void * DefaultMapFont(struct _FPDF_SYSFONTINFO *pThis, int weight, FPDF_BOOL use_italic, int charset, int pitch_family, const char *family, FPDF_BOOL *)
void * DefaultGetFont(struct _FPDF_SYSFONTINFO *pThis, const char *family)
static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO *pThis, void *hFont, unsigned int table, unsigned char *buffer, unsigned long buf_size)
FPDF_EXPORT void FPDF_CALLCONV FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO *pFontInfoExt)
static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO *pThis, void *hFont)
static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO *pThis, void *hFont)
FPDF_EXPORT const FPDF_CharsetFontMap *FPDF_CALLCONV FPDF_GetDefaultTTFMap()
FPDF_EXPORT FPDF_SYSFONTINFO *FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo()
static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO *pThis, void *hFont, char *buffer, unsigned long buf_size)
FPDF_EXPORT void FPDF_CALLCONV FPDF_AddInstalledFont(void *mapper, const char *face, int charset)
FPDF_EXPORT void FPDF_CALLCONV FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO *pFontInfo)
static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO *pThis, void *pMapper)
static void DefaultRelease(struct _FPDF_SYSFONTINFO *pThis)
#define FXFONT_DEFAULT_CHARSET
#define FXFONT_HANGEUL_CHARSET
#define FXFONT_EASTERNEUROPEAN_CHARSET
#define FXFONT_SHIFTJIS_CHARSET
#define FXFONT_SYMBOL_CHARSET
#define FXFONT_GREEK_CHARSET
#define FXFONT_CYRILLIC_CHARSET
#define FXFONT_HEBREW_CHARSET
#define FXFONT_ANSI_CHARSET
#define FXFONT_ARABIC_CHARSET
#define FXFONT_GB2312_CHARSET
#define FXFONT_CHINESEBIG5_CHARSET
#define FXFONT_VIETNAMESE_CHARSET
#define FXFONT_THAI_CHARSET
FX_Charset FX_GetCharsetFromInt(int value)
UnownedPtr< SystemFontInfoIface > m_pFontInfo
void(* Release)(struct _FPDF_SYSFONTINFO *pThis)
void(* DeleteFont)(struct _FPDF_SYSFONTINFO *pThis, void *hFont)
unsigned long(* GetFontData)(struct _FPDF_SYSFONTINFO *pThis, void *hFont, unsigned int table, unsigned char *buffer, unsigned long buf_size)
void *(* GetFont)(struct _FPDF_SYSFONTINFO *pThis, const char *face)
unsigned long(* GetFaceName)(struct _FPDF_SYSFONTINFO *pThis, void *hFont, char *buffer, unsigned long buf_size)
int(* GetFontCharset)(struct _FPDF_SYSFONTINFO *pThis, void *hFont)
void(* EnumFonts)(struct _FPDF_SYSFONTINFO *pThis, void *pMapper)
void *(* MapFont)(struct _FPDF_SYSFONTINFO *pThis, int weight, FPDF_BOOL bItalic, int charset, int pitch_family, const char *face, FPDF_BOOL *bExact)