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