Home | History | Annotate | Download | only in apple
      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 _APPLE_INT_H_
      8 #define _APPLE_INT_H_
      9 #if _FXM_PLATFORM_  == _FXM_PLATFORM_APPLE_
     10 #if _FX_OS_ == _FX_MACOSX_
     11 #include <Carbon/Carbon.h>
     12 #endif
     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,
     29 } FX_IOSCHARSET;
     30 FX_IOSCHARSET FX_GetiOSCharset(int charset);
     31 typedef enum eFXIOSFONTFLAG {
     32     eFXFontFlagBold         =  1,
     33     eFXFontFlagItalic       =  1 << 1,
     34     eFXFontFlagFixedPitch   =  1 << 2,
     35     eFXFontFlagSerif        =  1 << 3,
     36     eFXFontFlagScript       =  1 << 4,
     37 } FX_IOSFONTFLAG;
     38 typedef struct _IOS_FONTDATA {
     39     FX_DWORD        nHashCode;
     40     const char*       psName;
     41     FX_DWORD        charsets;
     42     FX_DWORD        styles;
     43 } IOS_FONTDATA;
     44 class CQuartz2D
     45 {
     46 public:
     47     void*	createGraphics(CFX_DIBitmap* bitmap);
     48     void	destroyGraphics(void* graphics);
     49 
     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,
     54                                void*                font,
     55                                FX_FLOAT             fontSize,
     56                                FX_WORD*             glyphIndices,
     57                                CGPoint*          glyphPositions,
     58                                FX_INT32             chars,
     59                                FX_ARGB              argb,
     60                                CFX_AffineMatrix*    matrix = NULL);
     61     void saveGraphicsState(void* graphics);
     62     void restoreGraphicsState(void* graphics);
     63 };
     64 class CApplePlatform : public CFX_Object
     65 {
     66 public:
     67     CApplePlatform()
     68     {
     69         m_pFontMapper = NULL;
     70     }
     71     ~CApplePlatform()
     72     {
     73         if (m_pFontMapper) {
     74             delete m_pFontMapper;
     75         }
     76     }
     77     CQuartz2D	_quartz2d;
     78     IFX_FontMapper* m_pFontMapper;
     79 };
     80 class CFX_QuartzDeviceDriver : public IFX_RenderDeviceDriver
     81 {
     82 public:
     83     CFX_QuartzDeviceDriver(CGContextRef context, FX_INT32 deviceClass);
     84     virtual ~CFX_QuartzDeviceDriver();
     85 
     86     virtual int		GetDeviceCaps(int caps_id);
     87     virtual CFX_Matrix	GetCTM() const;
     88     virtual CFX_DIBitmap*   GetBackDrop()
     89     {
     90         return NULL;
     91     }
     92     virtual void*	GetPlatformSurface()
     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,
    109                                      int fill_mode
    110                                     );
    111     virtual FX_BOOL	SetClip_PathStroke(const CFX_PathData* pPathData,
    112                                        const CFX_AffineMatrix* pObject2Device,
    113                                        const CFX_GraphStateData* pGraphState
    114                                       );
    115     virtual FX_BOOL	DrawPath(const CFX_PathData* pPathData,
    116                              const CFX_AffineMatrix* pObject2Device,
    117                              const CFX_GraphStateData* pGraphState,
    118                              FX_DWORD fill_color,
    119                              FX_DWORD stroke_color,
    120                              int fill_mode,
    121                              int alpha_flag = 0,
    122                              void* pIccTransform = NULL,
    123                              int blend_type = FXDIB_BLEND_NORMAL
    124                             );
    125     virtual FX_BOOL	SetPixel(int x, int y, FX_DWORD color,
    126                              int alpha_flag = 0, void* pIccTransform = NULL)
    127     {
    128         return FALSE;
    129     }
    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)
    146     {
    147         return FALSE;
    148     }
    149     virtual FX_BOOL	ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause)
    150     {
    151         return FALSE;
    152     }
    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();
    158 protected:
    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,
    165                            CFX_Font*                  pFont,
    166                            CFX_FontCache*             pCache,
    167                            const CFX_AffineMatrix*    pGlyphMatrix,
    168                            const CFX_AffineMatrix*    pObject2Device,
    169                            FX_FLOAT                   font_size,
    170                            FX_DWORD                   argb,
    171                            int                        alpha_flag,
    172                            void*                      pIccTransform);
    173     void    CG_SetImageTransform(int dest_left, int dest_top, int dest_width, int dest_height, CGRect* rect = NULL);
    174 protected:
    175     CGContextRef	_context;
    176     CGAffineTransform _foxitDevice2User;
    177     CGAffineTransform _user2FoxitDevice;
    178     FX_INT32        m_saveCount;
    179 
    180     FX_INT32		_width;
    181     FX_INT32		_height;
    182     FX_INT32		_bitsPerPixel;
    183     FX_INT32		_deviceClass;
    184     FX_INT32		_renderCaps;
    185     FX_INT32	_horzSize;
    186     FX_INT32	_vertSize;
    187 };
    188 class CFX_FontProvider : public IFX_FileRead
    189 {
    190 public:
    191     virtual void			Release()
    192     {
    193         delete this;
    194     }
    195     virtual FX_FILESIZE		GetSize()
    196     {
    197         return (FX_FILESIZE)_totalSize;
    198     }
    199     virtual FX_BOOL			ReadBlock(void* buffer, FX_FILESIZE offset, size_t size);
    200 
    201     virtual FX_BOOL			IsEOF()
    202     {
    203         return _offSet == _totalSize;
    204     }
    205     virtual FX_FILESIZE		GetPosition()
    206     {
    207         return (FX_FILESIZE)_offSet;
    208     }
    209     virtual size_t			ReadBlock(void* buffer, size_t size);
    210 public:
    211     CFX_FontProvider(CGFontRef cgFont);
    212     ~CFX_FontProvider();
    213     void            InitTableOffset();
    214     unsigned long   Read(unsigned long offset, unsigned char *buffer, unsigned long count);
    215 protected:
    216     uint32_t CalcTableCheckSum(const uint32_t *table, uint32_t numberOfBytesInTable);
    217     uint32_t CalcTableDataRefCheckSum(CFDataRef dataRef);
    218 private:
    219     CGFontRef   m_cgFont;
    220     UInt32      m_iTableSize;
    221     size_t      _offSet;
    222     typedef struct FontHeader {
    223         int32_t fVersion;
    224         uint16_t fNumTables;
    225         uint16_t fSearchRange;
    226         uint16_t fEntrySelector;
    227         uint16_t fRangeShift;
    228     } FontHeader;
    229     typedef struct TableEntry {
    230         uint32_t fTag;
    231         uint32_t fCheckSum;
    232         uint32_t fOffset;
    233         uint32_t fLength;
    234     } TableEntry;
    235     FontHeader _fontHeader;
    236     unsigned char * _tableEntries;
    237     size_t * _tableOffsets;
    238     int _tableCount;
    239     int _totalSize;
    240 };
    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);
    245 #endif
    246 #endif
    247