summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdfview.cpp18
-rw-r--r--fpdfsdk/fpdfview_embeddertest.cpp42
2 files changed, 43 insertions, 17 deletions
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 956e6db671..c51ee90fe0 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -967,12 +967,6 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
- CFX_Matrix transform_matrix = pPage->GetPageMatrix();
- if (matrix) {
- transform_matrix.Concat(CFX_Matrix(matrix->a, matrix->b, matrix->c,
- matrix->d, matrix->e, matrix->f));
- }
-
CFX_FloatRect clipping_rect;
if (clipping) {
clipping_rect.left = clipping->left;
@@ -980,8 +974,16 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
clipping_rect.right = clipping->right;
clipping_rect.top = clipping->top;
}
- RenderPageImpl(pContext, pPage, transform_matrix, clipping_rect.ToFxRect(),
- flags, true, nullptr);
+ FX_RECT clip_rect = clipping_rect.ToFxRect();
+
+ CFX_Matrix transform_matrix = pPage->GetDisplayMatrix(
+ clip_rect.left, clip_rect.top, clip_rect.Width(), clip_rect.Height(), 0);
+ if (matrix) {
+ transform_matrix.Concat(CFX_Matrix(matrix->a, matrix->b, matrix->c,
+ matrix->d, matrix->e, matrix->f));
+ }
+ RenderPageImpl(pContext, pPage, transform_matrix, clip_rect, flags, true,
+ nullptr);
pPage->SetRenderContext(nullptr);
}
diff --git a/fpdfsdk/fpdfview_embeddertest.cpp b/fpdfsdk/fpdfview_embeddertest.cpp
index f36edbc4d6..a986a1cd96 100644
--- a/fpdfsdk/fpdfview_embeddertest.cpp
+++ b/fpdfsdk/fpdfview_embeddertest.cpp
@@ -330,19 +330,21 @@ TEST_F(FPDFViewEmbeddertest, Hang_360) {
}
TEST_F(FPDFViewEmbeddertest, FPDF_RenderPageBitmapWithMatrix) {
- const char kAllBlackMd5sum[] = "5708fc5c4a8bd0abde99c8e8f0390615";
- const char kTopLeftQuarterBlackMd5sum[] = "24e4d1ec06fa0258af758cfc8b2ad50a";
+ const char kOriginalMD5[] = "210157942bcce97b057a1107a1fd62f8";
+ const char kTopLeftQuarterMD5[] = "c54d58dda13e3cd04eb63e1d0db0feda";
+ const char kTrimmedMD5[] = "88225d7951a21d0eef191cfed06c36ce";
+ const char kRotatedMD5[] = "7d38bc58aa50ad271bc432e77256d3de";
- EXPECT_TRUE(OpenDocument("black.pdf"));
+ 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(612, width);
- EXPECT_EQ(792, height);
+ EXPECT_EQ(200, width);
+ EXPECT_EQ(200, height);
FPDF_BITMAP bitmap = RenderPage(page);
- CompareBitmap(bitmap, width, height, kAllBlackMd5sum);
+ CompareBitmap(bitmap, width, height, kOriginalMD5);
FPDFBitmap_Destroy(bitmap);
// Try rendering with an identity matrix. The output should be the same as
@@ -364,17 +366,39 @@ TEST_F(FPDFViewEmbeddertest, FPDF_RenderPageBitmapWithMatrix) {
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, kAllBlackMd5sum);
+ CompareBitmap(bitmap, width, height, kOriginalMD5);
FPDFBitmap_Destroy(bitmap);
- // Now render again with the image scaled.
+ // Now render again with the image scaled smaller.
matrix.a = 0.5;
matrix.d = 0.5;
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, kTopLeftQuarterBlackMd5sum);
+ CompareBitmap(bitmap, width, height, kTopLeftQuarterMD5);
+ FPDFBitmap_Destroy(bitmap);
+
+ // Now render again with the image scaled larger horizontally (will be
+ // trimmed).
+ matrix.a = 2;
+ matrix.d = 1;
+ 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);
+ FPDFBitmap_Destroy(bitmap);
+
+ // Now try a 90 degree rotation
+ matrix.a = 0;
+ matrix.b = 1;
+ matrix.c = -1;
+ matrix.d = 0;
+ matrix.e = width;
+ 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);
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);