OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" | 7 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
11 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" | 11 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
12 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" | 12 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" |
13 #include "fpdfsdk/include/fsdk_define.h" | 13 #include "fpdfsdk/include/fsdk_define.h" |
14 #include "fpdfsdk/include/fsdk_mgr.h" | 14 #include "fpdfsdk/include/fsdk_mgr.h" |
15 #include "xfa/fxfa/include/xfa_ffdocview.h" | 15 #include "xfa/fxfa/include/xfa_ffdocview.h" |
16 #include "xfa/fxfa/include/xfa_ffpageview.h" | 16 #include "xfa/fxfa/include/xfa_ffpageview.h" |
17 | 17 |
18 CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) | 18 CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) |
19 : m_pPDFPage(NULL), | 19 : m_pXFAPageView(nullptr), |
20 m_pXFAPageView(NULL), | 20 m_pDocument(pDoc), |
21 m_iPageIndex(page_index), | 21 m_iPageIndex(page_index), |
22 m_pDocument(pDoc), | |
23 m_iRef(1) {} | 22 m_iRef(1) {} |
24 | 23 |
25 CPDFXFA_Page::~CPDFXFA_Page() { | 24 CPDFXFA_Page::~CPDFXFA_Page() {} |
26 if (m_pPDFPage) | |
27 delete m_pPDFPage; | |
28 m_pPDFPage = NULL; | |
29 m_pXFAPageView = NULL; | |
30 } | |
31 | 25 |
32 void CPDFXFA_Page::Release() { | 26 void CPDFXFA_Page::Release() { |
33 m_iRef--; | 27 if (--m_iRef > 0) |
34 if (m_iRef > 0) | |
35 return; | 28 return; |
36 | 29 |
37 if (m_pDocument) | 30 if (m_pDocument) |
38 m_pDocument->RemovePage(this); | 31 m_pDocument->RemovePage(this); |
39 | 32 |
40 delete this; | 33 delete this; |
41 } | 34 } |
42 | 35 |
43 FX_BOOL CPDFXFA_Page::LoadPDFPage() { | 36 FX_BOOL CPDFXFA_Page::LoadPDFPage() { |
44 if (!m_pDocument) | 37 if (!m_pDocument) |
45 return FALSE; | 38 return FALSE; |
39 | |
46 CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc(); | 40 CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc(); |
47 if (pPDFDoc) { | 41 if (!pPDFDoc) |
48 CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex); | 42 return FALSE; |
49 if (pDict == NULL) | |
50 return FALSE; | |
51 if (m_pPDFPage) { | |
52 if (m_pPDFPage->m_pFormDict == pDict) | |
53 return TRUE; | |
54 | 43 |
55 delete m_pPDFPage; | 44 CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex); |
56 m_pPDFPage = NULL; | 45 if (!pDict) |
57 } | 46 return FALSE; |
58 | 47 |
59 m_pPDFPage = new CPDF_Page; | 48 if (!m_pPDFPage || m_pPDFPage->m_pFormDict != pDict) { |
49 m_pPDFPage.reset(new CPDF_Page); | |
60 m_pPDFPage->Load(pPDFDoc, pDict); | 50 m_pPDFPage->Load(pPDFDoc, pDict); |
61 m_pPDFPage->ParseContent(nullptr); | 51 m_pPDFPage->ParseContent(nullptr); |
62 return TRUE; | |
63 } | 52 } |
64 | 53 return TRUE; |
65 return FALSE; | |
66 } | 54 } |
67 | 55 |
68 FX_BOOL CPDFXFA_Page::LoadXFAPageView() { | 56 FX_BOOL CPDFXFA_Page::LoadXFAPageView() { |
69 if (!m_pDocument) | 57 if (!m_pDocument) |
70 return FALSE; | 58 return FALSE; |
59 | |
71 CXFA_FFDoc* pXFADoc = m_pDocument->GetXFADoc(); | 60 CXFA_FFDoc* pXFADoc = m_pDocument->GetXFADoc(); |
72 if (!pXFADoc) | 61 if (!pXFADoc) |
73 return FALSE; | 62 return FALSE; |
74 | 63 |
75 CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView(); | 64 CXFA_FFDocView* pXFADocView = m_pDocument->GetXFADocView(); |
76 if (!pXFADocView) | 65 if (!pXFADocView) |
77 return FALSE; | 66 return FALSE; |
78 | 67 |
79 CXFA_FFPageView* pPageView = pXFADocView->GetPageView(m_iPageIndex); | 68 CXFA_FFPageView* pPageView = pXFADocView->GetPageView(m_iPageIndex); |
80 if (!pPageView) | 69 if (!pPageView) |
81 return FALSE; | 70 return FALSE; |
82 | 71 |
83 if (m_pXFAPageView == pPageView) | 72 if (m_pXFAPageView == pPageView) |
84 return TRUE; | 73 return TRUE; |
85 | 74 |
86 m_pXFAPageView = pPageView; | 75 m_pXFAPageView = pPageView; |
87 (void)m_pXFAPageView->LoadPageView(nullptr); | 76 m_pXFAPageView->LoadPageView(nullptr); |
Tom Sepez
2016/04/12 23:40:00
nit: I think this (void) was shorthand for // FIXM
Lei Zhang
2016/04/13 00:56:52
Not worth checking. See next patch set.
| |
88 return TRUE; | 77 return TRUE; |
89 } | 78 } |
90 | 79 |
91 FX_BOOL CPDFXFA_Page::LoadPage() { | 80 FX_BOOL CPDFXFA_Page::LoadPage() { |
92 if (!m_pDocument || m_iPageIndex < 0) | 81 if (!m_pDocument || m_iPageIndex < 0) |
93 return FALSE; | 82 return FALSE; |
94 | 83 |
95 int iDocType = m_pDocument->GetDocType(); | 84 int iDocType = m_pDocument->GetDocType(); |
96 switch (iDocType) { | 85 switch (iDocType) { |
97 case DOCTYPE_PDF: | 86 case DOCTYPE_PDF: |
98 case DOCTYPE_STATIC_XFA: { | 87 case DOCTYPE_STATIC_XFA: { |
99 return LoadPDFPage(); | 88 return LoadPDFPage(); |
100 } | 89 } |
101 case DOCTYPE_DYNAMIC_XFA: { | 90 case DOCTYPE_DYNAMIC_XFA: { |
102 return LoadXFAPageView(); | 91 return LoadXFAPageView(); |
103 } | 92 } |
104 default: | 93 default: |
105 return FALSE; | 94 return FALSE; |
106 } | 95 } |
107 } | 96 } |
108 | 97 |
109 FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { | 98 FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { |
110 if (!m_pDocument || m_iPageIndex < 0 || !pageDict) | 99 if (!m_pDocument || m_iPageIndex < 0 || !pageDict) |
111 return FALSE; | 100 return FALSE; |
112 | 101 |
113 if (m_pPDFPage) | 102 m_pPDFPage.reset(new CPDF_Page()); |
114 delete m_pPDFPage; | |
115 | |
116 m_pPDFPage = new CPDF_Page(); | |
117 m_pPDFPage->Load(m_pDocument->GetPDFDoc(), pageDict); | 103 m_pPDFPage->Load(m_pDocument->GetPDFDoc(), pageDict); |
118 m_pPDFPage->ParseContent(nullptr); | 104 m_pPDFPage->ParseContent(nullptr); |
119 | |
120 return TRUE; | 105 return TRUE; |
121 } | 106 } |
122 | 107 |
123 FX_FLOAT CPDFXFA_Page::GetPageWidth() { | 108 FX_FLOAT CPDFXFA_Page::GetPageWidth() const { |
124 if (!m_pPDFPage && !m_pXFAPageView) | 109 if (!m_pPDFPage && !m_pXFAPageView) |
125 return 0.0f; | 110 return 0.0f; |
126 | 111 |
127 int nDocType = m_pDocument->GetDocType(); | 112 int nDocType = m_pDocument->GetDocType(); |
128 switch (nDocType) { | 113 switch (nDocType) { |
129 case DOCTYPE_DYNAMIC_XFA: { | 114 case DOCTYPE_DYNAMIC_XFA: { |
130 if (m_pXFAPageView) { | 115 if (m_pXFAPageView) { |
131 CFX_RectF rect; | 116 CFX_RectF rect; |
132 m_pXFAPageView->GetPageViewRect(rect); | 117 m_pXFAPageView->GetPageViewRect(rect); |
133 return rect.width; | 118 return rect.width; |
134 } | 119 } |
135 } break; | 120 } break; |
136 case DOCTYPE_STATIC_XFA: | 121 case DOCTYPE_STATIC_XFA: |
137 case DOCTYPE_PDF: { | 122 case DOCTYPE_PDF: { |
138 if (m_pPDFPage) | 123 if (m_pPDFPage) |
139 return m_pPDFPage->GetPageWidth(); | 124 return m_pPDFPage->GetPageWidth(); |
140 } break; | 125 } break; |
141 default: | 126 default: |
142 return 0.0f; | 127 return 0.0f; |
143 } | 128 } |
144 | 129 |
145 return 0.0f; | 130 return 0.0f; |
146 } | 131 } |
147 | 132 |
148 FX_FLOAT CPDFXFA_Page::GetPageHeight() { | 133 FX_FLOAT CPDFXFA_Page::GetPageHeight() const { |
149 if (!m_pPDFPage && !m_pXFAPageView) | 134 if (!m_pPDFPage && !m_pXFAPageView) |
150 return 0.0f; | 135 return 0.0f; |
151 | 136 |
152 int nDocType = m_pDocument->GetDocType(); | 137 int nDocType = m_pDocument->GetDocType(); |
153 switch (nDocType) { | 138 switch (nDocType) { |
154 case DOCTYPE_PDF: | 139 case DOCTYPE_PDF: |
155 case DOCTYPE_STATIC_XFA: { | 140 case DOCTYPE_STATIC_XFA: { |
156 if (m_pPDFPage) | 141 if (m_pPDFPage) |
157 return m_pPDFPage->GetPageHeight(); | 142 return m_pPDFPage->GetPageHeight(); |
158 } break; | 143 } break; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 case DOCTYPE_PDF: | 226 case DOCTYPE_PDF: |
242 case DOCTYPE_STATIC_XFA: { | 227 case DOCTYPE_STATIC_XFA: { |
243 if (m_pPDFPage) { | 228 if (m_pPDFPage) { |
244 m_pPDFPage->GetDisplayMatrix(matrix, xPos, yPos, xSize, ySize, iRotate); | 229 m_pPDFPage->GetDisplayMatrix(matrix, xPos, yPos, xSize, ySize, iRotate); |
245 } | 230 } |
246 } break; | 231 } break; |
247 default: | 232 default: |
248 return; | 233 return; |
249 } | 234 } |
250 } | 235 } |
OLD | NEW |