• 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_gemodule.h"
17 #include "core/fxge/cfx_pathdata.h"
18 #include "core/fxge/cfx_windowsrenderdevice.h"
19 #include "core/fxge/renderdevicedriver_iface.h"
20 #include "core/fxge/win32/cfx_psrenderer.h"
21 #include "core/fxge/win32/cpsoutput.h"
22 #include "third_party/base/optional.h"
23 
24 class CFX_ImageRenderer;
25 class TextCharPos;
26 struct WINDIB_Open_Args_;
27 
28 RetainPtr<CFX_DIBitmap> FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
29                                                   LPVOID pData,
30                                                   bool bAlpha);
31 class CGdiplusExt {
32  public:
33   CGdiplusExt();
34   ~CGdiplusExt();
35 
36   void Load();
IsAvailable()37   bool IsAvailable() { return !!m_hModule; }
38   bool StretchDIBits(HDC hDC,
39                      const RetainPtr<CFX_DIBitmap>& pBitmap,
40                      int dest_left,
41                      int dest_top,
42                      int dest_width,
43                      int dest_height,
44                      const FX_RECT* pClipRect,
45                      const FXDIB_ResampleOptions& options);
46   bool DrawPath(HDC hDC,
47                 const CFX_PathData* pPathData,
48                 const CFX_Matrix* pObject2Device,
49                 const CFX_GraphStateData* pGraphState,
50                 uint32_t fill_argb,
51                 uint32_t stroke_argb,
52                 int fill_mode);
53 
54   RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
55 
56   std::vector<FARPROC> m_Functions;
57 
58  protected:
59   HMODULE m_hModule = nullptr;
60   HMODULE m_GdiModule = nullptr;
61 };
62 
63 class CWin32Platform : public CFX_GEModule::PlatformIface {
64  public:
65   CWin32Platform();
66   ~CWin32Platform() override;
67 
68   // CFX_GEModule::PlatformIface:
69   void Init() override;
70 
71   bool m_bHalfTone = false;
72   CGdiplusExt m_GdiplusExt;
73 };
74 
75 class CGdiDeviceDriver : public RenderDeviceDriverIface {
76  protected:
77   CGdiDeviceDriver(HDC hDC, DeviceType device_type);
78   ~CGdiDeviceDriver() override;
79 
80   // RenderDeviceDriverIface:
81   DeviceType GetDeviceType() const override;
82   int GetDeviceCaps(int caps_id) const override;
83   void SaveState() override;
84   void RestoreState(bool bKeepSaved) override;
85   void SetBaseClip(const FX_RECT& rect) override;
86   bool SetClip_PathFill(const CFX_PathData* pPathData,
87                         const CFX_Matrix* pObject2Device,
88                         int fill_mode) override;
89   bool SetClip_PathStroke(const CFX_PathData* pPathData,
90                           const CFX_Matrix* pObject2Device,
91                           const CFX_GraphStateData* pGraphState) override;
92   bool DrawPath(const CFX_PathData* pPathData,
93                 const CFX_Matrix* pObject2Device,
94                 const CFX_GraphStateData* pGraphState,
95                 uint32_t fill_color,
96                 uint32_t stroke_color,
97                 int fill_mode,
98                 BlendMode blend_type) override;
99   bool FillRectWithBlend(const FX_RECT& rect,
100                          uint32_t fill_color,
101                          BlendMode blend_type) override;
102   bool DrawCosmeticLine(const CFX_PointF& ptMoveTo,
103                         const CFX_PointF& ptLineTo,
104                         uint32_t color,
105                         BlendMode blend_type) override;
106   bool GetClipBox(FX_RECT* pRect) override;
107 
108   void DrawLine(float x1, float y1, float x2, float y2);
109 
110   bool GDI_SetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap,
111                      const FX_RECT& src_rect,
112                      int left,
113                      int top);
114   bool GDI_StretchDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap,
115                          int dest_left,
116                          int dest_top,
117                          int dest_width,
118                          int dest_height,
119                          const FXDIB_ResampleOptions& options);
120   bool GDI_StretchBitMask(const RetainPtr<CFX_DIBitmap>& pBitmap,
121                           int dest_left,
122                           int dest_top,
123                           int dest_width,
124                           int dest_height,
125                           uint32_t bitmap_color);
126 
127   const HDC m_hDC;
128   bool m_bMetafileDCType;
129   int m_Width;
130   int m_Height;
131   int m_nBitsPerPixel;
132   const DeviceType m_DeviceType;
133   int m_RenderCaps;
134   pdfium::Optional<FX_RECT> m_BaseClipBox;
135 };
136 
137 class CGdiDisplayDriver final : public CGdiDeviceDriver {
138  public:
139   explicit CGdiDisplayDriver(HDC hDC);
140   ~CGdiDisplayDriver() override;
141 
142  private:
143   // CGdiDisplayDriver:
144   int GetDeviceCaps(int caps_id) const override;
145   bool GetDIBits(const RetainPtr<CFX_DIBitmap>& pBitmap,
146                  int left,
147                  int top) override;
148   bool SetDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
149                  uint32_t color,
150                  const FX_RECT& src_rect,
151                  int left,
152                  int top,
153                  BlendMode blend_type) override;
154   bool StretchDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
155                      uint32_t color,
156                      int dest_left,
157                      int dest_top,
158                      int dest_width,
159                      int dest_height,
160                      const FX_RECT* pClipRect,
161                      const FXDIB_ResampleOptions& options,
162                      BlendMode blend_type) override;
163   bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
164                    int bitmap_alpha,
165                    uint32_t color,
166                    const CFX_Matrix& matrix,
167                    const FXDIB_ResampleOptions& options,
168                    std::unique_ptr<CFX_ImageRenderer>* handle,
169                    BlendMode blend_type) override;
170   bool UseFoxitStretchEngine(const RetainPtr<CFX_DIBBase>& pSource,
171                              uint32_t color,
172                              int dest_left,
173                              int dest_top,
174                              int dest_width,
175                              int dest_height,
176                              const FX_RECT* pClipRect,
177                              const FXDIB_ResampleOptions& options);
178 };
179 
180 class CGdiPrinterDriver final : public CGdiDeviceDriver {
181  public:
182   explicit CGdiPrinterDriver(HDC hDC);
183   ~CGdiPrinterDriver() override;
184 
185  private:
186   // CGdiPrinterDriver:
187   int GetDeviceCaps(int caps_id) const override;
188   bool SetDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
189                  uint32_t color,
190                  const FX_RECT& src_rect,
191                  int left,
192                  int top,
193                  BlendMode blend_type) override;
194   bool StretchDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
195                      uint32_t color,
196                      int dest_left,
197                      int dest_top,
198                      int dest_width,
199                      int dest_height,
200                      const FX_RECT* pClipRect,
201                      const FXDIB_ResampleOptions& options,
202                      BlendMode blend_type) override;
203   bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
204                    int bitmap_alpha,
205                    uint32_t color,
206                    const CFX_Matrix& matrix,
207                    const FXDIB_ResampleOptions& options,
208                    std::unique_ptr<CFX_ImageRenderer>* handle,
209                    BlendMode blend_type) override;
210   bool DrawDeviceText(int nChars,
211                       const TextCharPos* pCharPos,
212                       CFX_Font* pFont,
213                       const CFX_Matrix& mtObject2Device,
214                       float font_size,
215                       uint32_t color) override;
216 
217   const int m_HorzSize;
218   const int m_VertSize;
219 };
220 
221 class CPSPrinterDriver final : public RenderDeviceDriverIface {
222  public:
223   CPSPrinterDriver(HDC hDC,
224                    WindowsPrintMode mode,
225                    bool bCmykOutput,
226                    const EncoderIface* pEncoderIface);
227   ~CPSPrinterDriver() override;
228 
229  private:
230   // RenderDeviceDriverIface:
231   DeviceType GetDeviceType() const override;
232   int GetDeviceCaps(int caps_id) const override;
233   bool StartRendering() override;
234   void EndRendering() override;
235   void SaveState() override;
236   void RestoreState(bool bKeepSaved) override;
237   bool SetClip_PathFill(const CFX_PathData* pPathData,
238                         const CFX_Matrix* pObject2Device,
239                         int fill_mode) override;
240   bool SetClip_PathStroke(const CFX_PathData* pPathData,
241                           const CFX_Matrix* pObject2Device,
242                           const CFX_GraphStateData* pGraphState) override;
243   bool DrawPath(const CFX_PathData* pPathData,
244                 const CFX_Matrix* pObject2Device,
245                 const CFX_GraphStateData* pGraphState,
246                 uint32_t fill_color,
247                 uint32_t stroke_color,
248                 int fill_mode,
249                 BlendMode blend_type) override;
250   bool GetClipBox(FX_RECT* pRect) override;
251   bool SetDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
252                  uint32_t color,
253                  const FX_RECT& src_rect,
254                  int left,
255                  int top,
256                  BlendMode blend_type) override;
257   bool StretchDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
258                      uint32_t color,
259                      int dest_left,
260                      int dest_top,
261                      int dest_width,
262                      int dest_height,
263                      const FX_RECT* pClipRect,
264                      const FXDIB_ResampleOptions& options,
265                      BlendMode blend_type) override;
266   bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
267                    int bitmap_alpha,
268                    uint32_t color,
269                    const CFX_Matrix& matrix,
270                    const FXDIB_ResampleOptions& options,
271                    std::unique_ptr<CFX_ImageRenderer>* handle,
272                    BlendMode blend_type) override;
273   bool DrawDeviceText(int nChars,
274                       const TextCharPos* pCharPos,
275                       CFX_Font* pFont,
276                       const CFX_Matrix& mtObject2Device,
277                       float font_size,
278                       uint32_t color) override;
279 
280   HDC m_hDC;
281   const bool m_bCmykOutput;
282   int m_Width;
283   int m_Height;
284   int m_nBitsPerPixel;
285   int m_HorzSize;
286   int m_VertSize;
287   CFX_PSRenderer m_PSRenderer;
288 };
289 
290 class CTextOnlyPrinterDriver final : public RenderDeviceDriverIface {
291  public:
292   explicit CTextOnlyPrinterDriver(HDC hDC);
293   ~CTextOnlyPrinterDriver() override;
294 
295  private:
296   // RenderDeviceDriverIface:
297   DeviceType GetDeviceType() const override;
298   int GetDeviceCaps(int caps_id) const override;
SaveState()299   void SaveState() override {}
RestoreState(bool bKeepSaved)300   void RestoreState(bool bKeepSaved) override {}
301   bool SetClip_PathFill(const CFX_PathData* pPathData,
302                         const CFX_Matrix* pObject2Device,
303                         int fill_mode) override;
304   bool SetClip_PathStroke(const CFX_PathData* pPathData,
305                           const CFX_Matrix* pObject2Device,
306                           const CFX_GraphStateData* pGraphState) override;
307   bool DrawPath(const CFX_PathData* pPathData,
308                 const CFX_Matrix* pObject2Device,
309                 const CFX_GraphStateData* pGraphState,
310                 uint32_t fill_color,
311                 uint32_t stroke_color,
312                 int fill_mode,
313                 BlendMode blend_type) override;
314   bool GetClipBox(FX_RECT* pRect) override;
315   bool SetDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
316                  uint32_t color,
317                  const FX_RECT& src_rect,
318                  int left,
319                  int top,
320                  BlendMode blend_type) override;
321   bool StretchDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
322                      uint32_t color,
323                      int dest_left,
324                      int dest_top,
325                      int dest_width,
326                      int dest_height,
327                      const FX_RECT* pClipRect,
328                      const FXDIB_ResampleOptions& options,
329                      BlendMode blend_type) override;
330   bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap,
331                    int bitmap_alpha,
332                    uint32_t color,
333                    const CFX_Matrix& matrix,
334                    const FXDIB_ResampleOptions& options,
335                    std::unique_ptr<CFX_ImageRenderer>* handle,
336                    BlendMode blend_type) override;
337   bool DrawDeviceText(int nChars,
338                       const TextCharPos* pCharPos,
339                       CFX_Font* pFont,
340                       const CFX_Matrix& mtObject2Device,
341                       float font_size,
342                       uint32_t color) override;
343 
344   HDC m_hDC;
345   const int m_Width;
346   const int m_Height;
347   int m_nBitsPerPixel;
348   const int m_HorzSize;
349   const int m_VertSize;
350   float m_OriginY;
351   bool m_SetOrigin;
352 };
353 #endif  // CORE_FXGE_WIN32_WIN32_INT_H_
354