From 9f3dbbc54c6981f069b57e6714393ac6c0c64231 Mon Sep 17 00:00:00 2001 From: thestig Date: Wed, 13 Apr 2016 13:18:21 -0700 Subject: Cleanup CPDFXFA_Page. - Use std::unique_ptr. - Make dtor protected. - Simplify logic. - Remove unused bits from CXFA_FFPageView as well. Review URL: https://codereview.chromium.org/1878963004 --- fpdfsdk/fpdfxfa/fpdfxfa_page.cpp | 53 +++++++++++++--------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) (limited to 'fpdfsdk/fpdfxfa/fpdfxfa_page.cpp') diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp index 8179db5c11..8c0d6bbf98 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp @@ -16,22 +16,15 @@ #include "xfa/fxfa/include/xfa_ffpageview.h" CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) - : m_pPDFPage(NULL), - m_pXFAPageView(NULL), - m_iPageIndex(page_index), + : m_pXFAPageView(nullptr), m_pDocument(pDoc), + m_iPageIndex(page_index), m_iRef(1) {} -CPDFXFA_Page::~CPDFXFA_Page() { - if (m_pPDFPage) - delete m_pPDFPage; - m_pPDFPage = NULL; - m_pXFAPageView = NULL; -} +CPDFXFA_Page::~CPDFXFA_Page() {} void CPDFXFA_Page::Release() { - m_iRef--; - if (m_iRef > 0) + if (--m_iRef > 0) return; if (m_pDocument) @@ -43,31 +36,27 @@ void CPDFXFA_Page::Release() { FX_BOOL CPDFXFA_Page::LoadPDFPage() { if (!m_pDocument) return FALSE; + CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc(); - if (pPDFDoc) { - CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex); - if (pDict == NULL) - return FALSE; - if (m_pPDFPage) { - if (m_pPDFPage->m_pFormDict == pDict) - return TRUE; + if (!pPDFDoc) + return FALSE; - delete m_pPDFPage; - m_pPDFPage = NULL; - } + CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex); + if (!pDict) + return FALSE; - m_pPDFPage = new CPDF_Page; + if (!m_pPDFPage || m_pPDFPage->m_pFormDict != pDict) { + m_pPDFPage.reset(new CPDF_Page); m_pPDFPage->Load(pPDFDoc, pDict); m_pPDFPage->ParseContent(nullptr); - return TRUE; } - - return FALSE; + return TRUE; } FX_BOOL CPDFXFA_Page::LoadXFAPageView() { if (!m_pDocument) return FALSE; + CXFA_FFDoc* pXFADoc = m_pDocument->GetXFADoc(); if (!pXFADoc) return FALSE; @@ -80,11 +69,7 @@ FX_BOOL CPDFXFA_Page::LoadXFAPageView() { if (!pPageView) return FALSE; - if (m_pXFAPageView == pPageView) - return TRUE; - m_pXFAPageView = pPageView; - (void)m_pXFAPageView->LoadPageView(nullptr); return TRUE; } @@ -110,17 +95,13 @@ FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { if (!m_pDocument || m_iPageIndex < 0 || !pageDict) return FALSE; - if (m_pPDFPage) - delete m_pPDFPage; - - m_pPDFPage = new CPDF_Page(); + m_pPDFPage.reset(new CPDF_Page()); m_pPDFPage->Load(m_pDocument->GetPDFDoc(), pageDict); m_pPDFPage->ParseContent(nullptr); - return TRUE; } -FX_FLOAT CPDFXFA_Page::GetPageWidth() { +FX_FLOAT CPDFXFA_Page::GetPageWidth() const { if (!m_pPDFPage && !m_pXFAPageView) return 0.0f; @@ -145,7 +126,7 @@ FX_FLOAT CPDFXFA_Page::GetPageWidth() { return 0.0f; } -FX_FLOAT CPDFXFA_Page::GetPageHeight() { +FX_FLOAT CPDFXFA_Page::GetPageHeight() const { if (!m_pPDFPage && !m_pXFAPageView) return 0.0f; -- cgit v1.2.3