From ce8e51e6c444f6caaa160bf8b1decd5d7ec84e6f Mon Sep 17 00:00:00 2001 From: rbpotter Date: Fri, 28 Apr 2017 12:42:47 -0700 Subject: Fix rotations Normalize rotations read from PDF documents. Make FPDFPage_GetRotation always return a value 0 to 3 as specified in fpdf_edit.h instead of returning the page rotation / 90 (page rotation may be negative for some PDFs). BUG=chromium:713197 Change-Id: Ie477803f7d298b777a3ace89b21cfda8b7f6808b Reviewed-on: https://pdfium-review.googlesource.com/4532 Reviewed-by: Lei Zhang Commit-Queue: Lei Zhang --- core/fpdfapi/page/cpdf_page.cpp | 11 +++++++---- core/fpdfapi/page/cpdf_page.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp index 496ed7cc58..5ea575e307 100644 --- a/core/fpdfapi/page/cpdf_page.cpp +++ b/core/fpdfapi/page/cpdf_page.cpp @@ -35,10 +35,7 @@ CPDF_Page::CPDF_Page(CPDF_Document* pDocument, CPDF_Object* pageAttr = GetPageAttr("Resources"); m_pResources = pageAttr ? pageAttr->GetDict() : nullptr; m_pPageResources = m_pResources; - CPDF_Object* pRotate = GetPageAttr("Rotate"); - int rotate = pRotate ? pRotate->GetInteger() / 90 % 4 : 0; - if (rotate < 0) - rotate += 4; + int rotate = GetPageRotation(); CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); CFX_FloatRect mediabox; @@ -176,6 +173,12 @@ CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos, return matrix; } +int CPDF_Page::GetPageRotation() const { + CPDF_Object* pRotate = GetPageAttr("Rotate"); + int rotate = pRotate ? (pRotate->GetInteger() / 90) % 4 : 0; + return (rotate < 0) ? (rotate + 4) : rotate; +} + bool GraphicsData::operator<(const GraphicsData& other) const { if (fillAlpha != other.fillAlpha) return fillAlpha < other.fillAlpha; diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index 076ab3f93b..b0dfa26124 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -56,6 +56,7 @@ class CPDF_Page : public CPDF_PageObjectHolder { float GetPageHeight() const { return m_PageHeight; } 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(); } -- cgit v1.2.3