7#include "public/fpdf_sysfontinfo.h"
14#include "core/fxcrt/compiler_specific.h"
15#include "core/fxcrt/fx_codepage.h"
16#include "core/fxcrt/numerics/safe_conversions.h"
17#include "core/fxcrt/span.h"
18#include "core/fxcrt/stl_util.h"
19#include "core/fxcrt/unowned_ptr.h"
20#include "core/fxge/cfx_font.h"
21#include "core/fxge/cfx_fontmapper.h"
22#include "core/fxge/cfx_fontmgr.h"
23#include "core/fxge/cfx_gemodule.h"
24#include "core/fxge/fx_font.h"
25#include "core/fxge/systemfontinfo_iface.h"
28#include "xfa/fgas/font/cfgas_fontmgr.h"
29#include "xfa/fgas/font/cfgas_gemodule.h"
33 "Charset must match");
35 "Charset must match");
37 "Charset must match");
40 "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");
63 "Charset must match");
65 "Charset must match");
68 "Charset must match");
69static_assert(offsetof(CFX_Font::CharsetFontMap, charset) ==
70 offsetof(FPDF_CharsetFontMap, charset),
71 "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
72static_assert(offsetof(CFX_Font::CharsetFontMap, fontname) ==
73 offsetof(FPDF_CharsetFontMap, fontname),
74 "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
76 "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
83 m_pInfo->Release(m_pInfo);
87 if (m_pInfo->EnumFonts) {
88 m_pInfo->EnumFonts(m_pInfo, pMapper);
99 if (!m_pInfo->MapFont)
103 return m_pInfo->MapFont(m_pInfo, weight, bItalic,
static_cast<
int>(charset),
104 pitch_family, face.c_str(), &iExact);
108 if (!m_pInfo->GetFont)
110 return m_pInfo->GetFont(m_pInfo, family.c_str());
115 pdfium::span<uint8_t> buffer)
override {
116 if (!m_pInfo->GetFontData)
118 return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer.data(),
119 fxcrt::CollectionSize<
unsigned long>(buffer));
123 if (!m_pInfo->GetFaceName)
125 unsigned long size = m_pInfo->GetFaceName(m_pInfo, hFont,
nullptr, 0);
129 auto result_span = result.GetBuffer(size);
130 size = m_pInfo->GetFaceName(m_pInfo, hFont, result_span.data(), size);
131 result.ReleaseBuffer(size);
132 *name =
std::move(result);
137 if (!m_pInfo->GetFontCharset)
140 *charset = FX_GetCharsetFromInt(m_pInfo->GetFontCharset(m_pInfo, hFont));
145 if (m_pInfo->DeleteFont)
146 m_pInfo->DeleteFont(m_pInfo, hFont);
164 std::unique_ptr<SystemFontInfoIface> info = mapper->TakeSystemFontInfo();
172 mapper->SetSystemFontInfo(
173 std::make_unique<CFX_ExternalFontInfo>(pFontInfoExt));
176 CFGAS_GEModule::Get()->GetFontMgr()->EnumFonts();
181 return reinterpret_cast<
const FPDF_CharsetFontMap*>(
182 CFX_Font::GetDefaultTTFMapSpan().data());
186 return CFX_Font::GetDefaultTTFMapSpan().size();
191 pdfium::span<
const CFX_Font::CharsetFontMap> entries =
192 CFX_Font::GetDefaultTTFMapSpan();
193 return index < entries.size()
194 ?
reinterpret_cast<
const FPDF_CharsetFontMap*>(&entries[index])
198struct FPDF_SYSFONTINFO_DEFAULT
final :
public FPDF_SYSFONTINFO {
203 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
204 pDefault->m_pFontInfo.ClearAndDelete();
208 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
209 pDefault->m_pFontInfo->EnumFontList(
static_cast<
CFX_FontMapper*>(pMapper));
214 FPDF_BOOL use_italic,
219 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
220 return pDefault->m_pFontInfo->MapFont(weight, !!use_italic,
222 pitch_family, family);
226 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
227 return pDefault->m_pFontInfo->GetFont(family);
234 unsigned char* buffer,
235 unsigned long buf_size) {
236 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
238 return pdfium::checked_cast<
unsigned long>(pDefault->m_pFontInfo->GetFontData(
246 unsigned long buf_size) {
248 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
249 if (!pDefault->m_pFontInfo->GetFaceName(hFont, &name))
252 const unsigned long copy_length =
253 pdfium::checked_cast<
unsigned long>(name.GetLength() + 1);
254 if (copy_length <= buf_size)
255 strncpy(buffer, name.c_str(), copy_length *
sizeof(ByteString::CharType));
262 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
263 if (!pDefault->m_pFontInfo->GetFontCharset(hFont, &charset))
265 return static_cast<
int>(charset);
269 auto* pDefault =
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis);
270 pDefault->m_pFontInfo->DeleteFont(hFont);
274 std::unique_ptr<SystemFontInfoIface> pFontInfo =
279 FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt =
280 FX_Alloc(FPDF_SYSFONTINFO_DEFAULT, 1);
290 pFontInfoExt->m_pFontInfo = pFontInfo.release();
296 FX_Free(
static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pFontInfo));
fxcrt::ByteString ByteString
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
PlatformIface * GetPlatform() const
static CFX_GEModule * Get()
CFX_FontMgr * GetFontMgr() const
#define UNSAFE_BUFFERS(...)
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)
FPDF_EXPORT const FPDF_CharsetFontMap *FPDF_CALLCONV FPDF_GetDefaultTTFMapEntry(size_t index)
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 size_t FPDF_CALLCONV FPDF_GetDefaultTTFMapCount()
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)