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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
10 #if _FX_OS_ == _FX_MACOSX_
11 #include <Carbon/Carbon.h>
13 typedef enum eFXIOSFONTCHARSET {
14 eFXFontCharsetDEFAULT = 0,
15 eFXFontCharsetANSI = 1,
16 eFXFontCharsetSYMBOL = 1 << 1,
17 eFXFontCharsetSHIFTJIS = 1 << 2,
18 eFXFontCharsetHANGEUL = 1 << 3,
19 eFXFontCharsetGB2312 = 1 << 4,
20 eFXFontCharsetCHINESEBIG5 = 1 << 5,
21 eFXFontCharsetTHAI = 1 << 6,
22 eFXFontCharsetEASTEUROPE = 1 << 7,
23 eFXFontCharsetRUSSIAN = 1 << 8,
24 eFXFontCharsetGREEK = 1 << 9,
25 eFXFontCharsetTURKISH = 1 << 10,
26 eFXFontCharsetHEBREW = 1 << 11,
27 eFXFontCharsetARABIC = 1 << 12,
28 eFXFontCharsetBALTIC = 1 << 13,
30 FX_IOSCHARSET FX_GetiOSCharset(int charset);
31 typedef enum eFXIOSFONTFLAG {
33 eFXFontFlagItalic = 1 << 1,
34 eFXFontFlagFixedPitch = 1 << 2,
35 eFXFontFlagSerif = 1 << 3,
36 eFXFontFlagScript = 1 << 4,
38 typedef struct _IOS_FONTDATA {
47 void* createGraphics(CFX_DIBitmap* bitmap);
48 void destroyGraphics(void* graphics);
50 void* CreateFont(FX_LPCBYTE pFontData, FX_DWORD dwFontSize);
51 void DestroyFont(void* pFont);
52 void setGraphicsTextMatrix(void* graphics, CFX_AffineMatrix* matrix);
53 FX_BOOL drawGraphicsString(void* graphics,
56 FX_WORD* glyphIndices,
57 CGPoint* glyphPositions,
60 CFX_AffineMatrix* matrix = NULL);
61 void saveGraphicsState(void* graphics);
62 void restoreGraphicsState(void* graphics);
64 class CApplePlatform : public CFX_Object
78 IFX_FontMapper* m_pFontMapper;
80 class CFX_QuartzDeviceDriver : public IFX_RenderDeviceDriver
83 CFX_QuartzDeviceDriver(CGContextRef context, FX_INT32 deviceClass);
84 virtual ~CFX_QuartzDeviceDriver();
86 virtual int GetDeviceCaps(int caps_id);
87 virtual CFX_Matrix GetCTM() const;
88 virtual CFX_DIBitmap* GetBackDrop()
92 virtual void* GetPlatformSurface()
96 virtual FX_BOOL IsPSPrintDriver()
100 virtual FX_BOOL StartRendering()
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,
111 virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData,
112 const CFX_AffineMatrix* pObject2Device,
113 const CFX_GraphStateData* pGraphState
115 virtual FX_BOOL DrawPath(const CFX_PathData* pPathData,
116 const CFX_AffineMatrix* pObject2Device,
117 const CFX_GraphStateData* pGraphState,
119 FX_DWORD stroke_color,
122 void* pIccTransform = NULL,
123 int blend_type = FXDIB_BLEND_NORMAL
125 virtual FX_BOOL SetPixel(int x, int y, FX_DWORD color,
126 int alpha_flag = 0, void* pIccTransform = NULL)
130 virtual FX_BOOL FillRect(const FX_RECT* pRect, FX_DWORD fill_color,
131 int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL);
132 virtual FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_DWORD color,
133 int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL);
134 virtual FX_BOOL GetClipBox(FX_RECT* pRect);
135 virtual FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform = NULL, FX_BOOL bDEdge = FALSE);
136 virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, const FX_RECT* pSrcRect,
137 int dest_left, int dest_top, int blend_type,
138 int alpha_flag = 0, void* pIccTransform = NULL);
139 virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top,
140 int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags,
141 int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL);
142 virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color,
143 const CFX_AffineMatrix* pMatrix, FX_DWORD flags, FX_LPVOID& handle,
144 int alpha_flag = 0, void* pIccTransform = NULL,
145 int blend_type = FXDIB_BLEND_NORMAL)
149 virtual FX_BOOL ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause)
153 virtual void CancelDIBits(FX_LPVOID handle) {}
154 virtual FX_BOOL DrawDeviceText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont,
155 CFX_FontCache* pCache, const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color,
156 int alpha_flag = 0, void* pIccTransform = NULL);
157 virtual void ClearDriver();
159 void setStrokeInfo(const CFX_GraphStateData * graphState, FX_ARGB argb, FX_FLOAT lineWidth);
160 void setFillInfo(FX_ARGB argb);
161 void setPathToContext(const CFX_PathData * pathData);
162 FX_FLOAT getLineWidth(const CFX_GraphStateData * graphState, CGAffineTransform ctm);
163 FX_BOOL CG_DrawGlypRun(int nChars,
164 const FXTEXT_CHARPOS* pCharPos,
166 CFX_FontCache* pCache,
167 const CFX_AffineMatrix* pGlyphMatrix,
168 const CFX_AffineMatrix* pObject2Device,
172 void* pIccTransform);
173 void CG_SetImageTransform(int dest_left, int dest_top, int dest_width, int dest_height, CGRect* rect = NULL);
175 CGContextRef _context;
176 CGAffineTransform _foxitDevice2User;
177 CGAffineTransform _user2FoxitDevice;
178 FX_INT32 m_saveCount;
182 FX_INT32 _bitsPerPixel;
183 FX_INT32 _deviceClass;
184 FX_INT32 _renderCaps;
188 class CFX_FontProvider FX_FINAL : public IFX_FileRead
191 virtual void Release()
195 virtual FX_FILESIZE GetSize()
197 return (FX_FILESIZE)_totalSize;
199 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size);
201 virtual FX_BOOL IsEOF()
203 return _offSet == _totalSize;
205 virtual FX_FILESIZE GetPosition()
207 return (FX_FILESIZE)_offSet;
209 virtual size_t ReadBlock(void* buffer, size_t size);
211 CFX_FontProvider(CGFontRef cgFont);
213 void InitTableOffset();
214 unsigned long Read(unsigned long offset, unsigned char *buffer, unsigned long count);
216 uint32_t CalcTableCheckSum(const uint32_t *table, uint32_t numberOfBytesInTable);
217 uint32_t CalcTableDataRefCheckSum(CFDataRef dataRef);
222 typedef struct FontHeader {
225 uint16_t fSearchRange;
226 uint16_t fEntrySelector;
227 uint16_t fRangeShift;
229 typedef struct TableEntry {
235 FontHeader _fontHeader;
236 unsigned char * _tableEntries;
237 size_t * _tableOffsets;
241 FX_UINT32 FX_GetHashCode( FX_LPCSTR pStr);
242 FX_DWORD FX_IOSGetMatchFamilyNameHashcode(FX_LPCSTR pFontName);
243 FX_UINT32 FX_IOSGetFamilyNamesCount();
244 FX_LPCSTR FX_IOSGetFamilyName( FX_UINT32 uIndex);