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 struct WINDIB_Open_Args_; 8 class CGdiplusExt 9 { 10 public: 11 CGdiplusExt(); 12 ~CGdiplusExt(); 13 void Load(); 14 FX_BOOL IsAvailable() 15 { 16 return m_hModule != NULL; 17 } 18 FX_BOOL StretchBitMask(HDC hDC, BOOL bMonoDevice, const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, 19 int dest_width, int dest_height, FX_DWORD argb, const FX_RECT* pClipRect, int flags); 20 FX_BOOL StretchDIBits(HDC hDC, const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, 21 int dest_width, int dest_height, const FX_RECT* pClipRect, int flags); 22 FX_BOOL DrawPath(HDC hDC, const CFX_PathData* pPathData, 23 const CFX_AffineMatrix* pObject2Device, 24 const CFX_GraphStateData* pGraphState, 25 FX_DWORD fill_argb, 26 FX_DWORD stroke_argb, 27 int fill_mode 28 ); 29 30 void* LoadMemFont(FX_BYTE* pData, FX_DWORD size); 31 void DeleteMemFont(void* pFontCollection); 32 FX_BOOL GdipCreateFromImage(void* bitmap, void** graphics); 33 void GdipDeleteGraphics(void* graphics); 34 void GdipSetTextRenderingHint(void* graphics, int mode); 35 void GdipSetPageUnit(void* graphics, FX_DWORD unit); 36 void GdipSetWorldTransform(void* graphics, void* pMatrix); 37 FX_BOOL GdipDrawDriverString(void *graphics, unsigned short *text, int length, void *font, void* brush, void *positions, int flags, const void *matrix); 38 void GdipCreateBrush(FX_DWORD fill_argb, void** pBrush); 39 void GdipDeleteBrush(void* pBrush); 40 void GdipCreateMatrix(FX_FLOAT a, FX_FLOAT b, FX_FLOAT c, FX_FLOAT d, FX_FLOAT e, FX_FLOAT f, void** matrix); 41 void GdipDeleteMatrix(void* matrix); 42 FX_BOOL GdipCreateFontFamilyFromName(FX_LPCWSTR name, void* pFontCollection, void**pFamily); 43 void GdipDeleteFontFamily(void* pFamily); 44 FX_BOOL GdipCreateFontFromFamily(void* pFamily, FX_FLOAT font_size, int fontstyle, int flag, void** pFont); 45 void* GdipCreateFontFromCollection(void* pFontCollection, FX_FLOAT font_size, int fontstyle); 46 void GdipDeleteFont(void* pFont); 47 FX_BOOL GdipCreateBitmap(CFX_DIBitmap* pBitmap, void**bitmap); 48 void GdipDisposeImage(void* bitmap); 49 void GdipGetFontSize(void *pFont, FX_FLOAT *size); 50 void* GdiAddFontMemResourceEx(void *pFontdata, FX_DWORD size, void* pdv, FX_DWORD* num_face); 51 FX_BOOL GdiRemoveFontMemResourceEx(void* handle); 52 void* m_Functions[100]; 53 void* m_pGdiAddFontMemResourceEx; 54 void* m_pGdiRemoveFontMemResourseEx; 55 CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args); 56 protected: 57 HMODULE m_hModule; 58 HMODULE m_GdiModule; 59 }; 60 #include "dwrite_int.h" 61 class CWin32Platform : public CFX_Object 62 { 63 public: 64 FX_BOOL m_bHalfTone; 65 CGdiplusExt m_GdiplusExt; 66 CDWriteExt m_DWriteExt; 67 }; 68 class CGdiDeviceDriver : public IFX_RenderDeviceDriver 69 { 70 protected: 71 virtual int GetDeviceCaps(int caps_id); 72 virtual void SaveState() 73 { 74 SaveDC(m_hDC); 75 } 76 virtual void RestoreState(FX_BOOL bKeepSaved = FALSE) 77 { 78 RestoreDC(m_hDC, -1); 79 if (bKeepSaved) { 80 SaveDC(m_hDC); 81 } 82 } 83 virtual FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, 84 const CFX_AffineMatrix* pObject2Device, 85 int fill_mode 86 ); 87 virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, 88 const CFX_AffineMatrix* pObject2Device, 89 const CFX_GraphStateData* pGraphState 90 ); 91 virtual FX_BOOL DrawPath(const CFX_PathData* pPathData, 92 const CFX_AffineMatrix* pObject2Device, 93 const CFX_GraphStateData* pGraphState, 94 FX_DWORD fill_color, 95 FX_DWORD stroke_color, 96 int fill_mode, 97 int alpha_flag, 98 void* pIccTransform, 99 int blend_type 100 ); 101 virtual FX_BOOL FillRect(const FX_RECT* pRect, 102 FX_DWORD fill_color, 103 int alpha_flag, void* pIccTransform, int blend_type); 104 virtual FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_DWORD color, 105 int alpha_flag, void* pIccTransform, int blend_type); 106 virtual FX_LPVOID GetClipRgn() ; 107 virtual FX_BOOL SetClipRgn(FX_LPVOID pRgn) ; 108 virtual FX_BOOL GetClipBox(FX_RECT* pRect); 109 virtual FX_BOOL DeleteDeviceRgn(FX_LPVOID pRgn); 110 virtual void DrawLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2); 111 virtual void* GetPlatformSurface() 112 { 113 return (void*)m_hDC; 114 } 115 FX_BOOL GDI_SetDIBits(const CFX_DIBitmap* pBitmap, const FX_RECT* pSrcRect, int left, int top, 116 void* pIccTransform); 117 FX_BOOL GDI_StretchDIBits(const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, 118 int dest_width, int dest_height, FX_DWORD flags, 119 void* pIccTransform); 120 FX_BOOL GDI_StretchBitMask(const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, 121 int dest_width, int dest_height, FX_DWORD bitmap_color, FX_DWORD flags, 122 int alpha_flag, void* pIccTransform); 123 HDC m_hDC; 124 int m_Width, m_Height, m_nBitsPerPixel; 125 int m_DeviceClass, m_RenderCaps; 126 CGdiDeviceDriver(HDC hDC, int device_class); 127 ~CGdiDeviceDriver() {} 128 }; 129 class CGdiDisplayDriver : public CGdiDeviceDriver 130 { 131 public: 132 CGdiDisplayDriver(HDC hDC); 133 protected: 134 virtual FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform = NULL, FX_BOOL bDEdge = FALSE); 135 virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, const FX_RECT* pSrcRect, int left, int top, int blend_type, 136 int alpha_flag, void* pIccTransform); 137 virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, 138 int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags, 139 int alpha_flag, void* pIccTransform, int blend_type); 140 virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, 141 const CFX_AffineMatrix* pMatrix, FX_DWORD render_flags, FX_LPVOID& handle, 142 int alpha_flag, void* pIccTransform, int blend_type) 143 { 144 return FALSE; 145 } 146 FX_BOOL UseFoxitStretchEngine(const CFX_DIBSource* pSource, FX_DWORD color, int dest_left, int dest_top, 147 int dest_width, int dest_height, const FX_RECT* pClipRect, int render_flags, 148 int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); 149 }; 150 class CGdiPrinterDriver : public CGdiDeviceDriver 151 { 152 public: 153 CGdiPrinterDriver(HDC hDC); 154 protected: 155 virtual int GetDeviceCaps(int caps_id); 156 virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, const FX_RECT* pSrcRect, int left, int top, int blend_type, 157 int alpha_flag, void* pIccTransform); 158 virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, 159 int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags, 160 int alpha_flag, void* pIccTransform, int blend_type); 161 virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, 162 const CFX_AffineMatrix* pMatrix, FX_DWORD render_flags, FX_LPVOID& handle, 163 int alpha_flag, void* pIccTransform, int blend_type); 164 int m_HorzSize, m_VertSize; 165 FX_BOOL m_bSupportROP; 166 }; 167 class CPSOutput : public IFX_PSOutput, public CFX_Object 168 { 169 public: 170 CPSOutput(HDC hDC); 171 virtual ~CPSOutput(); 172 virtual void Release() 173 { 174 delete this; 175 } 176 void Init(); 177 virtual void OutputPS(FX_LPCSTR string, int len); 178 HDC m_hDC; 179 FX_LPSTR m_pBuf; 180 }; 181 class CPSPrinterDriver : public IFX_RenderDeviceDriver 182 { 183 public: 184 CPSPrinterDriver(); 185 FX_BOOL Init(HDC hDC, int ps_level, FX_BOOL bCmykOutput); 186 ~CPSPrinterDriver(); 187 protected: 188 virtual FX_BOOL IsPSPrintDriver() 189 { 190 return TRUE; 191 } 192 virtual int GetDeviceCaps(int caps_id); 193 virtual FX_BOOL StartRendering(); 194 virtual void EndRendering(); 195 virtual void SaveState(); 196 virtual void RestoreState(FX_BOOL bKeepSaved = FALSE); 197 virtual FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, 198 const CFX_AffineMatrix* pObject2Device, 199 int fill_mode 200 ); 201 virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, 202 const CFX_AffineMatrix* pObject2Device, 203 const CFX_GraphStateData* pGraphState 204 ); 205 virtual FX_BOOL DrawPath(const CFX_PathData* pPathData, 206 const CFX_AffineMatrix* pObject2Device, 207 const CFX_GraphStateData* pGraphState, 208 FX_DWORD fill_color, 209 FX_DWORD stroke_color, 210 int fill_mode, 211 int alpha_flag, 212 void* pIccTransform, 213 int blend_type 214 ); 215 virtual FX_BOOL GetClipBox(FX_RECT* pRect); 216 virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, const FX_RECT* pSrcRect, int left, int top, int blend_type, 217 int alpha_flag, void* pIccTransform); 218 virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, 219 int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags, 220 int alpha_flag, void* pIccTransform, int blend_type); 221 virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, 222 const CFX_AffineMatrix* pMatrix, FX_DWORD render_flags, FX_LPVOID& handle, 223 int alpha_flag, void* pIccTransform, int blend_type); 224 virtual FX_BOOL DrawDeviceText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, 225 CFX_FontCache* pCache, const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color, 226 int alpha_flag, void* pIccTransform); 227 virtual void* GetPlatformSurface() 228 { 229 return (void*)m_hDC; 230 } 231 HDC m_hDC; 232 FX_BOOL m_bCmykOutput; 233 int m_Width, m_Height, m_nBitsPerPixel; 234 int m_HorzSize, m_VertSize; 235 CPSOutput* m_pPSOutput; 236 CFX_PSRenderer m_PSRenderer; 237 }; 238 void _Color2Argb(FX_ARGB& argb, FX_DWORD color, int alpha_flag, void* pIccTransform); 239