5#include "public/fpdf_transformpage.h"
7#include "build/build_config.h"
8#include "core/fxge/cfx_defaultrenderdevice.h"
9#include "testing/embedder_test.h"
10#include "testing/embedder_test_constants.h"
12#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
13#include "third_party/base/test/scoped_locale.h"
16using pdfium::RectanglesChecksum;
20const char* ShrunkChecksum() {
22 return "78c52d6029283090036e6db6683401e2";
24 return "f4136cc9209207ab60eb8381a3df2e69";
32 ASSERT_TRUE(OpenDocument(
"cropped_text.pdf"));
33 ASSERT_EQ(4, FPDF_GetPageCount(document()));
36 FPDF_PAGE page = LoadPage(1);
41 &mediabox.right
, &mediabox.top
));
42 EXPECT_EQ(-50, mediabox.left);
43 EXPECT_EQ(-50, mediabox.bottom);
44 EXPECT_EQ(200, mediabox.right);
45 EXPECT_EQ(200, mediabox.top);
49 &cropbox.right
, &cropbox.top
));
50 EXPECT_EQ(50, cropbox.left);
51 EXPECT_EQ(50, cropbox.bottom);
52 EXPECT_EQ(150, cropbox.right);
53 EXPECT_EQ(150, cropbox.top);
57 &bleedbox.right
, &bleedbox.top
));
58 EXPECT_EQ(0, bleedbox.left);
59 EXPECT_EQ(10, bleedbox.bottom);
60 EXPECT_EQ(150, bleedbox.right);
61 EXPECT_EQ(145, bleedbox.top);
65 &trimbox.right
, &trimbox.top
));
66 EXPECT_EQ(25, trimbox.left);
67 EXPECT_EQ(30, trimbox.bottom);
68 EXPECT_EQ(140, trimbox.right);
69 EXPECT_EQ(145, trimbox.top);
73 &artbox.right
, &artbox.top
));
74 EXPECT_EQ(50, artbox.left);
75 EXPECT_EQ(60, artbox.bottom);
76 EXPECT_EQ(135, artbox.right);
77 EXPECT_EQ(140, artbox.top);
83 FPDF_PAGE page = LoadPage(3);
88 &mediabox.right
, &mediabox.top
));
89 EXPECT_EQ(0, mediabox.left);
90 EXPECT_EQ(0, mediabox.bottom);
91 EXPECT_EQ(200, mediabox.right);
92 EXPECT_EQ(200, mediabox.top);
96 &cropbox.right
, &cropbox.top
));
97 EXPECT_EQ(150, cropbox.left);
98 EXPECT_EQ(150, cropbox.bottom);
99 EXPECT_EQ(60, cropbox.right);
100 EXPECT_EQ(60, cropbox.top);
103 &cropbox.right
, &cropbox.top
));
105 &cropbox.right
, &cropbox.top
));
107 nullptr, &cropbox.top
));
109 &cropbox.right
, nullptr));
114 &bleedbox.right
, &bleedbox.top
));
115 EXPECT_EQ(160, bleedbox.left);
116 EXPECT_EQ(165, bleedbox.bottom);
117 EXPECT_EQ(0, bleedbox.right);
118 EXPECT_EQ(10, bleedbox.top);
122 &trimbox.right
, &trimbox.top
));
123 EXPECT_EQ(155, trimbox.left);
124 EXPECT_EQ(165, trimbox.bottom);
125 EXPECT_EQ(25, trimbox.right);
126 EXPECT_EQ(30, trimbox.top);
130 &artbox.right
, &artbox.top
));
131 EXPECT_EQ(140, artbox.left);
132 EXPECT_EQ(145, artbox.bottom);
133 EXPECT_EQ(65, artbox.right);
134 EXPECT_EQ(70, artbox.top);
141 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
142 ASSERT_EQ(1, FPDF_GetPageCount(document()));
144 FPDF_PAGE page = LoadPage(0);
147 FS_RECTF cropbox = {-1.0f, 0.0f, 3.0f, -2.0f};
149 &cropbox.right
, &cropbox.top
));
150 EXPECT_EQ(-1.0f, cropbox.left);
151 EXPECT_EQ(-2.0f, cropbox.bottom);
152 EXPECT_EQ(3.0f, cropbox.right);
153 EXPECT_EQ(0.0f, cropbox.top);
159 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
160 ASSERT_EQ(1, FPDF_GetPageCount(document()));
162 FPDF_PAGE page = LoadPage(0);
165 FS_RECTF bleedbox = {-1.0f, 10.f, 3.0f, -1.0f};
167 &bleedbox.right
, &bleedbox.top
));
168 EXPECT_EQ(-1.0f, bleedbox.left);
169 EXPECT_EQ(-1.0f, bleedbox.bottom);
170 EXPECT_EQ(3.0f, bleedbox.right);
171 EXPECT_EQ(10.0f, bleedbox.top);
177 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
178 ASSERT_EQ(1, FPDF_GetPageCount(document()));
180 FPDF_PAGE page = LoadPage(0);
183 FS_RECTF trimbox = {-11.0f, 0.0f, 3.0f, -10.0f};
185 &trimbox.right
, &trimbox.top
));
186 EXPECT_EQ(-11.0f, trimbox.left);
187 EXPECT_EQ(-10.0f, trimbox.bottom);
188 EXPECT_EQ(3.0f, trimbox.right);
189 EXPECT_EQ(0.0f, trimbox.top);
195 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
196 ASSERT_EQ(1, FPDF_GetPageCount(document()));
198 FPDF_PAGE page = LoadPage(0);
201 FS_RECTF artbox = {-1.0f, 0.0f, 3.0f, -1.0f};
203 &artbox.right
, &artbox.top
));
204 EXPECT_EQ(-1.0f, artbox.left);
205 EXPECT_EQ(-1.0f, artbox.bottom);
206 EXPECT_EQ(3.0f, artbox.right);
207 EXPECT_EQ(0.0f, artbox.top);
213 const char* cropped_checksum = []() {
215 return "4b9d2d2246be61c583f454245fe3172f";
217 return "9937883715d5144c079fb8f7e3d4f395";
220 ASSERT_TRUE(OpenDocument(
"rectangles.pdf"));
221 FPDF_PAGE page = LoadPage(0);
228 &cropbox.right
, &cropbox.top
));
231 EXPECT_EQ(200, page_width);
232 EXPECT_EQ(300, page_height);
233 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
234 CompareBitmap(bitmap.get(), page_width, page_height,
246 &cropbox.right
, &cropbox.top
));
247 EXPECT_EQ(10, cropbox.left);
248 EXPECT_EQ(20, cropbox.bottom);
249 EXPECT_EQ(100, cropbox.right);
250 EXPECT_EQ(150, cropbox.top);
253 EXPECT_EQ(90, page_width);
254 EXPECT_EQ(130, page_height);
255 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
256 CompareBitmap(bitmap.get(), page_width, page_height, cropped_checksum);
265 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
266 ASSERT_TRUE(OpenSavedDocument());
267 FPDF_PAGE saved_page = LoadSavedPage(0);
268 ASSERT_TRUE(saved_page);
272 &cropbox.right
, &cropbox.top
));
273 EXPECT_EQ(10, cropbox.left);
274 EXPECT_EQ(20, cropbox.bottom);
275 EXPECT_EQ(100, cropbox.right);
276 EXPECT_EQ(150, cropbox.top);
279 EXPECT_EQ(90, page_width);
280 EXPECT_EQ(130, page_height);
281 ScopedFPDFBitmap bitmap = RenderSavedPage(saved_page);
282 CompareBitmap(bitmap.get(), page_width, page_height, cropped_checksum);
284 CloseSavedPage(saved_page);
285 CloseSavedDocument();
290 const char* shrunk_checksum_set_media_box = []() {
292 return "9f28f0610a7f789c24cfd5f9bd5dc3de";
294 return "eab5958f62f7ce65d7c32de98389fee1";
298 ASSERT_TRUE(OpenDocument(
"rectangles.pdf"));
299 FPDF_PAGE page = LoadPage(0);
306 &mediabox.right
, &mediabox.top
));
309 EXPECT_EQ(200, page_width);
310 EXPECT_EQ(300, page_height);
311 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
312 CompareBitmap(bitmap.get(), page_width, page_height,
324 &mediabox.right
, &mediabox.top
));
325 EXPECT_EQ(20, mediabox.left);
326 EXPECT_EQ(30, mediabox.bottom);
327 EXPECT_EQ(100, mediabox.right);
328 EXPECT_EQ(150, mediabox.top);
331 EXPECT_EQ(80, page_width);
332 EXPECT_EQ(120, page_height);
333 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
334 CompareBitmap(bitmap.get(), page_width, page_height,
335 shrunk_checksum_set_media_box);
344 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
345 ASSERT_TRUE(OpenSavedDocument());
346 FPDF_PAGE saved_page = LoadSavedPage(0);
347 ASSERT_TRUE(saved_page);
351 &mediabox.bottom
, &mediabox.right
,
353 EXPECT_EQ(20, mediabox.left);
354 EXPECT_EQ(30, mediabox.bottom);
355 EXPECT_EQ(100, mediabox.right);
356 EXPECT_EQ(150, mediabox.top);
359 EXPECT_EQ(80, page_width);
360 EXPECT_EQ(120, page_height);
361 ScopedFPDFBitmap bitmap = RenderSavedPage(saved_page);
362 CompareBitmap(bitmap.get(), page_width, page_height,
363 shrunk_checksum_set_media_box);
365 CloseSavedPage(saved_page);
366 CloseSavedDocument();
371 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
373 FPDF_PAGE page = LoadPage(0);
377 ScopedFPDFClipPath clip(FPDF_CreateClipPath(10.0f, 10.0f, 90.0f, 90.0f));
381 FPDFPage_InsertClipPath(
nullptr, clip.get());
384 FPDFPage_InsertClipPath(page, clip.get());
393 const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0};
394 const FS_RECTF clip_rect = {0.0f, 0.0f, 20.0f, 10.0f};
396 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
398 FPDF_PAGE page = LoadPage(0);
414 const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0};
415 const FS_RECTF clip_rect = {0.0f, 0.0f, 20.0f, 10.0f};
417 ASSERT_TRUE(OpenDocument(
"bug_547706.pdf"));
419 FPDF_PAGE page = LoadPage(0);
431 ASSERT_TRUE(OpenDocument(
"rectangles.pdf"));
432 FPDF_PAGE page = LoadPage(0);
439 EXPECT_EQ(200, page_width);
440 EXPECT_EQ(300, page_height);
441 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
442 CompareBitmap(bitmap.get(), page_width, page_height,
452 const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0};
456 EXPECT_EQ(200, page_width);
457 EXPECT_EQ(300, page_height);
458 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
459 CompareBitmap(bitmap.get(), page_width, page_height,
469 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
470 ASSERT_TRUE(OpenSavedDocument());
471 FPDF_PAGE saved_page = LoadSavedPage(0);
472 ASSERT_TRUE(saved_page);
476 EXPECT_EQ(200, page_width);
477 EXPECT_EQ(300, page_height);
478 ScopedFPDFBitmap bitmap = RenderSavedPage(saved_page);
479 CompareBitmap(bitmap.get(), page_width, page_height, ShrunkChecksum());
481 CloseSavedPage(saved_page);
482 CloseSavedDocument();
486#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
487TEST_F(FPDFTransformEmbedderTest, TransFormWithClipAndSaveWithLocale) {
488 pdfium::base::ScopedLocale scoped_locale(
"da_DK.UTF-8");
491 ASSERT_TRUE(OpenDocument(
"rectangles.pdf"));
492 FPDF_PAGE page = LoadPage(0);
497 const int page_width =
static_cast<
int>(FPDF_GetPageWidth(page));
498 const int page_height =
static_cast<
int>(FPDF_GetPageHeight(page));
499 EXPECT_EQ(200, page_width);
500 EXPECT_EQ(300, page_height);
501 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
502 CompareBitmap(bitmap.get(), page_width, page_height,
503 RectanglesChecksum());
512 const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0};
513 EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix,
nullptr));
514 const int page_width =
static_cast<
int>(FPDF_GetPageWidth(page));
515 const int page_height =
static_cast<
int>(FPDF_GetPageHeight(page));
516 EXPECT_EQ(200, page_width);
517 EXPECT_EQ(300, page_height);
518 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
519 CompareBitmap(bitmap.get(), page_width, page_height,
520 RectanglesChecksum());
529 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
530 ASSERT_TRUE(OpenSavedDocument());
531 FPDF_PAGE saved_page = LoadSavedPage(0);
532 ASSERT_TRUE(saved_page);
534 const int page_width =
static_cast<
int>(FPDF_GetPageWidth(saved_page));
535 const int page_height =
static_cast<
int>(FPDF_GetPageHeight(saved_page));
536 EXPECT_EQ(200, page_width);
537 EXPECT_EQ(300, page_height);
538 ScopedFPDFBitmap bitmap = RenderSavedPage(saved_page);
539 CompareBitmap(bitmap.get(), page_width, page_height, ShrunkChecksum());
541 CloseSavedPage(saved_page);
542 CloseSavedDocument();
static bool UseSkiaRenderer()
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetArtBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetTrimBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetMediaBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetCropBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_TransFormWithClip(FPDF_PAGE page, const FS_MATRIX *matrix, const FS_RECTF *clipRect)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetBleedBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetMediaBox(FPDF_PAGE page, float left, float bottom, float right, float top)
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetCropBox(FPDF_PAGE page, float left, float bottom, float right, float top)
TEST_F(FPDFTransformEmbedderTest, GetBoundingBoxes)
FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageWidth(FPDF_PAGE page)
FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageHeight(FPDF_PAGE page)
const char * RectanglesChecksum()