summaryrefslogtreecommitdiff
path: root/core
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
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')
-rw-r--r--core/fpdfapi/page/cpdf_page.cpp34
-rw-r--r--core/fpdfapi/page/cpdf_page.h6
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<GraphicsData, CFX_ByteString> m_GraphicsMap;
std::map<FontData, CFX_ByteString> 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;