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