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