OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef _APPLE_INT_H_ | 7 #ifndef _APPLE_INT_H_ |
8 #define _APPLE_INT_H_ | 8 #define _APPLE_INT_H_ |
9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
10 #if _FX_OS_ == _FX_MACOSX_ | 10 #if _FX_OS_ == _FX_MACOSX_ |
11 #include <Carbon/Carbon.h> | 11 #include <Carbon/Carbon.h> |
12 #endif | 12 #endif |
13 typedef enum eFXIOSFONTCHARSET { | 13 typedef enum eFXIOSFONTCHARSET { |
14 eFXFontCharsetDEFAULT = 0, | 14 eFXFontCharsetDEFAULT = 0, |
15 eFXFontCharsetANSI = 1, | 15 eFXFontCharsetANSI = 1, |
16 eFXFontCharsetSYMBOL = 1 << 1, | 16 eFXFontCharsetSYMBOL = 1 << 1, |
17 eFXFontCharsetSHIFTJIS = 1 << 2, | 17 eFXFontCharsetSHIFTJIS = 1 << 2, |
18 eFXFontCharsetHANGEUL = 1 << 3, | 18 eFXFontCharsetHANGEUL = 1 << 3, |
19 eFXFontCharsetGB2312 = 1 << 4, | 19 eFXFontCharsetGB2312 = 1 << 4, |
20 eFXFontCharsetCHINESEBIG5 = 1 << 5, | 20 eFXFontCharsetCHINESEBIG5 = 1 << 5, |
21 eFXFontCharsetTHAI = 1 << 6, | 21 eFXFontCharsetTHAI = 1 << 6, |
22 eFXFontCharsetEASTEUROPE = 1 << 7, | 22 eFXFontCharsetEASTEUROPE = 1 << 7, |
23 eFXFontCharsetRUSSIAN = 1 << 8, | 23 eFXFontCharsetRUSSIAN = 1 << 8, |
24 eFXFontCharsetGREEK = 1 << 9, | 24 eFXFontCharsetGREEK = 1 << 9, |
25 eFXFontCharsetTURKISH = 1 << 10, | 25 eFXFontCharsetTURKISH = 1 << 10, |
26 eFXFontCharsetHEBREW = 1 << 11, | 26 eFXFontCharsetHEBREW = 1 << 11, |
27 eFXFontCharsetARABIC = 1 << 12, | 27 eFXFontCharsetARABIC = 1 << 12, |
28 eFXFontCharsetBALTIC = 1 << 13, | 28 eFXFontCharsetBALTIC = 1 << 13, |
29 } FX_IOSCHARSET; | 29 } FX_IOSCHARSET; |
30 FX_IOSCHARSET FX_GetiOSCharset(int charset); | 30 FX_IOSCHARSET FX_GetiOSCharset(int charset); |
31 typedef enum eFXIOSFONTFLAG { | 31 typedef enum eFXIOSFONTFLAG { |
32 eFXFontFlagBold = 1, | 32 eFXFontFlagBold = 1, |
33 eFXFontFlagItalic = 1 << 1, | 33 eFXFontFlagItalic = 1 << 1, |
34 eFXFontFlagFixedPitch = 1 << 2, | 34 eFXFontFlagFixedPitch = 1 << 2, |
35 eFXFontFlagSerif = 1 << 3, | 35 eFXFontFlagSerif = 1 << 3, |
36 eFXFontFlagScript = 1 << 4, | 36 eFXFontFlagScript = 1 << 4, |
37 } FX_IOSFONTFLAG; | 37 } FX_IOSFONTFLAG; |
38 typedef struct _IOS_FONTDATA { | 38 typedef struct _IOS_FONTDATA { |
39 FX_DWORD nHashCode; | 39 FX_DWORD nHashCode; |
40 const char* psName; | 40 const char* psName; |
41 FX_DWORD charsets; | 41 FX_DWORD charsets; |
42 FX_DWORD styles; | 42 FX_DWORD styles; |
43 } IOS_FONTDATA; | 43 } IOS_FONTDATA; |
44 class CQuartz2D | 44 class CQuartz2D { |
45 { | 45 public: |
46 public: | 46 void* createGraphics(CFX_DIBitmap* bitmap); |
47 void*» createGraphics(CFX_DIBitmap* bitmap); | 47 void destroyGraphics(void* graphics); |
48 void» destroyGraphics(void* graphics); | 48 |
49 | 49 void* CreateFont(FX_LPCBYTE pFontData, FX_DWORD dwFontSize); |
50 void*» CreateFont(FX_LPCBYTE pFontData, FX_DWORD dwFontSize); | 50 void DestroyFont(void* pFont); |
51 void» DestroyFont(void* pFont); | 51 void setGraphicsTextMatrix(void* graphics, CFX_AffineMatrix* matrix); |
52 void» setGraphicsTextMatrix(void* graphics, CFX_AffineMatrix* matrix); | 52 FX_BOOL drawGraphicsString(void* graphics, |
53 FX_BOOL» drawGraphicsString(void* graphics, | 53 void* font, |
54 void* font, | 54 FX_FLOAT fontSize, |
55 FX_FLOAT fontSize, | 55 FX_WORD* glyphIndices, |
56 FX_WORD* glyphIndices, | 56 CGPoint* glyphPositions, |
57 CGPoint* glyphPositions, | 57 FX_INT32 chars, |
58 FX_INT32 chars, | 58 FX_ARGB argb, |
59 FX_ARGB argb, | 59 CFX_AffineMatrix* matrix = NULL); |
60 CFX_AffineMatrix* matrix = NULL); | 60 void saveGraphicsState(void* graphics); |
61 void saveGraphicsState(void* graphics); | 61 void restoreGraphicsState(void* graphics); |
62 void restoreGraphicsState(void* graphics); | 62 }; |
63 }; | 63 class CApplePlatform : public CFX_Object { |
64 class CApplePlatform : public CFX_Object | 64 public: |
65 { | 65 CApplePlatform() { m_pFontMapper = NULL; } |
66 public: | 66 ~CApplePlatform() { |
67 CApplePlatform() | 67 if (m_pFontMapper) { |
68 { | 68 delete m_pFontMapper; |
69 m_pFontMapper = NULL; | |
70 } | 69 } |
71 ~CApplePlatform() | 70 } |
72 { | 71 CQuartz2D _quartz2d; |
73 if (m_pFontMapper) { | 72 IFX_FontMapper* m_pFontMapper; |
74 delete m_pFontMapper; | 73 }; |
75 } | 74 class CFX_QuartzDeviceDriver : public IFX_RenderDeviceDriver { |
76 } | 75 public: |
77 CQuartz2D» _quartz2d; | 76 CFX_QuartzDeviceDriver(CGContextRef context, FX_INT32 deviceClass); |
78 IFX_FontMapper* m_pFontMapper; | 77 virtual ~CFX_QuartzDeviceDriver(); |
79 }; | 78 |
80 class CFX_QuartzDeviceDriver : public IFX_RenderDeviceDriver | 79 virtual int GetDeviceCaps(int caps_id); |
81 { | 80 virtual CFX_Matrix GetCTM() const; |
82 public: | 81 virtual CFX_DIBitmap* GetBackDrop() { return NULL; } |
83 CFX_QuartzDeviceDriver(CGContextRef context, FX_INT32 deviceClass); | 82 virtual void* GetPlatformSurface() { return NULL; } |
84 virtual ~CFX_QuartzDeviceDriver(); | 83 virtual FX_BOOL IsPSPrintDriver() { return FALSE; } |
85 | 84 virtual FX_BOOL StartRendering() { return TRUE; } |
86 virtual int»» GetDeviceCaps(int caps_id); | 85 virtual void EndRendering() {} |
87 virtual CFX_Matrix» GetCTM() const; | 86 virtual void SaveState(); |
88 virtual CFX_DIBitmap* GetBackDrop() | 87 virtual void RestoreState(FX_BOOL bKeepSaved); |
89 { | 88 virtual FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, |
90 return NULL; | 89 const CFX_AffineMatrix* pObject2Device, |
91 } | 90 int fill_mode); |
92 virtual void*» GetPlatformSurface() | 91 virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, |
93 { | |
94 return NULL; | |
95 } | |
96 virtual FX_BOOL IsPSPrintDriver() | |
97 { | |
98 return FALSE; | |
99 } | |
100 virtual FX_BOOL» StartRendering() | |
101 { | |
102 return TRUE; | |
103 } | |
104 virtual void» EndRendering() {} | |
105 virtual void» SaveState(); | |
106 virtual void» RestoreState(FX_BOOL bKeepSaved); | |
107 virtual FX_BOOL» SetClip_PathFill(const CFX_PathData* pPathData, | |
108 const CFX_AffineMatrix* pObject2Device, | 92 const CFX_AffineMatrix* pObject2Device, |
109 int fill_mode | 93 const CFX_GraphStateData* pGraphState); |
110 ); | 94 virtual FX_BOOL DrawPath(const CFX_PathData* pPathData, |
111 virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, | 95 const CFX_AffineMatrix* pObject2Device, |
112 const CFX_AffineMatrix* pObject2Device, | 96 const CFX_GraphStateData* pGraphState, |
113 const CFX_GraphStateData* pGraphState | 97 FX_DWORD fill_color, |
114 ); | 98 FX_DWORD stroke_color, |
115 virtual FX_BOOL DrawPath(const CFX_PathData* pPathData, | 99 int fill_mode, |
116 const CFX_AffineMatrix* pObject2Device, | 100 int alpha_flag = 0, |
117 const CFX_GraphStateData* pGraphState, | 101 void* pIccTransform = NULL, |
118 FX_DWORD fill_color, | 102 int blend_type = FXDIB_BLEND_NORMAL); |
119 FX_DWORD stroke_color, | 103 virtual FX_BOOL SetPixel(int x, |
120 int fill_mode, | 104 int y, |
121 int alpha_flag = 0, | 105 FX_DWORD color, |
122 void* pIccTransform = NULL, | 106 int alpha_flag = 0, |
123 int blend_type = FXDIB_BLEND_NORMAL | 107 void* pIccTransform = NULL) { |
124 ); | 108 return FALSE; |
125 virtual FX_BOOL SetPixel(int x, int y, FX_DWORD color, | 109 } |
126 int alpha_flag = 0, void* pIccTransform = NULL) | 110 virtual FX_BOOL FillRect(const FX_RECT* pRect, |
127 { | 111 FX_DWORD fill_color, |
128 return FALSE; | 112 int alpha_flag = 0, |
129 } | 113 void* pIccTransform = NULL, |
130 virtual FX_BOOL FillRect(const FX_RECT* pRect, FX_DWORD fill_color, | 114 int blend_type = FXDIB_BLEND_NORMAL); |
131 int alpha_flag = 0, void* pIccTransform = NULL, int
blend_type = FXDIB_BLEND_NORMAL); | 115 virtual FX_BOOL DrawCosmeticLine(FX_FLOAT x1, |
132 virtual FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2,
FX_FLOAT y2, FX_DWORD color, | 116 FX_FLOAT y1, |
133 int alpha_flag = 0, void* pIccTransform = N
ULL, int blend_type = FXDIB_BLEND_NORMAL); | 117 FX_FLOAT x2, |
134 virtual FX_BOOL GetClipBox(FX_RECT* pRect); | 118 FX_FLOAT y2, |
135 virtual FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void
* pIccTransform = NULL, FX_BOOL bDEdge = FALSE); | 119 FX_DWORD color, |
136 virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color,
const FX_RECT* pSrcRect, | 120 int alpha_flag = 0, |
137 int dest_left, int dest_top, int blend_type, | 121 void* pIccTransform = NULL, |
138 int alpha_flag = 0, void* pIccTransform = NULL); | 122 int blend_type = FXDIB_BLEND_NORMAL); |
139 virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD col
or, int dest_left, int dest_top, | 123 virtual FX_BOOL GetClipBox(FX_RECT* pRect); |
140 int dest_width, int dest_height, const FX_RECT
* pClipRect, FX_DWORD flags, | 124 virtual FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, |
141 int alpha_flag = 0, void* pIccTransform = NULL
, int blend_type = FXDIB_BLEND_NORMAL); | 125 int left, |
142 virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alp
ha, FX_DWORD color, | 126 int top, |
143 const CFX_AffineMatrix* pMatrix, FX_DWORD flags,
FX_LPVOID& handle, | 127 void* pIccTransform = NULL, |
144 int alpha_flag = 0, void* pIccTransform = NULL, | 128 FX_BOOL bDEdge = FALSE); |
145 int blend_type = FXDIB_BLEND_NORMAL) | 129 virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, |
146 { | 130 FX_DWORD color, |
147 return FALSE; | 131 const FX_RECT* pSrcRect, |
148 } | 132 int dest_left, |
149 virtual FX_BOOL ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause) | 133 int dest_top, |
150 { | 134 int blend_type, |
151 return FALSE; | 135 int alpha_flag = 0, |
152 } | 136 void* pIccTransform = NULL); |
153 virtual void CancelDIBits(FX_LPVOID handle) {} | 137 virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, |
154 virtual FX_BOOL DrawDeviceText(int nChars, const FXTEXT_CHARPOS* pCharPos, C
FX_Font* pFont, | 138 FX_DWORD color, |
155 CFX_FontCache* pCache, const CFX_AffineMatrix
* pObject2Device, FX_FLOAT font_size, FX_DWORD color, | 139 int dest_left, |
156 int alpha_flag = 0, void* pIccTransform = NUL
L); | 140 int dest_top, |
157 virtual void ClearDriver(); | 141 int dest_width, |
158 protected: | 142 int dest_height, |
159 void setStrokeInfo(const CFX_GraphStateData * graphState, FX_ARGB argb, FX_F
LOAT lineWidth); | 143 const FX_RECT* pClipRect, |
160 void setFillInfo(FX_ARGB argb); | 144 FX_DWORD flags, |
161 void setPathToContext(const CFX_PathData * pathData); | 145 int alpha_flag = 0, |
162 FX_FLOAT getLineWidth(const CFX_GraphStateData * graphState, CGAffineTransfo
rm ctm); | 146 void* pIccTransform = NULL, |
163 FX_BOOL CG_DrawGlypRun(int nChars, | 147 int blend_type = FXDIB_BLEND_NORMAL); |
164 const FXTEXT_CHARPOS* pCharPos, | 148 virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, |
165 CFX_Font* pFont, | 149 int bitmap_alpha, |
166 CFX_FontCache* pCache, | 150 FX_DWORD color, |
167 const CFX_AffineMatrix* pGlyphMatrix, | 151 const CFX_AffineMatrix* pMatrix, |
168 const CFX_AffineMatrix* pObject2Device, | 152 FX_DWORD flags, |
169 FX_FLOAT font_size, | 153 FX_LPVOID& handle, |
170 FX_DWORD argb, | 154 int alpha_flag = 0, |
171 int alpha_flag, | 155 void* pIccTransform = NULL, |
172 void* pIccTransform); | 156 int blend_type = FXDIB_BLEND_NORMAL) { |
173 void CG_SetImageTransform(int dest_left, int dest_top, int dest_width, in
t dest_height, CGRect* rect = NULL); | 157 return FALSE; |
174 protected: | 158 } |
175 CGContextRef _context; | 159 virtual FX_BOOL ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause) { |
176 CGAffineTransform _foxitDevice2User; | 160 return FALSE; |
177 CGAffineTransform _user2FoxitDevice; | 161 } |
178 FX_INT32 m_saveCount; | 162 virtual void CancelDIBits(FX_LPVOID handle) {} |
179 | 163 virtual FX_BOOL DrawDeviceText(int nChars, |
180 FX_INT32 _width; | 164 const FXTEXT_CHARPOS* pCharPos, |
181 FX_INT32 _height; | 165 CFX_Font* pFont, |
182 FX_INT32 _bitsPerPixel; | 166 CFX_FontCache* pCache, |
183 FX_INT32 _deviceClass; | 167 const CFX_AffineMatrix* pObject2Device, |
184 FX_INT32 _renderCaps; | 168 FX_FLOAT font_size, |
185 FX_INT32 _horzSize; | 169 FX_DWORD color, |
186 FX_INT32 _vertSize; | 170 int alpha_flag = 0, |
187 }; | 171 void* pIccTransform = NULL); |
188 class CFX_FontProvider FX_FINAL : public IFX_FileRead | 172 virtual void ClearDriver(); |
189 { | 173 |
190 public: | 174 protected: |
191 virtual void Release() | 175 void setStrokeInfo(const CFX_GraphStateData* graphState, |
192 { | 176 FX_ARGB argb, |
193 delete this; | 177 FX_FLOAT lineWidth); |
194 } | 178 void setFillInfo(FX_ARGB argb); |
195 virtual FX_FILESIZE GetSize() | 179 void setPathToContext(const CFX_PathData* pathData); |
196 { | 180 FX_FLOAT getLineWidth(const CFX_GraphStateData* graphState, |
197 return (FX_FILESIZE)_totalSize; | 181 CGAffineTransform ctm); |
198 } | 182 FX_BOOL CG_DrawGlypRun(int nChars, |
199 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offs
et, size_t size); | 183 const FXTEXT_CHARPOS* pCharPos, |
200 | 184 CFX_Font* pFont, |
201 virtual FX_BOOL IsEOF() | 185 CFX_FontCache* pCache, |
202 { | 186 const CFX_AffineMatrix* pGlyphMatrix, |
203 return _offSet == _totalSize; | 187 const CFX_AffineMatrix* pObject2Device, |
204 } | 188 FX_FLOAT font_size, |
205 virtual FX_FILESIZE GetPosition() | 189 FX_DWORD argb, |
206 { | 190 int alpha_flag, |
207 return (FX_FILESIZE)_offSet; | 191 void* pIccTransform); |
208 } | 192 void CG_SetImageTransform(int dest_left, |
209 virtual size_t ReadBlock(void* buffer, size_t size); | 193 int dest_top, |
210 public: | 194 int dest_width, |
211 CFX_FontProvider(CGFontRef cgFont); | 195 int dest_height, |
212 ~CFX_FontProvider(); | 196 CGRect* rect = NULL); |
213 void InitTableOffset(); | 197 |
214 unsigned long Read(unsigned long offset, unsigned char *buffer, unsigned l
ong count); | 198 protected: |
215 protected: | 199 CGContextRef _context; |
216 uint32_t CalcTableCheckSum(const uint32_t *table, uint32_t numberOfBytesInTa
ble); | 200 CGAffineTransform _foxitDevice2User; |
217 uint32_t CalcTableDataRefCheckSum(CFDataRef dataRef); | 201 CGAffineTransform _user2FoxitDevice; |
218 private: | 202 FX_INT32 m_saveCount; |
219 CGFontRef m_cgFont; | 203 |
220 UInt32 m_iTableSize; | 204 FX_INT32 _width; |
221 size_t _offSet; | 205 FX_INT32 _height; |
222 typedef struct FontHeader { | 206 FX_INT32 _bitsPerPixel; |
223 int32_t fVersion; | 207 FX_INT32 _deviceClass; |
224 uint16_t fNumTables; | 208 FX_INT32 _renderCaps; |
225 uint16_t fSearchRange; | 209 FX_INT32 _horzSize; |
226 uint16_t fEntrySelector; | 210 FX_INT32 _vertSize; |
227 uint16_t fRangeShift; | 211 }; |
228 } FontHeader; | 212 class CFX_FontProvider FX_FINAL : public IFX_FileRead { |
229 typedef struct TableEntry { | 213 public: |
230 uint32_t fTag; | 214 virtual void Release() { delete this; } |
231 uint32_t fCheckSum; | 215 virtual FX_FILESIZE GetSize() { return (FX_FILESIZE)_totalSize; } |
232 uint32_t fOffset; | 216 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size); |
233 uint32_t fLength; | 217 |
234 } TableEntry; | 218 virtual FX_BOOL IsEOF() { return _offSet == _totalSize; } |
235 FontHeader _fontHeader; | 219 virtual FX_FILESIZE GetPosition() { return (FX_FILESIZE)_offSet; } |
236 unsigned char * _tableEntries; | 220 virtual size_t ReadBlock(void* buffer, size_t size); |
237 size_t * _tableOffsets; | 221 |
238 int _tableCount; | 222 public: |
239 int _totalSize; | 223 CFX_FontProvider(CGFontRef cgFont); |
240 }; | 224 ~CFX_FontProvider(); |
241 FX_UINT32 FX_GetHashCode( FX_LPCSTR pStr); | 225 void InitTableOffset(); |
242 FX_DWORD FX_IOSGetMatchFamilyNameHashcode(FX_LPCSTR pFontName); | 226 unsigned long Read(unsigned long offset, |
| 227 unsigned char* buffer, |
| 228 unsigned long count); |
| 229 |
| 230 protected: |
| 231 uint32_t CalcTableCheckSum(const uint32_t* table, |
| 232 uint32_t numberOfBytesInTable); |
| 233 uint32_t CalcTableDataRefCheckSum(CFDataRef dataRef); |
| 234 |
| 235 private: |
| 236 CGFontRef m_cgFont; |
| 237 UInt32 m_iTableSize; |
| 238 size_t _offSet; |
| 239 typedef struct FontHeader { |
| 240 int32_t fVersion; |
| 241 uint16_t fNumTables; |
| 242 uint16_t fSearchRange; |
| 243 uint16_t fEntrySelector; |
| 244 uint16_t fRangeShift; |
| 245 } FontHeader; |
| 246 typedef struct TableEntry { |
| 247 uint32_t fTag; |
| 248 uint32_t fCheckSum; |
| 249 uint32_t fOffset; |
| 250 uint32_t fLength; |
| 251 } TableEntry; |
| 252 FontHeader _fontHeader; |
| 253 unsigned char* _tableEntries; |
| 254 size_t* _tableOffsets; |
| 255 int _tableCount; |
| 256 int _totalSize; |
| 257 }; |
| 258 FX_UINT32 FX_GetHashCode(FX_LPCSTR pStr); |
| 259 FX_DWORD FX_IOSGetMatchFamilyNameHashcode(FX_LPCSTR pFontName); |
243 FX_UINT32 FX_IOSGetFamilyNamesCount(); | 260 FX_UINT32 FX_IOSGetFamilyNamesCount(); |
244 FX_LPCSTR FX_IOSGetFamilyName( FX_UINT32 uIndex); | 261 FX_LPCSTR FX_IOSGetFamilyName(FX_UINT32 uIndex); |
245 #endif | 262 #endif |
246 #endif | 263 #endif |
OLD | NEW |