Home | History | Annotate | Download | only in public
      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
     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);
     61 
     62   /**
     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);
     81 
     82   /**
     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);
    123 
    124   /**
    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);
    142 
    143   /**
    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);
    172 
    173   /**
    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);
    195 
    196   /**
    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);
    210 
    211   /**
    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);
    225 } FPDF_SYSFONTINFO;
    226 
    227 /**
    228  * Struct: FPDF_CharsetFontMap
    229  *    Provides the name of a font to use for a given charset value.
    230  **/
    231 typedef 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.
    234 } 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  **/
    246 DLLEXPORT const FPDF_CharsetFontMap* STDCALL FPDF_GetDefaultTTFMap();
    247 
    248 /**
    249  * Function: FPDF_AddInstalledFont
    250  *          Add a system font to the list in Foxit SDK.
    251  * Comments:
    252  *          This function is only called during the system font list building
    253  *process.
    254  * Parameters:
    255  *          mapper          -   Opaque pointer to Foxit font mapper
    256  *          face            -   The font face name
    257  *          charset         -   Font character set. See above defined constants.
    258  * Return Value:
    259  *          None.
    260  **/
    261 DLLEXPORT void STDCALL FPDF_AddInstalledFont(void* mapper,
    262                                              const char* face,
    263                                              int charset);
    264 
    265 /**
    266  * Function: FPDF_SetSystemFontInfo
    267  *          Set the system font info interface into Foxit SDK
    268  * Comments:
    269  *          Platform support implementation should implement required methods of
    270  *FFDF_SYSFONTINFO interface,
    271  *          then call this function during SDK initialization process.
    272  * Parameters:
    273  *          pFontInfo       -   Pointer to a FPDF_SYSFONTINFO structure
    274  * Return Value:
    275  *          None
    276  **/
    277 DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfo);
    278 
    279 /**
    280  * Function: FPDF_GetDefaultSystemFontInfo
    281  *          Get default system font info interface for current platform
    282  * Comments:
    283  *          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.
    287  * Parameters:
    288  *          None
    289  * Return Value:
    290  *          Pointer to a FPDF_SYSFONTINFO structure describing the default
    291  *interface.
    292  *          Or NULL if the platform doesn't have a default interface.
    293  *          Application should call FPDF_FreeMemory to free the returned
    294  *pointer.
    295  **/
    296 DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo();
    297 
    298 #ifdef __cplusplus
    299 }
    300 #endif
    301 
    302 #endif  // PUBLIC_FPDF_SYSFONTINFO_H_
    303