summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/page')
-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;