1 // Copyright 2014 The PDFium Authors 2 // 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 10 // clang-format off 11 // NOLINTNEXTLINE(build/include) 12 #include "fpdfview.h" 13 14 /* Character sets for the font */ 15 #define FXFONT_ANSI_CHARSET 0 16 #define FXFONT_DEFAULT_CHARSET 1 17 #define FXFONT_SYMBOL_CHARSET 2 18 #define FXFONT_SHIFTJIS_CHARSET 128 19 #define FXFONT_HANGEUL_CHARSET 129 20 #define FXFONT_GB2312_CHARSET 134 21 #define FXFONT_CHINESEBIG5_CHARSET 136 22 #define FXFONT_GREEK_CHARSET 161 23 #define FXFONT_VIETNAMESE_CHARSET 163 24 #define FXFONT_HEBREW_CHARSET 177 25 #define FXFONT_ARABIC_CHARSET 178 26 #define FXFONT_CYRILLIC_CHARSET 204 27 #define FXFONT_THAI_CHARSET 222 28 #define FXFONT_EASTERNEUROPEAN_CHARSET 238 29 30 /* Font pitch and family flags */ 31 #define FXFONT_FF_FIXEDPITCH (1 << 0) 32 #define FXFONT_FF_ROMAN (1 << 4) 33 #define FXFONT_FF_SCRIPT (4 << 4) 34 35 /* Typical weight values */ 36 #define FXFONT_FW_NORMAL 400 37 #define FXFONT_FW_BOLD 700 38 39 // Exported Functions 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* 45 * Interface: FPDF_SYSFONTINFO 46 * Interface for getting system font information and font mapping 47 */ 48 typedef struct _FPDF_SYSFONTINFO { 49 /* 50 * Version number of the interface. Currently must be 1. 51 */ 52 int version; 53 54 /* 55 * Method: Release 56 * Give implementation a chance to release any data after the 57 * interface is no longer used. 58 * Interface Version: 59 * 1 60 * Implementation Required: 61 * No 62 * Parameters: 63 * pThis - Pointer to the interface structure itself 64 * Return Value: 65 * None 66 * Comments: 67 * Called by PDFium during the final cleanup process. 68 */ 69 void (*Release)(struct _FPDF_SYSFONTINFO* pThis); 70 71 /* 72 * Method: EnumFonts 73 * Enumerate all fonts installed on the system 74 * Interface Version: 75 * 1 76 * Implementation Required: 77 * No 78 * Parameters: 79 * pThis - Pointer to the interface structure itself 80 * pMapper - An opaque pointer to internal font mapper, used 81 * when calling FPDF_AddInstalledFont(). 82 * Return Value: 83 * None 84 * Comments: 85 * Implementations should call FPDF_AddIntalledFont() function for 86 * each font found. Only TrueType/OpenType and Type1 fonts are accepted 87 * by PDFium. 88 */ 89 void (*EnumFonts)(struct _FPDF_SYSFONTINFO* pThis, void* pMapper); 90 91 /* 92 * Method: MapFont 93 * Use the system font mapper to get a font handle from requested 94 * parameters. 95 * Interface Version: 96 * 1 97 * Implementation Required: 98 * Required if GetFont method is not implemented. 99 * Parameters: 100 * pThis - Pointer to the interface structure itself 101 * weight - Weight of the requested font. 400 is normal and 102 * 700 is bold. 103 * bItalic - Italic option of the requested font, TRUE or 104 * FALSE. 105 * charset - Character set identifier for the requested font. 106 * See above defined constants. 107 * pitch_family - A combination of flags. See above defined 108 * constants. 109 * face - Typeface name. Currently use system local encoding 110 * only. 111 * bExact - Obsolete: this parameter is now ignored. 112 * Return Value: 113 * An opaque pointer for font handle, or NULL if system mapping is 114 * 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 */ 122 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); 129 130 /* 131 * Method: GetFont 132 * Get a handle to a particular font by its internal ID 133 * Interface Version: 134 * 1 135 * Implementation Required: 136 * Required if MapFont method is not implemented. 137 * Return Value: 138 * An opaque pointer for font handle. 139 * 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 */ 146 void* (*GetFont)(struct _FPDF_SYSFONTINFO* pThis, const char* face); 147 148 /* 149 * Method: GetFontData 150 * Get font data from a font 151 * Interface Version: 152 * 1 153 * Implementation Required: 154 * Yes 155 * 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 159 * TrueType specification), or 0 for the whole file. 160 * buffer - The buffer receiving the font data. Can be NULL if 161 * not provided. 162 * buf_size - Buffer size, can be zero if not provided. 163 * Return Value: 164 * Number of bytes needed, if buffer not provided or not large 165 * 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 */ 170 unsigned long (*GetFontData)(struct _FPDF_SYSFONTINFO* pThis, 171 void* hFont, 172 unsigned int table, 173 unsigned char* buffer, 174 unsigned long buf_size); 175 176 /* 177 * 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 187 * not provided 188 * 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 191 * enough, or number of bytes written into buffer otherwise. 192 */ 193 unsigned long (*GetFaceName)(struct _FPDF_SYSFONTINFO* pThis, 194 void* hFont, 195 char* buffer, 196 unsigned long buf_size); 197 198 /* 199 * 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. 210 */ 211 int (*GetFontCharset)(struct _FPDF_SYSFONTINFO* pThis, void* hFont); 212 213 /* 214 * 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 225 */ 226 void (*DeleteFont)(struct _FPDF_SYSFONTINFO* pThis, void* hFont); 227 } FPDF_SYSFONTINFO; 228 229 /* 230 * Struct: FPDF_CharsetFontMap 231 * Provides the name of a font to use for a given charset value. 232 */ 233 typedef 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. 236 } FPDF_CharsetFontMap; 237 238 /* 239 * 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. 247 */ 248 FPDF_EXPORT const FPDF_CharsetFontMap* FPDF_CALLCONV FPDF_GetDefaultTTFMap(); 249 250 /* 251 * Function: FPDF_AddInstalledFont 252 * Add a system font to the list in PDFium. 253 * Comments: 254 * This function is only called during the system font list building 255 * process. 256 * 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. 262 */ 263 FPDF_EXPORT void FPDF_CALLCONV FPDF_AddInstalledFont(void* mapper, 264 const char* face, 265 int charset); 266 267 /* 268 * Function: FPDF_SetSystemFontInfo 269 * Set the system font info interface into PDFium 270 * Parameters: 271 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure 272 * Return Value: 273 * None 274 * Comments: 275 * Platform support implementation should implement required methods of 276 * FFDF_SYSFONTINFO interface, then call this function during PDFium 277 * initialization process. 278 */ 279 FPDF_EXPORT void FPDF_CALLCONV 280 FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); 281 282 /* 283 * Function: FPDF_GetDefaultSystemFontInfo 284 * Get default system font info interface for current platform 285 * Parameters: 286 * None 287 * Return Value: 288 * Pointer to a FPDF_SYSFONTINFO structure describing the default 289 * interface, or NULL if the platform doesn't have a default interface. 290 * Application should call FPDF_FreeDefaultSystemFontInfo to free the 291 * 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 */ 297 FPDF_EXPORT FPDF_SYSFONTINFO* FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo(); 298 299 /* 300 * Function: FPDF_FreeDefaultSystemFontInfo 301 * Free a default system font info interface 302 * Parameters: 303 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure 304 * Return Value: 305 * None 306 * Comments: 307 * This function should be called on the output from 308 * FPDF_SetSystemFontInfo() once it is no longer needed. 309 */ 310 FPDF_EXPORT void FPDF_CALLCONV 311 FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); 312 313 #ifdef __cplusplus 314 } 315 #endif 316 317 #endif // PUBLIC_FPDF_SYSFONTINFO_H_ 318