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 "fpdfsdk/fpdfxfa/fpdfxfa_page.h" | |
8 | |
9 #include "core/fpdfapi/page/cpdf_page.h" | |
10 #include "core/fpdfapi/parser/cpdf_document.h" | |
11 #include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" | |
12 #include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" | |
13 #include "fpdfsdk/fsdk_define.h" | |
14 #include "public/fpdf_formfill.h" | |
15 #include "third_party/base/ptr_util.h" | |
16 #include "xfa/fxfa/xfa_ffdocview.h" | |
17 #include "xfa/fxfa/xfa_ffpageview.h" | |
18 | |
19 CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) | |
20 : m_pXFAPageView(nullptr), | |
21 m_pDocument(pDoc), | |
22 m_iPageIndex(page_index), | |
23 m_iRef(1) {} | |
24 | |
25 CPDFXFA_Page::~CPDFXFA_Page() { | |
26 if (m_pDocument) | |
27 m_pDocument->RemovePage(this); | |
28 } | |
29 | |
30 FX_BOOL CPDFXFA_Page::LoadPDFPage() { | |
31 if (!m_pDocument) | |
32 return FALSE; | |
33 | |
34 CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc(); | |
35 if (!pPDFDoc) | |
36 return FALSE; | |
37 | |
38 CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex); | |
39 if (!pDict) | |
40 return FALSE; | |
41 | |
42 if (!m_pPDFPage || m_pPDFPage->m_pFormDict != pDict) { | |
43 m_pPDFPage = pdfium::MakeUnique<CPDF_Page>(pPDFDoc, pDict, true); | |
44 m_pPDFPage->ParseContent(); | |
45 } | |
46 return TRUE; | |
47 } | |
48 | |
49 FX_BOOL CPDFXFA_Page::LoadXFAPageView() { | |
50 if (!m_pDocument) | |
51 return FALSE; | |
52 | |
53 CXFA_FFDoc* pXFADoc = m_pDocument->GetXFADoc(); | |
54 if (!pXFADoc) | |
55 return FALSE; | |
56 | |
57 CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView(); | |
58 if (!pXFADocView) | |
59 return FALSE; | |
60 | |
61 CXFA_FFPageView* pPageView = pXFADocView->GetPageView(m_iPageIndex); | |
62 if (!pPageView) | |
63 return FALSE; | |
64 | |
65 m_pXFAPageView = pPageView; | |
66 return TRUE; | |
67 } | |
68 | |
69 FX_BOOL CPDFXFA_Page::LoadPage() { | |
70 if (!m_pDocument || m_iPageIndex < 0) | |
71 return FALSE; | |
72 | |
73 int iDocType = m_pDocument->GetDocType(); | |
74 switch (iDocType) { | |
75 case DOCTYPE_PDF: | |
76 case DOCTYPE_STATIC_XFA: { | |
77 return LoadPDFPage(); | |
78 } | |
79 case DOCTYPE_DYNAMIC_XFA: { | |
80 return LoadXFAPageView(); | |
81 } | |
82 default: | |
83 return FALSE; | |
84 } | |
85 } | |
86 | |
87 FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { | |
88 if (!m_pDocument || m_iPageIndex < 0 || !pageDict) | |
89 return FALSE; | |
90 | |
91 m_pPDFPage = | |
92 pdfium::MakeUnique<CPDF_Page>(m_pDocument->GetPDFDoc(), pageDict, true); | |
93 m_pPDFPage->ParseContent(); | |
94 return TRUE; | |
95 } | |
96 | |
97 FX_FLOAT CPDFXFA_Page::GetPageWidth() const { | |
98 if (!m_pPDFPage && !m_pXFAPageView) | |
99 return 0.0f; | |
100 | |
101 int nDocType = m_pDocument->GetDocType(); | |
102 switch (nDocType) { | |
103 case DOCTYPE_DYNAMIC_XFA: { | |
104 if (m_pXFAPageView) { | |
105 CFX_RectF rect; | |
106 m_pXFAPageView->GetPageViewRect(rect); | |
107 return rect.width; | |
108 } | |
109 } break; | |
110 case DOCTYPE_STATIC_XFA: | |
111 case DOCTYPE_PDF: { | |
112 if (m_pPDFPage) | |
113 return m_pPDFPage->GetPageWidth(); | |
114 } break; | |
115 default: | |
116 return 0.0f; | |
117 } | |
118 | |
119 return 0.0f; | |
120 } | |
121 | |
122 FX_FLOAT CPDFXFA_Page::GetPageHeight() const { | |
123 if (!m_pPDFPage && !m_pXFAPageView) | |
124 return 0.0f; | |
125 | |
126 int nDocType = m_pDocument->GetDocType(); | |
127 switch (nDocType) { | |
128 case DOCTYPE_PDF: | |
129 case DOCTYPE_STATIC_XFA: { | |
130 if (m_pPDFPage) | |
131 return m_pPDFPage->GetPageHeight(); | |
132 } break; | |
133 case DOCTYPE_DYNAMIC_XFA: { | |
134 if (m_pXFAPageView) { | |
135 CFX_RectF rect; | |
136 m_pXFAPageView->GetPageViewRect(rect); | |
137 return rect.height; | |
138 } | |
139 } break; | |
140 default: | |
141 return 0.0f; | |
142 } | |
143 | |
144 return 0.0f; | |
145 } | |
146 | |
147 void CPDFXFA_Page::DeviceToPage(int start_x, | |
148 int start_y, | |
149 int size_x, | |
150 int size_y, | |
151 int rotate, | |
152 int device_x, | |
153 int device_y, | |
154 double* page_x, | |
155 double* page_y) { | |
156 if (!m_pPDFPage && !m_pXFAPageView) | |
157 return; | |
158 | |
159 CFX_Matrix page2device; | |
160 CFX_Matrix device2page; | |
161 FX_FLOAT page_x_f, page_y_f; | |
162 | |
163 GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); | |
164 | |
165 device2page.SetReverse(page2device); | |
166 device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, | |
167 page_y_f); | |
168 | |
169 *page_x = (page_x_f); | |
170 *page_y = (page_y_f); | |
171 } | |
172 | |
173 void CPDFXFA_Page::PageToDevice(int start_x, | |
174 int start_y, | |
175 int size_x, | |
176 int size_y, | |
177 int rotate, | |
178 double page_x, | |
179 double page_y, | |
180 int* device_x, | |
181 int* device_y) { | |
182 if (!m_pPDFPage && !m_pXFAPageView) | |
183 return; | |
184 | |
185 CFX_Matrix page2device; | |
186 FX_FLOAT device_x_f, device_y_f; | |
187 | |
188 GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); | |
189 | |
190 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, | |
191 device_y_f); | |
192 | |
193 *device_x = FXSYS_round(device_x_f); | |
194 *device_y = FXSYS_round(device_y_f); | |
195 } | |
196 | |
197 void CPDFXFA_Page::GetDisplayMatrix(CFX_Matrix& matrix, | |
198 int xPos, | |
199 int yPos, | |
200 int xSize, | |
201 int ySize, | |
202 int iRotate) const { | |
203 if (!m_pPDFPage && !m_pXFAPageView) | |
204 return; | |
205 | |
206 int nDocType = m_pDocument->GetDocType(); | |
207 switch (nDocType) { | |
208 case DOCTYPE_DYNAMIC_XFA: { | |
209 if (m_pXFAPageView) { | |
210 CFX_Rect rect; | |
211 rect.Set(xPos, yPos, xSize, ySize); | |
212 m_pXFAPageView->GetDisplayMatrix(matrix, rect, iRotate); | |
213 } | |
214 } break; | |
215 case DOCTYPE_PDF: | |
216 case DOCTYPE_STATIC_XFA: { | |
217 if (m_pPDFPage) { | |
218 m_pPDFPage->GetDisplayMatrix(matrix, xPos, yPos, xSize, ySize, iRotate); | |
219 } | |
220 } break; | |
221 default: | |
222 return; | |
223 } | |
224 } | |
OLD | NEW |