summaryrefslogtreecommitdiff
path: root/xfa/fgas/font/fgas_font.h
blob: 43d7d7ff96da8742daadbf967210c14e7149abe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FGAS_FONT_FGAS_FONT_H_
#define XFA_FGAS_FONT_FGAS_FONT_H_

#include "core/fxge/include/fx_font.h"
#include "xfa/fgas/crt/fgas_stream.h"

#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
#include "xfa/fgas/crt/fgas_memory.h"
#include "xfa/fgas/crt/fgas_utils.h"
#endif  // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_

class CFX_FontSourceEnum_File;
class CXFA_PDFFontMgr;
class IFGAS_Font;
class IFX_FontMgr;

#define FX_FONTSTYLE_Normal 0x00
#define FX_FONTSTYLE_FixedPitch 0x01
#define FX_FONTSTYLE_Serif 0x02
#define FX_FONTSTYLE_Symbolic 0x04
#define FX_FONTSTYLE_Script 0x08
#define FX_FONTSTYLE_Italic 0x40
#define FX_FONTSTYLE_Bold 0x40000
#define FX_FONTSTYLE_BoldItalic (FX_FONTSTYLE_Bold | FX_FONTSTYLE_Italic)
#define FX_FONTSTYLE_ExactMatch 0x80000000
#define FX_FONTDECORATION_Underline 0x00000001
#define FX_FONTDECORATION_Strikeout 0x00000002
#define FX_FONTDECORATION_Overline 0x00000004
#define FX_FONTDECORATION_Emphasis 0x00000008
#define FX_FONTDECORATION_Superscript 0x00000010
#define FX_FONTDECORATION_Subscript 0x00000020
#define FX_FONTDECORATION_SmallCapital 0x00000040
#define FX_FONTDECORATION_Capital 0x00000080
#define FX_FONTDECORATION_Lowercase 0x000000C0
#define FX_FONTDECORATION_Raised 0x00000100
#define FX_FONTDECORATION_Sunken 0x00000200
#define FX_FONTDECORATION_Shadow 0x00000400
#define FX_FONTDECORATION_BoundingShape 0x20000000
#define FX_FONTDECORATION_Hide 0x40000000
#define FX_FONTDECORATION_StrokeFill 0x80000000
#define FX_BOUNDINGSHAPE_None 0
#define FX_BOUNDINGSHAPE_Circle 1
#define FX_BOUNDINGSHAPE_Square 2
#define FX_BOUNDINGSHAPE_Triangle 3
#define FX_BOUNDINGSHAPE_Diamond 4

class IFGAS_Font {
 public:
  static IFGAS_Font* LoadFont(const FX_WCHAR* pszFontFamily,
                              uint32_t dwFontStyles,
                              uint16_t wCodePage,
                              IFX_FontMgr* pFontMgr);
  static IFGAS_Font* LoadFont(const uint8_t* pBuffer,
                              int32_t iLength,
                              IFX_FontMgr* pFontMgr);
  static IFGAS_Font* LoadFont(const FX_WCHAR* pszFileName,
                              IFX_FontMgr* pFontMgr);
  static IFGAS_Font* LoadFont(IFX_Stream* pFontStream,
                              IFX_FontMgr* pFontMgr,
                              FX_BOOL bSaveStream = FALSE);
  static IFGAS_Font* LoadFont(CFX_Font* pExtFont,
                              IFX_FontMgr* pFontMgr,
                              FX_BOOL bTakeOver = FALSE);
  virtual ~IFGAS_Font() {}
  virtual void Release() = 0;
  virtual IFGAS_Font* Retain() = 0;
  virtual IFGAS_Font* Derive(uint32_t dwFontStyles, uint16_t wCodePage = 0) = 0;
  virtual void GetFamilyName(CFX_WideString& wsFamily) const = 0;
  virtual uint32_t GetFontStyles() const = 0;
  virtual uint8_t GetCharSet() const = 0;
  virtual FX_BOOL GetCharWidth(FX_WCHAR wUnicode,
                               int32_t& iWidth,
                               FX_BOOL bCharCode = FALSE) = 0;
  virtual int32_t GetGlyphIndex(FX_WCHAR wUnicode,
                                FX_BOOL bCharCode = FALSE) = 0;
  virtual int32_t GetAscent() const = 0;
  virtual int32_t GetDescent() const = 0;
  virtual FX_BOOL GetCharBBox(FX_WCHAR wUnicode,
                              CFX_Rect& bbox,
                              FX_BOOL bCharCode = FALSE) = 0;
  virtual FX_BOOL GetBBox(CFX_Rect& bbox) = 0;
  virtual int32_t GetItalicAngle() const = 0;
  virtual void Reset() = 0;
  virtual IFGAS_Font* GetSubstFont(int32_t iGlyphIndex) const = 0;
  virtual void* GetDevFont() const = 0;
  virtual void SetFontProvider(CXFA_PDFFontMgr* pProvider) = 0;
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
  virtual void SetLogicalFontStyle(uint32_t dwLogFontStyle) = 0;
#endif
};

#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
struct FX_FONTMATCHPARAMS {
  const FX_WCHAR* pwsFamily;
  uint32_t dwFontStyles;
  uint32_t dwUSB;
  uint32_t dwMatchFlags;
  FX_WCHAR wUnicode;
  uint16_t wCodePage;
};
typedef FX_FONTMATCHPARAMS* FX_LPFONTMATCHPARAMS;
typedef FX_FONTMATCHPARAMS const* FX_LPCFONTMATCHPARAMS;

struct FX_FONTSIGNATURE {
  uint32_t fsUsb[4];
  uint32_t fsCsb[2];
};
inline bool operator==(const FX_FONTSIGNATURE& left,
                       const FX_FONTSIGNATURE& right) {
  return left.fsUsb[0] == right.fsUsb[0] && left.fsUsb[1] == right.fsUsb[1] &&
         left.fsUsb[2] == right.fsUsb[2] && left.fsUsb[3] == right.fsUsb[3] &&
         left.fsCsb[0] == right.fsCsb[0] && left.fsCsb[1] == right.fsCsb[1];
}

struct FX_FONTDESCRIPTOR {
  FX_WCHAR wsFontFace[32];
  uint32_t dwFontStyles;
  uint8_t uCharSet;
  FX_FONTSIGNATURE FontSignature;
};

typedef CFX_MassArrayTemplate<FX_FONTDESCRIPTOR> CFX_FontDescriptors;
inline bool operator==(const FX_FONTDESCRIPTOR& left,
                       const FX_FONTDESCRIPTOR& right) {
  return left.uCharSet == right.uCharSet &&
         left.dwFontStyles == right.dwFontStyles &&
         left.FontSignature == right.FontSignature &&
         FXSYS_wcscmp(left.wsFontFace, right.wsFontFace) == 0;
}

#define FX_FONTMATCHPARA_MacthStyle 0x01
#define FX_FONTMATCHPARA_MacthFamily 0x02
#define FX_FONTMATCHPARA_MacthUnicode 0x04
typedef void (*FX_LPEnumAllFonts)(CFX_FontDescriptors& fonts,
                                  const FX_WCHAR* pwsFaceName,
                                  FX_WCHAR wUnicode);
FX_LPEnumAllFonts FX_GetDefFontEnumerator();
typedef FX_FONTDESCRIPTOR const* (*FX_LPMatchFont)(
    FX_LPFONTMATCHPARAMS pParams,
    const CFX_FontDescriptors& fonts);
FX_LPMatchFont FX_GetDefFontMatchor();
class IFX_FontMgr {
 public:
  static IFX_FontMgr* Create(FX_LPEnumAllFonts pEnumerator);
  virtual ~IFX_FontMgr() {}
  virtual void Release() = 0;
  virtual IFGAS_Font* GetDefFontByCodePage(
      uint16_t wCodePage,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetDefFontByCharset(
      uint8_t nCharset,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetDefFontByUnicode(
      FX_WCHAR wUnicode,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetDefFontByLanguage(
      uint16_t wLanguage,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* LoadFont(const FX_WCHAR* pszFontFamily,
                               uint32_t dwFontStyles,
                               uint16_t wCodePage = 0xFFFF) = 0;
  virtual IFGAS_Font* LoadFont(const uint8_t* pBuffer, int32_t iLength) = 0;
  virtual IFGAS_Font* LoadFont(const FX_WCHAR* pszFileName) = 0;
  virtual IFGAS_Font* LoadFont(IFX_Stream* pFontStream,
                               const FX_WCHAR* pszFontAlias = NULL,
                               uint32_t dwFontStyles = 0,
                               uint16_t wCodePage = 0,
                               FX_BOOL bSaveStream = FALSE) = 0;
  virtual IFGAS_Font* LoadFont(IFGAS_Font* pSrcFont,
                               uint32_t dwFontStyles,
                               uint16_t wCodePage = 0xFFFF) = 0;
  virtual void ClearFontCache() = 0;
  virtual void RemoveFont(IFGAS_Font* pFont) = 0;
};

#else   //  _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_

class IFX_FontMgr {
 public:
  static IFX_FontMgr* Create(CFX_FontSourceEnum_File* pFontEnum);
  virtual ~IFX_FontMgr() {}
  virtual void Release() = 0;
  virtual IFGAS_Font* GetDefFontByCodePage(
      uint16_t wCodePage,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetDefFontByCharset(
      uint8_t nCharset,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetDefFontByUnicode(
      FX_WCHAR wUnicode,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetDefFontByLanguage(
      uint16_t wLanguage,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetFontByCodePage(
      uint16_t wCodePage,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  inline IFGAS_Font* LoadFont(const FX_WCHAR* pszFontFamily,
                              uint32_t dwFontStyles,
                              uint16_t wCodePage) {
    return GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily);
  }
  virtual IFGAS_Font* GetFontByCharset(
      uint8_t nCharset,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetFontByUnicode(
      FX_WCHAR wUnicode,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* GetFontByLanguage(
      uint16_t wLanguage,
      uint32_t dwFontStyles,
      const FX_WCHAR* pszFontFamily = NULL) = 0;
  virtual IFGAS_Font* LoadFont(const uint8_t* pBuffer,
                               int32_t iLength,
                               int32_t iFaceIndex,
                               int32_t* pFaceCount = NULL) = 0;
  virtual IFGAS_Font* LoadFont(const FX_WCHAR* pszFileName,
                               int32_t iFaceIndex,
                               int32_t* pFaceCount = NULL) = 0;
  virtual IFGAS_Font* LoadFont(IFX_Stream* pFontStream,
                               int32_t iFaceIndex,
                               int32_t* pFaceCount = NULL,
                               FX_BOOL bSaveStream = FALSE) = 0;

  virtual void ClearFontCache() = 0;
  virtual void RemoveFont(IFGAS_Font* pFont) = 0;
};
#endif  //  _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_

#endif  // XFA_FGAS_FONT_FGAS_FONT_H_