Merge to XFA: Fix ALL the include guards.
[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 "../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
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                        SetBackground(class IPDF_BackgroundDraw* pBackground);
100
101     void                        Render(CFX_RenderDevice* pDevice, const CPDF_RenderOptions* pOptions = NULL,
102                            const CFX_AffineMatrix* pFinalMatrix = NULL);
103
104     void                        DrawObjectList(CFX_RenderDevice* pDevice, CPDF_PageObjects* pObjs,
105                                    const CFX_AffineMatrix* pObject2Device, const CPDF_RenderOptions* pOptions);
106
107     void                        GetBackground(CFX_DIBitmap* pBuffer, const CPDF_PageObject* pObj,
108                                   const CPDF_RenderOptions* pOptions, CFX_AffineMatrix* pFinalMatrix);
109
110     CPDF_PageRenderCache*       GetPageCache() const
111     {
112         return m_pPageCache;
113     }
114
115
116
117     CPDF_Document*                      m_pDocument;
118
119     CPDF_Dictionary*            m_pPageResources;
120
121     CPDF_PageRenderCache*       m_pPageCache;
122
123 protected:
124
125     CFX_ArrayTemplate<struct _PDF_RenderItem>   m_ContentList;
126
127     IPDF_BackgroundDraw*        m_pBackgroundDraw;
128
129     FX_BOOL                                     m_bFirstLayer;
130
131     void                        Render(CFX_RenderDevice* pDevice, const CPDF_PageObject* pStopObj,
132                            const CPDF_RenderOptions* pOptions, const CFX_AffineMatrix* pFinalMatrix);
133     friend class CPDF_RenderStatus;
134     friend class CPDF_ProgressiveRenderer;
135 };
136 class IPDF_BackgroundDraw
137 {
138 public:
139     virtual ~IPDF_BackgroundDraw() { }
140     virtual     void    OnDrawBackground(
141         CFX_RenderDevice* pBitmapDevice,
142         const CFX_AffineMatrix* pOriginal2Bitmap
143     ) = 0;
144 };
145 class CPDF_ProgressiveRenderer 
146 {
147 public:
148
149     CPDF_ProgressiveRenderer();
150
151     ~CPDF_ProgressiveRenderer();
152
153     typedef enum {
154         Ready,
155         ToBeContinued,
156         Done,
157         Failed
158     } RenderStatus;
159
160     RenderStatus                GetStatus()
161     {
162         return m_Status;
163     }
164
165
166
167     void                                Start(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice,
168                               const CPDF_RenderOptions* pOptions, class IFX_Pause* pPause, FX_BOOL bDropObjects = FALSE);
169
170     void                                Continue(class IFX_Pause* pPause);
171
172
173     int                                 EstimateProgress();
174
175     void                                Clear();
176 protected:
177
178     RenderStatus                m_Status;
179
180     CPDF_RenderContext* m_pContext;
181
182     CFX_RenderDevice*   m_pDevice;
183
184     const CPDF_RenderOptions*   m_pOptions;
185
186     FX_BOOL                             m_bDropObjects;
187
188     class CPDF_RenderStatus*    m_pRenderer;
189
190     CFX_FloatRect               m_ClipRect;
191
192     FX_DWORD                    m_LayerIndex;
193
194     FX_DWORD                    m_ObjectIndex;
195
196     FX_POSITION                 m_ObjectPos;
197
198     FX_POSITION                 m_PrevLastPos;
199
200     void                                RenderStep();
201 };
202 class CPDF_TextRenderer 
203 {
204 public:
205
206     static void         DrawTextString(CFX_RenderDevice* pDevice, int left, int top,
207                                    CPDF_Font* pFont,
208                                    int height,
209                                    const CFX_ByteString& str,
210                                    FX_ARGB argb);
211
212     static void         DrawTextString(CFX_RenderDevice* pDevice, FX_FLOAT origin_x, FX_FLOAT origin_y,
213                                    CPDF_Font* pFont,
214                                    FX_FLOAT font_size,
215                                    const CFX_AffineMatrix* matrix,
216                                    const CFX_ByteString& str,
217                                    FX_ARGB fill_argb,
218                                    FX_ARGB stroke_argb = 0,
219                                    const CFX_GraphStateData* pGraphState = NULL,
220                                    const CPDF_RenderOptions* pOptions = NULL
221                                );
222
223     static FX_BOOL      DrawTextPath(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos,
224                                  CPDF_Font* pFont, FX_FLOAT font_size,
225                                  const CFX_AffineMatrix* pText2User, const CFX_AffineMatrix* pUser2Device,
226                                  const CFX_GraphStateData* pGraphState,
227                                  FX_ARGB fill_argb, FX_ARGB stroke_argb, CFX_PathData* pClippingPath, int nFlag = 0);
228
229     static FX_BOOL      DrawNormalText(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos,
230                                    CPDF_Font* pFont, FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device,
231                                    FX_ARGB fill_argb, const CPDF_RenderOptions* pOptions);
232
233     static FX_BOOL      DrawType3Text(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos,
234                                   CPDF_Font* pFont, FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device,
235                                   FX_ARGB fill_argb);
236 };
237 class IPDF_PageImageCache
238 {
239 public:
240
241     static IPDF_PageImageCache* Create();
242
243     virtual ~IPDF_PageImageCache() {}
244
245     virtual void                OutputPage(CFX_RenderDevice* pDevice, CPDF_Page* pPage,
246                                    int pos_x, int pos_y, int size_x, int size_y, int rotate) = 0;
247
248     virtual void                SetCacheLimit(FX_DWORD limit) = 0;
249 };
250 class CPDF_PageRenderCache 
251 {
252 public:
253     CPDF_PageRenderCache(CPDF_Page* pPage)
254     {
255         m_pPage = pPage;
256         m_nTimeCount = 0;
257         m_nCacheSize = 0;
258         m_pCurImageCache = NULL;
259         m_bCurFindCache = FALSE;
260         m_pCurImageCaches = NULL;
261     }
262     ~CPDF_PageRenderCache()
263     {
264         ClearAll();
265     }
266     void                                ClearAll();
267     void                                ClearImageData();
268
269     FX_DWORD                    EstimateSize();
270     void                                CacheOptimization(FX_INT32 dwLimitCacheSize);
271     FX_DWORD                    GetCachedSize(CPDF_Stream* pStream) const;
272     FX_DWORD                    GetTimeCount() const
273     {
274         return m_nTimeCount;
275     }
276     void                                SetTimeCount(FX_DWORD dwTimeCount)
277     {
278         m_nTimeCount = dwTimeCount;
279     }
280
281     void                                GetCachedBitmap(CPDF_Stream* pStream, CFX_DIBSource*& pBitmap, CFX_DIBSource*& pMask, FX_DWORD& MatteColor,
282                                         FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0, FX_BOOL bLoadMask = FALSE,
283                                         CPDF_RenderStatus* pRenderStatus = NULL, FX_INT32 downsampleWidth = 0, FX_INT32 downsampleHeight = 0);
284
285     void                                ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap* pBitmap);
286     void                                ClearImageCache(CPDF_Stream* pStream);
287     CPDF_Page*                  GetPage()
288     {
289         return m_pPage;
290     }
291     CFX_MapPtrToPtr             m_ImageCaches;
292 public:
293     FX_BOOL                             StartGetCachedBitmap(CPDF_Stream* pStream, FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0,
294             FX_BOOL bLoadMask = FALSE, CPDF_RenderStatus* pRenderStatus = NULL,
295             FX_INT32 downsampleWidth = 0, FX_INT32 downsampleHeight = 0);
296
297     FX_BOOL                             Continue(IFX_Pause* pPause);
298     CPDF_ImageCache*    m_pCurImageCache;
299     CFX_PtrArray*       m_pCurImageCaches;
300 protected:
301     friend class                CPDF_Page;
302     CPDF_Page*                  m_pPage;
303
304     FX_DWORD                    m_nTimeCount;
305     FX_DWORD                    m_nCacheSize;
306     FX_BOOL                             m_bCurFindCache;
307 };
308 class CPDF_RenderConfig 
309 {
310 public:
311     CPDF_RenderConfig();
312     ~CPDF_RenderConfig();
313     int                                 m_HalftoneLimit;
314     int                                 m_RenderStepLimit;
315 };
316
317 #endif  // CORE_INCLUDE_FPDFAPI_FPDF_RENDER_H_