9#include "build/build_config.h"
10#include "core/fxge/cfx_defaultrenderdevice.h"
11#include "core/fxge/dib/fx_dib.h"
12#include "public/fpdf_progressive.h"
13#include "testing/embedder_test.h"
14#include "testing/embedder_test_constants.h"
15#include "testing/gtest/include/gtest/gtest.h"
16#include "third_party/base/check.h"
20constexpr FX_ARGB kBlack = 0xFF000000;
21constexpr FX_ARGB kBlue = 0xFF0000FF;
22constexpr FX_ARGB kGreen = 0xFF00FF00;
23constexpr FX_ARGB kRed = 0xFFFF0000;
24constexpr FX_ARGB kWhite = 0xFFFFFFFF;
26const char* AnnotationStampWithApBaseContentChecksum() {
29 return "7f8437212ef1cd33ff505ece5a7e99f8";
30#elif BUILDFLAG(IS_APPLE)
31 return "346c4463cf822e39e29a602a504b9153";
33 return "4fedc838daa6762cf7eee180986a0f1b";
36#if BUILDFLAG(IS_APPLE)
37 return "243f3d6267d9db09198fed9f8c4957fd";
39 return "e31414933c9ff3950773981e5bf61678";
49 explicit FakePause(
bool should_pause) : should_pause_(should_pause) {
51 IFSDK_PAUSE
::user =
nullptr;
56 return static_cast<
FakePause*>(param)->should_pause_;
60 const bool should_pause_;
85 const FPDF_COLORSCHEME* color_scheme,
86 uint32_t background_color);
103 FPDF_FORMHANDLE handle);
115 FPDF_FORMHANDLE handle,
117 const FPDF_COLORSCHEME* color_scheme,
118 FX_ARGB background_color);
126 const FPDF_COLORSCHEME* color_scheme,
127 FX_ARGB background_color,
136 ScopedFPDFBitmap progressive_render_bitmap_;
137 int progressive_render_flags_ = 0;
141 IFSDK_PAUSE* pause) {
151 progressive_render_flags_ = flags;
153 progressive_render_bitmap_ =
154 ScopedFPDFBitmap(FPDFBitmap_Create(width, height, alpha));
155 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF;
156 FPDFBitmap_FillRect(progressive_render_bitmap_.get(), 0, 0, width, height,
158 int rv = FPDF_RenderPageBitmap_Start(progressive_render_bitmap_.get(), page,
159 0, 0, width, height, 0,
160 progressive_render_flags_, pause);
169 const FPDF_COLORSCHEME* color_scheme,
170 uint32_t background_color) {
173 progressive_render_flags_ = flags;
175 progressive_render_bitmap_ =
176 ScopedFPDFBitmap(FPDFBitmap_Create(width, height, alpha));
177 DCHECK(progressive_render_bitmap_);
178 FPDFBitmap_FillRect(progressive_render_bitmap_.get(), 0, 0, width, height,
180 int rv = FPDF_RenderPageBitmapWithColorScheme_Start(
181 progressive_render_bitmap_.get(), page, 0, 0, width, height, 0,
182 progressive_render_flags_, color_scheme, pause);
187 IFSDK_PAUSE* pause) {
188 DCHECK(progressive_render_bitmap_);
196 return FinishRenderPageWithForms(page,
nullptr);
201 FPDF_FORMHANDLE handle) {
202 DCHECK(progressive_render_bitmap_);
206 FPDF_FFLDraw(handle, progressive_render_bitmap_.get(), page, 0, 0, width,
207 height, 0, progressive_render_flags_);
209 return std::move(progressive_render_bitmap_);
215 FPDF_FORMHANDLE handle,
217 const FPDF_COLORSCHEME* color_scheme,
218 FX_ARGB background_color) {
221 page
, &pause
, flags
, color_scheme
, background_color
) ==
223 EXPECT_FALSE(render_done);
225 while (!render_done) {
228 return FinishRenderPageWithForms(page, form_handle());
234 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
235 FPDF_PAGE page = LoadPage(0);
237 FakePause pause(
false);
238 EXPECT_TRUE(StartRenderPage(page, &pause));
239 ScopedFPDFBitmap bitmap = FinishRenderPage(page);
240 CompareBitmap(bitmap.get(), 595, 842,
241 AnnotationStampWithApBaseContentChecksum());
248 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
249 FPDF_PAGE page = LoadPage(0);
251 FakePause pause(
true);
252 bool render_done = StartRenderPage(page, &pause);
253 EXPECT_FALSE(render_done);
255 while (!render_done) {
256 render_done = ContinueRenderPage(page, &pause);
258 ScopedFPDFBitmap bitmap = FinishRenderPage(page);
259 CompareBitmap(bitmap.get(), 595, 842,
260 AnnotationStampWithApBaseContentChecksum());
267 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
268 FPDF_PAGE page = LoadPage(0);
270 FakePause pause(
true);
271 bool render_done = StartRenderPageWithFlags(page, &pause,
FPDF_ANNOT);
272 EXPECT_FALSE(render_done);
274 while (!render_done) {
275 render_done = ContinueRenderPage(page, &pause);
277 ScopedFPDFBitmap bitmap = FinishRenderPage(page);
278 CompareBitmap(bitmap.get(), 595, 842,
286 ASSERT_TRUE(OpenDocument(
"text_form.pdf"));
287 FPDF_PAGE page = LoadPage(0);
289 FakePause pause(
true);
290 bool render_done = StartRenderPage(page, &pause);
291 EXPECT_FALSE(render_done);
293 while (!render_done) {
294 render_done = ContinueRenderPage(page, &pause);
296 ScopedFPDFBitmap bitmap = FinishRenderPageWithForms(page, form_handle());
304 const FPDF_COLORSCHEME* color_scheme,
305 FX_ARGB background_color,
311 FPDF_PAGE page =
LoadPage(page_num);
314 ScopedFPDFBitmap bitmap = RenderPageWithForcedColorScheme(
315 page, form_handle(), flags, color_scheme, background_color);
323 const char* content_with_text_checksum = []() {
326 return "e970b97a719ce4d8efdfcbc316255aac";
327#elif BUILDFLAG(IS_APPLE)
328 return "9eba0a0147f1d9685514d274e03d574e";
330 return "edd919ec8b59fab1f16b5f2adb1175f3";
333#if BUILDFLAG(IS_APPLE)
334 return "ee4ec12f54ce8d117a73bd9b85a8954d";
336 return "704db63ed2bf77254ecaa8035b85f21a";
340 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
342 FPDF_COLORSCHEME color_scheme{kBlack, kWhite, kWhite, kWhite};
343 VerifyRenderingWithColorScheme(0, 0, &color_scheme,
344 kBlack, 200, 200, content_with_text_checksum);
349 const char* rectangles_checksum = []() {
351 return "4b0f850a94698d07b6cd2814d1b4ccb7";
353 return "249f59b0d066c4f6bd89782a80822219";
356 ASSERT_TRUE(OpenDocument(
"rectangles.pdf"));
358 FPDF_COLORSCHEME color_scheme{kWhite, kRed, kBlue, kBlue};
359 VerifyRenderingWithColorScheme(0, 0, &color_scheme,
360 kBlack, 200, 300, rectangles_checksum);
367 const char* rectangles_checksum = []() {
369 return "c1cbbd2ce6921f608a3c55140592419b";
371 return "0ebcc11e617635eca1fa9ce475383a80";
374 ASSERT_TRUE(OpenDocument(
"rectangles.pdf"));
376 FPDF_COLORSCHEME color_scheme{kWhite, kRed, kBlue, kBlue};
378 &color_scheme, kBlack, 200, 300,
379 rectangles_checksum);
388 const char* content_with_highlight_fill_checksum = []() {
391 return "8ed2cbc6a362752fabdf9b50d3358c96";
392#elif BUILDFLAG(IS_APPLE)
393 return "fcd4dd021656f692f346780acaa24895";
395 return "49dcfcfdc38d200bb3d57a2ca3086034";
398#if BUILDFLAG(IS_APPLE)
399 return "a820afec9b99d3d3f2e9e9382bbad7c1";
401 return "a08a0639f89446f66f3689ee8e08b9fe";
405 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
407 FPDF_COLORSCHEME color_scheme{kRed, kGreen, kWhite, kWhite};
408 VerifyRenderingWithColorScheme(0,
FPDF_ANNOT, &color_scheme,
410 content_with_highlight_fill_checksum);
422 const char* md5_content_with_highlight = []() {
425 return "9389330c006d3e6054057992624684a8";
426#elif BUILDFLAG(IS_APPLE)
427 return "b7039f73f2d8a3ac3e1ef1492e425b99";
429 return "c609e8810fba2f12db8f8a2b043d97bd";
432#if BUILDFLAG(IS_APPLE)
433 return "8837bea0b3520164b1784e513c882a2d";
435 return "3dd8c02f5c06bac85e0d2c8bf37d1dc4";
439 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
441 FPDF_COLORSCHEME color_scheme{kRed, kGreen, kWhite, kWhite};
442 VerifyRenderingWithColorScheme(
444 kBlue, 612, 792, md5_content_with_highlight);
449 const char* content_with_ink_checksum = []() {
452 return "f6dfec1a38800973e57bba5da4fe77fe";
453#elif BUILDFLAG(IS_APPLE)
454 return "5108aa537b6ecc37b3f0a35b76c1b379";
456 return "b39d9f68ff71963d82c43eb20caa8f4d";
459 return "797bce7dc6c50ee86b095405df9fe5aa";
462 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
464 FPDF_COLORSCHEME color_scheme{kBlack, kGreen, kRed, kRed};
465 VerifyRenderingWithColorScheme(0,
FPDF_ANNOT, &color_scheme,
466 kBlack, 612, 792, content_with_ink_checksum);
471 const char* content_with_stamp_checksum = []() {
474 return "9365cd179a0109640bb2b7456f211524";
475#elif BUILDFLAG(IS_APPLE)
476 return "42d4d73d939cb4a1b40d003985eaf11e";
478 return "6e028012a4854ebfd9ee92da862bf679";
481#if BUILDFLAG(IS_APPLE)
482 return "8170c539e95f22f14eb8f266a5f1bbed";
484 return "d1fd087e59d4dcebf47b56570bdb8c22";
488 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
490 FPDF_COLORSCHEME color_scheme{kBlue, kGreen, kRed, kRed};
491 VerifyRenderingWithColorScheme(0,
FPDF_ANNOT, &color_scheme,
492 kWhite, 595, 842, content_with_stamp_checksum);
497 const char* content_with_form_checksum = []() {
499 return "9f75d98afc6d6313bd87e6562ea6df15";
501 return "080f7a4381606659301440e1b14dca35";
504 ASSERT_TRUE(OpenDocument(
"annotiter.pdf"));
506 FPDF_COLORSCHEME color_scheme{kGreen, kGreen, kRed, kRed};
507 VerifyRenderingWithColorScheme(0,
FPDF_ANNOT, &color_scheme,
508 kWhite, 612, 792, content_with_form_checksum);
512 nullptr, kWhite, 612, 792,
513 content_with_form_checksum);
static bool UseSkiaRenderer()
static void CompareBitmap(FPDF_BITMAP bitmap, int expected_width, int expected_height, const char *expected_md5sum)
void UnloadPage(FPDF_PAGE page)
FPDF_DOCUMENT document() const
FPDF_PAGE LoadPage(int page_number)
FakePause(bool should_pause)
static FPDF_BOOL Pause_NeedToPauseNow(IFSDK_PAUSE *param)
bool StartRenderPage(FPDF_PAGE page, IFSDK_PAUSE *pause)
bool ContinueRenderPage(FPDF_PAGE page, IFSDK_PAUSE *pause)
ScopedFPDFBitmap FinishRenderPageWithForms(FPDF_PAGE page, FPDF_FORMHANDLE handle)
ScopedFPDFBitmap RenderPageWithForcedColorScheme(FPDF_PAGE page, FPDF_FORMHANDLE handle, int flags, const FPDF_COLORSCHEME *color_scheme, FX_ARGB background_color)
bool StartRenderPageWithFlags(FPDF_PAGE page, IFSDK_PAUSE *pause, int flags)
bool StartRenderPageWithColorSchemeAndBackground(FPDF_PAGE page, IFSDK_PAUSE *pause, int flags, const FPDF_COLORSCHEME *color_scheme, uint32_t background_color)
void VerifyRenderingWithColorScheme(int page_num, int flags, const FPDF_COLORSCHEME *color_scheme, FX_ARGB background_color, int bitmap_width, int bitmap_height, const char *md5)
ScopedFPDFBitmap FinishRenderPage(FPDF_PAGE page)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_HasTransparency(FPDF_PAGE page)
#define FPDF_RENDER_TOBECONTINUED
FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage_Close(FPDF_PAGE page)
FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPage_Continue(FPDF_PAGE page, IFSDK_PAUSE *pause)
TEST_F(FPDFProgressiveRenderEmbedderTest, RenderWithoutPause)
FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageWidth(FPDF_PAGE page)
FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageHeight(FPDF_PAGE page)
#define FPDF_CONVERT_FILL_TO_STROKE
const char * AnnotationStampWithApChecksum()
const char * TextFormChecksum()