From d9281818c09a628668202558fbd1b79f39a98e4c Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 26 May 2017 10:33:45 -0700 Subject: Simplify CPDF_Page ctor. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a GetBox() helper method. Change-Id: I171b2e6714b6c001fad60baa0d4dff2f3c3c978f Reviewed-on: https://pdfium-review.googlesource.com/6011 Commit-Queue: Lei Zhang Reviewed-by: Nicolás Peña --- core/fpdfapi/page/cpdf_page.cpp | 34 ++++++++++++++++++---------------- core/fpdfapi/page/cpdf_page.h | 6 ++++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index 2f0c83556c..092a1cad41 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -31,32 +31,24 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, if (!pPageDict) return; - CPDF_Object* pageAttr = GetPageAttr("Resources"); - m_pResources = pageAttr ? pageAttr->GetDict() : nullptr; + CPDF_Object* pPageAttr = GetPageAttr("Resources"); + m_pResources = pPageAttr ? pPageAttr->GetDict() : nullptr; m_pPageResources = m_pResources; - int rotate = GetPageRotation(); - CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); - CFX_FloatRect mediabox; - if (pMediaBox) { - mediabox = pMediaBox->GetRect(); - mediabox.Normalize(); - } + CFX_FloatRect mediabox = GetBox("MediaBox"); if (mediabox.IsEmpty()) mediabox = CFX_FloatRect(0, 0, 612, 792); - CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); - if (pCropBox) { - m_BBox = pCropBox->GetRect(); - m_BBox.Normalize(); - } + m_BBox = GetBox("CropBox"); if (m_BBox.IsEmpty()) m_BBox = mediabox; else m_BBox.Intersect(mediabox); - m_PageWidth = m_BBox.right - m_BBox.left; - m_PageHeight = m_BBox.top - m_BBox.bottom; + m_PageWidth = m_BBox.Width(); + m_PageHeight = m_BBox.Height(); + + int rotate = GetPageRotation(); if (rotate % 2) std::swap(m_PageWidth, m_PageHeight); @@ -116,6 +108,16 @@ CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteString& name) const { return nullptr; } +CFX_FloatRect CPDF_Page::GetBox(const CFX_ByteString& name) const { + CFX_FloatRect box; + CPDF_Array* pBox = ToArray(GetPageAttr(name)); + if (pBox) { + box = pBox->GetRect(); + box.Normalize(); + } + return box; +} + CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos, int yPos, int xSize, diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index b0dfa26124..77cc793d81 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -57,7 +57,6 @@ class CPDF_Page : public CPDF_PageObjectHolder { CFX_FloatRect GetPageBBox() const { return m_BBox; } const CFX_Matrix& GetPageMatrix() const { return m_PageMatrix; } int GetPageRotation() const; - CPDF_Object* GetPageAttr(const CFX_ByteString& name) const; CPDF_PageRenderCache* GetRenderCache() const { return m_pPageRender.get(); } CPDF_PageRenderContext* GetRenderContext() const { @@ -71,9 +70,12 @@ class CPDF_Page : public CPDF_PageObjectHolder { std::map m_GraphicsMap; std::map m_FontsMap; - protected: + private: void StartParse(); + CPDF_Object* GetPageAttr(const CFX_ByteString& name) const; + CFX_FloatRect GetBox(const CFX_ByteString& name) const; + float m_PageWidth; float m_PageHeight; CFX_Matrix m_PageMatrix; -- cgit v1.2.3