blob: c9aa33856d4674353099bec366c4fa54a4e0e3a8 [file] [log] [blame]
John Abd-El-Malek5110c472014-05-17 22:33:34 -07001// 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 Sepez9857e202015-05-13 17:09:26 -07004
John Abd-El-Malek5110c472014-05-17 22:33:34 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez9857e202015-05-13 17:09:26 -07007#ifndef PUBLIC_FPDF_SYSFONTINFO_H_
8#define PUBLIC_FPDF_SYSFONTINFO_H_
John Abd-El-Malek5110c472014-05-17 22:33:34 -07009
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050010// NOLINTNEXTLINE(build/include)
John Abd-El-Malek5110c472014-05-17 22:33:34 -070011#include "fpdfview.h"
12
13/* Character sets for the font */
Nico Weber9d8ec5a2015-08-04 13:00:21 -070014#define FXFONT_ANSI_CHARSET 0
15#define FXFONT_DEFAULT_CHARSET 1
16#define FXFONT_SYMBOL_CHARSET 2
Tom Sepez9857e202015-05-13 17:09:26 -070017#define FXFONT_SHIFTJIS_CHARSET 128
Nico Weber9d8ec5a2015-08-04 13:00:21 -070018#define FXFONT_HANGEUL_CHARSET 129
19#define FXFONT_GB2312_CHARSET 134
20#define FXFONT_CHINESEBIG5_CHARSET 136
John Abd-El-Malek5110c472014-05-17 22:33:34 -070021
22/* Font pitch and family flags */
Dan Sinclair86f5cf12017-09-27 13:43:44 -040023#define FXFONT_FF_FIXEDPITCH (1 << 0)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024#define FXFONT_FF_ROMAN (1 << 4)
25#define FXFONT_FF_SCRIPT (4 << 4)
John Abd-El-Malek5110c472014-05-17 22:33:34 -070026
27/* Typical weight values */
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028#define FXFONT_FW_NORMAL 400
29#define FXFONT_FW_BOLD 700
John Abd-El-Malek5110c472014-05-17 22:33:34 -070030
31// Exported Functions
32#ifdef __cplusplus
33extern "C" {
34#endif
35
Tom Sepez9857e202015-05-13 17:09:26 -070036/**
John Abd-El-Malek5110c472014-05-17 22:33:34 -070037 * Interface: FPDF_SYSFONTINFO
Tom Sepez9857e202015-05-13 17:09:26 -070038 * Interface for getting system font information and font mapping
John Abd-El-Malek5110c472014-05-17 22:33:34 -070039 */
40typedef struct _FPDF_SYSFONTINFO {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 /**
42 * Version number of the interface. Currently must be 1.
43 **/
44 int version;
John Abd-El-Malek5110c472014-05-17 22:33:34 -070045
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 /**
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-Malek5110c472014-05-17 22:33:34 -070062
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 /**
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-Malek5110c472014-05-17 22:33:34 -070082
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 /**
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.
109 * bExact - Pointer to a boolean value receiving the indicator
110 *whether mapper found the exact match.
111 * If mapper is not sure whether it's exact match,
112 *ignore this paramter.
113 * Return Value:
114 * An opaque pointer for font handle, or NULL if system mapping is
115 *not supported.
116 **/
117 void* (*MapFont)(struct _FPDF_SYSFONTINFO* pThis,
118 int weight,
119 FPDF_BOOL bItalic,
120 int charset,
121 int pitch_family,
122 const char* face,
123 FPDF_BOOL* bExact);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700124
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 /**
126 * Method: GetFont
127 * Get a handle to a particular font by its internal ID
128 * Interface Version:
129 * 1
130 * Implementation Required:
131 * Yes only if MapFont method is not implemented.
132 * Comments:
133 * If the system mapping not supported, Foxit SDK will do the font
134 *mapping and use this method to get a font handle.
135 * Parameters:
136 * pThis - Pointer to the interface structure itself
137 * face - Typeface name. Currently use system local encoding
138 *only.
139 * Return Value:
140 * An opaque pointer for font handle.
141 **/
142 void* (*GetFont)(struct _FPDF_SYSFONTINFO* pThis, const char* face);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 /**
145 * Method: GetFontData
146 * Get font data from a font
147 * Interface Version:
148 * 1
149 * Implementation Required:
150 * Yes
151 * Comments:
152 * Can read either full font file, or a particular TrueType/OpenType
153 *table
154 * Parameters:
155 * pThis - Pointer to the interface structure itself
156 * hFont - Font handle returned by MapFont or GetFont method
157 * table - TrueType/OpenType table identifier (refer to
158 *TrueType specification).
159 * 0 for the whole font 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,
166 * or number of bytes written into buffer otherwise.
167 **/
168 unsigned long (*GetFontData)(struct _FPDF_SYSFONTINFO* pThis,
169 void* hFont,
170 unsigned int table,
171 unsigned char* buffer,
172 unsigned long buf_size);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700173
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 /**
175 * Method: GetFaceName
176 * Get face name from a font handle
177 * Interface Version:
178 * 1
179 * Implementation Required:
180 * No
181 * Parameters:
182 * pThis - Pointer to the interface structure itself
183 * hFont - Font handle returned by MapFont or GetFont method
184 * buffer - The buffer receiving the face name. Can be NULL if
185 *not provided
186 * buf_size - Buffer size, can be zero if not provided
187 * Return Value:
188 * Number of bytes needed, if buffer not provided or not large
189 *enough,
190 * or number of bytes written into buffer otherwise.
191 **/
192 unsigned long (*GetFaceName)(struct _FPDF_SYSFONTINFO* pThis,
193 void* hFont,
194 char* buffer,
195 unsigned long buf_size);
Tom Sepez9857e202015-05-13 17:09:26 -0700196
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 /**
198 * Method: GetFontCharset
199 * Get character set information for a font handle
200 * Interface Version:
201 * 1
202 * Implementation Required:
203 * No
204 * Parameters:
205 * pThis - Pointer to the interface structure itself
206 * hFont - Font handle returned by MapFont or GetFont method
207 * Return Value:
208 * Character set identifier. See defined constants above.
209 **/
210 int (*GetFontCharset)(struct _FPDF_SYSFONTINFO* pThis, void* hFont);
Tom Sepez9857e202015-05-13 17:09:26 -0700211
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 /**
213 * Method: DeleteFont
214 * Delete a font handle
215 * Interface Version:
216 * 1
217 * Implementation Required:
218 * Yes
219 * Parameters:
220 * pThis - Pointer to the interface structure itself
221 * hFont - Font handle returned by MapFont or GetFont method
222 * Return Value:
223 * None
224 **/
225 void (*DeleteFont)(struct _FPDF_SYSFONTINFO* pThis, void* hFont);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700226} FPDF_SYSFONTINFO;
227
228/**
Tom Sepez2a0bb3b2015-05-12 12:37:14 -0700229 * Struct: FPDF_CharsetFontMap
230 * Provides the name of a font to use for a given charset value.
231 **/
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232typedef struct FPDF_CharsetFontMap_ {
233 int charset; // Character Set Enum value, see FXFONT_*_CHARSET above.
234 const char* fontname; // Name of default font to use with that charset.
Tom Sepez2a0bb3b2015-05-12 12:37:14 -0700235} FPDF_CharsetFontMap;
236
237/**
238 * Function: FPDF_GetDefaultTTFMap
239 * Returns a pointer to the default character set to TT Font name map. The
240 * map is an array of FPDF_CharsetFontMap structs, with its end indicated
241 * by a { -1, NULL } entry.
242 * Parameters:
243 * None.
244 * Return Value:
245 * Pointer to the Charset Font Map.
246 **/
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400247FPDF_EXPORT const FPDF_CharsetFontMap* FPDF_CALLCONV FPDF_GetDefaultTTFMap();
Tom Sepez2a0bb3b2015-05-12 12:37:14 -0700248
249/**
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700250 * Function: FPDF_AddInstalledFont
Tom Sepez9857e202015-05-13 17:09:26 -0700251 * Add a system font to the list in Foxit SDK.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700252 * Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 * This function is only called during the system font list building
254 *process.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700255 * Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700256 * mapper - Opaque pointer to Foxit font mapper
257 * face - The font face name
258 * charset - Font character set. See above defined constants.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700259 * Return Value:
Tom Sepez9857e202015-05-13 17:09:26 -0700260 * None.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700261 **/
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400262FPDF_EXPORT void FPDF_CALLCONV FPDF_AddInstalledFont(void* mapper,
263 const char* face,
264 int charset);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700265
266/**
267 * Function: FPDF_SetSystemFontInfo
Tom Sepez9857e202015-05-13 17:09:26 -0700268 * Set the system font info interface into Foxit SDK
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700269 * Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 * Platform support implementation should implement required methods of
271 *FFDF_SYSFONTINFO interface,
Tom Sepez9857e202015-05-13 17:09:26 -0700272 * then call this function during SDK initialization process.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700273 * Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700274 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700275 * Return Value:
Tom Sepez9857e202015-05-13 17:09:26 -0700276 * None
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700277 **/
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400278FPDF_EXPORT void FPDF_CALLCONV
279FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700280
281/**
282 * Function: FPDF_GetDefaultSystemFontInfo
Tom Sepez9857e202015-05-13 17:09:26 -0700283 * Get default system font info interface for current platform
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700284 * Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 * For some platforms Foxit SDK implement a default version of system
286 *font info interface.
287 * The default implementation can be used in FPDF_SetSystemFontInfo
288 *function.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700289 * Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700290 * None
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700291 * Return Value:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 * Pointer to a FPDF_SYSFONTINFO structure describing the default
293 *interface.
Tom Sepez9857e202015-05-13 17:09:26 -0700294 * Or NULL if the platform doesn't have a default interface.
npm788217d2016-11-08 16:48:36 -0800295 * Application should call FPDF_FreeDefaultSystemFontInfo to free the
296 *returned pointer.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700297 **/
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400298FPDF_EXPORT FPDF_SYSFONTINFO* FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo();
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700299
npm788217d2016-11-08 16:48:36 -0800300/**
301 * Function: FPDF_FreeDefaultSystemFontInfo
302 * Free a default system font info interface
303 * Comments:
304 * This function should be called on the output from
305 *FPDF_SetSystemFontInfo once it is no longer needed by the client.
306 * Parameters:
307 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure
308 * Return Value:
309 * None
310 **/
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400311FPDF_EXPORT void FPDF_CALLCONV
Dan Sinclair4bb4e842017-07-18 09:58:58 -0400312FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo);
npm788217d2016-11-08 16:48:36 -0800313
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700314#ifdef __cplusplus
Tom Sepez9857e202015-05-13 17:09:26 -0700315}
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700316#endif
317
Tom Sepez9857e202015-05-13 17:09:26 -0700318#endif // PUBLIC_FPDF_SYSFONTINFO_H_