Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fpdf_flatten_embeddertest.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
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 "build/build_config.h"
6#include "core/fxge/cfx_defaultrenderdevice.h"
7#include "public/fpdf_flatten.h"
8#include "public/fpdfview.h"
9#include "testing/embedder_test.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12namespace {
13
14class FPDFFlattenEmbedderTest : public EmbedderTest {};
15
16} // namespace
17
18TEST_F(FPDFFlattenEmbedderTest, FlatNothing) {
19 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
20 FPDF_PAGE page = LoadPage(0);
21 EXPECT_TRUE(page);
23 UnloadPage(page);
24}
25
26TEST_F(FPDFFlattenEmbedderTest, FlatNormal) {
27 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
28 FPDF_PAGE page = LoadPage(0);
29 EXPECT_TRUE(page);
31 UnloadPage(page);
32}
33
34TEST_F(FPDFFlattenEmbedderTest, FlatPrint) {
35 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
36 FPDF_PAGE page = LoadPage(0);
37 EXPECT_TRUE(page);
39 UnloadPage(page);
40}
41
42TEST_F(FPDFFlattenEmbedderTest, BUG_861842) {
43 const char* checkbox_checksum = []() {
44 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
45#if BUILDFLAG(IS_APPLE)
46 return "84a527f16649880525a1a8edc6c24c16";
47#else
48 return "95fdaa000e81c80892b8d370f77be970";
49#endif
50 }
51#if BUILDFLAG(IS_APPLE)
52 return "6aafcb2d98da222964bcdbf5aa1f4f1f";
53#else
54 return "594265790b81df2d93120d33b72a6ada";
55#endif
56 }();
57
58 ASSERT_TRUE(OpenDocument("bug_861842.pdf"));
59 FPDF_PAGE page = LoadPage(0);
60 ASSERT_TRUE(page);
61
62 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
63 CompareBitmap(bitmap.get(), 100, 120, checkbox_checksum);
64
66 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
67
68 UnloadPage(page);
69
70 // TODO(crbug.com/861842): This should not render blank.
71 static constexpr char kBlankPageHash[] = "48400809c3862dae64b0cd00d51057a4";
72 VerifySavedDocument(100, 120, kBlankPageHash);
73}
74
75TEST_F(FPDFFlattenEmbedderTest, BUG_889099) {
76 const char* page_checksum = []() {
77 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
78#if BUILDFLAG(IS_WIN)
79 return "1d83328d2d1ca12b9c9ea5faa62ac515";
80#elif BUILDFLAG(IS_APPLE)
81 return "3b6f937deec2d27029cbce02111dc065";
82#else
83 return "de7119d99f42deab2f4215017bdb16af";
84#endif
85 }
86#if BUILDFLAG(IS_APPLE)
87 return "049ed3f1e21fc72f929af3410c64bc8f";
88#else
89 return "3db87245e3f4e37f4cb18654bbe22d97";
90#endif
91 }();
92 const char* flattened_page_checksum = []() {
93 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
94#if BUILDFLAG(IS_WIN)
95 return "07deccbd4a42aaf6bf45a525f0be388e";
96#elif BUILDFLAG(IS_APPLE)
97 return "f1bbe115355a2ad6d8ac34c7ff14ba75";
98#else
99 return "7978c7b3d643a5f0ac0f03ce759c55fe";
100#endif
101 }
102#if BUILDFLAG(IS_APPLE)
103 return "41debc60cf2a8f74c710ec6082d77b18";
104#else
105 return "0832157462ea70fbbf053e14b1d6457f";
106#endif
107 }();
108
109 ASSERT_TRUE(OpenDocument("bug_889099.pdf"));
110 FPDF_PAGE page = LoadPage(0);
111 ASSERT_TRUE(page);
112
113 // The original document has a malformed media box; the height is -400.
114 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
115 CompareBitmap(bitmap.get(), 300, 400, page_checksum);
116
118 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
119
120 UnloadPage(page);
121
122 VerifySavedDocument(300, 400, flattened_page_checksum);
123}
124
125TEST_F(FPDFFlattenEmbedderTest, BUG_890322) {
126 const char* checksum = []() {
127 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
128 return "793689536cf64fe792c2f241888c0cf3";
129 }
130 return "6c674642154408e877d88c6c082d67e9";
131 }();
132 ASSERT_TRUE(OpenDocument("bug_890322.pdf"));
133 FPDF_PAGE page = LoadPage(0);
134 ASSERT_TRUE(page);
135
136 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
137 CompareBitmap(bitmap.get(), 200, 200, checksum);
138
140 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
141
142 UnloadPage(page);
143
144 VerifySavedDocument(200, 200, checksum);
145}
146
147TEST_F(FPDFFlattenEmbedderTest, BUG_896366) {
148 const char* checksum = []() {
149 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
150 return "c3cccfadc4c5249e6aa0675e511fa4c3";
151 }
152 return "f71ab085c52c8445ae785eca3ec858b1";
153 }();
154 ASSERT_TRUE(OpenDocument("bug_896366.pdf"));
155 FPDF_PAGE page = LoadPage(0);
156 ASSERT_TRUE(page);
157
158 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
159 CompareBitmap(bitmap.get(), 612, 792, checksum);
160
162 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
163
164 UnloadPage(page);
165
166 VerifySavedDocument(612, 792, checksum);
167}
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag)
#define FLAT_PRINT
#define FLATTEN_NOTHINGTODO
#define FLATTEN_SUCCESS
#define FLAT_NORMALDISPLAY
TEST_F(FPDFFlattenEmbedderTest, FlatNothing)
#define FPDF_ANNOT
Definition fpdfview.h:804