summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_page.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-05-26 10:33:45 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-26 17:46:09 +0000
commitd9281818c09a628668202558fbd1b79f39a98e4c (patch)
tree30ad53d4d4ee89cc68be498870293b4cda5b2f17 /core/fpdfapi/page/cpdf_page.cpp
parent05f3359d0e74f6450c3f8d6e9a7b854ba2d35ac8 (diff)
downloadpdfium-d9281818c09a628668202558fbd1b79f39a98e4c.tar.xz
Simplify CPDF_Page ctor.
Add a GetBox() helper method. Change-Id: I171b2e6714b6c001fad60baa0d4dff2f3c3c978f Reviewed-on: https://pdfium-review.googlesource.com/6011 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/cpdf_page.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_page.cpp34
1 files changed, 18 insertions, 16 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,