John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 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. |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 7 | #ifndef PUBLIC_FPDF_SYSFONTINFO_H_ |
| 8 | #define PUBLIC_FPDF_SYSFONTINFO_H_ |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 10 | // NOLINTNEXTLINE(build/include) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 11 | #include "fpdfview.h" |
| 12 | |
| 13 | /* Character sets for the font */ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 14 | #define FXFONT_ANSI_CHARSET 0 |
| 15 | #define FXFONT_DEFAULT_CHARSET 1 |
| 16 | #define FXFONT_SYMBOL_CHARSET 2 |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 17 | #define FXFONT_SHIFTJIS_CHARSET 128 |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 18 | #define FXFONT_HANGEUL_CHARSET 129 |
| 19 | #define FXFONT_GB2312_CHARSET 134 |
| 20 | #define FXFONT_CHINESEBIG5_CHARSET 136 |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 21 | |
| 22 | /* Font pitch and family flags */ |
Dan Sinclair | 86f5cf1 | 2017-09-27 13:43:44 -0400 | [diff] [blame] | 23 | #define FXFONT_FF_FIXEDPITCH (1 << 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | #define FXFONT_FF_ROMAN (1 << 4) |
| 25 | #define FXFONT_FF_SCRIPT (4 << 4) |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 26 | |
| 27 | /* Typical weight values */ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | #define FXFONT_FW_NORMAL 400 |
| 29 | #define FXFONT_FW_BOLD 700 |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 30 | |
| 31 | // Exported Functions |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 36 | /** |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 37 | * Interface: FPDF_SYSFONTINFO |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 38 | * Interface for getting system font information and font mapping |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 39 | */ |
| 40 | typedef struct _FPDF_SYSFONTINFO { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | /** |
| 42 | * Version number of the interface. Currently must be 1. |
| 43 | **/ |
| 44 | int version; |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 45 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Method: Release |
| 48 | * Give implementation a chance to release any data after the |
| 49 | * interface is no longer used |
| 50 | * Interface Version: |
| 51 | * 1 |
| 52 | * Implementation Required: |
| 53 | * No |
| 54 | * Comments: |
| 55 | * Called by Foxit SDK during the final cleanup process. |
| 56 | * Parameters: |
| 57 | * pThis - Pointer to the interface structure itself |
| 58 | * Return Value: |
| 59 | * None |
| 60 | */ |
| 61 | void (*Release)(struct _FPDF_SYSFONTINFO* pThis); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 62 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Method: EnumFonts |
| 65 | * Enumerate all fonts installed on the system |
| 66 | * Interface Version: |
| 67 | * 1 |
| 68 | * Implementation Required: |
| 69 | * No |
| 70 | * Comments: |
| 71 | * Implementation should call FPDF_AddIntalledFont() function for |
| 72 | * each font found. |
| 73 | * Only TrueType/OpenType and Type1 fonts are accepted by Foxit SDK. |
| 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 | */ |
| 81 | void (*EnumFonts)(struct _FPDF_SYSFONTINFO* pThis, void* pMapper); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Method: MapFont |
| 85 | * Use the system font mapper to get a font handle from requested |
| 86 | *parameters |
| 87 | * Interface Version: |
| 88 | * 1 |
| 89 | * Implementation Required: |
| 90 | * Yes only if GetFont method is not implemented. |
| 91 | * Comments: |
| 92 | * If the system supports native font mapper (like Windows), |
| 93 | *implementation can implement this method to get a font handle. |
| 94 | * Otherwise, Foxit SDK will do the mapping and then call GetFont |
| 95 | *method. |
| 96 | * Only TrueType/OpenType and Type1 fonts are accepted by Foxit SDK. |
| 97 | * Parameters: |
| 98 | * pThis - Pointer to the interface structure itself |
| 99 | * weight - Weight of the requested font. 400 is normal and |
| 100 | *700 is bold. |
| 101 | * bItalic - Italic option of the requested font, TRUE or |
| 102 | *FALSE. |
| 103 | * charset - Character set identifier for the requested font. |
| 104 | *See above defined constants. |
| 105 | * pitch_family - A combination of flags. See above defined |
| 106 | *constants. |
| 107 | * face - Typeface name. Currently use system local encoding |
| 108 | *only. |
Nicolas Pena | 979e916 | 2017-11-07 16:32:20 +0000 | [diff] [blame] | 109 | * bExact - Obsolete: this parameter is now ignored. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | * Return Value: |
| 111 | * An opaque pointer for font handle, or NULL if system mapping is |
| 112 | *not supported. |
| 113 | **/ |
| 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); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 121 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | /** |
| 123 | * Method: GetFont |
| 124 | * Get a handle to a particular font by its internal ID |
| 125 | * Interface Version: |
| 126 | * 1 |
| 127 | * Implementation Required: |
| 128 | * Yes only if MapFont method is not implemented. |
| 129 | * Comments: |
| 130 | * If the system mapping not supported, Foxit SDK will do the font |
| 131 | *mapping and use this method to get a font handle. |
| 132 | * Parameters: |
| 133 | * pThis - Pointer to the interface structure itself |
| 134 | * face - Typeface name. Currently use system local encoding |
| 135 | *only. |
| 136 | * Return Value: |
| 137 | * An opaque pointer for font handle. |
| 138 | **/ |
| 139 | void* (*GetFont)(struct _FPDF_SYSFONTINFO* pThis, const char* face); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 140 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Method: GetFontData |
| 143 | * Get font data from a font |
| 144 | * Interface Version: |
| 145 | * 1 |
| 146 | * Implementation Required: |
| 147 | * Yes |
| 148 | * Comments: |
| 149 | * Can read either full font file, or a particular TrueType/OpenType |
| 150 | *table |
| 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). |
| 156 | * 0 for the whole font file. |
| 157 | * buffer - The buffer receiving the font data. Can be NULL if |
| 158 | *not provided |
| 159 | * buf_size - Buffer size, can be zero if not provided |
| 160 | * Return Value: |
| 161 | * Number of bytes needed, if buffer not provided or not large |
| 162 | *enough, |
| 163 | * or number of bytes written into buffer otherwise. |
| 164 | **/ |
| 165 | unsigned long (*GetFontData)(struct _FPDF_SYSFONTINFO* pThis, |
| 166 | void* hFont, |
| 167 | unsigned int table, |
| 168 | unsigned char* buffer, |
| 169 | unsigned long buf_size); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 170 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | /** |
| 172 | * Method: GetFaceName |
| 173 | * Get face name from a font handle |
| 174 | * Interface Version: |
| 175 | * 1 |
| 176 | * Implementation Required: |
| 177 | * No |
| 178 | * Parameters: |
| 179 | * pThis - Pointer to the interface structure itself |
| 180 | * hFont - Font handle returned by MapFont or GetFont method |
| 181 | * buffer - The buffer receiving the face name. Can be NULL if |
| 182 | *not provided |
| 183 | * buf_size - Buffer size, can be zero if not provided |
| 184 | * Return Value: |
| 185 | * Number of bytes needed, if buffer not provided or not large |
| 186 | *enough, |
| 187 | * 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); |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 193 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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); |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 208 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 223 | } FPDF_SYSFONTINFO; |
| 224 | |
| 225 | /** |
Tom Sepez | 2a0bb3b | 2015-05-12 12:37:14 -0700 | [diff] [blame] | 226 | * Struct: FPDF_CharsetFontMap |
| 227 | * Provides the name of a font to use for a given charset value. |
| 228 | **/ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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. |
Tom Sepez | 2a0bb3b | 2015-05-12 12:37:14 -0700 | [diff] [blame] | 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 | **/ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 244 | FPDF_EXPORT const FPDF_CharsetFontMap* FPDF_CALLCONV FPDF_GetDefaultTTFMap(); |
Tom Sepez | 2a0bb3b | 2015-05-12 12:37:14 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 247 | * Function: FPDF_AddInstalledFont |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 248 | * Add a system font to the list in Foxit SDK. |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 249 | * Comments: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | * This function is only called during the system font list building |
| 251 | *process. |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 252 | * Parameters: |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 253 | * mapper - Opaque pointer to Foxit font mapper |
| 254 | * face - The font face name |
| 255 | * charset - Font character set. See above defined constants. |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 256 | * Return Value: |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 257 | * None. |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 258 | **/ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 259 | FPDF_EXPORT void FPDF_CALLCONV FPDF_AddInstalledFont(void* mapper, |
| 260 | const char* face, |
| 261 | int charset); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * Function: FPDF_SetSystemFontInfo |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 265 | * Set the system font info interface into Foxit SDK |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 266 | * Comments: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | * Platform support implementation should implement required methods of |
| 268 | *FFDF_SYSFONTINFO interface, |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 269 | * then call this function during SDK initialization process. |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 270 | * Parameters: |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 271 | * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 272 | * Return Value: |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 273 | * None |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 274 | **/ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 275 | FPDF_EXPORT void FPDF_CALLCONV |
| 276 | FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 277 | |
| 278 | /** |
| 279 | * Function: FPDF_GetDefaultSystemFontInfo |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 280 | * Get default system font info interface for current platform |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 281 | * Comments: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | * For some platforms Foxit SDK implement a default version of system |
| 283 | *font info interface. |
| 284 | * The default implementation can be used in FPDF_SetSystemFontInfo |
| 285 | *function. |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 286 | * Parameters: |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 287 | * None |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 288 | * Return Value: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | * Pointer to a FPDF_SYSFONTINFO structure describing the default |
| 290 | *interface. |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 291 | * Or NULL if the platform doesn't have a default interface. |
npm | 788217d | 2016-11-08 16:48:36 -0800 | [diff] [blame] | 292 | * Application should call FPDF_FreeDefaultSystemFontInfo to free the |
| 293 | *returned pointer. |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 294 | **/ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 295 | FPDF_EXPORT FPDF_SYSFONTINFO* FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo(); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 296 | |
npm | 788217d | 2016-11-08 16:48:36 -0800 | [diff] [blame] | 297 | /** |
| 298 | * Function: FPDF_FreeDefaultSystemFontInfo |
| 299 | * Free a default system font info interface |
| 300 | * Comments: |
| 301 | * This function should be called on the output from |
| 302 | *FPDF_SetSystemFontInfo once it is no longer needed by the client. |
| 303 | * Parameters: |
| 304 | * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure |
| 305 | * Return Value: |
| 306 | * None |
| 307 | **/ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 308 | FPDF_EXPORT void FPDF_CALLCONV |
Dan Sinclair | 4bb4e84 | 2017-07-18 09:58:58 -0400 | [diff] [blame] | 309 | FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo); |
npm | 788217d | 2016-11-08 16:48:36 -0800 | [diff] [blame] | 310 | |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 311 | #ifdef __cplusplus |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 312 | } |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 313 | #endif |
| 314 | |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 315 | #endif // PUBLIC_FPDF_SYSFONTINFO_H_ |