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