summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_page.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/page/cpdf_page.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_page.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/fpdfapi/page/cpdf_page.cpp b/core/fpdfapi/page/cpdf_page.cpp
index dfbd342f13..6213e5fccb 100644
--- a/core/fpdfapi/page/cpdf_page.cpp
+++ b/core/fpdfapi/page/cpdf_page.cpp
@@ -178,6 +178,35 @@ CFX_Matrix CPDF_Page::GetDisplayMatrix(int xPos,
return matrix;
}
+// This method follows the same apparent logic as GetDisplayMatrix(). For
+// example, consider point 0. First, take the top left coordinate of the
+// rectangle in the transformed space. Now, calculate what this point was in the
+// original space by inverting. Note that this is not necessarily the same as
+// the top left corner of the original rectangle.
+CFX_Matrix CPDF_Page::GetDisplayMatrixWithTransformation(
+ int xPos,
+ int yPos,
+ int xSize,
+ int ySize,
+ const CFX_Matrix& transformation) {
+ CFX_FloatRect rect(xPos, yPos, xPos + xSize, yPos + ySize);
+ rect = transformation.TransformRect(rect);
+ CFX_Matrix inverse = transformation.GetInverse();
+ CFX_PointF point0(rect.left, rect.top);
+ CFX_PointF point1(rect.left, rect.bottom);
+ CFX_PointF point2(rect.right, rect.top);
+ point0 = inverse.Transform(point0);
+ point1 = inverse.Transform(point1);
+ point2 = inverse.Transform(point2);
+
+ CFX_Matrix matrix = m_PageMatrix;
+ matrix.Concat(CFX_Matrix(
+ (point2.x - point0.x) / m_PageWidth, (point2.y - point0.y) / m_PageWidth,
+ (point1.x - point0.x) / m_PageHeight,
+ (point1.y - point0.y) / m_PageHeight, point0.x, point0.y));
+ return matrix;
+}
+
int CPDF_Page::GetPageRotation() const {
CPDF_Object* pRotate = GetPageAttr("Rotate");
int rotate = pRotate ? (pRotate->GetInteger() / 90) % 4 : 0;