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 /fpdfsdk/fpdfview_embeddertest.cpp | |
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 'fpdfsdk/fpdfview_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdfview_embeddertest.cpp | 113 |
1 files changed, 79 insertions, 34 deletions
diff --git a/fpdfsdk/fpdfview_embeddertest.cpp b/fpdfsdk/fpdfview_embeddertest.cpp index 8576104c2e..97ba9d7c4c 100644 --- a/fpdfsdk/fpdfview_embeddertest.cpp +++ b/fpdfsdk/fpdfview_embeddertest.cpp @@ -5,6 +5,7 @@ #include <limits> #include <string> +#include "core/fxcrt/fx_coordinates.h" #include "fpdfsdk/fpdfview_c_api_test.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" @@ -350,75 +351,119 @@ TEST_F(FPDFViewEmbeddertest, Hang_360) { } TEST_F(FPDFViewEmbeddertest, FPDF_RenderPageBitmapWithMatrix) { - const char kOriginalMD5[] = "210157942bcce97b057a1107a1fd62f8"; - const char kTopLeftQuarterMD5[] = "c54d58dda13e3cd04eb63e1d0db0feda"; - const char kTrimmedMD5[] = "88225d7951a21d0eef191cfed06c36ce"; - const char kRotatedMD5[] = "7d38bc58aa50ad271bc432e77256d3de"; + const char* const kRotatedMD5[4] = { + "0a90de37f52127619c3dfb642b5fa2fe", "d599429574ff0dcad3bc898ea8b874ca", + "0113386bb0bd45125bacc6dee78bfe78", "051fcfa4c1f9de28765705633a8ef3a9"}; + const char kTopLeftQuarterMD5[] = "4982be08db3f6d2e6409186ebbced9eb"; + const char kHoriStretchedMD5[] = "004bf38f3c5c76a644e6fca204747f21"; + const char kRotateandStretchMD5[] = "0ea95cacc716d003cf063a2c5ed6c8d7"; EXPECT_TRUE(OpenDocument("rectangles.pdf")); FPDF_PAGE page = LoadPage(0); EXPECT_NE(nullptr, page); - const int width = static_cast<int>(FPDF_GetPageWidth(page)); - const int height = static_cast<int>(FPDF_GetPageHeight(page)); - EXPECT_EQ(200, width); - EXPECT_EQ(200, height); + const int initial_width = static_cast<int>(FPDF_GetPageWidth(page)); + const int initial_height = static_cast<int>(FPDF_GetPageHeight(page)); + EXPECT_EQ(200, initial_width); + EXPECT_EQ(300, initial_height); FPDF_BITMAP bitmap = RenderPage(page); - CompareBitmap(bitmap, width, height, kOriginalMD5); + CompareBitmap(bitmap, initial_width, initial_height, kRotatedMD5[0]); FPDFBitmap_Destroy(bitmap); - // Try rendering with an identity matrix. The output should be the same as - // the RenderPage() output. - FS_MATRIX matrix; - matrix.a = 1; - matrix.b = 0; - matrix.c = 0; - matrix.d = 1; - matrix.e = 0; - matrix.f = 0; - + int width; + int height; FS_RECTF rect; rect.left = 0; rect.top = 0; - rect.right = width; - rect.bottom = height; + FS_MATRIX matrix; - bitmap = FPDFBitmap_Create(width, height, 0); - FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); - FPDF_RenderPageBitmapWithMatrix(bitmap, page, &matrix, &rect, 0); - CompareBitmap(bitmap, width, height, kOriginalMD5); - FPDFBitmap_Destroy(bitmap); + // Try the easy rotations: 0, 90, 180, 270 clockwise. The output should be the + // same as FPDF_RenderPageBitmap with the appropriate rotation flag. Per PDF + // spec section 4.2.2, a t degree rotation is represented by [cos(t) sin(t) + // -sin(t) cos(t) 0 0] (matrix goes on the right in the multiplication). + rect.right = initial_width; + rect.bottom = initial_height; + CFX_Matrix rot_matrices[4] = { + CFX_Matrix(1, 0, 0, 1, 0, 0), CFX_Matrix(0, -1, 1, 0, 0, 0), + CFX_Matrix(-1, 0, 0, -1, 0, 0), CFX_Matrix(0, 1, -1, 0, 0, 0)}; + for (int rot = 0; rot < 4; ++rot) { + matrix.a = rot_matrices[rot].a; + matrix.b = rot_matrices[rot].b; + matrix.c = rot_matrices[rot].c; + matrix.d = rot_matrices[rot].d; + matrix.e = rot_matrices[rot].e; + matrix.f = rot_matrices[rot].f; + if (rot % 2 == 0) { + width = initial_width; + height = initial_height; + } else { + width = initial_height; + height = initial_width; + } + rect.right = width; + rect.bottom = height; + + bitmap = FPDFBitmap_Create(width, height, 0); + FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); + FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, rot, 0); + CompareBitmap(bitmap, width, height, kRotatedMD5[rot]); + FPDFBitmap_Destroy(bitmap); + + bitmap = FPDFBitmap_Create(width, height, 0); + FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); + FPDF_RenderPageBitmapWithMatrix(bitmap, page, &matrix, &rect, 0); + CompareBitmap(bitmap, width, height, kRotatedMD5[rot]); + FPDFBitmap_Destroy(bitmap); + } + // TODO(npm): what to do with transformations that do not align the page with + // the axis, like a 45 degree rotation (currently, part of the page gets cut + // out). pdfium:849 // Now render again with the image scaled smaller. + width = initial_width / 2; + height = initial_height / 2; matrix.a = 0.5; + matrix.b = 0; + matrix.c = 0; matrix.d = 0.5; + rect.right = width; + rect.bottom = height; + bitmap = FPDFBitmap_Create(width, height, 0); FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); FPDF_RenderPageBitmapWithMatrix(bitmap, page, &matrix, &rect, 0); CompareBitmap(bitmap, width, height, kTopLeftQuarterMD5); FPDFBitmap_Destroy(bitmap); - // Now render again with the image scaled larger horizontally (will be - // trimmed). + // Now render again with the image scaled larger horizontally. + width = initial_width * 2; + height = initial_height; matrix.a = 2; matrix.d = 1; + rect.right = width; + rect.bottom = height; bitmap = FPDFBitmap_Create(width, height, 0); FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); FPDF_RenderPageBitmapWithMatrix(bitmap, page, &matrix, &rect, 0); - CompareBitmap(bitmap, width, height, kTrimmedMD5); + CompareBitmap(bitmap, width, height, kHoriStretchedMD5); FPDFBitmap_Destroy(bitmap); - // Now try a 90 degree rotation + // Test a rotation followed by a stretch. + width = initial_height * 2; + height = initial_width; matrix.a = 0; - matrix.b = 1; - matrix.c = -1; + matrix.b = -1; + matrix.c = 2; matrix.d = 0; - matrix.e = width; + matrix.e = 0; + matrix.f = 0; + rect.right = width; + rect.bottom = height; bitmap = FPDFBitmap_Create(width, height, 0); FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); FPDF_RenderPageBitmapWithMatrix(bitmap, page, &matrix, &rect, 0); - CompareBitmap(bitmap, width, height, kRotatedMD5); + CompareBitmap(bitmap, width, height, kRotateandStretchMD5); FPDFBitmap_Destroy(bitmap); UnloadPage(page); |