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