• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_CFX_PSRENDERER_H_
8 #define CORE_FXGE_WIN32_CFX_PSRENDERER_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_coordinates.h"
14 #include "core/fxcrt/fx_system.h"
15 #include "core/fxge/cfx_graphstatedata.h"
16 #include "core/fxge/win32/cpsoutput.h"
17 
18 class CFX_DIBSource;
19 class CFX_FaceCache;
20 class CFX_Font;
21 class CFX_FontCache;
22 class CFX_Matrix;
23 class CFX_PathData;
24 class CPSFont;
25 class FXTEXT_CHARPOS;
26 
27 class CFX_PSRenderer {
28  public:
29   CFX_PSRenderer();
30   ~CFX_PSRenderer();
31 
32   void Init(CPSOutput* pOutput,
33             int pslevel,
34             int width,
35             int height,
36             bool bCmykOutput);
37   bool StartRendering();
38   void EndRendering();
39   void SaveState();
40   void RestoreState(bool bKeepSaved);
41   void SetClip_PathFill(const CFX_PathData* pPathData,
42                         const CFX_Matrix* pObject2Device,
43                         int fill_mode);
44   void SetClip_PathStroke(const CFX_PathData* pPathData,
45                           const CFX_Matrix* pObject2Device,
46                           const CFX_GraphStateData* pGraphState);
GetClipBox()47   FX_RECT GetClipBox() { return m_ClipBox; }
48   bool DrawPath(const CFX_PathData* pPathData,
49                 const CFX_Matrix* pObject2Device,
50                 const CFX_GraphStateData* pGraphState,
51                 uint32_t fill_color,
52                 uint32_t stroke_color,
53                 int fill_mode);
54   bool SetDIBits(const CFX_DIBSource* pBitmap,
55                  uint32_t color,
56                  int dest_left,
57                  int dest_top);
58   bool StretchDIBits(const CFX_DIBSource* pBitmap,
59                      uint32_t color,
60                      int dest_left,
61                      int dest_top,
62                      int dest_width,
63                      int dest_height,
64                      uint32_t flags);
65   bool DrawDIBits(const CFX_DIBSource* pBitmap,
66                   uint32_t color,
67                   const CFX_Matrix* pMatrix,
68                   uint32_t flags);
69   bool DrawText(int nChars,
70                 const FXTEXT_CHARPOS* pCharPos,
71                 CFX_Font* pFont,
72                 const CFX_Matrix* pObject2Device,
73                 FX_FLOAT font_size,
74                 uint32_t color);
75 
76  private:
77   void OutputPath(const CFX_PathData* pPathData,
78                   const CFX_Matrix* pObject2Device);
79   void SetGraphState(const CFX_GraphStateData* pGraphState);
80   void SetColor(uint32_t color);
81   void FindPSFontGlyph(CFX_FaceCache* pFaceCache,
82                        CFX_Font* pFont,
83                        const FXTEXT_CHARPOS& charpos,
84                        int* ps_fontnum,
85                        int* ps_glyphindex);
86   void WritePSBinary(const uint8_t* data, int len);
87 
88   CPSOutput* m_pOutput;
89   int m_PSLevel;
90   CFX_GraphStateData m_CurGraphState;
91   bool m_bGraphStateSet;
92   bool m_bCmykOutput;
93   bool m_bColorSet;
94   uint32_t m_LastColor;
95   FX_RECT m_ClipBox;
96   std::vector<std::unique_ptr<CPSFont>> m_PSFontList;
97   std::vector<FX_RECT> m_ClipBoxStack;
98   bool m_bInited;
99 };
100 
101 #endif  // CORE_FXGE_WIN32_CFX_PSRENDERER_H_
102