1 // Copyright 2014 PDFium Authors. All rights reserved. 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_ARABIC_CHARSET 178 23 #define FXFONT_CYRILLIC_CHARSET 204 24 #define FXFONT_EASTERNEUROPEAN_CHARSET 238 25 26 /* Font pitch and family flags */ 27 #define FXFONT_FF_FIXEDPITCH (1 << 0) 28 #define FXFONT_FF_ROMAN (1 << 4) 29 #define FXFONT_FF_SCRIPT (4 << 4) 30 31 /* Typical weight values */ 32 #define FXFONT_FW_NORMAL 400 33 #define FXFONT_FW_BOLD 700 34 35 // Exported Functions 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /* 41 * Interface: FPDF_SYSFONTINFO 42 * Interface for getting system font information and font mapping 43 */ 44 typedef struct _FPDF_SYSFONTINFO { 45 /* 46 * Version number of the interface. Currently must be 1. 47 */ 48 int version; 49 50 /* 51 * Method: Release 52 * Give implementation a chance to release any data after the 53 * interface is no longer used. 54 * Interface Version: 55 * 1 56 * Implementation Required: 57 * No 58 * Parameters: 59 * pThis - Pointer to the interface structure itself 60 * Return Value: 61 * None 62 * Comments: 63 * Called by PDFium during the final cleanup process. 64 */ 65 void (*Release)(struct _FPDF_SYSFONTINFO* pThis); 66 67 /* 68 * Method: EnumFonts 69 * Enumerate all fonts installed on the system 70 * Interface Version: 71 * 1 72 * Implementation Required: 73 * No 74 * Parameters: 75 * pThis - Pointer to the interface structure itself 76 * pMapper - An opaque pointer to internal font mapper, used 77 * when calling FPDF_AddInstalledFont(). 78 * Return Value: 79 * None 80 * Comments: 81 * Implementations should call FPDF_AddIntalledFont() function for 82 * each font found. Only TrueType/OpenType and Type1 fonts are accepted 83 * by PDFium. 84 */ 85 void (*EnumFonts)(struct _FPDF_SYSFONTINFO* pThis, void* pMapper); 86 87 /* 88 * Method: MapFont 89 * Use the system font mapper to get a font handle from requested 90 * parameters. 91 * Interface Version: 92 * 1 93 * Implementation Required: 94 * Required if GetFont method is not implemented. 95 * Parameters: 96 * pThis - Pointer to the interface structure itself 97 * weight - Weight of the requested font. 400 is normal and 98 * 700 is bold. 99 * bItalic - Italic option of the requested font, TRUE or 100 * FALSE. 101 * charset - Character set identifier for the requested font. 102 * See above defined constants. 103 * pitch_family - A combination of flags. See above defined 104 * constants. 105 * face - Typeface name. Currently use system local encoding 106 * only. 107 * bExact - Obsolete: this parameter is now ignored. 108 * Return Value: 109 * An opaque pointer for font handle, or NULL if system mapping is 110 * not supported. 111 * Comments: 112 * If the system supports native font mapper (like Windows), 113 * implementation can implement this method to get a font handle. 114 * Otherwise, PDFium will do the mapping and then call GetFont 115 * method. Only TrueType/OpenType and Type1 fonts are accepted 116 * by PDFium. 117 */ 118 void* (*MapFont)(struct _FPDF_SYSFONTINFO* pThis, 119 int weight, 120 FPDF_BOOL bItalic, 121 int charset, 122 int pitch_family, 123 const char* face, 124 FPDF_BOOL* bExact); 125 126 /* 127 * Method: GetFont 128 * Get a handle to a particular font by its internal ID 129 * Interface Version: 130 * 1 131 * Implementation Required: 132 * Required if MapFont method is not implemented. 133 * Return Value: 134 * An opaque pointer for font handle. 135 * Parameters: 136 * pThis - Pointer to the interface structure itself 137 * face - Typeface name in system local encoding. 138 * Comments: 139 * If the system mapping not supported, PDFium will do the font 140 * mapping and use this method to get a font handle. 141 */ 142 void* (*GetFont)(struct _FPDF_SYSFONTINFO* pThis, const char* face); 143 144 /* 145 * Method: GetFontData 146 * Get font data from a font 147 * Interface Version: 148 * 1 149 * Implementation Required: 150 * Yes 151 * Parameters: 152 * pThis - Pointer to the interface structure itself 153 * hFont - Font handle returned by MapFont or GetFont method 154 * table - TrueType/OpenType table identifier (refer to 155 * TrueType specification), or 0 for the whole file. 156 * buffer - The buffer receiving the font data. Can be NULL if 157 * not provided. 158 * buf_size - Buffer size, can be zero if not provided. 159 * Return Value: 160 * Number of bytes needed, if buffer not provided or not large 161 * enough, or number of bytes written into buffer otherwise. 162 * Comments: 163 * Can read either the full font file, or a particular 164 * TrueType/OpenType table. 165 */ 166 unsigned long (*GetFontData)(struct _FPDF_SYSFONTINFO* pThis, 167 void* hFont, 168 unsigned int table, 169 unsigned char* buffer, 170 unsigned long buf_size); 171 172 /* 173 * Method: GetFaceName 174 * Get face name from a font handle 175 * Interface Version: 176 * 1 177 * Implementation Required: 178 * No 179 * Parameters: 180 * pThis - Pointer to the interface structure itself 181 * hFont - Font handle returned by MapFont or GetFont method 182 * buffer - The buffer receiving the face name. Can be NULL if 183 * not provided 184 * buf_size - Buffer size, can be zero if not provided 185 * Return Value: 186 * Number of bytes needed, if buffer not provided or not large 187 * enough, or number of bytes written into buffer otherwise. 188 */ 189 unsigned long (*GetFaceName)(struct _FPDF_SYSFONTINFO* pThis, 190 void* hFont, 191 char* buffer, 192 unsigned long buf_size); 193 194 /* 195 * Method: GetFontCharset 196 * Get character set information for a font handle 197 * Interface Version: 198 * 1 199 * Implementation Required: 200 * No 201 * Parameters: 202 * pThis - Pointer to the interface structure itself 203 * hFont - Font handle returned by MapFont or GetFont method 204 * Return Value: 205 * Character set identifier. See defined constants above. 206 */ 207 int (*GetFontCharset)(struct _FPDF_SYSFONTINFO* pThis, void* hFont); 208 209 /* 210 * Method: DeleteFont 211 * Delete a font handle 212 * Interface Version: 213 * 1 214 * Implementation Required: 215 * Yes 216 * Parameters: 217 * pThis - Pointer to the interface structure itself 218 * hFont - Font handle returned by MapFont or GetFont method 219 * Return Value: 220 * None 221 */ 222 void (*DeleteFont)(struct _FPDF_SYSFONTINFO* pThis, void* hFont); 223 } FPDF_SYSFONTINFO; 224 225 /* 226 * Struct: FPDF_CharsetFontMap 227 * Provides the name of a font to use for a given charset value. 228 */ 229 typedef struct FPDF_CharsetFontMap_ { 230 int charset; // Character Set Enum value, see FXFONT_*_CHARSET above. 231 const char* fontname; // Name of default font to use with that charset. 232 } FPDF_CharsetFontMap; 233 234 /* 235 * Function: FPDF_GetDefaultTTFMap 236 * Returns a pointer to the default character set to TT Font name map. The 237 * map is an array of FPDF_CharsetFontMap structs, with its end indicated 238 * by a { -1, NULL } entry. 239 * Parameters: 240 * None. 241 * Return Value: 242 * Pointer to the Charset Font Map. 243 */ 244 FPDF_EXPORT const FPDF_CharsetFontMap* FPDF_CALLCONV FPDF_GetDefaultTTFMap(); 245 246 /* 247 * Function: FPDF_AddInstalledFont 248 * Add a system font to the list in PDFium. 249 * Comments: 250 * This function is only called during the system font list building 251 * process. 252 * Parameters: 253 * mapper - Opaque pointer to Foxit font mapper 254 * face - The font face name 255 * charset - Font character set. See above defined constants. 256 * Return Value: 257 * None. 258 */ 259 FPDF_EXPORT void FPDF_CALLCONV FPDF_AddInstalledFont(void* mapper, 260 const char* face, 261 int charset); 262 263 /* 264 * Function: FPDF_SetSystemFontInfo 265 * Set the system font info interface into PDFium 266 * Parameters: 267 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure 268 * Return Value: 269 * None 270 * Comments: 271 * Platform support implementation should implement required methods of 272 * FFDF_SYSFONTINFO interface, then call this function during PDFium 273 * initialization process. 274 */ 275 FPDF_EXPORT void FPDF_CALLCONV 276 FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); 277 278 /* 279 * Function: FPDF_GetDefaultSystemFontInfo 280 * Get default system font info interface for current platform 281 * Parameters: 282 * None 283 * Return Value: 284 * Pointer to a FPDF_SYSFONTINFO structure describing the default 285 * interface, or NULL if the platform doesn't have a default interface. 286 * Application should call FPDF_FreeDefaultSystemFontInfo to free the 287 * returned pointer. 288 * Comments: 289 * For some platforms, PDFium implements a default version of system 290 * font info interface. The default implementation can be passed to 291 * FPDF_SetSystemFontInfo(). 292 */ 293 FPDF_EXPORT FPDF_SYSFONTINFO* FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo(); 294 295 /* 296 * Function: FPDF_FreeDefaultSystemFontInfo 297 * Free a default system font info interface 298 * Parameters: 299 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure 300 * Return Value: 301 * None 302 * Comments: 303 * This function should be called on the output from 304 * FPDF_SetSystemFontInfo() once it is no longer needed. 305 */ 306 FPDF_EXPORT void FPDF_CALLCONV 307 FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); 308 309 #ifdef __cplusplus 310 } 311 #endif 312 313 #endif // PUBLIC_FPDF_SYSFONTINFO_H_ 314