blob: c2da74b70bb71d1929e68e3ae3db371553fd6f57 [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
10#include "fpdfview.h"
11
12/* Character sets for the font */
Nico Weber9d8ec5a2015-08-04 13:00:21 -070013#define FXFONT_ANSI_CHARSET 0
14#define FXFONT_DEFAULT_CHARSET 1
15#define FXFONT_SYMBOL_CHARSET 2
Tom Sepez9857e202015-05-13 17:09:26 -070016#define FXFONT_SHIFTJIS_CHARSET 128
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017#define FXFONT_HANGEUL_CHARSET 129
18#define FXFONT_GB2312_CHARSET 134
19#define FXFONT_CHINESEBIG5_CHARSET 136
John Abd-El-Malek5110c472014-05-17 22:33:34 -070020
21/* Font pitch and family flags */
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022#define FXFONT_FF_FIXEDPITCH 1
23#define FXFONT_FF_ROMAN (1 << 4)
24#define FXFONT_FF_SCRIPT (4 << 4)
John Abd-El-Malek5110c472014-05-17 22:33:34 -070025
26/* Typical weight values */
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027#define FXFONT_FW_NORMAL 400
28#define FXFONT_FW_BOLD 700
John Abd-El-Malek5110c472014-05-17 22:33:34 -070029
30// Exported Functions
31#ifdef __cplusplus
32extern "C" {
33#endif
34
Tom Sepez9857e202015-05-13 17:09:26 -070035/**
John Abd-El-Malek5110c472014-05-17 22:33:34 -070036 * Interface: FPDF_SYSFONTINFO
Tom Sepez9857e202015-05-13 17:09:26 -070037 * Interface for getting system font information and font mapping
John Abd-El-Malek5110c472014-05-17 22:33:34 -070038 */
39typedef struct _FPDF_SYSFONTINFO {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040 /**
41 * Version number of the interface. Currently must be 1.
42 **/
43 int version;
John Abd-El-Malek5110c472014-05-17 22:33:34 -070044
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 /**
46 * Method: Release
47 * Give implementation a chance to release any data after the
48 * interface is no longer used
49 * Interface Version:
50 * 1
51 * Implementation Required:
52 * No
53 * Comments:
54 * Called by Foxit SDK during the final cleanup process.
55 * Parameters:
56 * pThis - Pointer to the interface structure itself
57 * Return Value:
58 * None
59 */
60 void (*Release)(struct _FPDF_SYSFONTINFO* pThis);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070061
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062 /**
63 * Method: EnumFonts
64 * Enumerate all fonts installed on the system
65 * Interface Version:
66 * 1
67 * Implementation Required:
68 * No
69 * Comments:
70 * Implementation should call FPDF_AddIntalledFont() function for
71 * each font found.
72 * Only TrueType/OpenType and Type1 fonts are accepted by Foxit SDK.
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 */
80 void (*EnumFonts)(struct _FPDF_SYSFONTINFO* pThis, void* pMapper);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070081
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 /**
83 * Method: MapFont
84 * Use the system font mapper to get a font handle from requested
85 *parameters
86 * Interface Version:
87 * 1
88 * Implementation Required:
89 * Yes only if GetFont method is not implemented.
90 * Comments:
91 * If the system supports native font mapper (like Windows),
92 *implementation can implement this method to get a font handle.
93 * Otherwise, Foxit SDK will do the mapping and then call GetFont
94 *method.
95 * Only TrueType/OpenType and Type1 fonts are accepted by Foxit SDK.
96 * Parameters:
97 * pThis - Pointer to the interface structure itself
98 * weight - Weight of the requested font. 400 is normal and
99 *700 is bold.
100 * bItalic - Italic option of the requested font, TRUE or
101 *FALSE.
102 * charset - Character set identifier for the requested font.
103 *See above defined constants.
104 * pitch_family - A combination of flags. See above defined
105 *constants.
106 * face - Typeface name. Currently use system local encoding
107 *only.
108 * bExact - Pointer to a boolean value receiving the indicator
109 *whether mapper found the exact match.
110 * If mapper is not sure whether it's exact match,
111 *ignore this paramter.
112 * Return Value:
113 * An opaque pointer for font handle, or NULL if system mapping is
114 *not supported.
115 **/
116 void* (*MapFont)(struct _FPDF_SYSFONTINFO* pThis,
117 int weight,
118 FPDF_BOOL bItalic,
119 int charset,
120 int pitch_family,
121 const char* face,
122 FPDF_BOOL* bExact);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700123
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 /**
125 * Method: GetFont
126 * Get a handle to a particular font by its internal ID
127 * Interface Version:
128 * 1
129 * Implementation Required:
130 * Yes only if MapFont method is not implemented.
131 * Comments:
132 * If the system mapping not supported, Foxit SDK will do the font
133 *mapping and use this method to get a font handle.
134 * Parameters:
135 * pThis - Pointer to the interface structure itself
136 * face - Typeface name. Currently use system local encoding
137 *only.
138 * Return Value:
139 * An opaque pointer for font handle.
140 **/
141 void* (*GetFont)(struct _FPDF_SYSFONTINFO* pThis, const char* face);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 /**
144 * Method: GetFontData
145 * Get font data from a font
146 * Interface Version:
147 * 1
148 * Implementation Required:
149 * Yes
150 * Comments:
151 * Can read either full font file, or a particular TrueType/OpenType
152 *table
153 * Parameters:
154 * pThis - Pointer to the interface structure itself
155 * hFont - Font handle returned by MapFont or GetFont method
156 * table - TrueType/OpenType table identifier (refer to
157 *TrueType specification).
158 * 0 for the whole font file.
159 * buffer - The buffer receiving the font data. Can be NULL if
160 *not provided
161 * buf_size - Buffer size, can be zero if not provided
162 * Return Value:
163 * Number of bytes needed, if buffer not provided or not large
164 *enough,
165 * or number of bytes written into buffer otherwise.
166 **/
167 unsigned long (*GetFontData)(struct _FPDF_SYSFONTINFO* pThis,
168 void* hFont,
169 unsigned int table,
170 unsigned char* buffer,
171 unsigned long buf_size);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700172
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 /**
174 * Method: GetFaceName
175 * Get face name from a font handle
176 * Interface Version:
177 * 1
178 * Implementation Required:
179 * No
180 * Parameters:
181 * pThis - Pointer to the interface structure itself
182 * hFont - Font handle returned by MapFont or GetFont method
183 * buffer - The buffer receiving the face name. Can be NULL if
184 *not provided
185 * buf_size - Buffer size, can be zero if not provided
186 * Return Value:
187 * Number of bytes needed, if buffer not provided or not large
188 *enough,
189 * or number of bytes written into buffer otherwise.
190 **/
191 unsigned long (*GetFaceName)(struct _FPDF_SYSFONTINFO* pThis,
192 void* hFont,
193 char* buffer,
194 unsigned long buf_size);
Tom Sepez9857e202015-05-13 17:09:26 -0700195
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 /**
197 * Method: GetFontCharset
198 * Get character set information for a font handle
199 * Interface Version:
200 * 1
201 * Implementation Required:
202 * No
203 * Parameters:
204 * pThis - Pointer to the interface structure itself
205 * hFont - Font handle returned by MapFont or GetFont method
206 * Return Value:
207 * Character set identifier. See defined constants above.
208 **/
209 int (*GetFontCharset)(struct _FPDF_SYSFONTINFO* pThis, void* hFont);
Tom Sepez9857e202015-05-13 17:09:26 -0700210
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 /**
212 * Method: DeleteFont
213 * Delete a font handle
214 * Interface Version:
215 * 1
216 * Implementation Required:
217 * Yes
218 * Parameters:
219 * pThis - Pointer to the interface structure itself
220 * hFont - Font handle returned by MapFont or GetFont method
221 * Return Value:
222 * None
223 **/
224 void (*DeleteFont)(struct _FPDF_SYSFONTINFO* pThis, void* hFont);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700225} FPDF_SYSFONTINFO;
226
227/**
Tom Sepez2a0bb3b2015-05-12 12:37:14 -0700228 * Struct: FPDF_CharsetFontMap
229 * Provides the name of a font to use for a given charset value.
230 **/
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231typedef struct FPDF_CharsetFontMap_ {
232 int charset; // Character Set Enum value, see FXFONT_*_CHARSET above.
233 const char* fontname; // Name of default font to use with that charset.
Tom Sepez2a0bb3b2015-05-12 12:37:14 -0700234} FPDF_CharsetFontMap;
235
236/**
237 * Function: FPDF_GetDefaultTTFMap
238 * Returns a pointer to the default character set to TT Font name map. The
239 * map is an array of FPDF_CharsetFontMap structs, with its end indicated
240 * by a { -1, NULL } entry.
241 * Parameters:
242 * None.
243 * Return Value:
244 * Pointer to the Charset Font Map.
245 **/
246DLLEXPORT const FPDF_CharsetFontMap* STDCALL FPDF_GetDefaultTTFMap();
247
248/**
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700249 * Function: FPDF_AddInstalledFont
Tom Sepez9857e202015-05-13 17:09:26 -0700250 * Add a system font to the list in Foxit SDK.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700251 * Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 * This function is only called during the system font list building
253 *process.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700254 * Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700255 * mapper - Opaque pointer to Foxit font mapper
256 * face - The font face name
257 * charset - Font character set. See above defined constants.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700258 * Return Value:
Tom Sepez9857e202015-05-13 17:09:26 -0700259 * None.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700260 **/
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261DLLEXPORT void STDCALL FPDF_AddInstalledFont(void* mapper,
262 const char* face,
263 int charset);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700264
265/**
266 * Function: FPDF_SetSystemFontInfo
Tom Sepez9857e202015-05-13 17:09:26 -0700267 * Set the system font info interface into Foxit SDK
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700268 * Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269 * Platform support implementation should implement required methods of
270 *FFDF_SYSFONTINFO interface,
Tom Sepez9857e202015-05-13 17:09:26 -0700271 * then call this function during SDK initialization process.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700272 * Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700273 * pFontInfo - Pointer to a FPDF_SYSFONTINFO structure
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700274 * Return Value:
Tom Sepez9857e202015-05-13 17:09:26 -0700275 * None
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700276 **/
277DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo);
278
279/**
280 * Function: FPDF_GetDefaultSystemFontInfo
Tom Sepez9857e202015-05-13 17:09:26 -0700281 * Get default system font info interface for current platform
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700282 * Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 * For some platforms Foxit SDK implement a default version of system
284 *font info interface.
285 * The default implementation can be used in FPDF_SetSystemFontInfo
286 *function.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700287 * Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700288 * None
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700289 * Return Value:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 * Pointer to a FPDF_SYSFONTINFO structure describing the default
291 *interface.
Tom Sepez9857e202015-05-13 17:09:26 -0700292 * Or NULL if the platform doesn't have a default interface.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 * Application should call FPDF_FreeMemory to free the returned
294 *pointer.
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700295 **/
296DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo();
297
298#ifdef __cplusplus
Tom Sepez9857e202015-05-13 17:09:26 -0700299}
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700300#endif
301
Tom Sepez9857e202015-05-13 17:09:26 -0700302#endif // PUBLIC_FPDF_SYSFONTINFO_H_