Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 1 | // Copyright 2018 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "public/fpdf_transformpage.h" |
Lei Zhang | fc45549 | 2019-06-14 17:16:09 +0000 | [diff] [blame] | 6 | |
| 7 | #include "build/build_config.h" |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 8 | #include "testing/embedder_test.h" |
| 9 | |
Lei Zhang | fc45549 | 2019-06-14 17:16:09 +0000 | [diff] [blame] | 10 | #if defined(OS_LINUX) || defined(OS_FUCHSIA) |
| 11 | #include "third_party/base/test/scoped_locale.h" |
| 12 | #endif |
| 13 | |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 14 | class FPDFTransformEmbedderTest : public EmbedderTest {}; |
| 15 | |
| 16 | TEST_F(FPDFTransformEmbedderTest, GetBoundingBoxes) { |
| 17 | ASSERT_TRUE(OpenDocument("cropped_text.pdf")); |
| 18 | ASSERT_EQ(4, FPDF_GetPageCount(document())); |
| 19 | |
| 20 | { |
| 21 | FPDF_PAGE page = LoadPage(1); |
| 22 | ASSERT_TRUE(page); |
| 23 | |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 24 | FS_RECTF mediabox; |
| 25 | EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox.left, &mediabox.bottom, |
| 26 | &mediabox.right, &mediabox.top)); |
| 27 | EXPECT_EQ(-50, mediabox.left); |
| 28 | EXPECT_EQ(-50, mediabox.bottom); |
| 29 | EXPECT_EQ(200, mediabox.right); |
| 30 | EXPECT_EQ(200, mediabox.top); |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 31 | |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 32 | FS_RECTF cropbox; |
| 33 | EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom, |
| 34 | &cropbox.right, &cropbox.top)); |
| 35 | EXPECT_EQ(50, cropbox.left); |
| 36 | EXPECT_EQ(50, cropbox.bottom); |
| 37 | EXPECT_EQ(150, cropbox.right); |
| 38 | EXPECT_EQ(150, cropbox.top); |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 39 | |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 40 | FS_RECTF bleedbox; |
| 41 | EXPECT_TRUE(FPDFPage_GetBleedBox(page, &bleedbox.left, &bleedbox.bottom, |
| 42 | &bleedbox.right, &bleedbox.top)); |
| 43 | EXPECT_EQ(0, bleedbox.left); |
| 44 | EXPECT_EQ(10, bleedbox.bottom); |
| 45 | EXPECT_EQ(150, bleedbox.right); |
| 46 | EXPECT_EQ(145, bleedbox.top); |
| 47 | |
| 48 | FS_RECTF trimbox; |
| 49 | EXPECT_TRUE(FPDFPage_GetTrimBox(page, &trimbox.left, &trimbox.bottom, |
| 50 | &trimbox.right, &trimbox.top)); |
| 51 | EXPECT_EQ(25, trimbox.left); |
| 52 | EXPECT_EQ(30, trimbox.bottom); |
| 53 | EXPECT_EQ(140, trimbox.right); |
| 54 | EXPECT_EQ(145, trimbox.top); |
| 55 | |
| 56 | FS_RECTF artbox; |
| 57 | EXPECT_TRUE(FPDFPage_GetArtBox(page, &artbox.left, &artbox.bottom, |
| 58 | &artbox.right, &artbox.top)); |
| 59 | EXPECT_EQ(50, artbox.left); |
| 60 | EXPECT_EQ(60, artbox.bottom); |
| 61 | EXPECT_EQ(135, artbox.right); |
| 62 | EXPECT_EQ(140, artbox.top); |
xlou | c7f66ed | 2018-10-11 21:15:18 +0000 | [diff] [blame] | 63 | |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 64 | UnloadPage(page); |
| 65 | } |
| 66 | |
| 67 | { |
| 68 | FPDF_PAGE page = LoadPage(3); |
| 69 | ASSERT_TRUE(page); |
| 70 | |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 71 | FS_RECTF mediabox; |
| 72 | EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox.left, &mediabox.bottom, |
| 73 | &mediabox.right, &mediabox.top)); |
| 74 | EXPECT_EQ(0, mediabox.left); |
| 75 | EXPECT_EQ(0, mediabox.bottom); |
| 76 | EXPECT_EQ(200, mediabox.right); |
| 77 | EXPECT_EQ(200, mediabox.top); |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 78 | |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 79 | FS_RECTF cropbox; |
| 80 | EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom, |
| 81 | &cropbox.right, &cropbox.top)); |
| 82 | EXPECT_EQ(150, cropbox.left); |
| 83 | EXPECT_EQ(150, cropbox.bottom); |
| 84 | EXPECT_EQ(60, cropbox.right); |
| 85 | EXPECT_EQ(60, cropbox.top); |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 86 | |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 87 | EXPECT_FALSE(FPDFPage_GetCropBox(page, nullptr, &cropbox.bottom, |
| 88 | &cropbox.right, &cropbox.top)); |
| 89 | EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, nullptr, |
| 90 | &cropbox.right, &cropbox.top)); |
| 91 | EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom, |
| 92 | nullptr, &cropbox.top)); |
| 93 | EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom, |
| 94 | &cropbox.right, nullptr)); |
Lei Zhang | 76d01fe | 2018-06-08 18:05:58 +0000 | [diff] [blame] | 95 | EXPECT_FALSE(FPDFPage_GetCropBox(page, nullptr, nullptr, nullptr, nullptr)); |
| 96 | |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 97 | FS_RECTF bleedbox; |
| 98 | EXPECT_TRUE(FPDFPage_GetBleedBox(page, &bleedbox.left, &bleedbox.bottom, |
| 99 | &bleedbox.right, &bleedbox.top)); |
| 100 | EXPECT_EQ(160, bleedbox.left); |
| 101 | EXPECT_EQ(165, bleedbox.bottom); |
| 102 | EXPECT_EQ(0, bleedbox.right); |
| 103 | EXPECT_EQ(10, bleedbox.top); |
| 104 | |
| 105 | FS_RECTF trimbox; |
| 106 | EXPECT_TRUE(FPDFPage_GetTrimBox(page, &trimbox.left, &trimbox.bottom, |
| 107 | &trimbox.right, &trimbox.top)); |
| 108 | EXPECT_EQ(155, trimbox.left); |
| 109 | EXPECT_EQ(165, trimbox.bottom); |
| 110 | EXPECT_EQ(25, trimbox.right); |
| 111 | EXPECT_EQ(30, trimbox.top); |
| 112 | |
| 113 | FS_RECTF artbox; |
| 114 | EXPECT_TRUE(FPDFPage_GetArtBox(page, &artbox.left, &artbox.bottom, |
| 115 | &artbox.right, &artbox.top)); |
| 116 | EXPECT_EQ(140, artbox.left); |
| 117 | EXPECT_EQ(145, artbox.bottom); |
| 118 | EXPECT_EQ(65, artbox.right); |
| 119 | EXPECT_EQ(70, artbox.top); |
xlou | c7f66ed | 2018-10-11 21:15:18 +0000 | [diff] [blame] | 120 | |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 121 | UnloadPage(page); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | TEST_F(FPDFTransformEmbedderTest, NoCropBox) { |
| 126 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 127 | ASSERT_EQ(1, FPDF_GetPageCount(document())); |
| 128 | |
| 129 | FPDF_PAGE page = LoadPage(0); |
| 130 | ASSERT_TRUE(page); |
| 131 | |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 132 | FS_RECTF cropbox = {-1.0f, 0.0f, 3.0f, -2.0f}; |
| 133 | EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom, |
| 134 | &cropbox.right, &cropbox.top)); |
| 135 | EXPECT_EQ(-1.0f, cropbox.left); |
| 136 | EXPECT_EQ(-2.0f, cropbox.bottom); |
| 137 | EXPECT_EQ(3.0f, cropbox.right); |
| 138 | EXPECT_EQ(0.0f, cropbox.top); |
| 139 | |
| 140 | UnloadPage(page); |
| 141 | } |
| 142 | |
| 143 | TEST_F(FPDFTransformEmbedderTest, NoBleedBox) { |
| 144 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 145 | ASSERT_EQ(1, FPDF_GetPageCount(document())); |
| 146 | |
| 147 | FPDF_PAGE page = LoadPage(0); |
| 148 | ASSERT_TRUE(page); |
| 149 | |
| 150 | FS_RECTF bleedbox = {-1.0f, 10.f, 3.0f, -1.0f}; |
| 151 | EXPECT_FALSE(FPDFPage_GetBleedBox(page, &bleedbox.left, &bleedbox.bottom, |
| 152 | &bleedbox.right, &bleedbox.top)); |
| 153 | EXPECT_EQ(-1.0f, bleedbox.left); |
| 154 | EXPECT_EQ(-1.0f, bleedbox.bottom); |
| 155 | EXPECT_EQ(3.0f, bleedbox.right); |
| 156 | EXPECT_EQ(10.0f, bleedbox.top); |
| 157 | |
| 158 | UnloadPage(page); |
| 159 | } |
| 160 | |
| 161 | TEST_F(FPDFTransformEmbedderTest, NoTrimBox) { |
| 162 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 163 | ASSERT_EQ(1, FPDF_GetPageCount(document())); |
| 164 | |
| 165 | FPDF_PAGE page = LoadPage(0); |
| 166 | ASSERT_TRUE(page); |
| 167 | |
| 168 | FS_RECTF trimbox = {-11.0f, 0.0f, 3.0f, -10.0f}; |
| 169 | EXPECT_FALSE(FPDFPage_GetTrimBox(page, &trimbox.left, &trimbox.bottom, |
| 170 | &trimbox.right, &trimbox.top)); |
| 171 | EXPECT_EQ(-11.0f, trimbox.left); |
| 172 | EXPECT_EQ(-10.0f, trimbox.bottom); |
| 173 | EXPECT_EQ(3.0f, trimbox.right); |
| 174 | EXPECT_EQ(0.0f, trimbox.top); |
| 175 | |
| 176 | UnloadPage(page); |
| 177 | } |
| 178 | |
| 179 | TEST_F(FPDFTransformEmbedderTest, NoArtBox) { |
| 180 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 181 | ASSERT_EQ(1, FPDF_GetPageCount(document())); |
| 182 | |
| 183 | FPDF_PAGE page = LoadPage(0); |
| 184 | ASSERT_TRUE(page); |
| 185 | |
| 186 | FS_RECTF artbox = {-1.0f, 0.0f, 3.0f, -1.0f}; |
| 187 | EXPECT_FALSE(FPDFPage_GetArtBox(page, &artbox.left, &artbox.bottom, |
| 188 | &artbox.right, &artbox.top)); |
| 189 | EXPECT_EQ(-1.0f, artbox.left); |
| 190 | EXPECT_EQ(-1.0f, artbox.bottom); |
| 191 | EXPECT_EQ(3.0f, artbox.right); |
| 192 | EXPECT_EQ(0.0f, artbox.top); |
Lei Zhang | d8a8f27 | 2018-06-08 18:03:38 +0000 | [diff] [blame] | 193 | |
| 194 | UnloadPage(page); |
| 195 | } |
Tom Sepez | 8e926a4 | 2018-10-09 22:12:49 +0000 | [diff] [blame] | 196 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 197 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 198 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 199 | #define MAYBE_SetCropBox DISABLED_SetCropBox |
| 200 | #else |
| 201 | #define MAYBE_SetCropBox SetCropBox |
| 202 | #endif |
| 203 | TEST_F(FPDFTransformEmbedderTest, MAYBE_SetCropBox) { |
Lei Zhang | ce4b8f8 | 2018-12-23 03:53:10 +0000 | [diff] [blame] | 204 | const char kOriginalMD5[] = "0a90de37f52127619c3dfb642b5fa2fe"; |
| 205 | const char kCroppedMD5[] = "9937883715d5144c079fb8f7e3d4f395"; |
| 206 | |
| 207 | { |
| 208 | ASSERT_TRUE(OpenDocument("rectangles.pdf")); |
| 209 | FPDF_PAGE page = LoadPage(0); |
| 210 | ASSERT_TRUE(page); |
| 211 | |
| 212 | { |
| 213 | // Render the page as is. |
| 214 | FS_RECTF cropbox; |
| 215 | EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom, |
| 216 | &cropbox.right, &cropbox.top)); |
| 217 | const int page_width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 218 | const int page_height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 219 | EXPECT_EQ(200, page_width); |
| 220 | EXPECT_EQ(300, page_height); |
| 221 | ScopedFPDFBitmap bitmap = RenderLoadedPage(page); |
| 222 | CompareBitmap(bitmap.get(), page_width, page_height, kOriginalMD5); |
| 223 | } |
| 224 | |
| 225 | FPDFPage_SetCropBox(page, 10, 20, 100, 150); |
| 226 | |
| 227 | { |
| 228 | // Render the page after setting the CropBox. |
| 229 | // Note that the change affects the rendering, as expected. |
| 230 | // It behaves just like the case below, rather than the case above. |
| 231 | FS_RECTF cropbox; |
| 232 | EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom, |
| 233 | &cropbox.right, &cropbox.top)); |
| 234 | EXPECT_EQ(10, cropbox.left); |
| 235 | EXPECT_EQ(20, cropbox.bottom); |
| 236 | EXPECT_EQ(100, cropbox.right); |
| 237 | EXPECT_EQ(150, cropbox.top); |
| 238 | const int page_width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 239 | const int page_height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 240 | EXPECT_EQ(90, page_width); |
| 241 | EXPECT_EQ(130, page_height); |
| 242 | ScopedFPDFBitmap bitmap = RenderLoadedPage(page); |
| 243 | CompareBitmap(bitmap.get(), page_width, page_height, kCroppedMD5); |
| 244 | } |
| 245 | |
| 246 | UnloadPage(page); |
| 247 | } |
| 248 | |
| 249 | { |
| 250 | // Save a copy, open the copy, and render it. |
| 251 | // Note that it renders the rotation. |
| 252 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Lei Zhang | 0b49405 | 2019-01-31 21:41:15 +0000 | [diff] [blame] | 253 | ASSERT_TRUE(OpenSavedDocument()); |
Lei Zhang | ce4b8f8 | 2018-12-23 03:53:10 +0000 | [diff] [blame] | 254 | FPDF_PAGE saved_page = LoadSavedPage(0); |
| 255 | ASSERT_TRUE(saved_page); |
| 256 | |
| 257 | FS_RECTF cropbox; |
| 258 | EXPECT_TRUE(FPDFPage_GetCropBox(saved_page, &cropbox.left, &cropbox.bottom, |
| 259 | &cropbox.right, &cropbox.top)); |
| 260 | EXPECT_EQ(10, cropbox.left); |
| 261 | EXPECT_EQ(20, cropbox.bottom); |
| 262 | EXPECT_EQ(100, cropbox.right); |
| 263 | EXPECT_EQ(150, cropbox.top); |
| 264 | const int page_width = static_cast<int>(FPDF_GetPageWidth(saved_page)); |
| 265 | const int page_height = static_cast<int>(FPDF_GetPageHeight(saved_page)); |
| 266 | EXPECT_EQ(90, page_width); |
| 267 | EXPECT_EQ(130, page_height); |
| 268 | ScopedFPDFBitmap bitmap = RenderSavedPage(saved_page); |
| 269 | CompareBitmap(bitmap.get(), page_width, page_height, kCroppedMD5); |
| 270 | |
| 271 | CloseSavedPage(saved_page); |
| 272 | CloseSavedDocument(); |
| 273 | } |
| 274 | } |
| 275 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 276 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 277 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 278 | #define MAYBE_SetMediaBox DISABLED_SetMediaBox |
| 279 | #else |
| 280 | #define MAYBE_SetMediaBox SetMediaBox |
| 281 | #endif |
| 282 | TEST_F(FPDFTransformEmbedderTest, MAYBE_SetMediaBox) { |
Lei Zhang | ce4b8f8 | 2018-12-23 03:53:10 +0000 | [diff] [blame] | 283 | const char kOriginalMD5[] = "0a90de37f52127619c3dfb642b5fa2fe"; |
| 284 | const char kShrunkMD5[] = "eab5958f62f7ce65d7c32de98389fee1"; |
| 285 | |
| 286 | { |
| 287 | ASSERT_TRUE(OpenDocument("rectangles.pdf")); |
| 288 | FPDF_PAGE page = LoadPage(0); |
| 289 | ASSERT_TRUE(page); |
| 290 | |
| 291 | { |
| 292 | // Render the page as is. |
| 293 | FS_RECTF mediabox; |
| 294 | EXPECT_FALSE(FPDFPage_GetMediaBox(page, &mediabox.left, &mediabox.bottom, |
| 295 | &mediabox.right, &mediabox.top)); |
| 296 | const int page_width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 297 | const int page_height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 298 | EXPECT_EQ(200, page_width); |
| 299 | EXPECT_EQ(300, page_height); |
| 300 | ScopedFPDFBitmap bitmap = RenderLoadedPage(page); |
| 301 | CompareBitmap(bitmap.get(), page_width, page_height, kOriginalMD5); |
| 302 | } |
| 303 | |
| 304 | FPDFPage_SetMediaBox(page, 20, 30, 100, 150); |
| 305 | |
| 306 | { |
| 307 | // Render the page after setting the MediaBox. |
| 308 | // Note that the change affects the rendering, as expected. |
| 309 | // It behaves just like the case below, rather than the case above. |
| 310 | FS_RECTF mediabox; |
| 311 | EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox.left, &mediabox.bottom, |
| 312 | &mediabox.right, &mediabox.top)); |
| 313 | EXPECT_EQ(20, mediabox.left); |
| 314 | EXPECT_EQ(30, mediabox.bottom); |
| 315 | EXPECT_EQ(100, mediabox.right); |
| 316 | EXPECT_EQ(150, mediabox.top); |
| 317 | const int page_width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 318 | const int page_height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 319 | EXPECT_EQ(80, page_width); |
| 320 | EXPECT_EQ(120, page_height); |
| 321 | ScopedFPDFBitmap bitmap = RenderLoadedPage(page); |
| 322 | CompareBitmap(bitmap.get(), page_width, page_height, kShrunkMD5); |
| 323 | } |
| 324 | |
| 325 | UnloadPage(page); |
| 326 | } |
| 327 | |
| 328 | { |
| 329 | // Save a copy, open the copy, and render it. |
| 330 | // Note that it renders the rotation. |
| 331 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Lei Zhang | 0b49405 | 2019-01-31 21:41:15 +0000 | [diff] [blame] | 332 | ASSERT_TRUE(OpenSavedDocument()); |
Lei Zhang | ce4b8f8 | 2018-12-23 03:53:10 +0000 | [diff] [blame] | 333 | FPDF_PAGE saved_page = LoadSavedPage(0); |
| 334 | ASSERT_TRUE(saved_page); |
| 335 | |
| 336 | FS_RECTF mediabox; |
| 337 | EXPECT_TRUE(FPDFPage_GetMediaBox(saved_page, &mediabox.left, |
| 338 | &mediabox.bottom, &mediabox.right, |
| 339 | &mediabox.top)); |
| 340 | EXPECT_EQ(20, mediabox.left); |
| 341 | EXPECT_EQ(30, mediabox.bottom); |
| 342 | EXPECT_EQ(100, mediabox.right); |
| 343 | EXPECT_EQ(150, mediabox.top); |
| 344 | const int page_width = static_cast<int>(FPDF_GetPageWidth(saved_page)); |
| 345 | const int page_height = static_cast<int>(FPDF_GetPageHeight(saved_page)); |
| 346 | EXPECT_EQ(80, page_width); |
| 347 | EXPECT_EQ(120, page_height); |
| 348 | ScopedFPDFBitmap bitmap = RenderSavedPage(saved_page); |
| 349 | CompareBitmap(bitmap.get(), page_width, page_height, kShrunkMD5); |
| 350 | |
| 351 | CloseSavedPage(saved_page); |
| 352 | CloseSavedDocument(); |
| 353 | } |
| 354 | } |
| 355 | |
Tom Sepez | 8e926a4 | 2018-10-09 22:12:49 +0000 | [diff] [blame] | 356 | TEST_F(FPDFTransformEmbedderTest, ClipPath) { |
| 357 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 358 | |
| 359 | FPDF_PAGE page = LoadPage(0); |
| 360 | ASSERT_TRUE(page); |
| 361 | |
Lei Zhang | eaac1d0 | 2019-05-23 16:50:20 +0000 | [diff] [blame] | 362 | { |
| 363 | ScopedFPDFClipPath clip(FPDF_CreateClipPath(10.0f, 10.0f, 90.0f, 90.0f)); |
| 364 | EXPECT_TRUE(clip); |
Tom Sepez | 8e926a4 | 2018-10-09 22:12:49 +0000 | [diff] [blame] | 365 | |
Lei Zhang | eaac1d0 | 2019-05-23 16:50:20 +0000 | [diff] [blame] | 366 | // NULL arg call is a no-op. |
| 367 | FPDFPage_InsertClipPath(nullptr, clip.get()); |
Tom Sepez | 8e926a4 | 2018-10-09 22:12:49 +0000 | [diff] [blame] | 368 | |
Lei Zhang | eaac1d0 | 2019-05-23 16:50:20 +0000 | [diff] [blame] | 369 | // Do actual work. |
| 370 | FPDFPage_InsertClipPath(page, clip.get()); |
Tom Sepez | 8e926a4 | 2018-10-09 22:12:49 +0000 | [diff] [blame] | 371 | |
Lei Zhang | eaac1d0 | 2019-05-23 16:50:20 +0000 | [diff] [blame] | 372 | // TODO(tsepez): test how inserting path affects page rendering. |
| 373 | } |
Tom Sepez | 8e926a4 | 2018-10-09 22:12:49 +0000 | [diff] [blame] | 374 | |
Tom Sepez | 8e926a4 | 2018-10-09 22:12:49 +0000 | [diff] [blame] | 375 | UnloadPage(page); |
| 376 | } |
Lei Zhang | 970fcfe | 2018-12-20 19:51:18 +0000 | [diff] [blame] | 377 | |
| 378 | TEST_F(FPDFTransformEmbedderTest, TransFormWithClip) { |
| 379 | const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0}; |
| 380 | const FS_RECTF clip_rect = {0.0f, 0.0f, 20.0f, 10.0f}; |
| 381 | |
| 382 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 383 | |
| 384 | FPDF_PAGE page = LoadPage(0); |
| 385 | ASSERT_TRUE(page); |
| 386 | |
| 387 | EXPECT_FALSE(FPDFPage_TransFormWithClip(nullptr, nullptr, nullptr)); |
| 388 | EXPECT_FALSE(FPDFPage_TransFormWithClip(nullptr, &half_matrix, nullptr)); |
| 389 | EXPECT_FALSE(FPDFPage_TransFormWithClip(nullptr, nullptr, &clip_rect)); |
| 390 | EXPECT_FALSE(FPDFPage_TransFormWithClip(nullptr, &half_matrix, &clip_rect)); |
| 391 | EXPECT_FALSE(FPDFPage_TransFormWithClip(page, nullptr, nullptr)); |
| 392 | EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix, nullptr)); |
| 393 | EXPECT_TRUE(FPDFPage_TransFormWithClip(page, nullptr, &clip_rect)); |
| 394 | EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix, &clip_rect)); |
| 395 | |
| 396 | UnloadPage(page); |
| 397 | } |
Lei Zhang | ec68f99 | 2018-12-20 19:58:12 +0000 | [diff] [blame] | 398 | |
| 399 | TEST_F(FPDFTransformEmbedderTest, TransFormWithClipWithPatterns) { |
| 400 | const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0}; |
| 401 | const FS_RECTF clip_rect = {0.0f, 0.0f, 20.0f, 10.0f}; |
| 402 | |
| 403 | ASSERT_TRUE(OpenDocument("bug_547706.pdf")); |
| 404 | |
| 405 | FPDF_PAGE page = LoadPage(0); |
| 406 | ASSERT_TRUE(page); |
| 407 | |
| 408 | EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix, nullptr)); |
| 409 | EXPECT_TRUE(FPDFPage_TransFormWithClip(page, nullptr, &clip_rect)); |
| 410 | EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix, &clip_rect)); |
| 411 | |
| 412 | UnloadPage(page); |
| 413 | } |
Lei Zhang | ec267b4 | 2019-06-14 17:11:29 +0000 | [diff] [blame] | 414 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 415 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 416 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 417 | #define MAYBE_TransFormWithClipAndSave DISABLED_TransFormWithClipAndSave |
| 418 | #else |
| 419 | #define MAYBE_TransFormWithClipAndSave TransFormWithClipAndSave |
| 420 | #endif |
| 421 | TEST_F(FPDFTransformEmbedderTest, MAYBE_TransFormWithClipAndSave) { |
Lei Zhang | ec267b4 | 2019-06-14 17:11:29 +0000 | [diff] [blame] | 422 | const char kOriginalMD5[] = "0a90de37f52127619c3dfb642b5fa2fe"; |
| 423 | const char kShrunkMD5[] = "f4136cc9209207ab60eb8381a3df2e69"; |
| 424 | |
| 425 | { |
| 426 | ASSERT_TRUE(OpenDocument("rectangles.pdf")); |
| 427 | FPDF_PAGE page = LoadPage(0); |
| 428 | ASSERT_TRUE(page); |
| 429 | |
| 430 | { |
| 431 | // Render the page as is. |
| 432 | const int page_width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 433 | const int page_height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 434 | EXPECT_EQ(200, page_width); |
| 435 | EXPECT_EQ(300, page_height); |
| 436 | ScopedFPDFBitmap bitmap = RenderLoadedPage(page); |
| 437 | CompareBitmap(bitmap.get(), page_width, page_height, kOriginalMD5); |
| 438 | } |
| 439 | |
| 440 | { |
| 441 | // Render the page after transforming. |
| 442 | // Note that the change should affect the rendering, but does not. |
| 443 | // It should behaves just like the case below, rather than the case above. |
| 444 | // TODO(bug_1328): The checksum below should be |kShrunkMD5|. |
| 445 | const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0}; |
| 446 | EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix, nullptr)); |
| 447 | const int page_width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 448 | const int page_height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 449 | EXPECT_EQ(200, page_width); |
| 450 | EXPECT_EQ(300, page_height); |
| 451 | ScopedFPDFBitmap bitmap = RenderLoadedPage(page); |
| 452 | CompareBitmap(bitmap.get(), page_width, page_height, kOriginalMD5); |
| 453 | } |
| 454 | |
| 455 | UnloadPage(page); |
| 456 | } |
| 457 | |
| 458 | { |
| 459 | // Save a copy, open the copy, and render it. |
| 460 | // Note that it renders the transform. |
| 461 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 462 | ASSERT_TRUE(OpenSavedDocument()); |
| 463 | FPDF_PAGE saved_page = LoadSavedPage(0); |
| 464 | ASSERT_TRUE(saved_page); |
| 465 | |
| 466 | const int page_width = static_cast<int>(FPDF_GetPageWidth(saved_page)); |
| 467 | const int page_height = static_cast<int>(FPDF_GetPageHeight(saved_page)); |
| 468 | EXPECT_EQ(200, page_width); |
| 469 | EXPECT_EQ(300, page_height); |
| 470 | ScopedFPDFBitmap bitmap = RenderSavedPage(saved_page); |
| 471 | CompareBitmap(bitmap.get(), page_width, page_height, kShrunkMD5); |
| 472 | |
| 473 | CloseSavedPage(saved_page); |
| 474 | CloseSavedDocument(); |
| 475 | } |
| 476 | } |
Lei Zhang | fc45549 | 2019-06-14 17:16:09 +0000 | [diff] [blame] | 477 | |
| 478 | #if defined(OS_LINUX) || defined(OS_FUCHSIA) |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 479 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 480 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 481 | #define MAYBE_TransFormWithClipAndSaveWithLocale \ |
| 482 | DISABLED_TransFormWithClipAndSaveWithLocale |
| 483 | #else |
| 484 | #define MAYBE_TransFormWithClipAndSaveWithLocale \ |
| 485 | TransFormWithClipAndSaveWithLocale |
| 486 | #endif |
| 487 | TEST_F(FPDFTransformEmbedderTest, MAYBE_TransFormWithClipAndSaveWithLocale) { |
Lei Zhang | fc45549 | 2019-06-14 17:16:09 +0000 | [diff] [blame] | 488 | const char kOriginalMD5[] = "0a90de37f52127619c3dfb642b5fa2fe"; |
| 489 | const char kShrunkMD5[] = "f4136cc9209207ab60eb8381a3df2e69"; |
| 490 | |
| 491 | pdfium::base::ScopedLocale scoped_locale("da_DK.UTF-8"); |
| 492 | |
| 493 | { |
| 494 | ASSERT_TRUE(OpenDocument("rectangles.pdf")); |
| 495 | FPDF_PAGE page = LoadPage(0); |
| 496 | ASSERT_TRUE(page); |
| 497 | |
| 498 | { |
| 499 | // Render the page as is. |
| 500 | const int page_width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 501 | const int page_height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 502 | EXPECT_EQ(200, page_width); |
| 503 | EXPECT_EQ(300, page_height); |
| 504 | ScopedFPDFBitmap bitmap = RenderLoadedPage(page); |
| 505 | CompareBitmap(bitmap.get(), page_width, page_height, kOriginalMD5); |
| 506 | } |
| 507 | |
| 508 | { |
| 509 | // Render the page after transforming. |
| 510 | // Note that the change should affect the rendering, but does not. |
| 511 | // It should behaves just like the case below, rather than the case above. |
| 512 | // TODO(bug_1328): The checksum below should be |kShrunkMD5|. |
| 513 | const FS_MATRIX half_matrix{0.5, 0, 0, 0.5, 0, 0}; |
| 514 | EXPECT_TRUE(FPDFPage_TransFormWithClip(page, &half_matrix, nullptr)); |
| 515 | const int page_width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 516 | const int page_height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 517 | EXPECT_EQ(200, page_width); |
| 518 | EXPECT_EQ(300, page_height); |
| 519 | ScopedFPDFBitmap bitmap = RenderLoadedPage(page); |
| 520 | CompareBitmap(bitmap.get(), page_width, page_height, kOriginalMD5); |
| 521 | } |
| 522 | |
| 523 | UnloadPage(page); |
| 524 | } |
| 525 | |
| 526 | { |
| 527 | // Save a copy, open the copy, and render it. |
| 528 | // Note that it renders the transform. |
| 529 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 530 | ASSERT_TRUE(OpenSavedDocument()); |
| 531 | FPDF_PAGE saved_page = LoadSavedPage(0); |
| 532 | ASSERT_TRUE(saved_page); |
| 533 | |
| 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, kShrunkMD5); |
| 540 | |
| 541 | CloseSavedPage(saved_page); |
| 542 | CloseSavedDocument(); |
| 543 | } |
| 544 | } |
| 545 | #endif // defined(OS_LINUX) || defined(OS_FUCHSIA) |