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