OLD | NEW |
| (Empty) |
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 #include "xfa/src/fxfa/app/xfa_rendercontext.h" | |
8 | |
9 #include "xfa/include/fxgraphics/fx_graphics.h" | |
10 #include "xfa/src/fxfa/app/xfa_ffwidget.h" | |
11 | |
12 #define XFA_RENDERCONTEXT_MaxCount 30 | |
13 | |
14 IXFA_RenderContext* XFA_RenderContext_Create() { | |
15 return new CXFA_RenderContext; | |
16 } | |
17 CXFA_RenderContext::CXFA_RenderContext() { | |
18 m_pWidgetIterator = NULL; | |
19 m_pWidget = NULL; | |
20 m_pPageView = NULL; | |
21 m_pGS = NULL; | |
22 m_dwStatus = 0; | |
23 m_matrix.SetIdentity(); | |
24 m_rtClipRect.Reset(); | |
25 } | |
26 CXFA_RenderContext::~CXFA_RenderContext() { | |
27 StopRender(); | |
28 } | |
29 int32_t CXFA_RenderContext::StartRender(IXFA_PageView* pPageView, | |
30 CFX_Graphics* pGS, | |
31 const CFX_Matrix& matrix, | |
32 const CXFA_RenderOptions& options) { | |
33 m_pPageView = pPageView; | |
34 m_pGS = pGS; | |
35 m_matrix = matrix; | |
36 m_options = options; | |
37 CFX_RectF rtPage; | |
38 pGS->GetClipRect(rtPage); | |
39 CFX_Matrix mtRes; | |
40 mtRes.SetReverse(matrix); | |
41 m_rtClipRect.Set(rtPage.left, rtPage.top, rtPage.width, rtPage.height); | |
42 mtRes.TransformRect(m_rtClipRect); | |
43 m_dwStatus = m_options.m_bHighlight ? XFA_WIDGETSTATUS_Highlight : 0; | |
44 FX_DWORD dwFilterType = XFA_WIDGETFILTER_Visible | XFA_WIDGETFILTER_AllType | | |
45 (m_options.m_bPrint ? XFA_WIDGETSTATUS_Printable | |
46 : XFA_WIDGETSTATUS_Viewable); | |
47 m_pWidgetIterator = | |
48 m_pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, dwFilterType); | |
49 m_pWidget = m_pWidgetIterator->MoveToNext(); | |
50 return XFA_RENDERSTATUS_Ready; | |
51 } | |
52 int32_t CXFA_RenderContext::DoRender(IFX_Pause* pPause) { | |
53 int32_t iCount = 0; | |
54 while (m_pWidget) { | |
55 CXFA_FFWidget* pWidget = (CXFA_FFWidget*)m_pWidget; | |
56 CFX_RectF rtWidgetBox; | |
57 pWidget->GetBBox(rtWidgetBox, XFA_WIDGETSTATUS_Visible); | |
58 rtWidgetBox.width += 1; | |
59 rtWidgetBox.height += 1; | |
60 if (rtWidgetBox.IntersectWith(m_rtClipRect)) { | |
61 pWidget->RenderWidget(m_pGS, &m_matrix, m_dwStatus); | |
62 } | |
63 m_pWidget = m_pWidgetIterator->MoveToNext(); | |
64 iCount++; | |
65 if (iCount > XFA_RENDERCONTEXT_MaxCount && pPause && | |
66 pPause->NeedToPauseNow()) { | |
67 return XFA_RENDERSTATUS_ToBeContinued; | |
68 } | |
69 } | |
70 return XFA_RENDERSTATUS_Done; | |
71 } | |
72 void CXFA_RenderContext::StopRender() { | |
73 if (m_pWidgetIterator) { | |
74 m_pWidgetIterator->Release(); | |
75 m_pWidgetIterator = NULL; | |
76 } | |
77 } | |
OLD | NEW |