kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 1 | // Copyright 2019 The PDFium Authors |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 5 | #include <stdint.h> |
| 6 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
| 9 | #include "build/build_config.h" |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 10 | #include "core/fxge/cfx_defaultrenderdevice.h" |
| 11 | #include "core/fxge/dib/fx_dib.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 12 | #include "public/fpdf_progressive.h" |
| 13 | #include "testing/embedder_test.h" |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 14 | #include "testing/embedder_test_constants.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 15 | #include "testing/gtest/include/gtest/gtest.h" |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 16 | #include "third_party/base/check.h" |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | constexpr FX_ARGB kBlack = 0xFF000000; |
| 21 | constexpr FX_ARGB kBlue = 0xFF0000FF; |
| 22 | constexpr FX_ARGB kGreen = 0xFF00FF00; |
| 23 | constexpr FX_ARGB kRed = 0xFFFF0000; |
| 24 | constexpr FX_ARGB kWhite = 0xFFFFFFFF; |
| 25 | |
| 26 | const char* AnnotationStampWithApBaseContentChecksum() { |
| 27 | #if BUILDFLAG(IS_APPLE) |
| 28 | if (!CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 29 | return "243f3d6267d9db09198fed9f8c4957fd"; |
| 30 | #endif |
| 31 | return "e31414933c9ff3950773981e5bf61678"; |
| 32 | } |
| 33 | |
| 34 | } // namespace |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 35 | |
| 36 | class FPDFProgressiveRenderEmbedderTest : public EmbedderTest { |
| 37 | public: |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 38 | class FakePause : public IFSDK_PAUSE { |
| 39 | public: |
| 40 | explicit FakePause(bool should_pause) : should_pause_(should_pause) { |
| 41 | IFSDK_PAUSE::version = 1; |
| 42 | IFSDK_PAUSE::user = nullptr; |
| 43 | IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; |
| 44 | } |
| 45 | ~FakePause() = default; |
| 46 | static FPDF_BOOL Pause_NeedToPauseNow(IFSDK_PAUSE* param) { |
| 47 | return static_cast<FakePause*>(param)->should_pause_; |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | const bool should_pause_; |
| 52 | }; |
| 53 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 54 | // StartRenderPageWithFlags() with no flags. |
| 55 | // The call returns true if the rendering is complete. |
| 56 | bool StartRenderPage(FPDF_PAGE page, IFSDK_PAUSE* pause); |
| 57 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 58 | // Start rendering of |page| into a bitmap with the ability to |pause| the |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 59 | // rendering with the specified rendering |flags|. |
| 60 | // The call returns true if the rendering is complete. |
| 61 | // |
| 62 | // See public/fpdfview.h for a list of page rendering flags. |
| 63 | bool StartRenderPageWithFlags(FPDF_PAGE page, IFSDK_PAUSE* pause, int flags); |
| 64 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 65 | // Start rendering of |page| into a bitmap with the ability to pause the |
| 66 | // rendering with the specified rendering |flags| and the specified |
| 67 | // |color_scheme|. This also takes in the |background_color| for the bitmap. |
| 68 | // The call returns true if the rendering is complete. |
| 69 | // |
| 70 | // See public/fpdfview.h for the list of page rendering flags and |
| 71 | // the list of colors in the scheme. |
| 72 | bool StartRenderPageWithColorSchemeAndBackground( |
| 73 | FPDF_PAGE page, |
| 74 | IFSDK_PAUSE* pause, |
| 75 | int flags, |
| 76 | const FPDF_COLORSCHEME* color_scheme, |
| 77 | uint32_t background_color); |
| 78 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 79 | // Continue rendering of |page| into the bitmap created in |
| 80 | // StartRenderPageWithFlags(). |
| 81 | // The call returns true if the rendering is complete. |
| 82 | bool ContinueRenderPage(FPDF_PAGE page, IFSDK_PAUSE* pause); |
| 83 | |
| 84 | // Simplified form of FinishRenderPageWithForms() with no form handle. |
| 85 | ScopedFPDFBitmap FinishRenderPage(FPDF_PAGE page); |
| 86 | |
| 87 | // Finish rendering of |page| into the bitmap created in |
| 88 | // StartRenderPageWithFlags(). This also renders the forms associated with |
| 89 | // the page. The form handle associated with |page| should be passed in via |
| 90 | // |handle|. If |handle| is nullptr, then forms on the page will not be |
| 91 | // rendered. |
| 92 | // This returns the bitmap generated by the progressive render calls. |
| 93 | ScopedFPDFBitmap FinishRenderPageWithForms(FPDF_PAGE page, |
| 94 | FPDF_FORMHANDLE handle); |
| 95 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 96 | // Convert the |page| into a bitmap with a |background_color|, using the |
| 97 | // color scheme render API with the specific |flags| and |color_scheme|. |
| 98 | // The form handle associated with |page| should be passed in via |handle|. |
| 99 | // If |handle| is nullptr, then forms on the page will not be rendered. |
| 100 | // This returns the bitmap generated by the progressive render calls. |
| 101 | // |
| 102 | // See public/fpdfview.h for a list of page rendering flags and |
| 103 | // the color scheme that can be applied for rendering. |
| 104 | ScopedFPDFBitmap RenderPageWithForcedColorScheme( |
| 105 | FPDF_PAGE page, |
| 106 | FPDF_FORMHANDLE handle, |
| 107 | int flags, |
| 108 | const FPDF_COLORSCHEME* color_scheme, |
| 109 | FX_ARGB background_color); |
| 110 | |
| 111 | protected: |
| 112 | // Utility method to render the |page_num| of the currently loaded Pdf |
| 113 | // using RenderPageWithForcedColorScheme() passing in the render options |
| 114 | // and expected values for bitmap verification. |
| 115 | void VerifyRenderingWithColorScheme(int page_num, |
| 116 | int flags, |
| 117 | const FPDF_COLORSCHEME* color_scheme, |
| 118 | FX_ARGB background_color, |
| 119 | int bitmap_width, |
| 120 | int bitmap_height, |
| 121 | const char* md5); |
| 122 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 123 | private: |
| 124 | // Keeps the bitmap used for progressive rendering alive until |
| 125 | // FPDF_RenderPage_Close() is called after which the bitmap is returned |
| 126 | // to the caller. |
| 127 | ScopedFPDFBitmap progressive_render_bitmap_; |
| 128 | int progressive_render_flags_ = 0; |
| 129 | }; |
| 130 | |
| 131 | bool FPDFProgressiveRenderEmbedderTest::StartRenderPage(FPDF_PAGE page, |
| 132 | IFSDK_PAUSE* pause) { |
| 133 | return StartRenderPageWithFlags(page, pause, 0); |
| 134 | } |
| 135 | |
| 136 | bool FPDFProgressiveRenderEmbedderTest::StartRenderPageWithFlags( |
| 137 | FPDF_PAGE page, |
| 138 | IFSDK_PAUSE* pause, |
| 139 | int flags) { |
| 140 | int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 141 | int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 142 | progressive_render_flags_ = flags; |
| 143 | int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; |
| 144 | progressive_render_bitmap_ = |
| 145 | ScopedFPDFBitmap(FPDFBitmap_Create(width, height, alpha)); |
| 146 | FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; |
| 147 | FPDFBitmap_FillRect(progressive_render_bitmap_.get(), 0, 0, width, height, |
| 148 | fill_color); |
| 149 | int rv = FPDF_RenderPageBitmap_Start(progressive_render_bitmap_.get(), page, |
| 150 | 0, 0, width, height, 0, |
| 151 | progressive_render_flags_, pause); |
| 152 | return rv != FPDF_RENDER_TOBECONTINUED; |
| 153 | } |
| 154 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 155 | bool FPDFProgressiveRenderEmbedderTest:: |
| 156 | StartRenderPageWithColorSchemeAndBackground( |
| 157 | FPDF_PAGE page, |
| 158 | IFSDK_PAUSE* pause, |
| 159 | int flags, |
| 160 | const FPDF_COLORSCHEME* color_scheme, |
| 161 | uint32_t background_color) { |
| 162 | int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 163 | int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 164 | progressive_render_flags_ = flags; |
| 165 | int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; |
| 166 | progressive_render_bitmap_ = |
| 167 | ScopedFPDFBitmap(FPDFBitmap_Create(width, height, alpha)); |
| 168 | DCHECK(progressive_render_bitmap_); |
| 169 | FPDFBitmap_FillRect(progressive_render_bitmap_.get(), 0, 0, width, height, |
| 170 | background_color); |
| 171 | int rv = FPDF_RenderPageBitmapWithColorScheme_Start( |
| 172 | progressive_render_bitmap_.get(), page, 0, 0, width, height, 0, |
| 173 | progressive_render_flags_, color_scheme, pause); |
| 174 | return rv != FPDF_RENDER_TOBECONTINUED; |
| 175 | } |
| 176 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 177 | bool FPDFProgressiveRenderEmbedderTest::ContinueRenderPage(FPDF_PAGE page, |
| 178 | IFSDK_PAUSE* pause) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 179 | DCHECK(progressive_render_bitmap_); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 180 | |
| 181 | int rv = FPDF_RenderPage_Continue(page, pause); |
| 182 | return rv != FPDF_RENDER_TOBECONTINUED; |
| 183 | } |
| 184 | |
| 185 | ScopedFPDFBitmap FPDFProgressiveRenderEmbedderTest::FinishRenderPage( |
| 186 | FPDF_PAGE page) { |
| 187 | return FinishRenderPageWithForms(page, /*handle=*/nullptr); |
| 188 | } |
| 189 | |
| 190 | ScopedFPDFBitmap FPDFProgressiveRenderEmbedderTest::FinishRenderPageWithForms( |
| 191 | FPDF_PAGE page, |
| 192 | FPDF_FORMHANDLE handle) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 193 | DCHECK(progressive_render_bitmap_); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 194 | |
| 195 | int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 196 | int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 197 | FPDF_FFLDraw(handle, progressive_render_bitmap_.get(), page, 0, 0, width, |
| 198 | height, 0, progressive_render_flags_); |
| 199 | FPDF_RenderPage_Close(page); |
| 200 | return std::move(progressive_render_bitmap_); |
| 201 | } |
| 202 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 203 | ScopedFPDFBitmap |
| 204 | FPDFProgressiveRenderEmbedderTest::RenderPageWithForcedColorScheme( |
| 205 | FPDF_PAGE page, |
| 206 | FPDF_FORMHANDLE handle, |
| 207 | int flags, |
| 208 | const FPDF_COLORSCHEME* color_scheme, |
| 209 | FX_ARGB background_color) { |
| 210 | FakePause pause(true); |
| 211 | bool render_done = StartRenderPageWithColorSchemeAndBackground( |
| 212 | page, &pause, flags, color_scheme, background_color) == |
| 213 | FPDF_RENDER_TOBECONTINUED; |
| 214 | EXPECT_FALSE(render_done); |
| 215 | |
| 216 | while (!render_done) { |
| 217 | render_done = ContinueRenderPage(page, &pause); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 218 | } |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 219 | return FinishRenderPageWithForms(page, form_handle()); |
| 220 | } |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 221 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 222 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderWithoutPause) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 223 | // Test rendering of page content using progressive render APIs |
| 224 | // without pausing the rendering. |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 225 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 226 | FPDF_PAGE page = LoadPage(0); |
| 227 | ASSERT_TRUE(page); |
| 228 | FakePause pause(false); |
| 229 | EXPECT_TRUE(StartRenderPage(page, &pause)); |
| 230 | ScopedFPDFBitmap bitmap = FinishRenderPage(page); |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 231 | CompareBitmap(bitmap.get(), 595, 842, |
| 232 | AnnotationStampWithApBaseContentChecksum()); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 233 | UnloadPage(page); |
| 234 | } |
| 235 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 236 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderWithPause) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 237 | // Test rendering of page content using progressive render APIs |
| 238 | // with pause in rendering. |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 239 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 240 | FPDF_PAGE page = LoadPage(0); |
| 241 | ASSERT_TRUE(page); |
| 242 | FakePause pause(true); |
| 243 | bool render_done = StartRenderPage(page, &pause); |
| 244 | EXPECT_FALSE(render_done); |
| 245 | |
| 246 | while (!render_done) { |
| 247 | render_done = ContinueRenderPage(page, &pause); |
| 248 | } |
| 249 | ScopedFPDFBitmap bitmap = FinishRenderPage(page); |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 250 | CompareBitmap(bitmap.get(), 595, 842, |
| 251 | AnnotationStampWithApBaseContentChecksum()); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 252 | UnloadPage(page); |
| 253 | } |
| 254 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 255 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderAnnotWithPause) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 256 | // Test rendering of the page with annotations using progressive render APIs |
| 257 | // with pause in rendering. |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 258 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 259 | FPDF_PAGE page = LoadPage(0); |
| 260 | ASSERT_TRUE(page); |
| 261 | FakePause pause(true); |
| 262 | bool render_done = StartRenderPageWithFlags(page, &pause, FPDF_ANNOT); |
| 263 | EXPECT_FALSE(render_done); |
| 264 | |
| 265 | while (!render_done) { |
| 266 | render_done = ContinueRenderPage(page, &pause); |
| 267 | } |
| 268 | ScopedFPDFBitmap bitmap = FinishRenderPage(page); |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 269 | CompareBitmap(bitmap.get(), 595, 842, |
| 270 | pdfium::AnnotationStampWithApChecksum()); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 271 | UnloadPage(page); |
| 272 | } |
| 273 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 274 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderFormsWithPause) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 275 | // Test rendering of the page with forms using progressive render APIs |
| 276 | // with pause in rendering. |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 277 | ASSERT_TRUE(OpenDocument("text_form.pdf")); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 278 | FPDF_PAGE page = LoadPage(0); |
| 279 | ASSERT_TRUE(page); |
| 280 | FakePause pause(true); |
| 281 | bool render_done = StartRenderPage(page, &pause); |
| 282 | EXPECT_FALSE(render_done); |
| 283 | |
| 284 | while (!render_done) { |
| 285 | render_done = ContinueRenderPage(page, &pause); |
| 286 | } |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 287 | ScopedFPDFBitmap bitmap = FinishRenderPageWithForms(page, form_handle()); |
| 288 | CompareBitmap(bitmap.get(), 300, 300, pdfium::TextFormChecksum()); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 289 | UnloadPage(page); |
| 290 | } |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 291 | |
| 292 | void FPDFProgressiveRenderEmbedderTest::VerifyRenderingWithColorScheme( |
| 293 | int page_num, |
| 294 | int flags, |
| 295 | const FPDF_COLORSCHEME* color_scheme, |
| 296 | FX_ARGB background_color, |
| 297 | int bitmap_width, |
| 298 | int bitmap_height, |
| 299 | const char* md5) { |
| 300 | ASSERT_TRUE(document()); |
| 301 | |
| 302 | FPDF_PAGE page = LoadPage(page_num); |
| 303 | ASSERT_TRUE(page); |
| 304 | |
| 305 | ScopedFPDFBitmap bitmap = RenderPageWithForcedColorScheme( |
| 306 | page, form_handle(), flags, color_scheme, background_color); |
| 307 | ASSERT_TRUE(bitmap); |
| 308 | CompareBitmap(bitmap.get(), bitmap_width, bitmap_height, md5); |
| 309 | UnloadPage(page); |
| 310 | } |
| 311 | |
| 312 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderTextWithColorScheme) { |
| 313 | // Test rendering of text with forced color scheme on. |
| 314 | const char* content_with_text_checksum = []() { |
| 315 | if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 316 | return "5ece6059efdc2ecb2894fa3cf329dc94"; |
| 317 | #if BUILDFLAG(IS_APPLE) |
| 318 | return "ee4ec12f54ce8d117a73bd9b85a8954d"; |
| 319 | #else |
| 320 | return "704db63ed2bf77254ecaa8035b85f21a"; |
| 321 | #endif // BUILDFLAG(IS_APPLE) |
| 322 | }(); |
| 323 | |
| 324 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 325 | |
| 326 | FPDF_COLORSCHEME color_scheme{kBlack, kWhite, kWhite, kWhite}; |
| 327 | VerifyRenderingWithColorScheme(/*page_num=*/0, /*flags=*/0, &color_scheme, |
| 328 | kBlack, 200, 200, content_with_text_checksum); |
| 329 | } |
| 330 | |
| 331 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderPathWithColorScheme) { |
| 332 | // Test rendering of paths with forced color scheme on. |
| 333 | const char* rectangles_checksum = []() { |
| 334 | if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 335 | return "4b0f850a94698d07b6cd2814d1b4ccb7"; |
| 336 | return "249f59b0d066c4f6bd89782a80822219"; |
| 337 | }(); |
| 338 | |
| 339 | ASSERT_TRUE(OpenDocument("rectangles.pdf")); |
| 340 | |
| 341 | FPDF_COLORSCHEME color_scheme{kWhite, kRed, kBlue, kBlue}; |
| 342 | VerifyRenderingWithColorScheme(/*page_num=*/0, /*flags=*/0, &color_scheme, |
| 343 | kBlack, 200, 300, rectangles_checksum); |
| 344 | } |
| 345 | |
| 346 | TEST_F(FPDFProgressiveRenderEmbedderTest, |
| 347 | RenderPathWithColorSchemeAndConvertFillToStroke) { |
| 348 | // Test rendering of paths with forced color scheme on and conversion from |
| 349 | // fill to stroke enabled. The fill paths should be rendered as stroke. |
| 350 | const char* rectangles_checksum = []() { |
| 351 | if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 352 | return "c1cbbd2ce6921f608a3c55140592419b"; |
| 353 | return "0ebcc11e617635eca1fa9ce475383a80"; |
| 354 | }(); |
| 355 | |
| 356 | ASSERT_TRUE(OpenDocument("rectangles.pdf")); |
| 357 | |
| 358 | FPDF_COLORSCHEME color_scheme{kWhite, kRed, kBlue, kBlue}; |
| 359 | VerifyRenderingWithColorScheme(/*page_num=*/0, FPDF_CONVERT_FILL_TO_STROKE, |
| 360 | &color_scheme, kBlack, 200, 300, |
| 361 | rectangles_checksum); |
| 362 | } |
| 363 | |
| 364 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderHighlightWithColorScheme) { |
| 365 | // Test rendering of highlight with forced color scheme on. |
| 366 | // |
| 367 | // Note: The fill color rendered for highlight is different from the normal |
| 368 | // path since highlights have Multiply blend mode, while the other path has |
| 369 | // Normal blend mode. |
| 370 | const char* content_with_highlight_fill_checksum = []() { |
| 371 | if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 372 | return "9b6273fdbc9db780c49f7540756209f8"; |
| 373 | #if BUILDFLAG(IS_APPLE) |
| 374 | return "a820afec9b99d3d3f2e9e9382bbad7c1"; |
| 375 | #else |
| 376 | return "a08a0639f89446f66f3689ee8e08b9fe"; |
| 377 | #endif // BUILDFLAG(IS_APPLE) |
| 378 | }(); |
| 379 | |
| 380 | ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); |
| 381 | |
| 382 | FPDF_COLORSCHEME color_scheme{kRed, kGreen, kWhite, kWhite}; |
| 383 | VerifyRenderingWithColorScheme(/*page_num=*/0, FPDF_ANNOT, &color_scheme, |
| 384 | kBlue, 612, 792, |
| 385 | content_with_highlight_fill_checksum); |
| 386 | } |
| 387 | |
| 388 | TEST_F(FPDFProgressiveRenderEmbedderTest, |
| 389 | RenderHighlightWithColorSchemeAndConvertFillToStroke) { |
| 390 | // Test rendering of highlight with forced color and converting fill to |
| 391 | // stroke. The highlight should be rendered as a stroke of the rect. |
| 392 | // |
| 393 | // Note: The stroke color rendered for highlight is different from the normal |
| 394 | // path since highlights have Multiply blend mode, while the other path has |
| 395 | // Normal blend mode. |
| 396 | |
| 397 | const char* md5_content_with_highlight = []() { |
| 398 | if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 399 | return "772246195d18f75d40a22bee913c098f"; |
| 400 | #if BUILDFLAG(IS_APPLE) |
| 401 | return "8837bea0b3520164b1784e513c882a2d"; |
| 402 | #else |
| 403 | return "3dd8c02f5c06bac85e0d2c8bf37d1dc4"; |
| 404 | #endif // BUILDFLAG(IS_APPLE) |
| 405 | }(); |
| 406 | |
| 407 | ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); |
| 408 | |
| 409 | FPDF_COLORSCHEME color_scheme{kRed, kGreen, kWhite, kWhite}; |
| 410 | VerifyRenderingWithColorScheme( |
| 411 | /*page_num=*/0, FPDF_ANNOT | FPDF_CONVERT_FILL_TO_STROKE, &color_scheme, |
| 412 | kBlue, 612, 792, md5_content_with_highlight); |
| 413 | } |
| 414 | |
| 415 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderInkWithColorScheme) { |
| 416 | // Test rendering of multiple ink with forced color scheme on. |
| 417 | const char* content_with_ink_checksum = []() { |
| 418 | if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 419 | return "ebc57721e4c8da34156e09b9b2e62fb0"; |
| 420 | return "797bce7dc6c50ee86b095405df9fe5aa"; |
| 421 | }(); |
| 422 | |
| 423 | ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); |
| 424 | |
| 425 | FPDF_COLORSCHEME color_scheme{kBlack, kGreen, kRed, kRed}; |
| 426 | VerifyRenderingWithColorScheme(/*page_num=*/0, FPDF_ANNOT, &color_scheme, |
| 427 | kBlack, 612, 792, content_with_ink_checksum); |
| 428 | } |
| 429 | |
| 430 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderStampWithColorScheme) { |
| 431 | // Test rendering of static annotation with forced color scheme on. |
| 432 | const char* content_with_stamp_checksum = []() { |
| 433 | if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 434 | return "a791fdb4f595bb6c4187cc2aeed5e9e8"; |
| 435 | #if BUILDFLAG(IS_APPLE) |
| 436 | return "8170c539e95f22f14eb8f266a5f1bbed"; |
| 437 | #else |
| 438 | return "d1fd087e59d4dcebf47b56570bdb8c22"; |
| 439 | #endif |
| 440 | }(); |
| 441 | |
| 442 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
| 443 | |
| 444 | FPDF_COLORSCHEME color_scheme{kBlue, kGreen, kRed, kRed}; |
| 445 | VerifyRenderingWithColorScheme(/*page_num=*/0, FPDF_ANNOT, &color_scheme, |
| 446 | kWhite, 595, 842, content_with_stamp_checksum); |
| 447 | } |
| 448 | |
| 449 | TEST_F(FPDFProgressiveRenderEmbedderTest, RenderFormWithColorScheme) { |
| 450 | // Test rendering of form does not change with forced color scheme on. |
| 451 | const char* content_with_form_checksum = []() { |
| 452 | if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) |
| 453 | return "9f75d98afc6d6313bd87e6562ea6df15"; |
| 454 | return "080f7a4381606659301440e1b14dca35"; |
| 455 | }(); |
| 456 | |
| 457 | ASSERT_TRUE(OpenDocument("annotiter.pdf")); |
| 458 | |
| 459 | FPDF_COLORSCHEME color_scheme{kGreen, kGreen, kRed, kRed}; |
| 460 | VerifyRenderingWithColorScheme(/*page_num=*/0, FPDF_ANNOT, &color_scheme, |
| 461 | kWhite, 612, 792, content_with_form_checksum); |
| 462 | |
| 463 | // Verify that the MD5 hash matches when rendered without |color_scheme|. |
| 464 | VerifyRenderingWithColorScheme(/*page_num=*/0, FPDF_ANNOT, |
| 465 | /*color_scheme=*/nullptr, kWhite, 612, 792, |
| 466 | content_with_form_checksum); |
| 467 | } |