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