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 CORE_FXGE_WIN32_WIN32_INT_H_ 8 #define CORE_FXGE_WIN32_WIN32_INT_H_ 9 10 #include <windows.h> 11 12 #include <memory> 13 14 #include "core/fxge/cfx_pathdata.h" 15 #include "core/fxge/ifx_renderdevicedriver.h" 16 #include "core/fxge/win32/cfx_psrenderer.h" 17 #include "core/fxge/win32/cpsoutput.h" 18 #include "core/fxge/win32/dwrite_int.h" 19 20 class FXTEXT_CHARPOS; 21 struct WINDIB_Open_Args_; 22 23 typedef HANDLE(__stdcall* FuncType_GdiAddFontMemResourceEx)(PVOID pbFont, 24 DWORD cbFont, 25 PVOID pdv, 26 DWORD* pcFonts); 27 typedef BOOL(__stdcall* FuncType_GdiRemoveFontMemResourceEx)(HANDLE handle); 28 29 class CGdiplusExt { 30 public: 31 CGdiplusExt(); 32 ~CGdiplusExt(); 33 void Load(); IsAvailable()34 bool IsAvailable() { return !!m_hModule; } 35 bool StretchBitMask(HDC hDC, 36 BOOL bMonoDevice, 37 const CFX_DIBitmap* pBitmap, 38 int dest_left, 39 int dest_top, 40 int dest_width, 41 int dest_height, 42 uint32_t argb, 43 const FX_RECT* pClipRect, 44 int flags); 45 bool StretchDIBits(HDC hDC, 46 const CFX_DIBitmap* pBitmap, 47 int dest_left, 48 int dest_top, 49 int dest_width, 50 int dest_height, 51 const FX_RECT* pClipRect, 52 int flags); 53 bool DrawPath(HDC hDC, 54 const CFX_PathData* pPathData, 55 const CFX_Matrix* pObject2Device, 56 const CFX_GraphStateData* pGraphState, 57 uint32_t fill_argb, 58 uint32_t stroke_argb, 59 int fill_mode); 60 61 void* LoadMemFont(uint8_t* pData, uint32_t size); 62 void DeleteMemFont(void* pFontCollection); 63 bool GdipCreateFromImage(void* bitmap, void** graphics); 64 void GdipDeleteGraphics(void* graphics); 65 void GdipSetTextRenderingHint(void* graphics, int mode); 66 void GdipSetPageUnit(void* graphics, uint32_t unit); 67 void GdipSetWorldTransform(void* graphics, void* pMatrix); 68 bool GdipDrawDriverString(void* graphics, 69 unsigned short* text, 70 int length, 71 void* font, 72 void* brush, 73 void* positions, 74 int flags, 75 const void* matrix); 76 void GdipCreateBrush(uint32_t fill_argb, void** pBrush); 77 void GdipDeleteBrush(void* pBrush); 78 void GdipCreateMatrix(FX_FLOAT a, 79 FX_FLOAT b, 80 FX_FLOAT c, 81 FX_FLOAT d, 82 FX_FLOAT e, 83 FX_FLOAT f, 84 void** matrix); 85 void GdipDeleteMatrix(void* matrix); 86 bool GdipCreateFontFamilyFromName(const FX_WCHAR* name, 87 void* pFontCollection, 88 void** pFamily); 89 void GdipDeleteFontFamily(void* pFamily); 90 bool GdipCreateFontFromFamily(void* pFamily, 91 FX_FLOAT font_size, 92 int fontstyle, 93 int flag, 94 void** pFont); 95 void* GdipCreateFontFromCollection(void* pFontCollection, 96 FX_FLOAT font_size, 97 int fontstyle); 98 void GdipDeleteFont(void* pFont); 99 bool GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap); 100 void GdipDisposeImage(void* bitmap); 101 void GdipGetFontSize(void* pFont, FX_FLOAT* size); 102 void* GdiAddFontMemResourceEx(void* pFontdata, 103 uint32_t size, 104 void* pdv, 105 uint32_t* num_face); 106 bool GdiRemoveFontMemResourceEx(void* handle); 107 CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args); 108 109 FARPROC m_Functions[100]; 110 FuncType_GdiAddFontMemResourceEx m_pGdiAddFontMemResourceEx; 111 FuncType_GdiRemoveFontMemResourceEx m_pGdiRemoveFontMemResourseEx; 112 113 protected: 114 HMODULE m_hModule; 115 HMODULE m_GdiModule; 116 }; 117 118 class CWin32Platform { 119 public: 120 bool m_bHalfTone; 121 CGdiplusExt m_GdiplusExt; 122 CDWriteExt m_DWriteExt; 123 }; 124 125 class CGdiDeviceDriver : public IFX_RenderDeviceDriver { 126 protected: 127 CGdiDeviceDriver(HDC hDC, int device_class); 128 ~CGdiDeviceDriver() override; 129 130 // IFX_RenderDeviceDriver 131 int GetDeviceCaps(int caps_id) const override; 132 void SaveState() override; 133 void RestoreState(bool bKeepSaved) override; 134 bool SetClip_PathFill(const CFX_PathData* pPathData, 135 const CFX_Matrix* pObject2Device, 136 int fill_mode) override; 137 bool SetClip_PathStroke(const CFX_PathData* pPathData, 138 const CFX_Matrix* pObject2Device, 139 const CFX_GraphStateData* pGraphState) override; 140 bool DrawPath(const CFX_PathData* pPathData, 141 const CFX_Matrix* pObject2Device, 142 const CFX_GraphStateData* pGraphState, 143 uint32_t fill_color, 144 uint32_t stroke_color, 145 int fill_mode, 146 int blend_type) override; 147 bool FillRectWithBlend(const FX_RECT* pRect, 148 uint32_t fill_color, 149 int blend_type) override; 150 bool DrawCosmeticLine(FX_FLOAT x1, 151 FX_FLOAT y1, 152 FX_FLOAT x2, 153 FX_FLOAT y2, 154 uint32_t color, 155 int blend_type) override; 156 bool GetClipBox(FX_RECT* pRect) override; 157 void* GetPlatformSurface() const override; 158 159 void DrawLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2); 160 161 bool GDI_SetDIBits(CFX_DIBitmap* pBitmap, 162 const FX_RECT* pSrcRect, 163 int left, 164 int top); 165 bool GDI_StretchDIBits(CFX_DIBitmap* pBitmap, 166 int dest_left, 167 int dest_top, 168 int dest_width, 169 int dest_height, 170 uint32_t flags); 171 bool GDI_StretchBitMask(CFX_DIBitmap* pBitmap, 172 int dest_left, 173 int dest_top, 174 int dest_width, 175 int dest_height, 176 uint32_t bitmap_color, 177 uint32_t flags); 178 179 HDC m_hDC; 180 bool m_bMetafileDCType; 181 int m_Width; 182 int m_Height; 183 int m_nBitsPerPixel; 184 int m_DeviceClass; 185 int m_RenderCaps; 186 }; 187 188 class CGdiDisplayDriver : public CGdiDeviceDriver { 189 public: 190 explicit CGdiDisplayDriver(HDC hDC); 191 ~CGdiDisplayDriver() override; 192 193 protected: 194 bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override; 195 bool SetDIBits(const CFX_DIBSource* pBitmap, 196 uint32_t color, 197 const FX_RECT* pSrcRect, 198 int left, 199 int top, 200 int blend_type) override; 201 bool StretchDIBits(const CFX_DIBSource* pBitmap, 202 uint32_t color, 203 int dest_left, 204 int dest_top, 205 int dest_width, 206 int dest_height, 207 const FX_RECT* pClipRect, 208 uint32_t flags, 209 int blend_type) override; 210 bool StartDIBits(const CFX_DIBSource* pBitmap, 211 int bitmap_alpha, 212 uint32_t color, 213 const CFX_Matrix* pMatrix, 214 uint32_t render_flags, 215 void*& handle, 216 int blend_type) override; 217 bool UseFoxitStretchEngine(const CFX_DIBSource* pSource, 218 uint32_t color, 219 int dest_left, 220 int dest_top, 221 int dest_width, 222 int dest_height, 223 const FX_RECT* pClipRect, 224 int render_flags); 225 }; 226 227 class CGdiPrinterDriver : public CGdiDeviceDriver { 228 public: 229 explicit CGdiPrinterDriver(HDC hDC); 230 ~CGdiPrinterDriver() override; 231 232 protected: 233 int GetDeviceCaps(int caps_id) const override; 234 bool SetDIBits(const CFX_DIBSource* pBitmap, 235 uint32_t color, 236 const FX_RECT* pSrcRect, 237 int left, 238 int top, 239 int blend_type) override; 240 bool StretchDIBits(const CFX_DIBSource* pBitmap, 241 uint32_t color, 242 int dest_left, 243 int dest_top, 244 int dest_width, 245 int dest_height, 246 const FX_RECT* pClipRect, 247 uint32_t flags, 248 int blend_type) override; 249 bool StartDIBits(const CFX_DIBSource* pBitmap, 250 int bitmap_alpha, 251 uint32_t color, 252 const CFX_Matrix* pMatrix, 253 uint32_t render_flags, 254 void*& handle, 255 int blend_type) override; 256 bool DrawDeviceText(int nChars, 257 const FXTEXT_CHARPOS* pCharPos, 258 CFX_Font* pFont, 259 const CFX_Matrix* pObject2Device, 260 FX_FLOAT font_size, 261 uint32_t color) override; 262 263 const int m_HorzSize; 264 const int m_VertSize; 265 }; 266 267 class CPSPrinterDriver : public IFX_RenderDeviceDriver { 268 public: 269 CPSPrinterDriver(HDC hDC, int ps_level, bool bCmykOutput); 270 ~CPSPrinterDriver() override; 271 272 protected: 273 // IFX_RenderDeviceDriver 274 int GetDeviceCaps(int caps_id) const override; 275 bool StartRendering() override; 276 void EndRendering() override; 277 void SaveState() override; 278 void RestoreState(bool bKeepSaved) override; 279 bool SetClip_PathFill(const CFX_PathData* pPathData, 280 const CFX_Matrix* pObject2Device, 281 int fill_mode) override; 282 bool SetClip_PathStroke(const CFX_PathData* pPathData, 283 const CFX_Matrix* pObject2Device, 284 const CFX_GraphStateData* pGraphState) override; 285 bool DrawPath(const CFX_PathData* pPathData, 286 const CFX_Matrix* pObject2Device, 287 const CFX_GraphStateData* pGraphState, 288 uint32_t fill_color, 289 uint32_t stroke_color, 290 int fill_mode, 291 int blend_type) override; 292 bool GetClipBox(FX_RECT* pRect) override; 293 bool SetDIBits(const CFX_DIBSource* pBitmap, 294 uint32_t color, 295 const FX_RECT* pSrcRect, 296 int left, 297 int top, 298 int blend_type) override; 299 bool StretchDIBits(const CFX_DIBSource* pBitmap, 300 uint32_t color, 301 int dest_left, 302 int dest_top, 303 int dest_width, 304 int dest_height, 305 const FX_RECT* pClipRect, 306 uint32_t flags, 307 int blend_type) override; 308 bool StartDIBits(const CFX_DIBSource* pBitmap, 309 int bitmap_alpha, 310 uint32_t color, 311 const CFX_Matrix* pMatrix, 312 uint32_t render_flags, 313 void*& handle, 314 int blend_type) override; 315 bool DrawDeviceText(int nChars, 316 const FXTEXT_CHARPOS* pCharPos, 317 CFX_Font* pFont, 318 const CFX_Matrix* pObject2Device, 319 FX_FLOAT font_size, 320 uint32_t color) override; 321 void* GetPlatformSurface() const override; 322 323 HDC m_hDC; 324 bool m_bCmykOutput; 325 int m_Width; 326 int m_Height; 327 int m_nBitsPerPixel; 328 int m_HorzSize; 329 int m_VertSize; 330 std::unique_ptr<CPSOutput> m_pPSOutput; 331 CFX_PSRenderer m_PSRenderer; 332 }; 333 334 #endif // CORE_FXGE_WIN32_WIN32_INT_H_ 335