| 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) | |
| 84 return TRUE; | |
| 85 | |
| 86 m_pXFAPageView = pPageView; | 72 m_pXFAPageView = pPageView; |
| 87 (void)m_pXFAPageView->LoadPageView(nullptr); | |
| 88 return TRUE; | 73 return TRUE; |
| 89 } | 74 } |
| 90 | 75 |
| 91 FX_BOOL CPDFXFA_Page::LoadPage() { | 76 FX_BOOL CPDFXFA_Page::LoadPage() { |
| 92 if (!m_pDocument || m_iPageIndex < 0) | 77 if (!m_pDocument || m_iPageIndex < 0) |
| 93 return FALSE; | 78 return FALSE; |
| 94 | 79 |
| 95 int iDocType = m_pDocument->GetDocType(); | 80 int iDocType = m_pDocument->GetDocType(); |
| 96 switch (iDocType) { | 81 switch (iDocType) { |
| 97 case DOCTYPE_PDF: | 82 case DOCTYPE_PDF: |
| 98 case DOCTYPE_STATIC_XFA: { | 83 case DOCTYPE_STATIC_XFA: { |
| 99 return LoadPDFPage(); | 84 return LoadPDFPage(); |
| 100 } | 85 } |
| 101 case DOCTYPE_DYNAMIC_XFA: { | 86 case DOCTYPE_DYNAMIC_XFA: { |
| 102 return LoadXFAPageView(); | 87 return LoadXFAPageView(); |
| 103 } | 88 } |
| 104 default: | 89 default: |
| 105 return FALSE; | 90 return FALSE; |
| 106 } | 91 } |
| 107 } | 92 } |
| 108 | 93 |
| 109 FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { | 94 FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { |
| 110 if (!m_pDocument || m_iPageIndex < 0 || !pageDict) | 95 if (!m_pDocument || m_iPageIndex < 0 || !pageDict) |
| 111 return FALSE; | 96 return FALSE; |
| 112 | 97 |
| 113 if (m_pPDFPage) | 98 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); | 99 m_pPDFPage->Load(m_pDocument->GetPDFDoc(), pageDict); |
| 118 m_pPDFPage->ParseContent(nullptr); | 100 m_pPDFPage->ParseContent(nullptr); |
| 119 | |
| 120 return TRUE; | 101 return TRUE; |
| 121 } | 102 } |
| 122 | 103 |
| 123 FX_FLOAT CPDFXFA_Page::GetPageWidth() { | 104 FX_FLOAT CPDFXFA_Page::GetPageWidth() const { |
| 124 if (!m_pPDFPage && !m_pXFAPageView) | 105 if (!m_pPDFPage && !m_pXFAPageView) |
| 125 return 0.0f; | 106 return 0.0f; |
| 126 | 107 |
| 127 int nDocType = m_pDocument->GetDocType(); | 108 int nDocType = m_pDocument->GetDocType(); |
| 128 switch (nDocType) { | 109 switch (nDocType) { |
| 129 case DOCTYPE_DYNAMIC_XFA: { | 110 case DOCTYPE_DYNAMIC_XFA: { |
| 130 if (m_pXFAPageView) { | 111 if (m_pXFAPageView) { |
| 131 CFX_RectF rect; | 112 CFX_RectF rect; |
| 132 m_pXFAPageView->GetPageViewRect(rect); | 113 m_pXFAPageView->GetPageViewRect(rect); |
| 133 return rect.width; | 114 return rect.width; |
| 134 } | 115 } |
| 135 } break; | 116 } break; |
| 136 case DOCTYPE_STATIC_XFA: | 117 case DOCTYPE_STATIC_XFA: |
| 137 case DOCTYPE_PDF: { | 118 case DOCTYPE_PDF: { |
| 138 if (m_pPDFPage) | 119 if (m_pPDFPage) |
| 139 return m_pPDFPage->GetPageWidth(); | 120 return m_pPDFPage->GetPageWidth(); |
| 140 } break; | 121 } break; |
| 141 default: | 122 default: |
| 142 return 0.0f; | 123 return 0.0f; |
| 143 } | 124 } |
| 144 | 125 |
| 145 return 0.0f; | 126 return 0.0f; |
| 146 } | 127 } |
| 147 | 128 |
| 148 FX_FLOAT CPDFXFA_Page::GetPageHeight() { | 129 FX_FLOAT CPDFXFA_Page::GetPageHeight() const { |
| 149 if (!m_pPDFPage && !m_pXFAPageView) | 130 if (!m_pPDFPage && !m_pXFAPageView) |
| 150 return 0.0f; | 131 return 0.0f; |
| 151 | 132 |
| 152 int nDocType = m_pDocument->GetDocType(); | 133 int nDocType = m_pDocument->GetDocType(); |
| 153 switch (nDocType) { | 134 switch (nDocType) { |
| 154 case DOCTYPE_PDF: | 135 case DOCTYPE_PDF: |
| 155 case DOCTYPE_STATIC_XFA: { | 136 case DOCTYPE_STATIC_XFA: { |
| 156 if (m_pPDFPage) | 137 if (m_pPDFPage) |
| 157 return m_pPDFPage->GetPageHeight(); | 138 return m_pPDFPage->GetPageHeight(); |
| 158 } break; | 139 } break; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 case DOCTYPE_PDF: | 222 case DOCTYPE_PDF: |
| 242 case DOCTYPE_STATIC_XFA: { | 223 case DOCTYPE_STATIC_XFA: { |
| 243 if (m_pPDFPage) { | 224 if (m_pPDFPage) { |
| 244 m_pPDFPage->GetDisplayMatrix(matrix, xPos, yPos, xSize, ySize, iRotate); | 225 m_pPDFPage->GetDisplayMatrix(matrix, xPos, yPos, xSize, ySize, iRotate); |
| 245 } | 226 } |
| 246 } break; | 227 } break; |
| 247 default: | 228 default: |
| 248 return; | 229 return; |
| 249 } | 230 } |
| 250 } | 231 } |
| OLD | NEW |