diff options
author | Nicolas Pena <npm@chromium.org> | 2017-09-13 18:02:11 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-13 22:12:47 +0000 |
commit | 24b0733a72bbc4013bff8628f198b0aea807aa06 (patch) | |
tree | ad2d50860409b5746ac467534ca433890999a821 /core/fpdfapi/page | |
parent | cb32712be1e545e3ceb4f41b77a8bebc2bf2726f (diff) | |
download | pdfium-24b0733a72bbc4013bff8628f198b0aea807aa06.tar.xz |
Change behaviour of FPDF_RenderPageBitmapWithMatrix
This CL changes the behavior of FPDF_RenderPageBitmapWithMatrix so it
transforms the bitmap. Before, the page would be transformed and the
assumption was that it would be drawn on a bitmap with the same
dimensions as the original page. This does not work well because a
transformation generally changes the dimensions of the page. The
rectangles test is modified to include small rectangles in the corner
of the page, so that it's clear that the whole original page is being
displayed.
Bug: pdfium:849
Change-Id: Ie89f959a1605fea59a15d239ca871ccd939ec92b
Reviewed-on: https://pdfium-review.googlesource.com/13510
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r-- | core/fpdfapi/page/cpdf_page.cpp | 29 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_page.h | 7 |
2 files changed, 35 insertions, 1 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; diff --git a/core/fpdfapi/page/cpdf_page.h b/core/fpdfapi/page/cpdf_page.h index 1891e651be..47fba3caec 100644 --- a/core/fpdfapi/page/cpdf_page.h +++ b/core/fpdfapi/page/cpdf_page.h @@ -38,11 +38,16 @@ class CPDF_Page : public CPDF_PageObjectHolder { int xSize, int ySize, int iRotate) const; + CFX_Matrix GetDisplayMatrixWithTransformation( + int xPos, + int yPos, + int xSize, + int ySize, + const CFX_Matrix& transformation); float GetPageWidth() const { return m_PageWidth; } 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_PageRenderCache* GetRenderCache() const { return m_pPageRender.get(); } |