9#include "build/build_config.h"
10#include "core/fxcrt/check.h"
11#include "core/fxge/cfx_defaultrenderdevice.h"
12#include "core/fxge/dib/fx_dib.h"
13#include "public/fpdf_progressive.h"
14#include "testing/embedder_test.h"
15#include "testing/embedder_test_constants.h"
16#include "testing/gtest/include/gtest/gtest.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,
126 const FPDF_COLORSCHEME* color_scheme,
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 if (!FPDFBitmap_FillRect(progressive_render_bitmap_.get(), 0, 0, width,
157 height, fill_color)) {
160 int rv = FPDF_RenderPageBitmap_Start(progressive_render_bitmap_.get(), page,
161 0, 0, width, height, 0,
162 progressive_render_flags_, pause);
171 const FPDF_COLORSCHEME* color_scheme,
172 uint32_t background_color) {
175 progressive_render_flags_ = flags;
177 progressive_render_bitmap_ =
178 ScopedFPDFBitmap(FPDFBitmap_Create(width, height, alpha));
179 DCHECK(progressive_render_bitmap_);
180 if (!FPDFBitmap_FillRect(progressive_render_bitmap_.get(), 0, 0, width,
181 height, background_color)) {
184 int rv = FPDF_RenderPageBitmapWithColorScheme_Start(
185 progressive_render_bitmap_.get(), page, 0, 0, width, height, 0,
186 progressive_render_flags_, color_scheme, pause);
191 IFSDK_PAUSE* pause) {
192 DCHECK(progressive_render_bitmap_);
200 return FinishRenderPageWithForms(page,
nullptr);
205 FPDF_FORMHANDLE handle) {
206 DCHECK(progressive_render_bitmap_);
210 FPDF_FFLDraw(handle, progressive_render_bitmap_.get(), page, 0, 0, width,
211 height, 0, progressive_render_flags_);
213 return std::move(progressive_render_bitmap_);
219 FPDF_FORMHANDLE handle,
221 const FPDF_COLORSCHEME* color_scheme,
225 page
, &pause
, flags
, color_scheme
, background_color
) ==
227 EXPECT_FALSE(render_done);
229 while (!render_done) {
232 return FinishRenderPageWithForms(page, form_handle());
238 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
239 FPDF_PAGE page = LoadPage(0);
241 FakePause pause(
false);
242 EXPECT_TRUE(StartRenderPage(page, &pause));
243 ScopedFPDFBitmap bitmap = FinishRenderPage(page);
244 CompareBitmap(bitmap.get(), 595, 842,
245 AnnotationStampWithApBaseContentChecksum());
252 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
253 FPDF_PAGE page = LoadPage(0);
255 FakePause pause(
true);
256 bool render_done = StartRenderPage(page, &pause);
257 EXPECT_FALSE(render_done);
259 while (!render_done) {
260 render_done = ContinueRenderPage(page, &pause);
262 ScopedFPDFBitmap bitmap = FinishRenderPage(page);
263 CompareBitmap(bitmap.get(), 595, 842,
264 AnnotationStampWithApBaseContentChecksum());
271 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
272 FPDF_PAGE page = LoadPage(0);
274 FakePause pause(
true);
275 bool render_done = StartRenderPageWithFlags(page, &pause,
FPDF_ANNOT);
276 EXPECT_FALSE(render_done);
278 while (!render_done) {
279 render_done = ContinueRenderPage(page, &pause);
281 ScopedFPDFBitmap bitmap = FinishRenderPage(page);
282 CompareBitmap(bitmap.get(), 595, 842,
290 ASSERT_TRUE(OpenDocument(
"text_form.pdf"));
291 FPDF_PAGE page = LoadPage(0);
293 FakePause pause(
true);
294 bool render_done = StartRenderPage(page, &pause);
295 EXPECT_FALSE(render_done);
297 while (!render_done) {
298 render_done = ContinueRenderPage(page, &pause);
300 ScopedFPDFBitmap bitmap = FinishRenderPageWithForms(page, form_handle());
308 const FPDF_COLORSCHEME* color_scheme,
315 FPDF_PAGE page =
LoadPage(page_num);
318 ScopedFPDFBitmap bitmap = RenderPageWithForcedColorScheme(
319 page, form_handle(), flags, color_scheme, background_color);
327 const char* content_with_text_checksum = []() {
330 return "e970b97a719ce4d8efdfcbc316255aac";
331#elif BUILDFLAG(IS_APPLE)
332 return "9eba0a0147f1d9685514d274e03d574e";
334 return "edd919ec8b59fab1f16b5f2adb1175f3";
337#if BUILDFLAG(IS_APPLE)
338 return "ee4ec12f54ce8d117a73bd9b85a8954d";
340 return "704db63ed2bf77254ecaa8035b85f21a";
344 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
346 FPDF_COLORSCHEME color_scheme{kBlack, kWhite, kWhite, kWhite};
347 VerifyRenderingWithColorScheme(0, 0, &color_scheme,
348 kBlack, 200, 200, content_with_text_checksum);
353 const char* rectangles_checksum = []() {
355 return "4b0f850a94698d07b6cd2814d1b4ccb7";
357 return "249f59b0d066c4f6bd89782a80822219";
360 ASSERT_TRUE(OpenDocument(
"rectangles.pdf"));
362 FPDF_COLORSCHEME color_scheme{kWhite, kRed, kBlue, kBlue};
363 VerifyRenderingWithColorScheme(0, 0, &color_scheme,
364 kBlack, 200, 300, rectangles_checksum);
371 const char* rectangles_checksum = []() {
373 return "c1cbbd2ce6921f608a3c55140592419b";
375 return "0ebcc11e617635eca1fa9ce475383a80";
378 ASSERT_TRUE(OpenDocument(
"rectangles.pdf"));
380 FPDF_COLORSCHEME color_scheme{kWhite, kRed, kBlue, kBlue};
382 &color_scheme, kBlack, 200, 300,
383 rectangles_checksum);
392 const char* content_with_highlight_fill_checksum = []() {
395 return "8ed2cbc6a362752fabdf9b50d3358c96";
396#elif BUILDFLAG(IS_APPLE)
397 return "fcd4dd021656f692f346780acaa24895";
399 return "49dcfcfdc38d200bb3d57a2ca3086034";
402#if BUILDFLAG(IS_APPLE)
403 return "a820afec9b99d3d3f2e9e9382bbad7c1";
405 return "a08a0639f89446f66f3689ee8e08b9fe";
409 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
411 FPDF_COLORSCHEME color_scheme{kRed, kGreen, kWhite, kWhite};
412 VerifyRenderingWithColorScheme(0,
FPDF_ANNOT, &color_scheme,
414 content_with_highlight_fill_checksum);
426 const char* md5_content_with_highlight = []() {
429 return "9389330c006d3e6054057992624684a8";
430#elif BUILDFLAG(IS_APPLE)
431 return "b7039f73f2d8a3ac3e1ef1492e425b99";
433 return "c609e8810fba2f12db8f8a2b043d97bd";
436#if BUILDFLAG(IS_APPLE)
437 return "8837bea0b3520164b1784e513c882a2d";
439 return "3dd8c02f5c06bac85e0d2c8bf37d1dc4";
443 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
445 FPDF_COLORSCHEME color_scheme{kRed, kGreen, kWhite, kWhite};
446 VerifyRenderingWithColorScheme(
448 kBlue, 612, 792, md5_content_with_highlight);
453 const char* content_with_ink_checksum = []() {
456 return "cddb7472b064782b2866aa3dc87ca73e";
457#elif BUILDFLAG(IS_APPLE)
458 return "0ef02da77fc1e08455148ecadd257e06";
460 return "bd9d457356dba5fcf33ec9afdaefcab8";
463 return "797bce7dc6c50ee86b095405df9fe5aa";
466 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
468 FPDF_COLORSCHEME color_scheme{kBlack, kGreen, kRed, kRed};
469 VerifyRenderingWithColorScheme(0,
FPDF_ANNOT, &color_scheme,
470 kBlack, 612, 792, content_with_ink_checksum);
475 const char* content_with_stamp_checksum = []() {
478 return "c35d1256f6684da13023a0e74622c885";
479#elif BUILDFLAG(IS_APPLE)
480 return "bb302d8808633fede3b6e2e39ac8aaa7";
482 return "1bd68054628cf193b399a16638ecb5f9";
485#if BUILDFLAG(IS_APPLE)
486 return "8170c539e95f22f14eb8f266a5f1bbed";
488 return "d1fd087e59d4dcebf47b56570bdb8c22";
492 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
494 FPDF_COLORSCHEME color_scheme{kBlue, kGreen, kRed, kRed};
495 VerifyRenderingWithColorScheme(0,
FPDF_ANNOT, &color_scheme,
496 kWhite, 595, 842, content_with_stamp_checksum);
501 const char* content_with_form_checksum = []() {
503 return "9f75d98afc6d6313bd87e6562ea6df15";
505 return "080f7a4381606659301440e1b14dca35";
508 ASSERT_TRUE(OpenDocument(
"annotiter.pdf"));
510 FPDF_COLORSCHEME color_scheme{kGreen, kGreen, kRed, kRed};
511 VerifyRenderingWithColorScheme(0,
FPDF_ANNOT, &color_scheme,
512 kWhite, 612, 792, content_with_form_checksum);
516 nullptr, kWhite, 612, 792,
517 content_with_form_checksum);
static bool UseSkiaRenderer()
FPDF_PAGE LoadPage(int page_index)
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
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()