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