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_INCLUDE_FPDFAPI_FPDF_RENDER_H_
8 #define CORE_INCLUDE_FPDFAPI_FPDF_RENDER_H_
9 
10 #include "../fxge/fx_ge.h"
11 #include "fpdf_page.h"
12 
13 class CPDF_RenderContext;
14 class CPDF_RenderOptions;
15 class CPDF_ImageCache;
16 class IPDF_OCContext;
17 class CPDF_QuickStretcher;
18 class CFX_PathData;
19 class CFX_GraphStateData;
20 class CFX_RenderDevice;
21 class CPDF_TextObject;
22 class CPDF_PathObject;
23 class CPDF_ImageObject;
24 class CPDF_ShadingObject;
25 class CPDF_FormObject;
26 class IPDF_OCContext
27 {
28 public:
29 
~IPDF_OCContext()30     virtual ~IPDF_OCContext() {}
31 
32     virtual FX_BOOL	CheckOCGVisible(const CPDF_Dictionary* pOCG) = 0;
33 
34     FX_BOOL CheckObjectVisible(const CPDF_PageObject* pObj);
35 };
36 #define RENDER_COLOR_NORMAL		0
37 #define RENDER_COLOR_GRAY		1
38 #define RENDER_COLOR_TWOCOLOR	2
39 #define RENDER_COLOR_ALPHA		3
40 #define RENDER_CLEARTYPE			0x00000001
41 #define RENDER_PRINTGRAPHICTEXT		0x00000002
42 #define RENDER_FORCE_DOWNSAMPLE		0x00000004
43 #define RENDER_PRINTPREVIEW			0x00000008
44 #define RENDER_BGR_STRIPE			0x00000010
45 #define RENDER_NO_NATIVETEXT		0x00000020
46 #define RENDER_FORCE_HALFTONE		0x00000040
47 #define RENDER_RECT_AA				0x00000080
48 #define RENDER_FILL_FULLCOVER		0x00000100
49 #define RENDER_PRINTIMAGETEXT       0x00000200
50 #define RENDER_OVERPRINT            0x00000400
51 #define RENDER_THINLINE             0x00000800
52 #define RENDER_NOTEXTSMOOTH			0x10000000
53 #define RENDER_NOPATHSMOOTH			0x20000000
54 #define RENDER_NOIMAGESMOOTH		0x40000000
55 #define RENDER_LIMITEDIMAGECACHE	0x80000000
56 class CPDF_RenderOptions
57 {
58 public:
59 
60     CPDF_RenderOptions();
61 
62     int				m_ColorMode;
63 
64     FX_COLORREF		m_BackColor;
65 
66     FX_COLORREF		m_ForeColor;
67 
68     FX_DWORD		m_Flags;
69 
70     int				m_Interpolation;
71 
72     FX_DWORD		m_AddFlags;
73 
74     IPDF_OCContext*	m_pOCContext;
75 
76     FX_DWORD		m_dwLimitCacheSize;
77 
78     int				m_HalftoneLimit;
79 
80     FX_ARGB			TranslateColor(FX_ARGB argb) const;
81 };
82 class CPDF_RenderContext
83 {
84 public:
85 
86     CPDF_RenderContext();
87 
88     void			Create(CPDF_Page* pPage, FX_BOOL bFirstLayer = TRUE);
89 
90     void			Create(CPDF_Document* pDoc = NULL, CPDF_PageRenderCache* pPageCache = NULL,
91                            CPDF_Dictionary* pPageResources = NULL, FX_BOOL bFirstLayer = TRUE);
92 
93     ~CPDF_RenderContext();
94 
95     void			Clear();
96 
97     void			AppendObjectList(CPDF_PageObjects* pObjs, const CFX_AffineMatrix* pObject2Device);
98 
99     void			Render(CFX_RenderDevice* pDevice, const CPDF_RenderOptions* pOptions = NULL,
100                            const CFX_AffineMatrix* pFinalMatrix = NULL);
101 
102     void			DrawObjectList(CFX_RenderDevice* pDevice, CPDF_PageObjects* pObjs,
103                                    const CFX_AffineMatrix* pObject2Device, const CPDF_RenderOptions* pOptions);
104 
105     void			GetBackground(CFX_DIBitmap* pBuffer, const CPDF_PageObject* pObj,
106                                   const CPDF_RenderOptions* pOptions, CFX_AffineMatrix* pFinalMatrix);
107 
GetPageCache()108     CPDF_PageRenderCache*	GetPageCache() const
109     {
110         return m_pPageCache;
111     }
112 
113 
114 
115     CPDF_Document*			m_pDocument;
116 
117     CPDF_Dictionary*		m_pPageResources;
118 
119     CPDF_PageRenderCache*	m_pPageCache;
120 
121 protected:
122 
123     CFX_ArrayTemplate<struct _PDF_RenderItem>	m_ContentList;
124 
125     FX_BOOL					m_bFirstLayer;
126 
127     void			Render(CFX_RenderDevice* pDevice, const CPDF_PageObject* pStopObj,
128                            const CPDF_RenderOptions* pOptions, const CFX_AffineMatrix* pFinalMatrix);
129     friend class CPDF_RenderStatus;
130     friend class CPDF_ProgressiveRenderer;
131 };
132 class CPDF_ProgressiveRenderer
133 {
134 public:
135 
136     CPDF_ProgressiveRenderer();
137 
138     ~CPDF_ProgressiveRenderer();
139 
140     typedef enum {
141         Ready,
142         ToBeContinued,
143         Done,
144         Failed
145     } RenderStatus;
146 
GetStatus()147     RenderStatus		GetStatus()
148     {
149         return m_Status;
150     }
151 
152 
153 
154     void				Start(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice,
155                               const CPDF_RenderOptions* pOptions, class IFX_Pause* pPause, FX_BOOL bDropObjects = FALSE);
156 
157     void				Continue(class IFX_Pause* pPause);
158 
159 
160     int					EstimateProgress();
161 
162     void				Clear();
163 protected:
164 
165     RenderStatus		m_Status;
166 
167     CPDF_RenderContext*	m_pContext;
168 
169     CFX_RenderDevice*	m_pDevice;
170 
171     const CPDF_RenderOptions*	m_pOptions;
172 
173     FX_BOOL				m_bDropObjects;
174 
175     class CPDF_RenderStatus*	m_pRenderer;
176 
177     CFX_FloatRect		m_ClipRect;
178 
179     FX_DWORD			m_LayerIndex;
180 
181     FX_DWORD			m_ObjectIndex;
182 
183     FX_POSITION			m_ObjectPos;
184 
185     FX_POSITION			m_PrevLastPos;
186 
187     void				RenderStep();
188 };
189 class CPDF_TextRenderer
190 {
191 public:
192 
193     static void		DrawTextString(CFX_RenderDevice* pDevice, int left, int top,
194                                    CPDF_Font* pFont,
195                                    int height,
196                                    const CFX_ByteString& str,
197                                    FX_ARGB argb);
198 
199     static void		DrawTextString(CFX_RenderDevice* pDevice, FX_FLOAT origin_x, FX_FLOAT origin_y,
200                                    CPDF_Font* pFont,
201                                    FX_FLOAT font_size,
202                                    const CFX_AffineMatrix* matrix,
203                                    const CFX_ByteString& str,
204                                    FX_ARGB fill_argb,
205                                    FX_ARGB stroke_argb = 0,
206                                    const CFX_GraphStateData* pGraphState = NULL,
207                                    const CPDF_RenderOptions* pOptions = NULL
208                                );
209 
210     static FX_BOOL	DrawTextPath(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos,
211                                  CPDF_Font* pFont, FX_FLOAT font_size,
212                                  const CFX_AffineMatrix* pText2User, const CFX_AffineMatrix* pUser2Device,
213                                  const CFX_GraphStateData* pGraphState,
214                                  FX_ARGB fill_argb, FX_ARGB stroke_argb, CFX_PathData* pClippingPath, int nFlag = 0);
215 
216     static FX_BOOL	DrawNormalText(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos,
217                                    CPDF_Font* pFont, FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device,
218                                    FX_ARGB fill_argb, const CPDF_RenderOptions* pOptions);
219 
220     static FX_BOOL	DrawType3Text(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos,
221                                   CPDF_Font* pFont, FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device,
222                                   FX_ARGB fill_argb);
223 };
224 class CPDF_PageRenderCache
225 {
226 public:
CPDF_PageRenderCache(CPDF_Page * pPage)227     CPDF_PageRenderCache(CPDF_Page* pPage)
228     {
229         m_pPage = pPage;
230         m_nTimeCount = 0;
231         m_nCacheSize = 0;
232         m_pCurImageCache = NULL;
233         m_bCurFindCache = FALSE;
234         m_pCurImageCaches = NULL;
235     }
~CPDF_PageRenderCache()236     ~CPDF_PageRenderCache()
237     {
238         ClearAll();
239     }
240     void				ClearAll();
241     void				ClearImageData();
242 
243     FX_DWORD			EstimateSize();
244     void				CacheOptimization(FX_INT32 dwLimitCacheSize);
245     FX_DWORD			GetCachedSize(CPDF_Stream* pStream) const;
GetTimeCount()246     FX_DWORD			GetTimeCount() const
247     {
248         return m_nTimeCount;
249     }
SetTimeCount(FX_DWORD dwTimeCount)250     void				SetTimeCount(FX_DWORD dwTimeCount)
251     {
252         m_nTimeCount = dwTimeCount;
253     }
254 
255     void				GetCachedBitmap(CPDF_Stream* pStream, CFX_DIBSource*& pBitmap, CFX_DIBSource*& pMask, FX_DWORD& MatteColor,
256                                         FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0, FX_BOOL bLoadMask = FALSE,
257                                         CPDF_RenderStatus* pRenderStatus = NULL, FX_INT32 downsampleWidth = 0, FX_INT32 downsampleHeight = 0);
258 
259     void				ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap* pBitmap);
260     void				ClearImageCache(CPDF_Stream* pStream);
GetPage()261     CPDF_Page*			GetPage()
262     {
263         return m_pPage;
264     }
265     CFX_MapPtrToPtr		m_ImageCaches;
266 public:
267     FX_BOOL				StartGetCachedBitmap(CPDF_Stream* pStream, FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0,
268             FX_BOOL bLoadMask = FALSE, CPDF_RenderStatus* pRenderStatus = NULL,
269             FX_INT32 downsampleWidth = 0, FX_INT32 downsampleHeight = 0);
270 
271     FX_BOOL				Continue(IFX_Pause* pPause);
272     CPDF_ImageCache*	m_pCurImageCache;
273     CFX_PtrArray*       m_pCurImageCaches;
274 protected:
275     friend class		CPDF_Page;
276     CPDF_Page*			m_pPage;
277 
278     FX_DWORD			m_nTimeCount;
279     FX_DWORD			m_nCacheSize;
280     FX_BOOL				m_bCurFindCache;
281 };
282 class CPDF_RenderConfig
283 {
284 public:
285     CPDF_RenderConfig();
286     ~CPDF_RenderConfig();
287     int					m_HalftoneLimit;
288     int					m_RenderStepLimit;
289 };
290 
291 #endif  // CORE_INCLUDE_FPDFAPI_FPDF_RENDER_H_
292