Home | History | Annotate | Download | only in include
      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 _FX_FONT
      8 #define _FX_FONT
      9 class IFX_Font;
     10 class IFX_FontMgr;
     11 #define FX_FONTSTYLE_Normal 0x00
     12 #define FX_FONTSTYLE_FixedPitch 0x01
     13 #define FX_FONTSTYLE_Serif 0x02
     14 #define FX_FONTSTYLE_Symbolic 0x04
     15 #define FX_FONTSTYLE_Script 0x08
     16 #define FX_FONTSTYLE_Italic 0x40
     17 #define FX_FONTSTYLE_Bold 0x40000
     18 #define FX_FONTSTYLE_BoldItalic (FX_FONTSTYLE_Bold | FX_FONTSTYLE_Italic)
     19 #define FX_FONTSTYLE_ExactMatch 0x80000000
     20 #define FX_FONTDECORATION_Underline 0x00000001
     21 #define FX_FONTDECORATION_Strikeout 0x00000002
     22 #define FX_FONTDECORATION_Overline 0x00000004
     23 #define FX_FONTDECORATION_Emphasis 0x00000008
     24 #define FX_FONTDECORATION_Superscript 0x00000010
     25 #define FX_FONTDECORATION_Subscript 0x00000020
     26 #define FX_FONTDECORATION_SmallCapital 0x00000040
     27 #define FX_FONTDECORATION_Capital 0x00000080
     28 #define FX_FONTDECORATION_Lowercase 0x000000C0
     29 #define FX_FONTDECORATION_Raised 0x00000100
     30 #define FX_FONTDECORATION_Sunken 0x00000200
     31 #define FX_FONTDECORATION_Shadow 0x00000400
     32 #define FX_FONTDECORATION_BoundingShape 0x20000000
     33 #define FX_FONTDECORATION_Hide 0x40000000
     34 #define FX_FONTDECORATION_StrokeFill 0x80000000
     35 #define FX_BOUNDINGSHAPE_None 0
     36 #define FX_BOUNDINGSHAPE_Circle 1
     37 #define FX_BOUNDINGSHAPE_Square 2
     38 #define FX_BOUNDINGSHAPE_Triangle 3
     39 #define FX_BOUNDINGSHAPE_Diamond 4
     40 
     41 class IFX_FontProvider {
     42  public:
     43   virtual ~IFX_FontProvider() {}
     44   virtual FX_BOOL GetCharWidth(IFX_Font* pFont,
     45                                FX_WCHAR wUnicode,
     46                                int32_t& iWidth,
     47                                FX_BOOL bCharCode = FALSE) = 0;
     48 };
     49 
     50 class IFX_Font {
     51  public:
     52   static IFX_Font* LoadFont(const FX_WCHAR* pszFontFamily,
     53                             FX_DWORD dwFontStyles,
     54                             FX_WORD wCodePage,
     55                             IFX_FontMgr* pFontMgr);
     56   static IFX_Font* LoadFont(const uint8_t* pBuffer,
     57                             int32_t iLength,
     58                             IFX_FontMgr* pFontMgr);
     59   static IFX_Font* LoadFont(const FX_WCHAR* pszFileName, IFX_FontMgr* pFontMgr);
     60   static IFX_Font* LoadFont(IFX_Stream* pFontStream,
     61                             IFX_FontMgr* pFontMgr,
     62                             FX_BOOL bSaveStream = FALSE);
     63   static IFX_Font* LoadFont(CFX_Font* pExtFont,
     64                             IFX_FontMgr* pFontMgr,
     65                             FX_BOOL bTakeOver = FALSE);
     66   virtual ~IFX_Font() {}
     67   virtual void Release() = 0;
     68   virtual IFX_Font* Retain() = 0;
     69   virtual IFX_Font* Derive(FX_DWORD dwFontStyles, FX_WORD wCodePage = 0) = 0;
     70   virtual void GetFamilyName(CFX_WideString& wsFamily) const = 0;
     71   virtual void GetPsName(CFX_WideString& wsName) const = 0;
     72   virtual FX_DWORD GetFontStyles() const = 0;
     73   virtual uint8_t GetCharSet() const = 0;
     74   virtual FX_BOOL GetCharWidth(FX_WCHAR wUnicode,
     75                                int32_t& iWidth,
     76                                FX_BOOL bCharCode = FALSE) = 0;
     77   virtual int32_t GetGlyphIndex(FX_WCHAR wUnicode,
     78                                 FX_BOOL bCharCode = FALSE) = 0;
     79   virtual int32_t GetAscent() const = 0;
     80   virtual int32_t GetDescent() const = 0;
     81   virtual FX_BOOL GetCharBBox(FX_WCHAR wUnicode,
     82                               CFX_Rect& bbox,
     83                               FX_BOOL bCharCode = FALSE) = 0;
     84   virtual FX_BOOL GetBBox(CFX_Rect& bbox) = 0;
     85   virtual int32_t GetItalicAngle() const = 0;
     86   virtual void Reset() = 0;
     87   virtual IFX_Font* GetSubstFont(int32_t iGlyphIndex) const = 0;
     88   virtual void* GetDevFont() const = 0;
     89   virtual void SetFontProvider(IFX_FontProvider* pProvider) = 0;
     90 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
     91   virtual void SetLogicalFontStyle(FX_DWORD dwLogFontStyle) = 0;
     92 #endif
     93 };
     94 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
     95 typedef struct _FX_FONTMATCHPARAMS {
     96   const FX_WCHAR* pwsFamily;
     97   FX_DWORD dwFontStyles;
     98   FX_DWORD dwUSB;
     99   FX_DWORD dwMatchFlags;
    100   FX_WCHAR wUnicode;
    101   FX_WORD wCodePage;
    102 } FX_FONTMATCHPARAMS, *FX_LPFONTMATCHPARAMS;
    103 typedef FX_FONTMATCHPARAMS const* FX_LPCFONTMATCHPARAMS;
    104 typedef struct _FX_FONTSIGNATURE : public CFX_Target {
    105   FX_DWORD fsUsb[4];
    106   FX_DWORD fsCsb[2];
    107 } FX_FONTSIGNATURE;
    108 typedef struct _FX_FONTDESCRIPTOR : public CFX_Target {
    109   FX_WCHAR wsFontFace[32];
    110   FX_DWORD dwFontStyles;
    111   uint8_t uCharSet;
    112   FX_FONTSIGNATURE FontSignature;
    113 } FX_FONTDESCRIPTOR, *FX_LPFONTDESCRIPTOR;
    114 typedef FX_FONTDESCRIPTOR const* FX_LPCFONTDESCRIPTOR;
    115 typedef CFX_MassArrayTemplate<FX_FONTDESCRIPTOR> CFX_FontDescriptors;
    116 inline FX_BOOL operator==(const FX_FONTDESCRIPTOR& left,
    117                           const FX_FONTDESCRIPTOR& right) {
    118   return left.uCharSet == right.uCharSet &&
    119          left.dwFontStyles == right.dwFontStyles &&
    120          FXSYS_wcscmp(left.wsFontFace, right.wsFontFace) == 0 &&
    121          FXSYS_memcmp(&left.FontSignature, &right.FontSignature,
    122                       sizeof(FX_FONTSIGNATURE)) == 0;
    123 }
    124 #define FX_FONTMATCHPARA_MacthStyle 0x01
    125 #define FX_FONTMATCHPARA_MacthFamily 0x02
    126 #define FX_FONTMATCHPARA_MacthUnicode 0x04
    127 typedef void (*FX_LPEnumAllFonts)(CFX_FontDescriptors& fonts,
    128                                   void* pUserData,
    129                                   const FX_WCHAR* pwsFaceName,
    130                                   FX_WCHAR wUnicode);
    131 FX_LPEnumAllFonts FX_GetDefFontEnumerator();
    132 typedef FX_LPCFONTDESCRIPTOR (*FX_LPMatchFont)(FX_LPFONTMATCHPARAMS pParams,
    133                                                const CFX_FontDescriptors& fonts,
    134                                                void* pUserData);
    135 FX_LPMatchFont FX_GetDefFontMatchor();
    136 class IFX_FontMgr {
    137  public:
    138   static IFX_FontMgr* Create(FX_LPEnumAllFonts pEnumerator,
    139                              FX_LPMatchFont pMatcher = NULL,
    140                              void* pUserData = NULL);
    141   virtual ~IFX_FontMgr() {}
    142   virtual void Release() = 0;
    143   virtual IFX_Font* GetDefFontByCodePage(
    144       FX_WORD wCodePage,
    145       FX_DWORD dwFontStyles,
    146       const FX_WCHAR* pszFontFamily = NULL) = 0;
    147   virtual IFX_Font* GetDefFontByCharset(
    148       uint8_t nCharset,
    149       FX_DWORD dwFontStyles,
    150       const FX_WCHAR* pszFontFamily = NULL) = 0;
    151   virtual IFX_Font* GetDefFontByUnicode(
    152       FX_WCHAR wUnicode,
    153       FX_DWORD dwFontStyles,
    154       const FX_WCHAR* pszFontFamily = NULL) = 0;
    155   virtual IFX_Font* GetDefFontByLanguage(
    156       FX_WORD wLanguage,
    157       FX_DWORD dwFontStyles,
    158       const FX_WCHAR* pszFontFamily = NULL) = 0;
    159   virtual IFX_Font* LoadFont(const FX_WCHAR* pszFontFamily,
    160                              FX_DWORD dwFontStyles,
    161                              FX_WORD wCodePage = 0xFFFF) = 0;
    162   virtual IFX_Font* LoadFont(const uint8_t* pBuffer, int32_t iLength) = 0;
    163   virtual IFX_Font* LoadFont(const FX_WCHAR* pszFileName) = 0;
    164   virtual IFX_Font* LoadFont(IFX_Stream* pFontStream,
    165                              const FX_WCHAR* pszFontAlias = NULL,
    166                              FX_DWORD dwFontStyles = 0,
    167                              FX_WORD wCodePage = 0,
    168                              FX_BOOL bSaveStream = FALSE) = 0;
    169   virtual IFX_Font* LoadFont(IFX_Font* pSrcFont,
    170                              FX_DWORD dwFontStyles,
    171                              FX_WORD wCodePage = 0xFFFF) = 0;
    172   virtual void ClearFontCache() = 0;
    173   virtual void RemoveFont(IFX_Font* pFont) = 0;
    174 };
    175 #else
    176 class IFX_FontMgrDelegate {
    177  public:
    178   virtual ~IFX_FontMgrDelegate() {}
    179   virtual IFX_Font* GetDefFontByCodePage(
    180       IFX_FontMgr* pFontMgr,
    181       FX_WORD wCodePage,
    182       FX_DWORD dwFontStyles,
    183       const FX_WCHAR* pszFontFamily = NULL) = 0;
    184   virtual IFX_Font* GetDefFontByCharset(
    185       IFX_FontMgr* pFontMgr,
    186       uint8_t nCharset,
    187       FX_DWORD dwFontStyles,
    188       const FX_WCHAR* pszFontFamily = NULL) = 0;
    189   virtual IFX_Font* GetDefFontByUnicode(
    190       IFX_FontMgr* pFontMgr,
    191       FX_WCHAR wUnicode,
    192       FX_DWORD dwFontStyles,
    193       const FX_WCHAR* pszFontFamily = NULL) = 0;
    194   virtual IFX_Font* GetDefFontByLanguage(
    195       IFX_FontMgr* pFontMgr,
    196       FX_WORD wLanguage,
    197       FX_DWORD dwFontStyles,
    198       const FX_WCHAR* pszFontFamily = NULL) = 0;
    199 };
    200 class IFX_FontSourceEnum {
    201  public:
    202   virtual ~IFX_FontSourceEnum() {}
    203   virtual void Release() = 0;
    204   virtual FX_POSITION GetStartPosition(void* pUserData = NULL) = 0;
    205   virtual IFX_FileAccess* GetNext(FX_POSITION& pos, void* pUserData = NULL) = 0;
    206 };
    207 IFX_FontSourceEnum* FX_CreateDefaultFontSourceEnum();
    208 class IFX_FontMgr {
    209  public:
    210   static IFX_FontMgr* Create(IFX_FontSourceEnum* pFontEnum,
    211                              IFX_FontMgrDelegate* pDelegate = NULL,
    212                              void* pUserData = NULL);
    213   virtual ~IFX_FontMgr() {}
    214   virtual void Release() = 0;
    215   virtual IFX_Font* GetDefFontByCodePage(
    216       FX_WORD wCodePage,
    217       FX_DWORD dwFontStyles,
    218       const FX_WCHAR* pszFontFamily = NULL) = 0;
    219   virtual IFX_Font* GetDefFontByCharset(
    220       uint8_t nCharset,
    221       FX_DWORD dwFontStyles,
    222       const FX_WCHAR* pszFontFamily = NULL) = 0;
    223   virtual IFX_Font* GetDefFontByUnicode(
    224       FX_WCHAR wUnicode,
    225       FX_DWORD dwFontStyles,
    226       const FX_WCHAR* pszFontFamily = NULL) = 0;
    227   virtual IFX_Font* GetDefFontByLanguage(
    228       FX_WORD wLanguage,
    229       FX_DWORD dwFontStyles,
    230       const FX_WCHAR* pszFontFamily = NULL) = 0;
    231   virtual IFX_Font* GetFontByCodePage(FX_WORD wCodePage,
    232                                       FX_DWORD dwFontStyles,
    233                                       const FX_WCHAR* pszFontFamily = NULL) = 0;
    234   inline IFX_Font* LoadFont(const FX_WCHAR* pszFontFamily,
    235                             FX_DWORD dwFontStyles,
    236                             FX_WORD wCodePage) {
    237     return GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily);
    238   }
    239   virtual IFX_Font* GetFontByCharset(uint8_t nCharset,
    240                                      FX_DWORD dwFontStyles,
    241                                      const FX_WCHAR* pszFontFamily = NULL) = 0;
    242   virtual IFX_Font* GetFontByUnicode(FX_WCHAR wUnicode,
    243                                      FX_DWORD dwFontStyles,
    244                                      const FX_WCHAR* pszFontFamily = NULL) = 0;
    245   virtual IFX_Font* GetFontByLanguage(FX_WORD wLanguage,
    246                                       FX_DWORD dwFontStyles,
    247                                       const FX_WCHAR* pszFontFamily = NULL) = 0;
    248   virtual IFX_Font* LoadFont(const uint8_t* pBuffer,
    249                              int32_t iLength,
    250                              int32_t iFaceIndex,
    251                              int32_t* pFaceCount = NULL) = 0;
    252   virtual IFX_Font* LoadFont(const FX_WCHAR* pszFileName,
    253                              int32_t iFaceIndex,
    254                              int32_t* pFaceCount = NULL) = 0;
    255   virtual IFX_Font* LoadFont(IFX_Stream* pFontStream,
    256                              int32_t iFaceIndex,
    257                              int32_t* pFaceCount = NULL,
    258                              FX_BOOL bSaveStream = FALSE) = 0;
    259 
    260   virtual void ClearFontCache() = 0;
    261   virtual void RemoveFont(IFX_Font* pFont) = 0;
    262 };
    263 #endif
    264 #endif
    265