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