blob: 7dcf25de50bba8a83a58c157282d536c17e95607 [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2014 The PDFium Authors
Svet Ganove6986e12015-06-04 14:52:15 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef PUBLIC_FPDF_SYSFONTINFO_H_
8#define PUBLIC_FPDF_SYSFONTINFO_H_
9
Haibo Huang49cc9302020-04-27 16:14:24 -070010// clang-format off
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070011// NOLINTNEXTLINE(build/include)
Svet Ganove6986e12015-06-04 14:52:15 -070012#include "fpdfview.h"
13
14/* Character sets for the font */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080015#define FXFONT_ANSI_CHARSET 0
16#define FXFONT_DEFAULT_CHARSET 1
17#define FXFONT_SYMBOL_CHARSET 2
Svet Ganove6986e12015-06-04 14:52:15 -070018#define FXFONT_SHIFTJIS_CHARSET 128
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080019#define FXFONT_HANGEUL_CHARSET 129
20#define FXFONT_GB2312_CHARSET 134
21#define FXFONT_CHINESEBIG5_CHARSET 136
kumarashishg826308d2023-06-23 13:21:22 +000022#define FXFONT_GREEK_CHARSET 161
23#define FXFONT_VIETNAMESE_CHARSET 163
24#define FXFONT_HEBREW_CHARSET 177
Haibo Huang49cc9302020-04-27 16:14:24 -070025#define FXFONT_ARABIC_CHARSET 178
26#define FXFONT_CYRILLIC_CHARSET 204
kumarashishg826308d2023-06-23 13:21:22 +000027#define FXFONT_THAI_CHARSET 222
Haibo Huang49cc9302020-04-27 16:14:24 -070028#define FXFONT_EASTERNEUROPEAN_CHARSET 238
Svet Ganove6986e12015-06-04 14:52:15 -070029
30/* Font pitch and family flags */
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070031#define FXFONT_FF_FIXEDPITCH (1 << 0)
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080032#define FXFONT_FF_ROMAN (1 << 4)
33#define FXFONT_FF_SCRIPT (4 << 4)
Svet Ganove6986e12015-06-04 14:52:15 -070034
35/* Typical weight values */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080036#define FXFONT_FW_NORMAL 400
37#define FXFONT_FW_BOLD 700
Svet Ganove6986e12015-06-04 14:52:15 -070038
39// Exported Functions
40#ifdef __cplusplus
41extern "C" {
42#endif
43
Haibo Huang49cc9302020-04-27 16:14:24 -070044/*
Svet Ganove6986e12015-06-04 14:52:15 -070045 * Interface: FPDF_SYSFONTINFO
46 * Interface for getting system font information and font mapping
47 */
48typedef struct _FPDF_SYSFONTINFO {
Haibo Huang49cc9302020-04-27 16:14:24 -070049 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080050 * Version number of the interface. Currently must be 1.
Haibo Huang49cc9302020-04-27 16:14:24 -070051 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080052 int version;
Svet Ganove6986e12015-06-04 14:52:15 -070053
Haibo Huang49cc9302020-04-27 16:14:24 -070054 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080055 * Method: Release
56 * Give implementation a chance to release any data after the
Haibo Huang49cc9302020-04-27 16:14:24 -070057 * interface is no longer used.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080058 * Interface Version:
59 * 1
60 * Implementation Required:
61 * No
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080062 * Parameters:
63 * pThis - Pointer to the interface structure itself
64 * Return Value:
65 * None
Haibo Huang49cc9302020-04-27 16:14:24 -070066 * Comments:
67 * Called by PDFium during the final cleanup process.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080068 */
69 void (*Release)(struct _FPDF_SYSFONTINFO* pThis);
Svet Ganove6986e12015-06-04 14:52:15 -070070
Haibo Huang49cc9302020-04-27 16:14:24 -070071 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080072 * Method: EnumFonts
73 * Enumerate all fonts installed on the system
74 * Interface Version:
75 * 1
76 * Implementation Required:
77 * No
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080078 * Parameters:
79 * pThis - Pointer to the interface structure itself
80 * pMapper - An opaque pointer to internal font mapper, used
Haibo Huang49cc9302020-04-27 16:14:24 -070081 * when calling FPDF_AddInstalledFont().
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080082 * Return Value:
83 * None
Haibo Huang49cc9302020-04-27 16:14:24 -070084 * Comments:
85 * Implementations should call FPDF_AddIntalledFont() function for
86 * each font found. Only TrueType/OpenType and Type1 fonts are accepted
87 * by PDFium.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080088 */
89 void (*EnumFonts)(struct _FPDF_SYSFONTINFO* pThis, void* pMapper);
Svet Ganove6986e12015-06-04 14:52:15 -070090
Haibo Huang49cc9302020-04-27 16:14:24 -070091 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080092 * Method: MapFont
93 * Use the system font mapper to get a font handle from requested
Haibo Huang49cc9302020-04-27 16:14:24 -070094 * parameters.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080095 * Interface Version:
96 * 1
97 * Implementation Required:
Haibo Huang49cc9302020-04-27 16:14:24 -070098 * Required if GetFont method is not implemented.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -080099 * Parameters:
100 * pThis - Pointer to the interface structure itself
101 * weight - Weight of the requested font. 400 is normal and
Haibo Huang49cc9302020-04-27 16:14:24 -0700102 * 700 is bold.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800103 * bItalic - Italic option of the requested font, TRUE or
Haibo Huang49cc9302020-04-27 16:14:24 -0700104 * FALSE.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800105 * charset - Character set identifier for the requested font.
Haibo Huang49cc9302020-04-27 16:14:24 -0700106 * See above defined constants.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800107 * pitch_family - A combination of flags. See above defined
Haibo Huang49cc9302020-04-27 16:14:24 -0700108 * constants.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800109 * face - Typeface name. Currently use system local encoding
Haibo Huang49cc9302020-04-27 16:14:24 -0700110 * only.
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700111 * bExact - Obsolete: this parameter is now ignored.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800112 * Return Value:
113 * An opaque pointer for font handle, or NULL if system mapping is
Haibo Huang49cc9302020-04-27 16:14:24 -0700114 * not supported.
115 * Comments:
116 * If the system supports native font mapper (like Windows),
117 * implementation can implement this method to get a font handle.
118 * Otherwise, PDFium will do the mapping and then call GetFont
119 * method. Only TrueType/OpenType and Type1 fonts are accepted
120 * by PDFium.
121 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800122 void* (*MapFont)(struct _FPDF_SYSFONTINFO* pThis,
123 int weight,
124 FPDF_BOOL bItalic,
125 int charset,
126 int pitch_family,
127 const char* face,
128 FPDF_BOOL* bExact);
Svet Ganove6986e12015-06-04 14:52:15 -0700129
Haibo Huang49cc9302020-04-27 16:14:24 -0700130 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800131 * Method: GetFont
132 * Get a handle to a particular font by its internal ID
133 * Interface Version:
134 * 1
135 * Implementation Required:
Haibo Huang49cc9302020-04-27 16:14:24 -0700136 * Required if MapFont method is not implemented.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800137 * Return Value:
138 * An opaque pointer for font handle.
Haibo Huang49cc9302020-04-27 16:14:24 -0700139 * Parameters:
140 * pThis - Pointer to the interface structure itself
141 * face - Typeface name in system local encoding.
142 * Comments:
143 * If the system mapping not supported, PDFium will do the font
144 * mapping and use this method to get a font handle.
145 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800146 void* (*GetFont)(struct _FPDF_SYSFONTINFO* pThis, const char* face);
Svet Ganove6986e12015-06-04 14:52:15 -0700147
Haibo Huang49cc9302020-04-27 16:14:24 -0700148 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800149 * Method: GetFontData
150 * Get font data from a font
151 * Interface Version:
152 * 1
153 * Implementation Required:
154 * Yes
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800155 * Parameters:
156 * pThis - Pointer to the interface structure itself
157 * hFont - Font handle returned by MapFont or GetFont method
158 * table - TrueType/OpenType table identifier (refer to
Haibo Huang49cc9302020-04-27 16:14:24 -0700159 * TrueType specification), or 0 for the whole file.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800160 * buffer - The buffer receiving the font data. Can be NULL if
Haibo Huang49cc9302020-04-27 16:14:24 -0700161 * not provided.
162 * buf_size - Buffer size, can be zero if not provided.
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800163 * Return Value:
164 * Number of bytes needed, if buffer not provided or not large
Haibo Huang49cc9302020-04-27 16:14:24 -0700165 * enough, or number of bytes written into buffer otherwise.
166 * Comments:
167 * Can read either the full font file, or a particular
168 * TrueType/OpenType table.
169 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800170 unsigned long (*GetFontData)(struct _FPDF_SYSFONTINFO* pThis,
171 void* hFont,
172 unsigned int table,
173 unsigned char* buffer,
174 unsigned long buf_size);
Svet Ganove6986e12015-06-04 14:52:15 -0700175
Haibo Huang49cc9302020-04-27 16:14:24 -0700176 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800177 * Method: GetFaceName
178 * Get face name from a font handle
179 * Interface Version:
180 * 1
181 * Implementation Required:
182 * No
183 * Parameters:
184 * pThis - Pointer to the interface structure itself
185 * hFont - Font handle returned by MapFont or GetFont method
186 * buffer - The buffer receiving the face name. Can be NULL if
Haibo Huang49cc9302020-04-27 16:14:24 -0700187 * not provided
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800188 * buf_size - Buffer size, can be zero if not provided
189 * Return Value:
190 * Number of bytes needed, if buffer not provided or not large
Haibo Huang49cc9302020-04-27 16:14:24 -0700191 * enough, or number of bytes written into buffer otherwise.
192 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800193 unsigned long (*GetFaceName)(struct _FPDF_SYSFONTINFO* pThis,
194 void* hFont,
195 char* buffer,
196 unsigned long buf_size);
Svet Ganove6986e12015-06-04 14:52:15 -0700197
Haibo Huang49cc9302020-04-27 16:14:24 -0700198 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800199 * Method: GetFontCharset
200 * Get character set information for a font handle
201 * Interface Version:
202 * 1
203 * Implementation Required:
204 * No
205 * Parameters:
206 * pThis - Pointer to the interface structure itself
207 * hFont - Font handle returned by MapFont or GetFont method
208 * Return Value:
209 * Character set identifier. See defined constants above.
Haibo Huang49cc9302020-04-27 16:14:24 -0700210 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800211 int (*GetFontCharset)(struct _FPDF_SYSFONTINFO* pThis, void* hFont);
Svet Ganove6986e12015-06-04 14:52:15 -0700212
Haibo Huang49cc9302020-04-27 16:14:24 -0700213 /*
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800214 * Method: DeleteFont
215 * Delete a font handle
216 * Interface Version:
217 * 1
218 * Implementation Required:
219 * Yes
220 * Parameters:
221 * pThis - Pointer to the interface structure itself
222 * hFont - Font handle returned by MapFont or GetFont method
223 * Return Value:
224 * None
Haibo Huang49cc9302020-04-27 16:14:24 -0700225 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800226 void (*DeleteFont)(struct _FPDF_SYSFONTINFO* pThis, void* hFont);
Svet Ganove6986e12015-06-04 14:52:15 -0700227} FPDF_SYSFONTINFO;
228
Haibo Huang49cc9302020-04-27 16:14:24 -0700229/*
Svet Ganove6986e12015-06-04 14:52:15 -0700230 * Struct: FPDF_CharsetFontMap
231 * Provides the name of a font to use for a given charset value.
Haibo Huang49cc9302020-04-27 16:14:24 -0700232 */
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800233typedef struct FPDF_CharsetFontMap_ {
234 int charset; // Character Set Enum value, see FXFONT_*_CHARSET above.
235 const char* fontname; // Name of default font to use with that charset.
Svet Ganove6986e12015-06-04 14:52:15 -0700236} FPDF_CharsetFontMap;
237
Haibo Huang49cc9302020-04-27 16:14:24 -0700238/*
Svet Ganove6986e12015-06-04 14:52:15 -0700239 * Function: FPDF_GetDefaultTTFMap
240 * Returns a pointer to the default character set to TT Font name map. The
241 * map is an array of FPDF_CharsetFontMap structs, with its end indicated
242 * by a { -1, NULL } entry.
243 * Parameters:
244 * None.
245 * Return Value:
246 * Pointer to the Charset Font Map.
Haibo Huang49cc9302020-04-27 16:14:24 -0700247 */
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700248FPDF_EXPORT const FPDF_CharsetFontMap* FPDF_CALLCONV FPDF_GetDefaultTTFMap();
Svet Ganove6986e12015-06-04 14:52:15 -0700249
Haibo Huang49cc9302020-04-27 16:14:24 -0700250/*
Svet Ganove6986e12015-06-04 14:52:15 -0700251 * Function: FPDF_AddInstalledFont
Haibo Huang49cc9302020-04-27 16:14:24 -0700252 * Add a system font to the list in PDFium.
Svet Ganove6986e12015-06-04 14:52:15 -0700253 * Comments:
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800254 * This function is only called during the system font list building
Haibo Huang49cc9302020-04-27 16:14:24 -0700255 * process.
Svet Ganove6986e12015-06-04 14:52:15 -0700256 * Parameters:
257 * mapper - Opaque pointer to Foxit font mapper
258 * face - The font face name
259 * charset - Font character set. See above defined constants.
260 * Return Value:
261 * None.
Haibo Huang49cc9302020-04-27 16:14:24 -0700262 */
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700263FPDF_EXPORT void FPDF_CALLCONV FPDF_AddInstalledFont(void* mapper,
264 const char* face,
265 int charset);
Svet Ganove6986e12015-06-04 14:52:15 -0700266
Haibo Huang49cc9302020-04-27 16:14:24 -0700267/*
Svet Ganove6986e12015-06-04 14:52:15 -0700268 * Function: FPDF_SetSystemFontInfo
Haibo Huang49cc9302020-04-27 16:14:24 -0700269 * Set the system font info interface into PDFium
Svet Ganove6986e12015-06-04 14:52:15 -0700270 * Parameters:
271 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure
272 * Return Value:
273 * None
Haibo Huang49cc9302020-04-27 16:14:24 -0700274 * Comments:
275 * Platform support implementation should implement required methods of
276 * FFDF_SYSFONTINFO interface, then call this function during PDFium
277 * initialization process.
278 */
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700279FPDF_EXPORT void FPDF_CALLCONV
280FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo);
Svet Ganove6986e12015-06-04 14:52:15 -0700281
Haibo Huang49cc9302020-04-27 16:14:24 -0700282/*
Svet Ganove6986e12015-06-04 14:52:15 -0700283 * Function: FPDF_GetDefaultSystemFontInfo
284 * Get default system font info interface for current platform
Svet Ganove6986e12015-06-04 14:52:15 -0700285 * Parameters:
286 * None
287 * Return Value:
Philip P. Moltmannac3d58c2016-03-04 15:19:21 -0800288 * Pointer to a FPDF_SYSFONTINFO structure describing the default
Haibo Huang49cc9302020-04-27 16:14:24 -0700289 * interface, or NULL if the platform doesn't have a default interface.
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700290 * Application should call FPDF_FreeDefaultSystemFontInfo to free the
Haibo Huang49cc9302020-04-27 16:14:24 -0700291 * returned pointer.
292 * Comments:
293 * For some platforms, PDFium implements a default version of system
294 * font info interface. The default implementation can be passed to
295 * FPDF_SetSystemFontInfo().
296 */
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700297FPDF_EXPORT FPDF_SYSFONTINFO* FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo();
Svet Ganove6986e12015-06-04 14:52:15 -0700298
Haibo Huang49cc9302020-04-27 16:14:24 -0700299/*
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700300 * Function: FPDF_FreeDefaultSystemFontInfo
301 * Free a default system font info interface
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700302 * Parameters:
303 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure
304 * Return Value:
Haibo Huang49cc9302020-04-27 16:14:24 -0700305 * None
306 * Comments:
307 * This function should be called on the output from
308 * FPDF_SetSystemFontInfo() once it is no longer needed.
309 */
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700310FPDF_EXPORT void FPDF_CALLCONV
311FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700312
Svet Ganove6986e12015-06-04 14:52:15 -0700313#ifdef __cplusplus
314}
315#endif
316
317#endif // PUBLIC_FPDF_SYSFONTINFO_H_