12#include "build/build_config.h"
13#include "core/fpdfapi/font/cpdf_font.h"
14#include "core/fpdfapi/page/cpdf_page.h"
15#include "core/fpdfapi/page/cpdf_pageobject.h"
16#include "core/fpdfapi/parser/cpdf_array.h"
17#include "core/fpdfapi/parser/cpdf_dictionary.h"
18#include "core/fpdfapi/parser/cpdf_number.h"
19#include "core/fpdfapi/parser/cpdf_stream.h"
20#include "core/fpdfapi/parser/cpdf_stream_acc.h"
21#include "core/fxcrt/fx_codepage.h"
22#include "core/fxcrt/fx_system.h"
23#include "core/fxge/cfx_defaultrenderdevice.h"
24#include "core/fxge/fx_font.h"
25#include "fpdfsdk/cpdfsdk_helpers.h"
26#include "public/cpp/fpdf_scopers.h"
27#include "public/fpdf_annot.h"
28#include "public/fpdf_edit.h"
29#include "public/fpdfview.h"
30#include "testing/embedder_test.h"
31#include "testing/embedder_test_constants.h"
32#include "testing/fx_string_testhelpers.h"
33#include "testing/gmock/include/gmock/gmock-matchers.h"
34#include "testing/gtest/include/gtest/gtest.h"
35#include "testing/utils/file_util.h"
36#include "testing/utils/hash.h"
37#include "testing/utils/path_service.h"
38#include "third_party/base/check.h"
40using pdfium::HelloWorldChecksum;
41using testing::HasSubstr;
43using testing::UnorderedElementsAreArray;
47const char kAllRemovedChecksum[] =
"eee4600ac08b458ac7ac2320e225674c";
49const wchar_t kBottomText[] = L"I'm at the bottom of the page";
51const char* BottomTextChecksum() {
54 return "5d8f2b613a2f9591a52373c72d6b88ee";
55#elif BUILDFLAG(IS_APPLE)
56 return "8ca7dc6269ee68507389aa40eebcb9f8";
58 return "c62d315856a558d2666b80d474831efe";
61#if BUILDFLAG(IS_APPLE)
62 return "81636489006a31fcb00cf29efcdf7909";
64 return "891dcb6e914c8360998055f1f47c9727";
68const char* FirstRemovedChecksum() {
71 return "251007e902e512d0359240ad957ee2dc";
72#elif BUILDFLAG(IS_APPLE)
73 return "dcb929fae86d5b935888ce7f9f1ab71b";
75 return "3006ab2b12d27246eae4faad509ac575";
78#if BUILDFLAG(IS_APPLE)
79 return "a1dc2812692fcc7ee4f01ca77435df9d";
81 return "e1477dc3b5b3b9c560814c4d1135a02b";
85const wchar_t kLoadedFontText[] = L"I am testing my loaded font, WEE.";
87const char* LoadedFontTextChecksum() {
90 return "b0efd562e84958f06bb006ba27d5f4bd";
91#elif BUILDFLAG(IS_APPLE)
92 return "23e7874d160692b0ef3e0c8780f73dab";
94 return "fc2334c350cbd0d2ae6076689da09741";
97#if BUILDFLAG(IS_APPLE)
98 return "0f3e4a7d71f9e7eb8a1a0d69403b9848";
100 return "d58570cc045dfb818b92cbabbd1a364c";
104const char kRedRectangleChecksum[] =
"66d02eaa6181e2c069ce2ea99beda497";
107const char kEmbeddedImage33Checksum[] =
"cb3637934bb3b95a6e4ae1ea9eb9e56e";
109struct FPDFEditMoveEmbedderTestCase {
110 std::vector<
int> page_indices;
111 int page_indices_len;
114 bool expected_result;
116 std::vector<
int> expected_order;
117 const char*
const name;
120std::ostream& operator<<(
std::ostream& os,
121 const FPDFEditMoveEmbedderTestCase& t) {
122 os << t.name <<
": Indices are {";
123 for (size_t i = 0; i < t.page_indices.size(); ++i) {
124 os << t.page_indices[i];
125 if (i != t.page_indices.size() - 1) {
129 os <<
"}, page order len is " << t.page_indices_len <<
", dest page index is "
130 << t.dest_page_index <<
", expected result is " << t.expected_result;
140 cpdf_doc_ = CPDFDocumentFromFPDFDocument(
document());
148 pdfium::span<
const uint8_t> span) {
149 RetainPtr<
const CPDF_Dictionary> font_desc =
150 font_dict->GetDictFor(
"FontDescriptor");
151 ASSERT_TRUE(font_desc);
152 EXPECT_EQ(
"FontDescriptor", font_desc->GetNameFor(
"Type"));
153 ByteString font_name = font_desc->GetNameFor(
"FontName");
159 ASSERT_TRUE(font_desc->KeyExist(
"Flags"));
161 int font_flags = font_desc->GetIntegerFor(
"Flags");
165 ASSERT_TRUE(font_desc->KeyExist(
"FontBBox"));
167 RetainPtr<
const CPDF_Array> fontBBox = font_desc->GetArrayFor(
"FontBBox");
168 ASSERT_TRUE(fontBBox);
169 EXPECT_EQ(4u, fontBBox->size());
172 EXPECT_TRUE(fontBBox->GetIntegerAt(0) < fontBBox->GetIntegerAt(2));
173 EXPECT_TRUE(fontBBox->GetIntegerAt(1) < fontBBox->GetIntegerAt(3));
175 EXPECT_TRUE(font_desc->KeyExist(
"ItalicAngle"));
176 EXPECT_TRUE(font_desc->KeyExist(
"Ascent"));
177 EXPECT_TRUE(font_desc->KeyExist(
"Descent"));
178 EXPECT_TRUE(font_desc->KeyExist(
"CapHeight"));
179 EXPECT_TRUE(font_desc->KeyExist(
"StemV"));
180 ByteString present
("FontFile");
181 ByteString absent
("FontFile2");
183 std::swap(present, absent);
184 EXPECT_TRUE(font_desc->KeyExist(present));
185 EXPECT_FALSE(font_desc->KeyExist(absent));
188 pdfium::MakeRetain<CPDF_StreamAcc>(font_desc->GetStreamFor(present));
189 streamAcc->LoadAllDataRaw();
192 ASSERT_EQ(span.size(), streamAcc->GetSize());
194 ASSERT_EQ(
static_cast<
int>(span.size()), streamAcc->GetLength1ForTest());
197 pdfium::span<
const uint8_t> stream_data = streamAcc->GetSpan();
198 for (size_t j = 0; j < span.size(); j++)
199 EXPECT_EQ(span[j], stream_data[j]) <<
" at byte " << j;
207 EXPECT_GT(widths_array->size(), 1u);
208 int num_cids_checked = 0;
210 for (size_t idx = 0; idx < widths_array->size(); idx++) {
211 int cid = widths_array->GetFloatAt(idx);
212 EXPECT_GE(cid, cur_cid);
213 ASSERT_FALSE(++idx == widths_array->size());
215 if (next->IsArray()) {
217 const CPDF_Array* arr = next->AsArray();
218 int cnt =
static_cast<
int>(arr->size());
219 size_t inner_idx = 0;
220 for (cur_cid = cid; cur_cid < cid + cnt; cur_cid++) {
221 int width = arr->GetFloatAt(inner_idx++);
223 <<
" at cid " << cur_cid;
225 num_cids_checked += cnt;
229 ASSERT_TRUE(next->IsNumber());
230 int last_cid = next->AsNumber()->GetInteger();
231 ASSERT_FALSE(++idx == widths_array->size());
232 int width = widths_array->GetFloatAt(idx);
233 for (cur_cid = cid; cur_cid <= last_cid; cur_cid++) {
235 <<
" at cid " << cur_cid;
237 num_cids_checked += last_cid - cid + 1;
240 EXPECT_GT(num_cids_checked, 200);
250const char kExpectedPDF[] =
252 "%\xA1\xB3\xC5\xD7\r\n"
254 "<</Pages 2 0 R /Type/Catalog>>\r\n"
257 "<</Count 1/Kids\\[ 4 0 R \\]/Type/Pages>>\r\n"
260 "<</CreationDate\\(D:.*\\)/Creator\\(PDFium\\)>>\r\n"
263 "<</MediaBox\\[ 0 0 640 480\\]/Parent 2 0 R "
265 "/Rotate 0/Type/Page"
270 "0000000000 65535 f\r\n"
271 "0000000017 00000 n\r\n"
272 "0000000066 00000 n\r\n"
273 "0000000122 00000 n\r\n"
274 "0000000192 00000 n\r\n"
279 "/Size 5/ID\\[<.*><.*>\\]>>\r\n"
287 CreateEmptyDocument();
288 ScopedFPDFPage page(FPDFPage_New(document(), 0, 400, 400));
289 std::string font_path;
291 "NotoSansCJK/NotoSansSC-Regular.subset.otf", &font_path));
293 std::vector<uint8_t> font_data = GetFileContents(font_path.c_str());
294 ASSERT_FALSE(font_data.empty());
296 ScopedFPDFFont font(FPDFText_LoadFont(document(), font_data.data(),
299 FPDF_PAGEOBJECT text_object =
300 FPDFPageObj_CreateTextObj(document(), font.get(), 20.0f);
301 EXPECT_TRUE(text_object);
305 ScopedFPDFWideString text = GetFPDFWideString(L"这是第一句。 这是第二行。");
306 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
309 FPDFPage_InsertObject(page.get(), text_object);
310 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
312 const char* checksum = []() {
315 return "a1bc9e4007dc2155e9f56bf16234573e";
316#elif BUILDFLAG(IS_APPLE)
317 return "9a31fb87d1c6d2346bba22d1196041cd";
319 return "5bb65e15fc0a685934cd5006dec08a76";
322 return "9a31fb87d1c6d2346bba22d1196041cd";
324 ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
325 CompareBitmap(page_bitmap.get(), 400, 400, checksum);
327 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
328 VerifySavedDocument(400, 400, checksum);
332 CreateEmptyDocument();
333 ScopedFPDFPage page(FPDFPage_New(document(), 0, 400, 400));
334 std::string font_path;
336 "NotoSansCJK/NotoSansSC-Regular.subset.otf", &font_path));
338 std::vector<uint8_t> font_data = GetFileContents(font_path.c_str());
339 ASSERT_FALSE(font_data.empty());
341 ScopedFPDFFont font(FPDFText_LoadFont(document(), font_data.data(),
344 FPDF_PAGEOBJECT text_object =
345 FPDFPageObj_CreateTextObj(document(), font.get(), 20.0f);
346 EXPECT_TRUE(text_object);
349 const std::vector<uint32_t> charcodes = {9, 6, 7, 3, 5, 2, 1,
352 FPDFText_SetCharcodes(text_object, charcodes.data(), charcodes.size()));
355 FPDFPage_InsertObject(page.get(), text_object);
356 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
358 const char* checksum = []() {
361 return "a1bc9e4007dc2155e9f56bf16234573e";
362#elif BUILDFLAG(IS_APPLE)
363 return "9a31fb87d1c6d2346bba22d1196041cd";
365 return "5bb65e15fc0a685934cd5006dec08a76";
368 return "9a31fb87d1c6d2346bba22d1196041cd";
370 ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
371 CompareBitmap(page_bitmap.get(), 400, 400, checksum);
373 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
374 VerifySavedDocument(400, 400, checksum);
378 CreateEmptyDocument();
379 ScopedFPDFPage page(FPDFPage_New(document(), 0, 400, 400));
380 std::string font_path = PathService::GetTestFilePath(
"fonts/bug_2094.ttf");
381 ASSERT_FALSE(font_path.empty());
383 std::vector<uint8_t> font_data = GetFileContents(font_path.c_str());
384 ASSERT_FALSE(font_data.empty());
386 ScopedFPDFFont font(FPDFText_LoadFont(document(), font_data.data(),
393 CreateEmptyDocument();
394 FPDF_PAGE page = FPDFPage_New(document(), 0, 640.0, 480.0);
398 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
400 EXPECT_THAT(GetString(), testing::MatchesRegex(std::string(
401 kExpectedPDF,
sizeof(kExpectedPDF))));
407 const char kAllBlackChecksum[] =
"5708fc5c4a8bd0abde99c8e8f0390615";
410 ScopedFPDFBitmap orig_bitmap;
412 ASSERT_TRUE(OpenDocument(
"black.pdf"));
413 FPDF_PAGE orig_page = LoadPage(0);
414 ASSERT_TRUE(orig_page);
415 orig_bitmap = RenderLoadedPage(orig_page);
416 CompareBitmap(orig_bitmap.get(), 612, 792, kAllBlackChecksum);
417 UnloadPage(orig_page);
422 ScopedFPDFDocument temp_doc(FPDF_CreateNewDocument());
423 ScopedFPDFPage temp_page(FPDFPage_New(temp_doc.get(), 0, 612, 792));
427 ScopedFPDFPageObject temp_img(FPDFPageObj_NewImageObj(temp_doc.get()));
428 FPDF_PAGE pages_array[] = {temp_page.get()};
429 EXPECT_TRUE(FPDFImageObj_SetBitmap(pages_array, 1, temp_img.get(),
431 static constexpr FS_MATRIX kLetterScaleMatrix{612, 0, 0, 792, 0, 0};
432 EXPECT_TRUE(FPDFPageObj_SetMatrix(temp_img.get(), &kLetterScaleMatrix));
433 FPDFPage_InsertObject(temp_page.get(), temp_img.release());
434 EXPECT_TRUE(FPDFPage_GenerateContent(temp_page.get()));
435 EXPECT_TRUE(FPDF_SaveAsCopy(temp_doc.get(),
this, 0));
440 EXPECT_GT(GetString().size(), 923u);
441 VerifySavedDocument(612, 792, kAllBlackChecksum);
446 FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
451 ASSERT_TRUE(red_rect);
461 FPDF_BOOL stroke =
true;
464 EXPECT_FALSE(stroke);
466 static constexpr FS_MATRIX kMatrix = {1, 2, 3, 4, 5, 6};
471 EXPECT_FLOAT_EQ(1.0f, matrix.a);
472 EXPECT_FLOAT_EQ(2.0f, matrix.b);
473 EXPECT_FLOAT_EQ(3.0f, matrix.c);
474 EXPECT_FLOAT_EQ(4.0f, matrix.d);
475 EXPECT_FLOAT_EQ(5.0f, matrix.e);
476 EXPECT_FLOAT_EQ(6.0f, matrix.f);
479 matrix = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
484 ScopedFPDFBitmap page_bitmap = RenderPage(page);
485 CompareBitmap(page_bitmap.get(), 612, 792, kRedRectangleChecksum);
546 ScopedFPDFBitmap page_bitmap = RenderPage(page);
547 CompareBitmap(page_bitmap.get(), 612, 792,
548 "7b0b87604594e773add528fae567a558");
586 ScopedFPDFBitmap page_bitmap = RenderPage(page);
587 CompareBitmap(page_bitmap.get(), 612, 792,
588 "eadc8020a14dfcf091da2688733d8806");
602 const char* last_checksum = []() {
604 return "ed14c60702b1489c597c7d46ece7f86d";
606 return "9823e1a21bd9b72b6a442ba4f12af946";
609 ScopedFPDFBitmap page_bitmap = RenderPage(page);
610 CompareBitmap(page_bitmap.get(), 612, 792, last_checksum);
615 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
619 VerifySavedDocument(612, 792, last_checksum);
624 ASSERT_TRUE(OpenDocument(
"clip_path.pdf"));
625 FPDF_PAGE page = LoadPage(0);
631 ASSERT_TRUE(triangle);
667 ASSERT_TRUE(clip_path);
720 ASSERT_TRUE(OpenDocument(
"bug_1399.pdf"));
721 FPDF_PAGE page = LoadPage(0);
735 EXPECT_FLOAT_EQ(107.718f, x);
736 EXPECT_FLOAT_EQ(719.922f, y);
742 EXPECT_FLOAT_EQ(394.718f, x);
743 EXPECT_FLOAT_EQ(719.922f, y);
748 ASSERT_TRUE(clip_path);
758 static const char kOriginalChecksum[] =
"126366fb95e6caf8ea196780075b22b2";
759 static const char kRemovedChecksum[] =
"6ec2f27531927882624b37bc7d8e12f4";
761 ASSERT_TRUE(OpenDocument(
"bug_1549.pdf"));
762 FPDF_PAGE page = LoadPage(0);
765 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
766 CompareBitmap(bitmap.get(), 100, 150, kOriginalChecksum);
768 ScopedFPDFPageObject obj(FPDFPage_GetObject(page, 0));
770 ASSERT_TRUE(FPDFPage_RemoveObject(page, obj.get()));
776 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
777 CompareBitmap(bitmap.get(), 100, 150, kRemovedChecksum);
780 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
784 VerifySavedDocument(100, 150,
"4f9889cd5993db20f1ab37d677ac8d26");
789 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
790 FPDF_PAGE page = LoadPage(0);
796 ASSERT_TRUE(page_object);
797 ScopedFPDFWideString text1 = GetFPDFWideString(L"Changed for SetText test");
798 EXPECT_TRUE(FPDFText_SetText(page_object, text1.get()));
804 const char* changed_checksum = []() {
807 return "e1c530ca0705424f19a1b7ff0bffdbaa";
808#elif BUILDFLAG(IS_APPLE)
809 return "c65881cb16125c23e5513a16dc68f3a2";
811 return "4a8345a139507932729e07d4831cbe2b";
814#if BUILDFLAG(IS_APPLE)
815 return "b720e83476fd6819d47c533f1f43c728";
817 return "9a85b9354a69c61772ed24151c140f46";
821 ScopedFPDFBitmap page_bitmap = RenderPage(page);
822 CompareBitmap(page_bitmap.get(), 200, 200, changed_checksum);
827 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
832 ASSERT_TRUE(OpenSavedDocument());
833 FPDF_PAGE saved_page = LoadSavedPage(0);
834 ASSERT_TRUE(saved_page);
837 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
838 CompareBitmap(page_bitmap.get(), 200, 200, changed_checksum);
841 CloseSavedPage(saved_page);
842 CloseSavedDocument();
846 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
847 FPDF_PAGE page = LoadPage(0);
852 ASSERT_TRUE(page_object);
854 const uint32_t kDummyValue = 42;
855 EXPECT_FALSE(FPDFText_SetCharcodes(
nullptr,
nullptr, 0));
856 EXPECT_FALSE(FPDFText_SetCharcodes(
nullptr,
nullptr, 1));
857 EXPECT_FALSE(FPDFText_SetCharcodes(
nullptr, &kDummyValue, 0));
858 EXPECT_FALSE(FPDFText_SetCharcodes(
nullptr, &kDummyValue, 1));
859 EXPECT_FALSE(FPDFText_SetCharcodes(page_object,
nullptr, 1));
866 ASSERT_TRUE(OpenDocument(
"bug_1558.pdf"));
867 FPDF_PAGE page = LoadPage(0);
870 const char* original_checksum = []() {
873 return "0822ec5d476e8371544ef4bb7a0596e1";
874#elif BUILDFLAG(IS_APPLE)
875 return "721dae4e2258a52a000af88d09ec75ca";
877 return "3c04e3acc732faaf39fb0c19efd056ac";
880#if BUILDFLAG(IS_APPLE)
881 return "ae7a25c85e0e2dd0c5cb9dd5cd37f6df";
883 return "7af7fe5b281298261eb66ac2d22f5054";
888 ScopedFPDFBitmap original_bitmap = RenderPage(page);
889 CompareBitmap(original_bitmap.get(), 200, 200, original_checksum);
895 ScopedFPDFTextPage text_page(FPDFText_LoadPage(page));
896 ASSERT_TRUE(text_page);
898 ASSERT_EQ(2, obj_count);
899 for (
int i = 0; i < obj_count; ++i) {
903 FPDFTextObj_GetText(text_obj, text_page.get(),
906 std::vector<FPDF_WCHAR> buffer = GetFPDFWideStringBuffer(size);
907 ASSERT_EQ(size, FPDFTextObj_GetText(text_obj, text_page.get(),
908 buffer.data(), size));
909 EXPECT_TRUE(FPDFText_SetText(text_obj, buffer.data()));
915 ScopedFPDFBitmap edited_bitmap = RenderPage(page);
916 CompareBitmap(edited_bitmap.get(), 200, 200, original_checksum);
921 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
925 ASSERT_TRUE(OpenSavedDocument());
926 FPDF_PAGE saved_page = LoadSavedPage(0);
927 ASSERT_TRUE(saved_page);
930 ScopedFPDFBitmap saved_bitmap = RenderSavedPage(saved_page);
931 CompareBitmap(saved_bitmap.get(), 200, 200, original_checksum);
934 CloseSavedPage(saved_page);
935 CloseSavedDocument();
940 ASSERT_TRUE(OpenDocument(
"bug_1574.pdf"));
941 FPDF_PAGE page = LoadPage(0);
944 const char* original_checksum = []() {
947 return "6f22adb3ba2a2c60a940bfb52e14dd58";
948#elif BUILDFLAG(IS_APPLE)
949 return "afa2260cbe84be78867940d72420d0b4";
951 return "d76a31d931a350f0809226a41029a9a4";
954#if BUILDFLAG(IS_APPLE)
955 return "1226bc2b8072622eb28f52321876e814";
957 return "c5241eef60b9eac68ed1f2a5fd002703";
962 ScopedFPDFBitmap original_bitmap = RenderPage(page);
963 CompareBitmap(original_bitmap.get(), 200, 300, original_checksum);
969 ScopedFPDFTextPage text_page(FPDFText_LoadPage(page));
970 ASSERT_TRUE(text_page);
976 unsigned long size = FPDFTextObj_GetText(text_obj, text_page.get(),
979 std::vector<FPDF_WCHAR> buffer = GetFPDFWideStringBuffer(size);
980 ASSERT_EQ(size, FPDFTextObj_GetText(text_obj, text_page.get(),
981 buffer.data(), size));
982 EXPECT_TRUE(FPDFText_SetText(text_obj, buffer.data()));
987 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
991 ASSERT_TRUE(OpenSavedDocument());
992 FPDF_PAGE saved_page = LoadSavedPage(0);
993 ASSERT_TRUE(saved_page);
996 ScopedFPDFBitmap saved_bitmap = RenderSavedPage(saved_page);
997 CompareBitmap(saved_bitmap.get(), 200, 300, original_checksum);
1000 CloseSavedPage(saved_page);
1001 CloseSavedDocument();
1005 ASSERT_TRUE(OpenDocument(
"bug_1893.pdf"));
1006 FPDF_PAGE page = LoadPage(0);
1008 const char* original_checksum = []() {
1010#if BUILDFLAG(IS_WIN)
1011 return "10c8257bb54b4431196d963d68d45f12";
1012#elif BUILDFLAG(IS_APPLE)
1013 return "c42eef2028cb86a0a8601d61707b126f";
1015 return "d8be4379e729242785945458924318a3";
1018#if BUILDFLAG(IS_APPLE)
1019 return "0964322399241618539b474dbf9d40c6";
1021 return "c3672f206e47d98677401f1617ad56eb";
1025 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1026 CompareBitmap(bitmap.get(), 200, 300, original_checksum);
1031 const char* removed_checksum = []() {
1033#if BUILDFLAG(IS_WIN)
1034 return "95484d03b9da898617f297b1429f7f84";
1035#elif BUILDFLAG(IS_APPLE)
1036 return "7222709eca0e8f72a66ce06283f7c10f";
1038 return "4a02191e033dddeb2110d55af3f14544";
1041#if BUILDFLAG(IS_APPLE)
1042 return "d0837f2b8809a5902d3c4219441fbafe";
1044 return "e9c0cbd6adcb2151b4e36a61ab26a20a";
1050 ScopedFPDFPageObject object(FPDFPage_GetObject(page, 0));
1051 ASSERT_TRUE(FPDFPage_RemoveObject(page, object.get()));
1054 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1055 CompareBitmap(bitmap.get(), 200, 300, removed_checksum);
1058 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1066 const char* wrong_checksum = []() {
1068#if BUILDFLAG(IS_WIN)
1069 return "441cada6218d4fd79dbe0ba95093524e";
1070#elif BUILDFLAG(IS_APPLE)
1071 return "627290533339e0ae493dc9385fac53e2";
1073 return "57da26dcb24503403cadb27ed8bb46c6";
1076#if BUILDFLAG(IS_APPLE)
1077 return "c3b6a8ecd863914044f5f79137c606b5";
1079 return "cb19480a846e4efd36418cbd7412118e";
1083 ASSERT_TRUE(OpenSavedDocument());
1084 FPDF_PAGE saved_page = LoadSavedPage(0);
1085 ScopedFPDFBitmap bitmap = RenderSavedPageWithFlags(saved_page,
FPDF_ANNOT);
1086 CompareBitmap(bitmap.get(), 200, 300, wrong_checksum);
1087 CloseSavedPage(saved_page);
1088 CloseSavedDocument();
1094 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
1095 FPDF_PAGE page = LoadPage(0);
1100 ScopedFPDFBitmap page_bitmap = RenderPage(page);
1107 ScopedFPDFPageObject page_object(FPDFPage_GetObject(page, 0));
1108 ASSERT_TRUE(page_object);
1110 EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object.get()));
1116 ScopedFPDFBitmap page_bitmap = RenderPage(page);
1117 CompareBitmap(page_bitmap.get(), 200, 200, FirstRemovedChecksum());
1123 ScopedFPDFBitmap page_bitmap = RenderPage(page);
1124 CompareBitmap(page_bitmap.get(), 200, 200, FirstRemovedChecksum());
1128 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1129 VerifySavedDocument(200, 200, FirstRemovedChecksum());
1132 EXPECT_THAT(GetString(), Not(HasSubstr(
"/F1")));
1133 EXPECT_THAT(GetString(), Not(HasSubstr(
"/F2")));
1134 EXPECT_THAT(GetString(), Not(HasSubstr(
"/Times-Roman")));
1142 ASSERT_TRUE(OpenDocument(
"hello_world_2_pages.pdf"));
1143 FPDF_PAGE page1 = LoadPage(0);
1145 FPDF_PAGE page2 = LoadPage(1);
1150 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1152 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1159 ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1, 0));
1160 ASSERT_TRUE(page_object);
1162 EXPECT_TRUE(FPDFPage_RemoveObject(page1, page_object.get()));
1168 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1169 CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
1170 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1177 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1178 CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
1179 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1184 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1185 ASSERT_TRUE(OpenSavedDocument());
1186 FPDF_PAGE saved_page1 = LoadSavedPage(0);
1187 VerifySavedRendering(saved_page1, 200, 200, FirstRemovedChecksum());
1188 CloseSavedPage(saved_page1);
1189 FPDF_PAGE saved_page2 = LoadSavedPage(1);
1191 CloseSavedPage(saved_page2);
1192 CloseSavedDocument();
1194 std::vector<std::string> split_saved_data = StringSplit(GetString(),
'\n');
1197 EXPECT_THAT(split_saved_data, Contains(HasSubstr(
"/F1")).Times(1));
1198 EXPECT_THAT(split_saved_data, Contains(HasSubstr(
"/F2")).Times(1));
1199 EXPECT_THAT(split_saved_data, Contains(HasSubstr(
"/Times-Roman")).Times(1));
1208 ASSERT_TRUE(OpenDocument(
"hello_world_2_pages_split_streams.pdf"));
1209 FPDF_PAGE page1 = LoadPage(0);
1211 FPDF_PAGE page2 = LoadPage(1);
1216 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1218 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1225 ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1, 0));
1226 ASSERT_TRUE(page_object);
1228 EXPECT_TRUE(FPDFPage_RemoveObject(page1, page_object.get()));
1234 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1235 CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
1236 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1243 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1244 CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
1245 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1250 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1251 ASSERT_TRUE(OpenSavedDocument());
1252 FPDF_PAGE saved_page1 = LoadSavedPage(0);
1253 VerifySavedRendering(saved_page1, 200, 200, FirstRemovedChecksum());
1254 CloseSavedPage(saved_page1);
1255 FPDF_PAGE saved_page2 = LoadSavedPage(1);
1257 CloseSavedPage(saved_page2);
1258 CloseSavedDocument();
1266 ASSERT_TRUE(OpenDocument(
"hello_world_2_pages_shared_resources_dict.pdf"));
1267 FPDF_PAGE page1 = LoadPage(0);
1269 FPDF_PAGE page2 = LoadPage(1);
1274 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1276 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1283 ScopedFPDFPageObject page_object(FPDFPage_GetObject(page1, 0));
1284 ASSERT_TRUE(page_object);
1286 EXPECT_TRUE(FPDFPage_RemoveObject(page1, page_object.get()));
1292 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1293 CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
1294 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1301 ScopedFPDFBitmap page1_bitmap = RenderPage(page1);
1302 CompareBitmap(page1_bitmap.get(), 200, 200, FirstRemovedChecksum());
1303 ScopedFPDFBitmap page2_bitmap = RenderPage(page2);
1308 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1309 ASSERT_TRUE(OpenSavedDocument());
1310 FPDF_PAGE saved_page1 = LoadSavedPage(0);
1311 VerifySavedRendering(saved_page1, 200, 200, FirstRemovedChecksum());
1312 CloseSavedPage(saved_page1);
1313 FPDF_PAGE saved_page2 = LoadSavedPage(1);
1315 CloseSavedPage(saved_page2);
1316 CloseSavedDocument();
1324 int expected_object_count,
1325 size_t expected_prime_count,
1326 size_t expected_square_count,
1327 size_t expected_greater_than_ten_count,
1328 size_t expected_bounds_count) {
1330 ASSERT_EQ(expected_object_count, object_count);
1332 size_t prime_count = 0;
1333 size_t square_count = 0;
1334 size_t greater_than_ten_count = 0;
1335 size_t bounds_count = 0;
1336 for (
int i = 0; i < object_count; ++i) {
1340 for (
int j = 0; j < mark_count; ++j) {
1344 unsigned long name_len = 999u;
1347 EXPECT_GT(name_len, 0u);
1348 EXPECT_NE(999u, name_len);
1350 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
1351 if (name == L"Prime") {
1353 }
else if (name == L"Square") {
1355 int expected_square = start_from + i;
1358 unsigned long get_param_key_return = 999u;
1360 &get_param_key_return
));
1361 EXPECT_EQ((6u + 1u) * 2u, get_param_key_return);
1363 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
1364 EXPECT_EQ(L"Factor", key);
1371 EXPECT_EQ(expected_square, square_root * square_root);
1372 }
else if (name == L"GreaterThanTen") {
1373 greater_than_ten_count++;
1374 }
else if (name == L"Bounds") {
1378 unsigned long get_param_key_return = 999u;
1380 &get_param_key_return
));
1381 EXPECT_EQ((8u + 1u) * 2u, get_param_key_return);
1383 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
1384 EXPECT_EQ(L"Position", key);
1388 unsigned long length;
1390 mark
, "Position", buffer
, sizeof(buffer)
, &length
));
1391 ASSERT_GT(length, 0u);
1392 std::wstring value =
1393 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
1397 EXPECT_EQ((5u + 1u) * 2u, length);
1398 EXPECT_EQ(L"First", value);
1399 }
else if (i == object_count - 1) {
1400 if (length == (4u + 1u) * 2u) {
1401 EXPECT_EQ(L"Last", value);
1402 }
else if (length == (3u + 1u) * 2u) {
1403 EXPECT_EQ(L"End", value);
1418 EXPECT_EQ(expected_prime_count, prime_count);
1419 EXPECT_EQ(expected_square_count, square_count);
1420 EXPECT_EQ(expected_greater_than_ten_count, greater_than_ten_count);
1421 EXPECT_EQ(expected_bounds_count, bounds_count);
1426 ASSERT_TRUE(OpenDocument(
"text_in_page_marked_indirect.pdf"));
1427 FPDF_PAGE page = LoadPage(0);
1437 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
1438 FPDF_PAGE page = LoadPage(0);
1443 const char* original_checksum = []() {
1445#if BUILDFLAG(IS_WIN)
1446 return "cefa45d13f92fb761251661a2c889157";
1447#elif BUILDFLAG(IS_APPLE)
1448 return "b2044dc5b49fdca723d74bd6277df689";
1450 return "efc2206b313fff03be8e701907322b06";
1453#if BUILDFLAG(IS_APPLE)
1454#ifdef ARCH_CPU_ARM64
1455 return "cdc8e22cf1e7e06999dc456288672a3b";
1457 return "966579fb98206858ce2f0a1f94a74d05";
1460 return "3d5a3de53d5866044c2b6bf339742c97";
1463 ScopedFPDFBitmap page_bitmap = RenderPage(page);
1464 CompareBitmap(page_bitmap.get(), 200, 200, original_checksum);
1467 constexpr int expected_object_count = 19;
1471 std::vector<FPDF_PAGEOBJECT> primes;
1472 for (
int i = 0; i < expected_object_count; ++i) {
1476 for (
int j = 0; j < mark_count; ++j) {
1480 unsigned long name_len = 999u;
1483 EXPECT_GT(name_len, 0u);
1484 EXPECT_NE(999u, name_len);
1486 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
1487 if (name == L"Prime") {
1488 primes.push_back(page_object);
1494 for (FPDF_PAGEOBJECT page_object : primes) {
1495 EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
1496 FPDFPageObj_Destroy(page_object);
1500 const char* non_primes_checksum = []() {
1502#if BUILDFLAG(IS_WIN)
1503 return "690c7d4c7850fbe726c2299208425f4f";
1504#elif BUILDFLAG(IS_APPLE)
1505 return "427228e73125ede1050a641cd9b9c8ec";
1507 return "10a6558c9e40ea837922e6f2882a2d57";
1510#if BUILDFLAG(IS_APPLE)
1511#ifdef ARCH_CPU_ARM64
1512 return "23c4aec321547f51591fe7363a9ea2d6";
1514 return "6e19a4dd674b522cd39cf41956559bd6";
1517 return "bc8623c052f12376c3d8dd09a6cd27df";
1520 const char* non_primes_after_save_checksum = []() {
1522#if BUILDFLAG(IS_WIN)
1523 return "690c7d4c7850fbe726c2299208425f4f";
1524#elif BUILDFLAG(IS_APPLE)
1525 return "427228e73125ede1050a641cd9b9c8ec";
1527 return "10a6558c9e40ea837922e6f2882a2d57";
1530#if BUILDFLAG(IS_APPLE)
1531#ifdef ARCH_CPU_ARM64
1532 return "6bb1ea0d0a512f29edabda33064a0725";
1534 return "3cb35c681f8fb5a43a49146ac7caa818";
1537 return "bc8623c052f12376c3d8dd09a6cd27df";
1541 ScopedFPDFBitmap page_bitmap = RenderPage(page);
1542 CompareBitmap(page_bitmap.get(), 200, 200, non_primes_checksum);
1547 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1551 ASSERT_TRUE(OpenSavedDocument());
1552 FPDF_PAGE saved_page = LoadSavedPage(0);
1553 ASSERT_TRUE(saved_page);
1557 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
1558 CompareBitmap(page_bitmap.get(), 200, 200, non_primes_after_save_checksum);
1561 CloseSavedPage(saved_page);
1562 CloseSavedDocument();
1567 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
1568 FPDF_PAGE page = LoadPage(0);
1571 constexpr int kExpectedObjectCount = 19;
1575 for (
int i = 0; i < kExpectedObjectCount; ++i) {
1579 for (
int j = mark_count - 1; j >= 0; --j) {
1583 unsigned long name_len = 999u;
1586 EXPECT_GT(name_len, 0u);
1587 EXPECT_NE(999u, name_len);
1589 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
1590 if (name == L"Prime") {
1605 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1609 ASSERT_TRUE(OpenSavedDocument());
1610 FPDF_PAGE saved_page = LoadSavedPage(0);
1611 ASSERT_TRUE(saved_page);
1615 CloseSavedPage(saved_page);
1616 CloseSavedDocument();
1621 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
1622 FPDF_PAGE page = LoadPage(0);
1625 constexpr int kExpectedObjectCount = 19;
1629 for (
int i = 0; i < kExpectedObjectCount; ++i) {
1633 for (
int j = 0; j < mark_count; ++j) {
1637 unsigned long name_len = 999u;
1640 EXPECT_GT(name_len, 0u);
1641 EXPECT_NE(999u, name_len);
1643 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
1644 if (name == L"Square") {
1662 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1666 ASSERT_TRUE(OpenSavedDocument());
1667 FPDF_PAGE saved_page = LoadSavedPage(0);
1668 ASSERT_TRUE(saved_page);
1670 size_t square_count = 0;
1671 for (
int i = 0; i < kExpectedObjectCount; ++i) {
1675 for (
int j = 0; j < mark_count; ++j) {
1679 unsigned long name_len = 999u;
1682 EXPECT_GT(name_len, 0u);
1683 EXPECT_NE(999u, name_len);
1685 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
1686 if (name == L"Square") {
1698 EXPECT_EQ(4u, square_count);
1700 CloseSavedPage(saved_page);
1701 CloseSavedDocument();
1706 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
1707 FPDF_PAGE page = LoadPage(0);
1722 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1726 ASSERT_TRUE(OpenSavedDocument());
1727 FPDF_PAGE saved_page = LoadSavedPage(0);
1728 ASSERT_TRUE(saved_page);
1732 CloseSavedPage(saved_page);
1733 CloseSavedDocument();
1738 ASSERT_TRUE(OpenDocument(
"text_in_page_marked_indirect.pdf"));
1739 FPDF_PAGE page = LoadPage(0);
1754 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1758 ASSERT_TRUE(OpenSavedDocument());
1759 FPDF_PAGE saved_page = LoadSavedPage(0);
1760 ASSERT_TRUE(saved_page);
1764 CloseSavedPage(saved_page);
1765 CloseSavedDocument();
1770 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
1771 FPDF_PAGE page = LoadPage(0);
1777 ASSERT_TRUE(page_object);
1785 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1790 ASSERT_TRUE(OpenSavedDocument());
1791 FPDF_PAGE saved_page = LoadSavedPage(0);
1792 ASSERT_TRUE(saved_page);
1794 CloseSavedPage(saved_page);
1795 CloseSavedDocument();
1800 ASSERT_TRUE(OpenDocument(
"hello_world_split_streams.pdf"));
1801 FPDF_PAGE page = LoadPage(0);
1808 ASSERT_TRUE(page_object);
1813 const char* hello_removed_checksum = []() {
1815#if BUILDFLAG(IS_WIN)
1816 return "48b5524e20e942d2a8f7e15611968cc7";
1817#elif BUILDFLAG(IS_APPLE)
1818 return "5b9d1dee233eb9d51e23a36c6c631443";
1820 return "204c11472f5b93719487de7b9c1b1c93";
1823#if BUILDFLAG(IS_APPLE)
1824 return "5508c2f06d104050f74f655693e38c2c";
1826 return "a8cd82499cf744e0862ca468c9d4ceb8";
1830 ScopedFPDFBitmap page_bitmap = RenderPage(page);
1831 CompareBitmap(page_bitmap.get(), 200, 200, hello_removed_checksum);
1836 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1841 ASSERT_TRUE(OpenSavedDocument());
1842 FPDF_PAGE saved_page = LoadSavedPage(0);
1843 ASSERT_TRUE(saved_page);
1847 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
1848 CompareBitmap(page_bitmap.get(), 200, 200, hello_removed_checksum);
1851 CloseSavedPage(saved_page);
1852 CloseSavedDocument();
1857 ASSERT_TRUE(OpenDocument(
"hello_world_split_streams.pdf"));
1858 FPDF_PAGE page = LoadPage(0);
1865 ASSERT_TRUE(page_object);
1871 ScopedFPDFBitmap page_bitmap = RenderPage(page);
1877 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1882 ASSERT_TRUE(OpenSavedDocument());
1883 FPDF_PAGE saved_page = LoadSavedPage(0);
1884 ASSERT_TRUE(saved_page);
1888 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
1892 CloseSavedPage(saved_page);
1893 CloseSavedDocument();
1898 ASSERT_TRUE(OpenDocument(
"split_streams.pdf"));
1899 FPDF_PAGE page = LoadPage(0);
1906 for (
int i = 0; i < 19; i++) {
1908 ASSERT_TRUE(page_object);
1924 ASSERT_TRUE(OpenDocument(
"split_streams.pdf"));
1925 FPDF_PAGE page = LoadPage(0);
1935 for (
int i = 18; i >= 0; i--) {
1937 ASSERT_TRUE(page_object);
1951 for (
int i = 0; i < 16; i++) {
1953 ASSERT_TRUE(page_object);
1969 for (
int i = 0; i < 16; i++) {
1971 ASSERT_TRUE(page_object);
1980 const char* stream1_removed_checksum = []() {
1982#if BUILDFLAG(IS_WIN)
1983 return "d7e6debf2dc02de449860ee8012a18d2";
1984#elif BUILDFLAG(IS_APPLE)
1985 return "b26ac6d9bef9c756a19a9aafc60709bd";
1987 return "0b3ef335b8d86a3f9d609368b9d075e0";
1990#if BUILDFLAG(IS_APPLE)
1992 return "08505db7b598f7397a2260ecb1f6d86d";
1994 return "3cdc75af44c15bed80998facd6e674c9";
1997 return "b474826df1acedb05c7b82e1e49e64a6";
2001 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2002 CompareBitmap(page_bitmap.get(), 200, 200, stream1_removed_checksum);
2006 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2011 ASSERT_TRUE(OpenSavedDocument());
2012 FPDF_PAGE saved_page = LoadSavedPage(0);
2013 ASSERT_TRUE(saved_page);
2018 for (
int i = 0; i < 16; i++) {
2020 ASSERT_TRUE(page_object);
2030 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
2031 CompareBitmap(page_bitmap.get(), 200, 200, stream1_removed_checksum);
2034 CloseSavedPage(saved_page);
2035 CloseSavedDocument();
2040 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
2041 FPDF_PAGE page = LoadPage(0);
2049 for (
int i = 1; i >= 0; i--) {
2051 ASSERT_TRUE(page_object);
2069 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2070 CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum);
2074 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2078 ASSERT_TRUE(OpenSavedDocument());
2079 FPDF_PAGE saved_page = LoadSavedPage(0);
2080 ASSERT_TRUE(saved_page);
2084 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
2085 CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum);
2088 CloseSavedPage(saved_page);
2089 CloseSavedDocument();
2094 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
2095 FPDF_PAGE page = LoadPage(0);
2103 ASSERT_TRUE(page_object);
2113 ASSERT_TRUE(page_object);
2122 ASSERT_TRUE(page_object);
2127 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2128 CompareBitmap(page_bitmap.get(), 200, 200, FirstRemovedChecksum());
2132 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2136 ASSERT_TRUE(OpenSavedDocument());
2137 FPDF_PAGE saved_page = LoadSavedPage(0);
2138 ASSERT_TRUE(saved_page);
2142 ASSERT_TRUE(page_object);
2146 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
2147 CompareBitmap(page_bitmap.get(), 200, 200, FirstRemovedChecksum());
2150 CloseSavedPage(saved_page);
2151 CloseSavedDocument();
2156 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
2157 FPDF_PAGE page = LoadPage(0);
2165 ASSERT_TRUE(page_object);
2175 ASSERT_TRUE(page_object);
2184 ASSERT_TRUE(page_object);
2188 using pdfium::HelloWorldRemovedChecksum;
2190 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2195 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2199 ASSERT_TRUE(OpenSavedDocument());
2200 FPDF_PAGE saved_page = LoadSavedPage(0);
2201 ASSERT_TRUE(saved_page);
2205 ASSERT_TRUE(page_object);
2209 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
2213 CloseSavedPage(saved_page);
2214 CloseSavedDocument();
2219 ASSERT_TRUE(OpenDocument(
"hello_world_split_streams.pdf"));
2220 FPDF_PAGE page = LoadPage(0);
2229 for (
int i = 2; i >= 0; i--) {
2231 ASSERT_TRUE(page_object);
2246 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2247 CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum);
2251 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2255 ASSERT_TRUE(OpenSavedDocument());
2256 FPDF_PAGE saved_page = LoadSavedPage(0);
2257 ASSERT_TRUE(saved_page);
2261 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
2262 CompareBitmap(page_bitmap.get(), 200, 200, kAllRemovedChecksum);
2265 CloseSavedPage(saved_page);
2266 CloseSavedDocument();
2271 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
2272 FPDF_PAGE page = LoadPage(0);
2287 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2291 ASSERT_TRUE(OpenSavedDocument());
2292 FPDF_PAGE saved_page = LoadSavedPage(0);
2293 ASSERT_TRUE(saved_page);
2295 CloseSavedPage(saved_page);
2296 CloseSavedDocument();
2301 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
2302 FPDF_PAGE page = LoadPage(0);
2321 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2325 ASSERT_TRUE(OpenSavedDocument());
2326 FPDF_PAGE saved_page = LoadSavedPage(0);
2327 ASSERT_TRUE(saved_page);
2329 CloseSavedPage(saved_page);
2330 CloseSavedDocument();
2334 const int kOriginalObjectCount = 600;
2337 ASSERT_TRUE(OpenDocument(
"many_rectangles.pdf"));
2338 FPDF_PAGE page = LoadPage(0);
2341 using pdfium::ManyRectanglesChecksum;
2343 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2356 const char* plus_rectangle_checksum = []() {
2358 return "0d3715fcfb9bd0dd25dcce60800bff47";
2360 return "6b9396ab570754b32b04ca629e902f77";
2363 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2364 CompareBitmap(page_bitmap.get(), 200, 300, plus_rectangle_checksum);
2369 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2373 ASSERT_TRUE(OpenSavedDocument());
2374 FPDF_PAGE saved_page = LoadSavedPage(0);
2375 ASSERT_TRUE(saved_page);
2378 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
2379 CompareBitmap(page_bitmap.get(), 200, 300, plus_rectangle_checksum);
2383 FPDF_PAGEOBJECT added_object =
2388 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
2395 EXPECT_TRUE(FPDF_SaveAsCopy(saved_document(),
this, 0));
2397 CloseSavedPage(saved_page);
2398 CloseSavedDocument();
2402 ASSERT_TRUE(OpenSavedDocument());
2403 saved_page = LoadSavedPage(0);
2404 ASSERT_TRUE(saved_page);
2407 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
2411 CloseSavedPage(saved_page);
2412 CloseSavedDocument();
2417 FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
2421 using pdfium::kBlankPage612By792Checksum;
2423 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2430 ASSERT_TRUE(red_rect);
2435 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2436 CompareBitmap(page_bitmap.get(), 612, 792, kRedRectangleChecksum);
2444 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2457 CreateNewDocument();
2458 FPDF_PAGEOBJECT img = FPDFPageObj_NewImageObj(document());
2485 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
2486 FPDF_PAGE page = LoadPage(0);
2505 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
2506 const char* checksum = []() {
2508#if BUILDFLAG(IS_WIN)
2509 return "52c133b5b6bf76760c59cffc12c1131a";
2510#elif BUILDFLAG(IS_APPLE)
2511 return "9eba2a1a6599c2abcf002012217a6505";
2513 return "72523cfac069f8a81057164682998961";
2516#if BUILDFLAG(IS_APPLE)
2517 return "279693baca9f48da2d75a8e289aed58e";
2519 return "fe415d47945c10b9cc8e9ca08887369e";
2522 CompareBitmap(bitmap.get(), 200, 200, checksum);
2528 ASSERT_TRUE(OpenDocument(
"bug_717.pdf"));
2529 FPDF_PAGE page = LoadPage(0);
2544 const char* original_checksum = []() {
2546 return "1e82fbdd21490cee9d3479fe6125af67";
2548 return "ad04e5bd0f471a9a564fb034bd0fb073";
2550 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
2551 CompareBitmap(bitmap.get(), 612, 792, original_checksum);
2555 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2558 ASSERT_TRUE(OpenSavedDocument());
2559 FPDF_PAGE saved_page = LoadSavedPage(0);
2560 ASSERT_TRUE(saved_page);
2561 VerifySavedRendering(saved_page, 612, 792, original_checksum);
2575 const char* last_checksum = []() {
2577 return "8705d023e5fec3499d1e30cf2bcc5dc1";
2579 return "4b5b00f824620f8c9b8801ebb98e1cdd";
2582 ScopedFPDFBitmap new_bitmap = RenderSavedPage(saved_page);
2583 CompareBitmap(new_bitmap.get(), 612, 792, last_checksum);
2588 EXPECT_TRUE(FPDF_SaveAsCopy(saved_document(),
this, 0));
2590 CloseSavedPage(saved_page);
2591 CloseSavedDocument();
2594 VerifySavedDocument(612, 792, last_checksum);
2599 FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
2609 EXPECT_EQ(15.0f, width);
2614 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2615 const char* checksum_1 = []() {
2617 return "1469acf60e7647ebeb8e1fb08c5d6c7a";
2619 return "64bd31f862a89e0a9e505a5af6efd506";
2621 CompareBitmap(page_bitmap.get(), 612, 792, checksum_1);
2635 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2636 const char* checksum_2 = []() {
2638 return "68b3194f74abd9d471695ce1415be43f";
2640 return "4b6f3b9d25c4e194821217d5016c3724";
2642 CompareBitmap(page_bitmap.get(), 612, 792, checksum_2);
2657 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2658 const char* checksum_3 = []() {
2660 return "ea784068651df2b9ba132ce9215e6780";
2662 return "ff3e6a22326754944cc6e56609acd73b";
2664 CompareBitmap(page_bitmap.get(), 612, 792, checksum_3);
2672 ScopedFPDFPage page(FPDFPage_New(CreateNewDocument(), 0, 612, 792));
2675 FPDF_PAGEOBJECT text_object1 =
2676 FPDFPageObj_NewTextObj(document(),
"Arial", 12.0f);
2677 EXPECT_TRUE(text_object1);
2678 ScopedFPDFWideString text1 = GetFPDFWideString(kBottomText);
2679 EXPECT_TRUE(FPDFText_SetText(text_object1, text1.get()));
2680 static constexpr FS_MATRIX kMatrix1{1, 0, 0, 1, 20, 20};
2682 FPDFPage_InsertObject(page.get(), text_object1);
2683 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
2685 ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
2686 CompareBitmap(page_bitmap.get(), 612, 792, BottomTextChecksum());
2688 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2689 VerifySavedDocument(612, 792, BottomTextChecksum());
2693 FPDF_PAGEOBJECT text_object2 =
2694 FPDFPageObj_NewTextObj(document(),
"TimesNewRomanBold", 15.0f);
2695 EXPECT_TRUE(text_object2);
2696 ScopedFPDFWideString text2 =
2697 GetFPDFWideString(L"Hi, I'm Bold. Times New Roman Bold.");
2698 EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get()));
2700 FPDFPage_InsertObject(page.get(), text_object2);
2701 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
2703 ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
2704 const char* checksum = []() {
2706#if BUILDFLAG(IS_WIN)
2707 return "667f74c7cbf72c75bce303ca2de975a3";
2708#elif BUILDFLAG(IS_APPLE)
2709 return "86d51a764615b843465695786e92fec5";
2711 return "3fa05f8935a43a38a8923e9d5fb94365";
2714#if BUILDFLAG(IS_APPLE)
2715 return "983baaa1f688eff7a14b1bf91c171a1a";
2717 return "161523e196eb5341604cd73e12c97922";
2720 CompareBitmap(page_bitmap.get(), 612, 792, checksum);
2722 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2723 VerifySavedDocument(612, 792, checksum);
2727 FPDF_PAGEOBJECT text_object3 =
2728 FPDFPageObj_NewTextObj(document(),
"Courier-Bold", 20.0f);
2729 EXPECT_TRUE(text_object3);
2730 ScopedFPDFWideString text3 = GetFPDFWideString(L"Can you read me? <:)>");
2731 EXPECT_TRUE(FPDFText_SetText(text_object3, text3.get()));
2733 FPDFPage_InsertObject(page.get(), text_object3);
2734 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
2736 ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
2737 const char* checksum = []() {
2739#if BUILDFLAG(IS_WIN)
2740 return "4695b3de213d6795a591f27cd8d86e26";
2741#elif BUILDFLAG(IS_APPLE)
2742 return "422f1384c13e95c218498a8f18b9e5a7";
2744 return "63385a217934d9ee9e17ef4d7f7b2128";
2747#if BUILDFLAG(IS_APPLE)
2748 return "e0b3493c5c16e41d0d892ffb48e63fba";
2750 return "1fbf772dca8d82b960631e6683934964";
2753 CompareBitmap(page_bitmap.get(), 612, 792, checksum);
2755 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2756 VerifySavedDocument(612, 792, checksum);
2761 EXPECT_FLOAT_EQ(1.0f, matrix.a);
2762 EXPECT_FLOAT_EQ(1.5f, matrix.b);
2763 EXPECT_FLOAT_EQ(2.0f, matrix.c);
2764 EXPECT_FLOAT_EQ(0.5f, matrix.d);
2765 EXPECT_FLOAT_EQ(200.0f, matrix.e);
2766 EXPECT_FLOAT_EQ(200.0f, matrix.f);
2771 EXPECT_EQ(55, size);
2773 EXPECT_EQ(20, size);
2781 ScopedFPDFPage page(FPDFPage_New(CreateNewDocument(), 0, 612, 792));
2784 FPDF_PAGEOBJECT text_object =
2785 FPDFPageObj_NewTextObj(document(),
"Arial", 0.0f);
2786 EXPECT_TRUE(text_object);
2787 ScopedFPDFWideString text = GetFPDFWideString(kBottomText);
2788 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
2793 EXPECT_EQ(0.0f, size);
2795 FPDFPage_InsertObject(page.get(), text_object);
2796 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
2798 ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
2799 CompareBitmap(page_bitmap.get(), 612, 792,
2802 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2808 ASSERT_TRUE(OpenDocument(
"text_render_mode.pdf"));
2809 FPDF_PAGE page = LoadPage(0);
2813 EXPECT_EQ(FPDF_TEXTRENDERMODE_UNKNOWN,
2826 const char* original_checksum = []() {
2828#if BUILDFLAG(IS_WIN)
2829 return "e17a6453cb48a600f180c5907c4ea02e";
2830#elif BUILDFLAG(IS_APPLE)
2831 return "e2d5c32499173c0ff939ad2e7fc01fd6";
2833 return "48c7f21b2a1a1bbeab24cccccc131e47";
2836#if BUILDFLAG(IS_APPLE)
2837 return "c488514ce0fc949069ff560407edacd2";
2839 return "97a4fcf3c9581e19917895631af31d41";
2842 const char* stroke_checksum = []() {
2844 return "d16eb1bb4748eeb5fb801594da70d519";
2846 return "e06ee84aeebe926e8c980b7822027e8a";
2850 ASSERT_TRUE(OpenDocument(
"text_render_mode.pdf"));
2851 FPDF_PAGE page = LoadPage(0);
2857 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2858 CompareBitmap(page_bitmap.get(), 612, 446, original_checksum);
2868 ASSERT_TRUE(page_object);
2869 EXPECT_EQ(FPDF_TEXTRENDERMODE_FILL,
2874 FPDF_TEXTRENDERMODE_UNKNOWN
));
2878 EXPECT_EQ(FPDF_TEXTRENDERMODE_STROKE,
2883 ScopedFPDFBitmap page_bitmap = RenderPage(page);
2884 CompareBitmap(page_bitmap.get(), 612, 446, stroke_checksum);
2889 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2897 ASSERT_TRUE(OpenSavedDocument());
2898 FPDF_PAGE saved_page = LoadSavedPage(0);
2899 ASSERT_TRUE(saved_page);
2902 EXPECT_TRUE(page_object);
2903 EXPECT_EQ(FPDF_TEXTRENDERMODE_STROKE,
2906 ScopedFPDFBitmap bitmap = RenderSavedPage(saved_page);
2907 CompareBitmap(bitmap.get(), 612, 446, stroke_checksum);
2909 CloseSavedPage(saved_page);
2910 CloseSavedDocument();
2927 ASSERT_TRUE(OpenDocument(
"text_font.pdf"));
2928 FPDF_PAGE page = LoadPage(0);
2951 EXPECT_EQ(0, angle);
2955 EXPECT_FLOAT_EQ(891 * font_size / 1000.0f, ascent);
2959 EXPECT_FLOAT_EQ(-216 * font_size / 1000.0f, descent);
2964 EXPECT_FLOAT_EQ(a12, 5.316f);
2966 EXPECT_FLOAT_EQ(a24, 10.632f);
2972 const char kExpectedFontName[] =
"Liberation Serif";
2973 ASSERT_EQ(
sizeof(kExpectedFontName), size);
2974 std::vector<
char> font_name(size);
2975 ASSERT_EQ(size, FPDFFont_GetFontName(font, font_name.data(), size));
2976 ASSERT_STREQ(kExpectedFontName, font_name.data());
2981 font_name.resize(2);
2983 font_name[1] =
'\0';
2984 size = FPDFFont_GetFontName(font, font_name.data(), font_name.size());
2985 ASSERT_EQ(
sizeof(kExpectedFontName), size);
2986 ASSERT_STREQ(
"x", font_name.data());
2991 constexpr size_t kExpectedSize = 8268;
2992 std::vector<uint8_t> buf;
2993 size_t buf_bytes_required = 123;
2994 ASSERT_TRUE(FPDFFont_GetFontData(font,
nullptr, 0, &buf_bytes_required));
2995 ASSERT_EQ(kExpectedSize, buf_bytes_required);
2997 buf.resize(kExpectedSize);
2998 EXPECT_EQ(
"495800b8e56e2d37f3bc48a1b52db952", GenerateMD5Base16(buf));
2999 buf_bytes_required = 234;
3001 EXPECT_TRUE(FPDFFont_GetFontData(font, buf.data(), buf.size() - 1,
3002 &buf_bytes_required));
3003 EXPECT_EQ(
"495800b8e56e2d37f3bc48a1b52db952", GenerateMD5Base16(buf));
3004 EXPECT_EQ(kExpectedSize, buf_bytes_required);
3007 buf_bytes_required = 234;
3008 EXPECT_TRUE(FPDFFont_GetFontData(font, buf.data(), buf.size(),
3009 &buf_bytes_required));
3010 EXPECT_EQ(
"1a67be75f719b6c476804d85bb9e4844", GenerateMD5Base16(buf));
3011 EXPECT_EQ(kExpectedSize, buf_bytes_required);
3014 EXPECT_FALSE(FPDFFont_GetFontData(
nullptr,
nullptr, 0,
nullptr));
3015 EXPECT_FALSE(FPDFFont_GetFontData(font,
nullptr, 0,
nullptr));
3017 buf_bytes_required = 345;
3019 FPDFFont_GetFontData(
nullptr,
nullptr, 0, &buf_bytes_required));
3020 EXPECT_EQ(345u, buf_bytes_required);
3023 FPDFFont_GetFontData(
nullptr, buf.data(), buf.size(),
nullptr));
3024 EXPECT_FALSE(FPDFFont_GetFontData(font, buf.data(), buf.size(),
nullptr));
3026 buf_bytes_required = 345;
3027 EXPECT_FALSE(FPDFFont_GetFontData(
nullptr, buf.data(), buf.size(),
3028 &buf_bytes_required));
3029 EXPECT_EQ(345u, buf_bytes_required);
3040 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
3041 FPDF_PAGE page = LoadPage(0);
3048 constexpr size_t kTinosRegularSize = 469968;
3053 std::vector<uint8_t> buf;
3054 buf.resize(kTinosRegularSize);
3055 size_t buf_bytes_required;
3057 FPDFFont_GetFontData(font, buf.data(), buf.size(), &buf_bytes_required));
3058 EXPECT_EQ(kTinosRegularSize, buf_bytes_required);
3059 EXPECT_EQ(
"2b019558f2c2de0b7cbc0a6e64b20599", GenerateMD5Base16(buf));
3063 constexpr size_t kArimoRegularSize = 436180;
3068 buf.resize(kArimoRegularSize);
3070 FPDFFont_GetFontData(font, buf.data(), buf.size(), &buf_bytes_required));
3071 EXPECT_EQ(kArimoRegularSize, buf_bytes_required);
3072 EXPECT_EQ(
"7ac02a544211773d9636e056e9da6c35", GenerateMD5Base16(buf));
3083 ASSERT_TRUE(OpenDocument(
"text_font.pdf"));
3084 FPDF_PAGE page = LoadPage(0);
3100 ASSERT_GT(count, 0);
3105 ASSERT_TRUE(segment);
3112 ASSERT_TRUE(OpenDocument(
"form_object.pdf"));
3113 FPDF_PAGE page = LoadPage(0);
3130 ASSERT_EQ(271,
static_cast<
int>(top));
3135 ASSERT_EQ(221,
static_cast<
int>(top));
3143 static constexpr FS_MATRIX kMatrix = {1.0f, 1.5f, 2.0f, 2.5f, 100.0f, 200.0f};
3148 EXPECT_FLOAT_EQ(kMatrix.a, matrix.a);
3149 EXPECT_FLOAT_EQ(kMatrix.b, matrix.b);
3150 EXPECT_FLOAT_EQ(kMatrix.c, matrix.c);
3151 EXPECT_FLOAT_EQ(kMatrix.d, matrix.d);
3152 EXPECT_FLOAT_EQ(kMatrix.e, matrix.e);
3153 EXPECT_FLOAT_EQ(kMatrix.f, matrix.f);
3168 const char* orig_checksum = []() {
3170#if BUILDFLAG(IS_WIN)
3171 return "9d0ca0d471efc12950f337a867ab1694";
3172#elif BUILDFLAG(IS_APPLE)
3173 return "4cfff1919007a7faf099be5cc2cea00a";
3175 return "1c6dae4b04fea7430a791135721eaba5";
3178#if BUILDFLAG(IS_APPLE)
3179 return "a637057185f50aac1aa5490f726aef95";
3181 return "34a9ec0a9581a7970e073c0bcc4ca676";
3184 const char* new_checksum = []() {
3186#if BUILDFLAG(IS_WIN)
3187 return "dbebf244eb706dfebfd0594c23e993a9";
3188#elif BUILDFLAG(IS_APPLE)
3189 return "eb88a6842f5e12f5180385261db1f81d";
3191 return "7282fe98693c0a7ad2c1b3f3f9563977";
3194#if BUILDFLAG(IS_APPLE)
3195 return "8ad9d79b02b609ff734e2a2195c96e2d";
3197 return "609b5632a21c886fa93182dbc290bf7a";
3201 ASSERT_TRUE(OpenDocument(
"form_object.pdf"));
3202 FPDF_PAGE page = LoadPage(0);
3207 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
3208 CompareBitmap(bitmap.get(), 62, 69, orig_checksum);
3218 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
3219 CompareBitmap(bitmap.get(), 62, 69, new_checksum);
3222 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3223 VerifySavedDocument(62, 69, new_checksum);
3231 ScopedFPDFPage page(FPDFPage_New(CreateNewDocument(), 0, 612, 792));
3234 ScopedFPDFFont font(FPDFText_LoadStandardFont(document(),
"Helvetica"));
3238 FPDF_PAGEOBJECT text_object =
3239 FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f);
3240 EXPECT_TRUE(text_object);
3241 ScopedFPDFWideString text = GetFPDFWideString(kBottomText);
3242 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
3244 FPDFPage_InsertObject(page.get(), text_object);
3245 ScopedFPDFBitmap page_bitmap = RenderPage(page.get());
3246 CompareBitmap(page_bitmap.get(), 612, 792, BottomTextChecksum());
3250 CreateNewDocument();
3251 static constexpr const char* kStandardFontNames[] = {
3257 "Courier-BoldOblique",
3262 "CourierNew-BoldItalic",
3263 "CourierNew-Italic",
3266 "Helvetica-BoldOblique",
3267 "Helvetica-Oblique",
3270 "TimesNewRoman-Bold",
3271 "TimesNewRoman-BoldItalic",
3272 "TimesNewRoman-Italic",
3274 for (
const char* font_name : kStandardFontNames) {
3275 ScopedFPDFFont font(FPDFText_LoadStandardFont(document(), font_name));
3276 EXPECT_TRUE(font) << font_name <<
" should be considered a standard font.";
3278 static constexpr const char* kNotStandardFontNames[] = {
3279 "Abcdefg",
"ArialB",
"Arial-Style",
3280 "Font Name",
"FontArial",
"NotAStandardFontName",
3281 "TestFontName",
"Quack",
"Symbol-Italic",
3283 for (
const char* font_name : kNotStandardFontNames) {
3284 ScopedFPDFFont font(FPDFText_LoadStandardFont(document(), font_name));
3285 EXPECT_FALSE(font) << font_name
3286 <<
" should not be considered a standard font.";
3292 ScopedFPDFPage page(FPDFPage_New(CreateNewDocument(), 0, 612, 792));
3297 FPDFPage_InsertObject(page.get(), rect1);
3298 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
3301 CPDF_Page* cpage = CPDFPageFromFPDFPage(page.get());
3302 RetainPtr<
const CPDF_Dictionary> graphics_dict =
3303 cpage->GetResources()->GetDictFor(
"ExtGState");
3304 ASSERT_TRUE(graphics_dict);
3305 EXPECT_THAT(graphics_dict->GetKeys(),
3306 UnorderedElementsAreArray({
"FXE1",
"FXE2"}));
3309 FPDF_PAGEOBJECT text1 = FPDFPageObj_NewTextObj(document(),
"Arial", 12.0f);
3313 FPDFPage_InsertObject(page.get(), text1);
3314 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
3315 EXPECT_THAT(graphics_dict->GetKeys(),
3316 UnorderedElementsAreArray({
"FXE1",
"FXE2"}));
3319 FPDF_PAGEOBJECT text2 =
3320 FPDFPageObj_NewTextObj(document(),
"Times-Roman", 12.0f);
3321 FPDFPage_InsertObject(page.get(), text2);
3324 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
3325 EXPECT_THAT(graphics_dict->GetKeys(),
3326 UnorderedElementsAreArray({
"FXE1",
"FXE2",
"FXE3"}));
3332 FPDFPage_InsertObject(page.get(), path);
3333 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
3334 EXPECT_THAT(graphics_dict->GetKeys(),
3335 UnorderedElementsAreArray({
"FXE1",
"FXE2",
"FXE3"}));
3342 FPDFPage_InsertObject(page.get(), rect2);
3343 EXPECT_TRUE(FPDFPage_GenerateContent(page.get()));
3344 EXPECT_THAT(graphics_dict->GetKeys(),
3345 UnorderedElementsAreArray({
"FXE1",
"FXE2",
"FXE3",
"FXE4"}));
3350 FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
3361 RetainPtr<
const CPDF_Dictionary> graphics_dict =
3362 cpage->GetResources()->GetDictFor(
"ExtGState");
3363 ASSERT_TRUE(graphics_dict);
3364 EXPECT_THAT(graphics_dict->GetKeys(),
3365 UnorderedElementsAreArray({
"FXE1",
"FXE2"}));
3369 ScopedFPDFBitmap page_bitmap = RenderPage(page);
3370 CompareBitmap(page_bitmap.get(), 612, 792,
3371 "5384da3406d62360ffb5cac4476fff1c");
3378 EXPECT_THAT(graphics_dict->GetKeys(),
3379 UnorderedElementsAreArray({
"FXE1",
"FXE3"}));
3383 ScopedFPDFBitmap page_bitmap = RenderPage(page);
3384 CompareBitmap(page_bitmap.get(), 612, 792,
3385 "2e51656f5073b0bee611d9cd086aa09c");
3390 EXPECT_THAT(graphics_dict->GetKeys(),
3391 UnorderedElementsAreArray({
"FXE1",
"FXE3"}));
3393 ScopedFPDFBitmap page_bitmap = RenderPage(page);
3394 CompareBitmap(page_bitmap.get(), 612, 792,
3395 "2e51656f5073b0bee611d9cd086aa09c");
3399 RetainPtr<
const CPDF_Dictionary> font_dict =
3400 cpage->GetResources()->GetDictFor(
"Font");
3401 EXPECT_FALSE(font_dict);
3402 FPDF_PAGEOBJECT text_object =
3403 FPDFPageObj_NewTextObj(document(),
"Arial", 12.0f);
3404 ScopedFPDFWideString text =
3405 GetFPDFWideString(L"Something something #text# something");
3406 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
3412 font_dict = cpage->GetResources()->GetDictFor(
"Font");
3413 ASSERT_TRUE(font_dict);
3414 EXPECT_THAT(graphics_dict->GetKeys(),
3415 UnorderedElementsAreArray({
"FXE1",
"FXE3"}));
3416 EXPECT_THAT(font_dict->GetKeys(), UnorderedElementsAreArray({
"FXF1"}));
3420 EXPECT_THAT(graphics_dict->GetKeys(),
3421 UnorderedElementsAreArray({
"FXE1",
"FXE3"}));
3422 EXPECT_THAT(font_dict->GetKeys(), UnorderedElementsAreArray({
"FXF1"}));
3427 CreateNewDocument();
3430 CPDF_Font::GetStockFont(cpdf_doc(),
"Times-Bold");
3431 pdfium::span<
const uint8_t> span = stock_font->GetFont()->GetFontSpan();
3432 ScopedFPDFFont font(FPDFText_LoadFont(document(), span.data(), span.size(),
3434 ASSERT_TRUE(font.get());
3435 CPDF_Font* typed_font = CPDFFontFromFPDFFont(font.get());
3438 RetainPtr<
const CPDF_Dictionary> font_dict = typed_font->GetFontDict();
3439 EXPECT_EQ(
"Font", font_dict->GetNameFor(
"Type"));
3440 EXPECT_EQ(
"Type1", font_dict->GetNameFor(
"Subtype"));
3441 EXPECT_EQ(
"Tinos-Bold", font_dict->GetNameFor(
"BaseFont"));
3442 ASSERT_TRUE(font_dict->KeyExist(
"FirstChar"));
3443 ASSERT_TRUE(font_dict->KeyExist(
"LastChar"));
3444 EXPECT_EQ(32, font_dict->GetIntegerFor(
"FirstChar"));
3445 EXPECT_EQ(255, font_dict->GetIntegerFor(
"LastChar"));
3447 RetainPtr<
const CPDF_Array> widths_array = font_dict->GetArrayFor(
"Widths");
3448 ASSERT_TRUE(widths_array);
3449 ASSERT_EQ(224u, widths_array->size());
3450 EXPECT_EQ(250, widths_array->GetFloatAt(0));
3451 EXPECT_EQ(569, widths_array->GetFloatAt(11));
3452 EXPECT_EQ(500, widths_array->GetFloatAt(223));
3457 CreateNewDocument();
3459 CPDF_Font::GetStockFont(cpdf_doc(),
"Courier");
3460 pdfium::span<
const uint8_t> span = stock_font->GetFont()->GetFontSpan();
3461 ScopedFPDFFont font(FPDFText_LoadFont(document(), span.data(), span.size(),
3463 ASSERT_TRUE(font.get());
3464 CPDF_Font* typed_font = CPDFFontFromFPDFFont(font.get());
3467 RetainPtr<
const CPDF_Dictionary> font_dict = typed_font->GetFontDict();
3468 EXPECT_EQ(
"Font", font_dict->GetNameFor(
"Type"));
3469 EXPECT_EQ(
"TrueType", font_dict->GetNameFor(
"Subtype"));
3470 EXPECT_EQ(
"Cousine-Regular", font_dict->GetNameFor(
"BaseFont"));
3471 ASSERT_TRUE(font_dict->KeyExist(
"FirstChar"));
3472 ASSERT_TRUE(font_dict->KeyExist(
"LastChar"));
3473 EXPECT_EQ(32, font_dict->GetIntegerFor(
"FirstChar"));
3474 EXPECT_EQ(255, font_dict->GetIntegerFor(
"LastChar"));
3476 RetainPtr<
const CPDF_Array> widths_array = font_dict->GetArrayFor(
"Widths");
3477 ASSERT_TRUE(widths_array);
3478 ASSERT_EQ(224u, widths_array->size());
3479 EXPECT_EQ(600, widths_array->GetFloatAt(33));
3480 EXPECT_EQ(600, widths_array->GetFloatAt(74));
3481 EXPECT_EQ(600, widths_array->GetFloatAt(223));
3486 CreateNewDocument();
3488 CPDF_Font::GetStockFont(cpdf_doc(),
"Times-Roman");
3489 pdfium::span<
const uint8_t> span = stock_font->GetFont()->GetFontSpan();
3490 ScopedFPDFFont font(FPDFText_LoadFont(document(), span.data(), span.size(),
3492 ASSERT_TRUE(font.get());
3493 CPDF_Font* typed_font = CPDFFontFromFPDFFont(font.get());
3497 RetainPtr<
const CPDF_Dictionary> font_dict = typed_font->GetFontDict();
3498 EXPECT_EQ(
"Font", font_dict->GetNameFor(
"Type"));
3499 EXPECT_EQ(
"Type0", font_dict->GetNameFor(
"Subtype"));
3500 EXPECT_EQ(
"Tinos-Regular-Identity-H", font_dict->GetNameFor(
"BaseFont"));
3501 EXPECT_EQ(
"Identity-H", font_dict->GetNameFor(
"Encoding"));
3502 RetainPtr<
const CPDF_Array> descendant_array =
3503 font_dict->GetArrayFor(
"DescendantFonts");
3504 ASSERT_TRUE(descendant_array);
3505 EXPECT_EQ(1u, descendant_array->size());
3508 RetainPtr<
const CPDF_Dictionary> cidfont_dict =
3509 descendant_array->GetDictAt(0);
3510 EXPECT_EQ(
"Font", cidfont_dict->GetNameFor(
"Type"));
3511 EXPECT_EQ(
"CIDFontType0", cidfont_dict->GetNameFor(
"Subtype"));
3512 EXPECT_EQ(
"Tinos-Regular", cidfont_dict->GetNameFor(
"BaseFont"));
3513 RetainPtr<
const CPDF_Dictionary> cidinfo_dict =
3514 cidfont_dict->GetDictFor(
"CIDSystemInfo");
3515 ASSERT_TRUE(cidinfo_dict);
3517 cidinfo_dict->GetObjectFor(
"Registry");
3518 ASSERT_TRUE(registry);
3520 EXPECT_EQ(
"Adobe", registry->GetString());
3522 cidinfo_dict->GetObjectFor(
"Ordering");
3523 ASSERT_TRUE(ordering);
3525 EXPECT_EQ(
"Identity", ordering->GetString());
3526 EXPECT_EQ(0, cidinfo_dict->GetFloatFor(
"Supplement"));
3527 CheckFontDescriptor(cidfont_dict.Get(),
FPDF_FONT_TYPE1,
false,
false, span);
3530 RetainPtr<
const CPDF_Array> widths_array = cidfont_dict->GetArrayFor(
"W");
3531 ASSERT_TRUE(widths_array);
3532 EXPECT_GT(widths_array->size(), 1u);
3533 CheckCompositeFontWidths(widths_array.Get(), typed_font);
3537 CreateNewDocument();
3539 CPDF_Font::GetStockFont(cpdf_doc(),
"Helvetica-Oblique");
3540 pdfium::span<
const uint8_t> span = stock_font->GetFont()->GetFontSpan();
3541 ScopedFPDFFont font(FPDFText_LoadFont(document(), span.data(), span.size(),
3543 ASSERT_TRUE(font.get());
3544 CPDF_Font* typed_font = CPDFFontFromFPDFFont(font.get());
3548 RetainPtr<
const CPDF_Dictionary> font_dict = typed_font->GetFontDict();
3549 EXPECT_EQ(
"Font", font_dict->GetNameFor(
"Type"));
3550 EXPECT_EQ(
"Type0", font_dict->GetNameFor(
"Subtype"));
3551 EXPECT_EQ(
"Arimo-Italic", font_dict->GetNameFor(
"BaseFont"));
3552 EXPECT_EQ(
"Identity-H", font_dict->GetNameFor(
"Encoding"));
3553 RetainPtr<
const CPDF_Array> descendant_array =
3554 font_dict->GetArrayFor(
"DescendantFonts");
3555 ASSERT_TRUE(descendant_array);
3556 EXPECT_EQ(1u, descendant_array->size());
3559 RetainPtr<
const CPDF_Dictionary> cidfont_dict =
3560 descendant_array->GetDictAt(0);
3561 EXPECT_EQ(
"Font", cidfont_dict->GetNameFor(
"Type"));
3562 EXPECT_EQ(
"CIDFontType2", cidfont_dict->GetNameFor(
"Subtype"));
3563 EXPECT_EQ(
"Arimo-Italic", cidfont_dict->GetNameFor(
"BaseFont"));
3564 RetainPtr<
const CPDF_Dictionary> cidinfo_dict =
3565 cidfont_dict->GetDictFor(
"CIDSystemInfo");
3566 ASSERT_TRUE(cidinfo_dict);
3567 EXPECT_EQ(
"Adobe", cidinfo_dict->GetByteStringFor(
"Registry"));
3568 EXPECT_EQ(
"Identity", cidinfo_dict->GetByteStringFor(
"Ordering"));
3569 EXPECT_EQ(0, cidinfo_dict->GetFloatFor(
"Supplement"));
3574 RetainPtr<
const CPDF_Array> widths_array = cidfont_dict->GetArrayFor(
"W");
3575 ASSERT_TRUE(widths_array);
3576 CheckCompositeFontWidths(widths_array.Get(), typed_font);
3581 ASSERT_TRUE(OpenDocument(
"bug_713197.pdf"));
3582 FPDF_PAGE page = LoadPage(0);
3591 FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
3594 CPDF_Font::GetStockFont(cpdf_doc(),
"Arial");
3595 pdfium::span<
const uint8_t> span = stock_font->GetFont()->GetFontSpan();
3596 ScopedFPDFFont font(FPDFText_LoadFont(document(), span.data(), span.size(),
3598 ASSERT_TRUE(font.get());
3601 FPDF_PAGEOBJECT text_object =
3602 FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f);
3603 EXPECT_TRUE(text_object);
3604 ScopedFPDFWideString text = GetFPDFWideString(kLoadedFontText);
3605 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
3608 ScopedFPDFBitmap page_bitmap = RenderPage(page);
3609 CompareBitmap(page_bitmap.get(), 612, 792, LoadedFontTextChecksum());
3612 FPDF_PAGEOBJECT text_object2 =
3613 FPDFPageObj_CreateTextObj(document(), font.get(), 15.0f);
3614 ScopedFPDFWideString text2 = GetFPDFWideString(L"Bigger font size");
3615 EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get()));
3619 ScopedFPDFBitmap page_bitmap2 = RenderPage(page);
3620 const char* insert_true_type_checksum = []() {
3622#if BUILDFLAG(IS_WIN)
3623 return "7e44d135666d8bfcef5cdb4c8161fd4b";
3624#elif BUILDFLAG(IS_APPLE)
3625 return "6bab7f663daca1aab63d787a0f5cb33b";
3627 return "4f9a6c7752ac7d4e4c731260fdb5af15";
3630#if BUILDFLAG(IS_APPLE)
3631 return "c7e2271a7f30e5b919a13ead47cea105";
3633 return "683f4a385a891494100192cb338b11f0";
3636 CompareBitmap(page_bitmap2.get(), 612, 792, insert_true_type_checksum);
3639 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3642 VerifySavedDocument(612, 792, insert_true_type_checksum);
3647 ASSERT_TRUE(OpenDocument(
"annotation_highlight_long_content.pdf"));
3648 FPDF_PAGE page = LoadPage(0);
3653 ScopedFPDFAnnotation annot(
3665#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
3666TEST_F(FPDFEditEmbedderTest, AddCIDFontText) {
3668 FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
3672 CIDfont.LoadSubst(
"Noto Sans CJK JP",
true, 0, 400, 0,
3673 FX_CodePage::kShiftJIS,
false);
3674 EXPECT_EQ(
"Noto Sans CJK JP", CIDfont.GetFaceName());
3675 pdfium::span<
const uint8_t> span = CIDfont.GetFontSpan();
3678 ScopedFPDFFont font(FPDFText_LoadFont(document(), span.data(), span.size(),
3679 FPDF_FONT_TRUETYPE, 1));
3680 ASSERT_TRUE(font.get());
3683 FPDF_PAGEOBJECT text_object =
3684 FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f);
3685 ASSERT_TRUE(text_object);
3686 std::wstring wstr = L"ABCDEFGhijklmnop.";
3687 ScopedFPDFWideString text = GetFPDFWideString(wstr);
3688 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
3689 FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 200);
3690 FPDFPage_InsertObject(page, text_object);
3693 FPDF_PAGEOBJECT text_object2 =
3694 FPDFPageObj_CreateTextObj(document(), font.get(), 18.0f);
3695 ASSERT_TRUE(text_object2);
3696 std::wstring wstr2 =
3697 L"\u3053\u3093\u306B\u3061\u306f\u4e16\u754C\u3002\u3053\u3053\u306B1"
3699 ScopedFPDFWideString text2 = GetFPDFWideString(wstr2);
3700 EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get()));
3701 FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 100, 500);
3702 FPDFPage_InsertObject(page, text_object2);
3706 const char* checksum = []() {
3707 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
3708 return "2e174d17de96a760d42ca3a06acbf36a";
3710 return "84d31d11b76845423a2cfc1879c0fbb9";
3714 ScopedFPDFBitmap page_bitmap = RenderPage(page);
3715 CompareBitmap(page_bitmap.get(), 612, 792, checksum);
3719 EXPECT_TRUE(FPDFPage_GenerateContent(page));
3720 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3721 FPDF_ClosePage(page);
3723 VerifySavedDocument(612, 792, checksum);
3728 const char* checksum = []() {
3730 return "9a78649e85e69d220c22e0fc316da740";
3732 return "3c20472b0552c0c22b88ab1ed8c6202b";
3735 ASSERT_TRUE(OpenDocument(
"bug_779.pdf"));
3736 FPDF_PAGE page = LoadPage(0);
3737 ASSERT_NE(
nullptr, page);
3751 ScopedFPDFBitmap page_bitmap = RenderLoadedPage(page);
3752 CompareBitmap(page_bitmap.get(), 612, 792, checksum);
3756 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3760 VerifySavedDocument(612, 792, checksum);
3765 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
3766 FPDF_PAGE page = LoadPage(0);
3775 EXPECT_TRUE(FPDFPageObjMark_SetStringParam(document(), page_object, mark,
3776 "Position",
"First"));
3782 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3786 ASSERT_TRUE(OpenSavedDocument());
3787 FPDF_PAGE saved_page = LoadSavedPage(0);
3788 ASSERT_TRUE(saved_page);
3792 CloseSavedPage(saved_page);
3793 CloseSavedDocument();
3798 ASSERT_TRUE(OpenDocument(
"hello_world_compressed_stream.pdf"));
3799 FPDF_PAGE page = LoadPage(0);
3804 ScopedFPDFBitmap page_bitmap = RenderPage(page);
3813 EXPECT_TRUE(FPDFPageObjMark_SetStringParam(document(), page_object, mark,
3814 "Position",
"First"));
3818 ScopedFPDFBitmap page_bitmap = RenderPage(page);
3825 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3829 ASSERT_TRUE(OpenSavedDocument());
3830 FPDF_PAGE saved_page = LoadSavedPage(0);
3831 ASSERT_TRUE(saved_page);
3834 ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
3839 CloseSavedPage(saved_page);
3840 CloseSavedDocument();
3845 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
3846 FPDF_PAGE page = LoadPage(0);
3849 constexpr int kExpectedObjectCount = 19;
3857 unsigned long name_len = 999u;
3859 EXPECT_EQ((6u + 1u) * 2u, name_len);
3860 ASSERT_EQ(L"Bounds",
3861 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer)));
3862 unsigned long out_buffer_len;
3864 mark
, "Position", buffer
, sizeof(buffer)
, &out_buffer_len
));
3866 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer)));
3869 EXPECT_TRUE(FPDFPageObjMark_SetStringParam(document(), page_object, mark,
3870 "Position",
"End"));
3874 EXPECT_FALSE(FPDFPageObjMark_SetStringParam(document(), another_page_object,
3875 mark,
"Position",
"End"));
3882 mark
, "Position", buffer
, sizeof(buffer)
, &out_buffer_len
));
3884 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer)));
3888 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3892 ASSERT_TRUE(OpenSavedDocument());
3893 FPDF_PAGE saved_page = LoadSavedPage(0);
3894 ASSERT_TRUE(saved_page);
3900 mark
, "Position", buffer
, sizeof(buffer)
, &out_buffer_len
));
3902 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer)));
3904 CloseSavedPage(saved_page);
3905 CloseSavedDocument();
3910 FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
3913 CPDF_Font::GetStockFont(cpdf_doc(),
"Arial");
3914 pdfium::span<
const uint8_t> span = stock_font->GetFont()->GetFontSpan();
3915 ScopedFPDFFont font(FPDFText_LoadFont(document(), span.data(), span.size(),
3917 ASSERT_TRUE(font.get());
3920 FPDF_PAGEOBJECT text_object =
3921 FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f);
3923 EXPECT_TRUE(text_object);
3924 ScopedFPDFWideString text1 = GetFPDFWideString(kLoadedFontText);
3925 EXPECT_TRUE(FPDFText_SetText(text_object, text1.get()));
3936 unsigned long name_len = 999u;
3938 EXPECT_EQ((14u + 1u) * 2, name_len);
3940 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
3941 EXPECT_EQ(L"Test Mark Name", name);
3947 constexpr size_t kBlobLen = 28;
3948 char block_value[kBlobLen];
3949 memcpy(block_value,
"\x01\x02\x03\0BlobValue1\0\0\0BlobValue2\0", kBlobLen);
3952 FPDFPageObjMark_SetIntParam(document(), text_object, mark,
"IntKey", 42));
3953 EXPECT_TRUE(FPDFPageObjMark_SetStringParam(document(), text_object, mark,
3954 "StringKey",
"StringValue"));
3955 EXPECT_TRUE(FPDFPageObjMark_SetBlobParam(document(), text_object, mark,
3956 "BlobKey", block_value, kBlobLen));
3964 EXPECT_EQ(42, int_value);
3968 unsigned long out_buffer_len = 999u;
3970 mark
, "StringKey", buffer
, sizeof(buffer)
, &out_buffer_len
));
3971 EXPECT_GT(out_buffer_len, 0u);
3972 EXPECT_NE(999u, out_buffer_len);
3973 name = GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
3974 EXPECT_EQ(L"StringValue", name);
3980 mark
, "BlobKey", buffer
, sizeof(buffer)
, &out_buffer_len
));
3981 EXPECT_EQ(kBlobLen, out_buffer_len);
3982 EXPECT_EQ(0, memcmp(block_value, buffer, kBlobLen));
3986 ScopedFPDFBitmap page_bitmap = RenderPage(page);
3987 CompareBitmap(page_bitmap.get(), 612, 792, LoadedFontTextChecksum());
3993 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3998 ASSERT_TRUE(OpenSavedDocument());
3999 FPDF_PAGE saved_page = LoadSavedPage(0);
4000 ASSERT_TRUE(saved_page);
4004 EXPECT_TRUE(text_object);
4011 EXPECT_EQ((14u + 1u) * 2, name_len);
4012 name = GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer));
4013 EXPECT_EQ(L"Test Mark Name", name);
4015 CloseSavedPage(saved_page);
4016 CloseSavedDocument();
4020 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
4021 FPDF_PAGE page = LoadPage(0);
4028 unsigned long out_len;
4033 EXPECT_EQ((6u + 1u) * 2u, out_len);
4037 EXPECT_EQ(L"Bounds",
4038 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer)));
4039 EXPECT_EQ((6u + 1u) * 2u, out_len);
4045 EXPECT_EQ(999u, out_len);
4053 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
4054 FPDF_PAGE page = LoadPage(0);
4061 unsigned long out_len;
4066 EXPECT_EQ((8u + 1u) * 2u, out_len);
4071 EXPECT_EQ(L"Position",
4072 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer)));
4073 EXPECT_EQ((8u + 1u) * 2u, out_len);
4079 EXPECT_EQ(999u, out_len);
4084 EXPECT_EQ(999u, out_len);
4093 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
4094 FPDF_PAGE page = LoadPage(0);
4105 EXPECT_EQ(3, out_value);
4110 EXPECT_EQ(999, out_value);
4115 EXPECT_EQ(999, out_value);
4123 EXPECT_EQ(999, out_value);
4129 ASSERT_TRUE(OpenDocument(
"text_in_page_marked.pdf"));
4130 FPDF_PAGE page = LoadPage(0);
4137 unsigned long out_len;
4143 EXPECT_EQ((4u + 1u) * 2u, out_len);
4147 sizeof(buffer)
, &out_len
));
4149 GetPlatformWString(
reinterpret_cast<
unsigned short*>(buffer)));
4150 EXPECT_EQ((4u + 1u) * 2u, out_len);
4155 sizeof(buffer)
, &out_len
));
4156 EXPECT_EQ(999u, out_len);
4160 mark
, "ParamThatDoesNotExist", buffer
, sizeof(buffer)
, &out_len
));
4161 EXPECT_EQ(999u, out_len);
4164 sizeof(buffer)
, nullptr));
4170 sizeof(buffer)
, &out_len
));
4171 EXPECT_EQ(999u, out_len);
4179 ASSERT_TRUE(OpenDocument(
"marked_content_id.pdf"));
4180 FPDF_PAGE page = LoadPage(0);
4185 ASSERT_TRUE(object1);
4189 ASSERT_TRUE(mark11);
4190 unsigned long len = 0;
4191 unsigned short buf[40];
4193 EXPECT_EQ(18u, len);
4194 EXPECT_EQ(L"Artifact", GetPlatformWString(buf));
4197 EXPECT_EQ(10u, len);
4198 EXPECT_EQ(L"BBox", GetPlatformWString(buf));
4202 EXPECT_EQ(10u, len);
4203 EXPECT_EQ(L"Type", GetPlatformWString(buf));
4208 ASSERT_TRUE(object2);
4213 ASSERT_TRUE(mark21);
4215 EXPECT_EQ(14u, len);
4216 EXPECT_EQ(L"Figure", GetPlatformWString(buf));
4219 EXPECT_EQ(10u, len);
4220 EXPECT_EQ(L"MCID", GetPlatformWString(buf));
4228 ASSERT_TRUE(mark22);
4230 EXPECT_EQ(18u, len);
4231 EXPECT_EQ(L"ClipSpan", GetPlatformWString(buf));
4238 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4239 FPDF_PAGE page = LoadPage(0);
4250 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4252 CompareBitmap(bitmap.get(), 109, 88, kEmbeddedImage33Checksum);
4258 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4260 CompareBitmap(bitmap.get(), 103, 75,
"c8d51fa6821ceb2a67f08446ff236c40");
4266 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4268 CompareBitmap(bitmap.get(), 92, 68,
"7e34551035943e30a9f353db17de62ab");
4274 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4276 CompareBitmap(bitmap.get(), 79, 60,
"f4e72fb783a01c7b4614cdc25eaa98ac");
4282 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4284 CompareBitmap(bitmap.get(), 126, 106,
"2cf9e66414c72461f4ccbf9cdebdfa1b");
4290 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4292 CompareBitmap(bitmap.get(), 194, 119,
"a8f3a126cec274dab8242fd2ccdc1b8b");
4299 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4300 FPDF_PAGE page = LoadPage(0);
4309 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4311 CompareBitmap(bitmap.get(), 109, 88, kEmbeddedImage33Checksum);
4317 EXPECT_FLOAT_EQ(53.0f, matrix.a);
4318 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4319 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4320 EXPECT_FLOAT_EQ(43.0f, matrix.d);
4321 EXPECT_FLOAT_EQ(72.0f, matrix.e);
4322 EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
4330 EXPECT_FLOAT_EQ(120.0f, matrix.a);
4331 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4332 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4333 EXPECT_FLOAT_EQ(43.0f, matrix.d);
4334 EXPECT_FLOAT_EQ(72.0f, matrix.e);
4335 EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
4340 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4342 CompareBitmap(bitmap.get(), 109, 88, kEmbeddedImage33Checksum);
4349 ASSERT_TRUE(OpenDocument(
"bug_631912.pdf"));
4350 FPDF_PAGE page = LoadPage(0);
4357 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4358 ASSERT_TRUE(bitmap);
4360 CompareBitmap(bitmap.get(), 1152, 720,
"3f6a48e2b3e91b799bf34567f55cb4de");
4367 ASSERT_TRUE(OpenDocument(
"matte.pdf"));
4368 FPDF_PAGE page = LoadPage(0);
4371 constexpr int kExpectedObjects = 4;
4374 for (
int i = 0; i < kExpectedObjects; ++i) {
4377 ScopedFPDFBitmap bitmap(FPDFImageObj_GetBitmap(obj));
4378 ASSERT_TRUE(bitmap);
4380 CompareBitmap(bitmap.get(), 50, 50,
"46c9a1dbe0b44765ce46017ad629a2fe");
4387 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4388 FPDF_PAGE page = LoadPage(0);
4397 ScopedFPDFBitmap bitmap(
4398 FPDFImageObj_GetRenderedBitmap(document(), page, obj));
4400 const char* checksum = []() {
4402 return "3b51fc066ee18efbf70bab0501763603";
4404 return "582ca300e003f512d7b552c7b5b45d2e";
4406 CompareBitmap(bitmap.get(), 53, 43, checksum);
4412 EXPECT_FLOAT_EQ(53.0f, matrix.a);
4413 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4414 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4415 EXPECT_FLOAT_EQ(43.0f, matrix.d);
4416 EXPECT_FLOAT_EQ(72.0f, matrix.e);
4417 EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
4425 EXPECT_FLOAT_EQ(120.0f, matrix.a);
4426 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4427 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4428 EXPECT_FLOAT_EQ(43.0f, matrix.d);
4429 EXPECT_FLOAT_EQ(72.0f, matrix.e);
4430 EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
4435 ScopedFPDFBitmap bitmap(
4436 FPDFImageObj_GetRenderedBitmap(document(), page, obj));
4438 const char* checksum = []() {
4440 return "1003585870ad0fe37baf1c5bb3f5fd76";
4442 return "0824c16dcf2dfcef44b45d88db1fddce";
4444 CompareBitmap(bitmap.get(), 120, 43, checksum);
4451 ASSERT_TRUE(OpenDocument(
"matte.pdf"));
4452 FPDF_PAGE page = LoadPage(0);
4455 constexpr int kExpectedObjects = 4;
4458 const char* smask_checksum = []() {
4460 return "0653a18f3bf9b4d8413a2aa10bc11c38";
4462 return "5a3ae4a660ce919e29c42ec2258142f1";
4464 const char* no_smask_checksum = []() {
4466 return "0da49e63e7d6337aca78b19938e3bf65";
4468 return "67504e83f5d78214ea00efc19082c5c1";
4471 for (
int i = 0; i < kExpectedObjects; ++i) {
4474 ScopedFPDFBitmap bitmap(
4475 FPDFImageObj_GetRenderedBitmap(document(), page, obj));
4476 ASSERT_TRUE(bitmap);
4479 CompareBitmap(bitmap.get(), 40, 60, smask_checksum);
4481 CompareBitmap(bitmap.get(), 40, 60, no_smask_checksum);
4488 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4489 FPDF_PAGE page = LoadPage(0);
4497 EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(document(),
nullptr,
nullptr));
4500 EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(document(), page,
nullptr));
4504 ScopedFPDFDocument new_document(FPDF_CreateNewDocument());
4505 EXPECT_FALSE(FPDFImageObj_GetRenderedBitmap(new_document.get(), page, obj));
4511 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4512 FPDF_PAGE page = LoadPage(0);
4522 std::vector<uint8_t> buf(len);
4523 EXPECT_EQ(4091u, FPDFImageObj_GetImageDataRaw(obj, buf.data(), len));
4524 EXPECT_EQ(
"f73802327d2e88e890f653961bcda81a", GenerateMD5Base16(buf));
4530 EXPECT_EQ(28776u, FPDFImageObj_GetImageDataDecoded(obj, buf.data(), len));
4531 EXPECT_EQ(kEmbeddedImage33Checksum, GenerateMD5Base16(buf));
4541 EXPECT_EQ(4370u, FPDFImageObj_GetImageDataRaw(obj, buf.data(), len));
4542 EXPECT_EQ(
"6aae1f3710335023a9e12191be66b64b", GenerateMD5Base16(buf));
4550 EXPECT_EQ(4370u, FPDFImageObj_GetImageDataDecoded(obj, buf.data(), len));
4551 EXPECT_EQ(
"6aae1f3710335023a9e12191be66b64b", GenerateMD5Base16(buf));
4557 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4558 FPDF_PAGE page = LoadPage(0);
4562 FPDF_PAGEOBJECT obj;
4568 EXPECT_FLOAT_EQ(53.0f, matrix.a);
4569 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4570 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4571 EXPECT_FLOAT_EQ(43.0f, matrix.d);
4572 EXPECT_FLOAT_EQ(72.0f, matrix.e);
4573 EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
4578 EXPECT_FLOAT_EQ(70.0f, matrix.a);
4579 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4580 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4581 EXPECT_FLOAT_EQ(51.0f, matrix.d);
4582 EXPECT_FLOAT_EQ(216.0f, matrix.e);
4583 EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
4588 EXPECT_FLOAT_EQ(69.0f, matrix.a);
4589 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4590 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4591 EXPECT_FLOAT_EQ(51.0f, matrix.d);
4592 EXPECT_FLOAT_EQ(360.0f, matrix.e);
4593 EXPECT_FLOAT_EQ(646.510009765625f, matrix.f);
4598 EXPECT_FLOAT_EQ(59.0f, matrix.a);
4599 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4600 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4601 EXPECT_FLOAT_EQ(45.0f, matrix.d);
4602 EXPECT_FLOAT_EQ(72.0f, matrix.e);
4603 EXPECT_FLOAT_EQ(553.510009765625f, matrix.f);
4608 EXPECT_FLOAT_EQ(55.94000244140625f, matrix.a);
4609 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4610 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4611 EXPECT_FLOAT_EQ(46.950000762939453f, matrix.d);
4612 EXPECT_FLOAT_EQ(216.0f, matrix.e);
4613 EXPECT_FLOAT_EQ(552.510009765625f, matrix.f);
4618 EXPECT_FLOAT_EQ(70.528999328613281f, matrix.a);
4619 EXPECT_FLOAT_EQ(0.0f, matrix.b);
4620 EXPECT_FLOAT_EQ(0.0f, matrix.c);
4621 EXPECT_FLOAT_EQ(43.149997711181641f, matrix.d);
4622 EXPECT_FLOAT_EQ(360.0f, matrix.e);
4623 EXPECT_FLOAT_EQ(553.3599853515625f, matrix.f);
4637 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4638 FPDF_PAGE page = LoadPage(0);
4652 std::vector<
char> buf(len);
4653 static constexpr char kFlateDecode[] =
"FlateDecode";
4654 EXPECT_EQ(
sizeof(kFlateDecode),
4655 FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len));
4656 EXPECT_STREQ(kFlateDecode, buf.data());
4666 static constexpr char kASCIIHexDecode[] =
"ASCIIHexDecode";
4667 EXPECT_EQ(
sizeof(kASCIIHexDecode),
4668 FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len));
4669 EXPECT_STREQ(kASCIIHexDecode, buf.data());
4674 static constexpr char kDCTDecode[] =
"DCTDecode";
4675 EXPECT_EQ(
sizeof(kDCTDecode),
4676 FPDFImageObj_GetImageFilter(obj, 1, buf.data(), len));
4677 EXPECT_STREQ(kDCTDecode, buf.data());
4683 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4684 FPDF_PAGE page = LoadPage(0);
4688 FPDF_IMAGEOBJ_METADATA metadata;
4700 EXPECT_EQ(92u, metadata
.width);
4701 EXPECT_EQ(68u, metadata
.height);
4710 EXPECT_EQ(92u, metadata
.width);
4711 EXPECT_EQ(68u, metadata
.height);
4722 EXPECT_EQ(126u, metadata
.width);
4723 EXPECT_EQ(106u, metadata
.height);
4733 ASSERT_TRUE(OpenDocument(
"jpx_lzw.pdf"));
4734 FPDF_PAGE page = LoadPage(0);
4740 FPDF_IMAGEOBJ_METADATA metadata;
4743 EXPECT_EQ(612u, metadata
.width);
4744 EXPECT_EQ(792u, metadata
.height);
4754 ASSERT_TRUE(OpenDocument(
"embedded_images.pdf"));
4755 FPDF_PAGE page = LoadPage(0);
4759 unsigned int width = 0;
4760 unsigned int height = 0;
4773 EXPECT_EQ(92u, width);
4774 EXPECT_EQ(68u, height);
4779 EXPECT_EQ(126u, width);
4780 EXPECT_EQ(106u, height);
4786 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
4787 FPDF_PAGE page = LoadPage(0);
4794 ScopedFPDFBitmap bitmap(
4795 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 1));
4796 ASSERT_TRUE(bitmap);
4797 const char* checksum = []() {
4799#if BUILDFLAG(IS_WIN)
4800 return "5cef5b3e56e91e1a66b6780fb26bb5e3";
4801#elif BUILDFLAG(IS_APPLE)
4802 return "9e7774173acee966fcaa72e599eb9a93";
4804 return "b17801afe8a36d6aad6c2239b88f2a73";
4807 return "bb0abe1accca1cfeaaf78afa35762350";
4809 CompareBitmap(bitmap.get(), 64, 11, checksum);
4811 ScopedFPDFBitmap x2_bitmap(
4812 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 2.4f));
4813 ASSERT_TRUE(x2_bitmap);
4814 const char* x2_checksum = []() {
4816#if BUILDFLAG(IS_WIN)
4817 return "3cea4255285df04659e3c7477287bdb1";
4818#elif BUILDFLAG(IS_APPLE)
4819 return "2b34bddd2a1471e245cf72603c6799b4";
4821 return "33af8b151ab26ebce5a71b39eedea6b1";
4824 return "80db528ec7146d92247f2339a8f10ba5";
4826 CompareBitmap(x2_bitmap.get(), 153, 25, x2_checksum);
4828 ScopedFPDFBitmap x10_bitmap(
4829 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 10));
4830 ASSERT_TRUE(x10_bitmap);
4831 const char* x10_checksum = []() {
4833#if BUILDFLAG(IS_WIN)
4834 return "1cc617da9ed5922eeac2414108509ef5";
4835#elif BUILDFLAG(IS_APPLE)
4836 return "0450d576560274a7df31cb93d040e721";
4838 return "93dd7ad07bdaaba9ecd268350cb91596";
4841 return "149f63de758ab01d3b75605cdfd4c176";
4843 CompareBitmap(x10_bitmap.get(), 631, 103, x10_checksum);
4850 ScopedFPDFBitmap bitmap(
4851 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 1));
4852 ASSERT_TRUE(bitmap);
4853 const char* checksum = []() {
4855#if BUILDFLAG(IS_WIN)
4856 return "336be21110c795cefcab9bbdbc3afcdd";
4857#elif BUILDFLAG(IS_APPLE)
4858 return "0b9efedcb8f5aa9246c52e90811cb046";
4860 return "63fd059d984a5bea10f27ba026420202";
4863 return "3fc1101b2408c5484adc24ba0a11ff3d";
4865 CompareBitmap(bitmap.get(), 116, 16, checksum);
4867 ScopedFPDFBitmap x2_bitmap(
4868 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 2.4f));
4869 ASSERT_TRUE(x2_bitmap);
4870 const char* x2_checksum = []() {
4872#if BUILDFLAG(IS_WIN)
4873 return "c5cecc5553843a4dd4fff3ceb4855a82";
4874#elif BUILDFLAG(IS_APPLE)
4875 return "10f4d9528a5471ab0b235984f0354dd4";
4877 return "fc45021e3ea3ebd406fe6ffaa8c5c5b7";
4880 return "429960ae7b822f0c630432535e637465";
4882 CompareBitmap(x2_bitmap.get(), 276, 36, x2_checksum);
4884 ScopedFPDFBitmap x10_bitmap(
4885 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 10));
4886 ASSERT_TRUE(x10_bitmap);
4887 const char* x10_checksum = []() {
4889#if BUILDFLAG(IS_WIN)
4890 return "cff29dcbe77092ec7f73e46766a289c7";
4891#elif BUILDFLAG(IS_APPLE)
4892 return "9e87791ffdf4cca0a0f118be245970c8";
4894 return "61476636eaa0da0b93d8b1937cf22b75";
4897 return "f5f93bf64de579b59e775d7076ca0a5a";
4899 CompareBitmap(x10_bitmap.get(), 1143, 150, x10_checksum);
4906 ASSERT_TRUE(OpenDocument(
"rotated_text.pdf"));
4907 FPDF_PAGE page = LoadPage(0);
4913 ScopedFPDFBitmap bitmap(
4914 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 1));
4915 ASSERT_TRUE(bitmap);
4916 const char* checksum = []() {
4918#if BUILDFLAG(IS_WIN)
4919 return "ba5322a4e6b0f79dca42be88f3007708";
4920#elif BUILDFLAG(IS_APPLE)
4921 return "22cf71716a7059f481a63e32b6088c8c";
4923 return "f515a7209d7892065d3716ec462f5c10";
4926 return "08ada0802f780d3fefb161dc6fb45977";
4928 CompareBitmap(bitmap.get(), 29, 28, checksum);
4930 ScopedFPDFBitmap x2_bitmap(
4931 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 2.4f));
4932 ASSERT_TRUE(x2_bitmap);
4933 const char* x2_checksum = []() {
4935#if BUILDFLAG(IS_WIN)
4936 return "e8fb0a707b2924726757a2ed32d6f28d";
4937#elif BUILDFLAG(IS_APPLE)
4938 return "5d4be6808bdcec3f6ee7352122dd986d";
4940 return "c69bbe5318ec149f63228e276e708612";
4943 return "09d7ddb647b8653cb59aede349a0c3e1";
4945 CompareBitmap(x2_bitmap.get(), 67, 67, x2_checksum);
4947 ScopedFPDFBitmap x10_bitmap(
4948 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 10));
4949 ASSERT_TRUE(x10_bitmap);
4950 const char* x10_checksum = []() {
4952#if BUILDFLAG(IS_WIN)
4953 return "eb0cbf56707d1c39ce0ab89a9b43d6a8";
4954#elif BUILDFLAG(IS_APPLE)
4955 return "98757f865abde60c7f7f60c74435cb85";
4957 return "bb7c2ec575f27cf882dcd38f2563c00f";
4960 return "bbd3842a4b50dbfcbce4eee2b067a297";
4962 CompareBitmap(x10_bitmap.get(), 275, 275, x10_checksum);
4968 ASSERT_TRUE(OpenDocument(
"text_color.pdf"));
4969 FPDF_PAGE page = LoadPage(0);
4975 ScopedFPDFBitmap bitmap(
4976 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 7.3f));
4977 ASSERT_TRUE(bitmap);
4978 const char* checksum = []() {
4980 return "1d74731d23a056c0e3fb88f2f85b2581";
4982 return "e8154fa8ededf4d9b8b35b5260897b6c";
4984 CompareBitmap(bitmap.get(), 120, 186, checksum);
4991 ASSERT_TRUE(CreateNewDocument());
4994 ScopedFPDFPageObject text_object(
4995 FPDFPageObj_NewTextObj(document(),
"Arial", 12.0f));
4997 ScopedFPDFWideString text = GetFPDFWideString(kBottomText);
4998 EXPECT_TRUE(FPDFText_SetText(text_object.get(), text.get()));
5000 ScopedFPDFBitmap bitmap(
5001 FPDFTextObj_GetRenderedBitmap(document(),
nullptr, text_object.get(), 1));
5002 ASSERT_TRUE(bitmap);
5003 const char* checksum = []() {
5005#if BUILDFLAG(IS_WIN)
5006 return "ef501232372617a545ae35d7664fd9ec";
5007#elif BUILDFLAG(IS_APPLE)
5008 return "a637d62f2e8ae10c3267b2ff5fcc2246";
5010 return "574ae982d02e653ab6a8f23a6cdf4085";
5013 return "fa947759dab76d68a07ccf6f97b2d9c2";
5015 CompareBitmap(bitmap.get(), 151, 12, checksum);
5019 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
5020 FPDF_PAGE page = LoadPage(0);
5024 ASSERT_TRUE(text_object);
5028 EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(),
nullptr,
nullptr, 0));
5032 EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), page,
nullptr, 0));
5033 EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(),
nullptr,
nullptr, 1));
5037 EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), page,
nullptr, 1));
5041 EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 0));
5043 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, -1));
5045 FPDFTextObj_GetRenderedBitmap(document(), page, text_object, 10000));
5046 EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(
5047 document(), page, text_object,
std::numeric_limits<
float>::max()));
5048 EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(
5049 document(), page, text_object,
std::numeric_limits<
float>::infinity()));
5054 ScopedFPDFBitmap bitmap(
5055 FPDFTextObj_GetRenderedBitmap(document(),
nullptr, text_object, 1));
5056 EXPECT_TRUE(bitmap);
5060 ScopedFPDFDocument empty_document(FPDF_CreateNewDocument());
5061 EXPECT_FALSE(FPDFTextObj_GetRenderedBitmap(empty_document.get(), page,
5068 ASSERT_TRUE(OpenDocument(
"multiple_graphics_states.pdf"));
5069 FPDF_PAGE page = LoadPage(0);
5073 ScopedFPDFPageObject path(FPDFPageObj_CreateNewPath(400, 100));
5074 EXPECT_TRUE(FPDFPageObj_SetFillColor(path.get(), 255, 0, 0, 255));
5076 EXPECT_TRUE(FPDFPath_MoveTo(path.get(), 100, 100));
5077 EXPECT_TRUE(FPDFPath_LineTo(path.get(), 100, 125));
5078 EXPECT_TRUE(FPDFPath_Close(path.get()));
5080 FPDFPage_InsertObject(page, path.release());
5085 ?
"7ebec75d95c64b522999a710de76c52c"
5086 :
"f4b36616a7fea81a4f06cc7b01a55ac1";
5088 ScopedFPDFBitmap bitmap = RenderPage(page);
5089 CompareBitmap(bitmap.get(), 200, 300, checksum);
5091 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
5092 VerifySavedDocument(200, 300, checksum);
5100 std::vector<std::string> hashes;
5101 hashes.reserve(page_count);
5102 for (
int i = 0; i < page_count; ++i) {
5103 hashes.push_back(HashForPage(i));
5109 std::string HashForPage(
int page_index) {
5110 FPDF_PAGE page =
LoadPage(page_index);
5112 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
5113 std::string hash = HashBitmap(bitmap.get());
5120 static const FPDFEditMoveEmbedderTestCase kTestCases[] = {
5121 {{0, 1, 2, 3, 4}, 5, 0,
true, {0, 1, 2, 3, 4},
"no change"},
5122 {{0, 4, 2, 1, 3}, 5, 0,
true, {0, 4, 2, 1, 3},
"reorder all pages"},
5123 {{0, 2, 4, 3}, 4, 1,
true, {1, 0, 2, 4, 3},
"reorder 4 pages"},
5124 {{1, 4, 2}, 3, 2,
true, {0, 3, 1, 4, 2},
"reorder 3 pages"},
5125 {{3, 2}, 2, 3,
true, {0, 1, 4, 3, 2},
"reorder 2 pages"},
5126 {{3}, 1, 4,
true, {0, 1, 2, 4, 3},
"reorder 1 page"},
5127 {{1, 1}, 2, 2,
false, {},
"duplicate index"},
5128 {{5, 3, 2}, 3, 0,
false, {},
"out of range index"},
5129 {{3}, 0, 0,
false, {},
"page_indices_len needs to be in range [1, 5]"},
5130 {{4, 3, 2, 1, 0}, 6, 0,
false, {},
"page_indices_len is too big"},
5131 {{3}, 0, 5,
false, {},
"dest_page_index is out of range"},
5132 {{3, 1, 4}, 0, -1,
false, {},
"dest_page_index is out of range"},
5136 for (
const FPDFEditMoveEmbedderTestCase& tc : kTestCases) {
5137 ASSERT_TRUE(OpenDocument(
"rectangles_multi_pages.pdf"));
5138 const int page_count = GetPageCount();
5139 ASSERT_EQ(page_count, 5);
5141 if (tc.expected_result) {
5142 ASSERT_THAT(tc.expected_order, testing::SizeIs(page_count));
5144 ASSERT_THAT(tc.expected_order, testing::SizeIs(0));
5148 std::vector<std::string> orig_hashes = HashesForDocument(page_count);
5149 ASSERT_THAT(orig_hashes, testing::SizeIs(page_count));
5151 EXPECT_EQ(FPDF_MovePages(document(), &tc.page_indices[0],
5152 tc.page_indices_len, tc.dest_page_index),
5156 if (tc.expected_result) {
5158 std::vector<std::string> new_hashes = HashesForDocument(page_count);
5159 std::vector<std::string> expected_hashes;
5160 expected_hashes.reserve(page_count);
5161 for (
int i = 0; i < page_count; ++i) {
5162 expected_hashes.push_back(orig_hashes[tc.expected_order[i]]);
5164 EXPECT_THAT(new_hashes, testing::ContainerEq(expected_hashes)) << tc;
5167 EXPECT_THAT(HashesForDocument(page_count),
5168 testing::ContainerEq(orig_hashes))
static bool UseSkiaRenderer()
ByteString GetNameFor(const ByteString &key) const
virtual bool IsTrueTypeFont() const
virtual int GetCharWidthF(uint32_t charcode)=0
virtual bool IsType1Font() const
virtual bool IsCIDFont() const
int32_t GetContentStream() const
void UnloadPage(FPDF_PAGE page)
FPDF_DOCUMENT document() const
FPDF_PAGE LoadPage(int page_number)
void CreateEmptyDocumentWithoutFormFillEnvironment()
CPDF_Document * cpdf_doc()
void CheckCompositeFontWidths(const CPDF_Array *widths_array, CPDF_Font *typed_font)
FPDF_DOCUMENT CreateNewDocument()
void CheckFontDescriptor(const CPDF_Dictionary *font_dict, int font_type, bool bold, bool italic, pdfium::span< const uint8_t > span)
std::vector< std::string > HashesForDocument(int page_count)
ByteString(const char *ptr)
CPDF_Page * CPDFPageFromFPDFPage(FPDF_PAGE page)
CPDF_PageObject * CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object)
#define FPDF_ANNOT_UNDERLINE
FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV FPDFPath_GetPathSegment(FPDF_PAGEOBJECT path, int index)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFFont_GetFontName(FPDF_FONT font, char *buffer, unsigned long length)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFFont_GetGlyphWidth(FPDF_FONT font, uint32_t glyph, float font_size, float *width)
#define FPDF_FILLMODE_ALTERNATE
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetRotation(FPDF_PAGE page)
FPDF_EXPORT int FPDF_CALLCONV FPDFFont_GetWeight(FPDF_FONT font)
#define FPDF_COLORSPACE_UNKNOWN
FPDF_EXPORT int FPDF_CALLCONV FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetStrokeColor(FPDF_PAGEOBJECT page_object, unsigned int R, unsigned int G, unsigned int B, unsigned int A)
FPDF_EXPORT int FPDF_CALLCONV FPDFFont_GetIsEmbedded(FPDF_FONT font)
FPDF_EXPORT int FPDF_CALLCONV FPDFPathSegment_GetType(FPDF_PATHSEGMENT segment)
#define FPDF_FONT_TRUETYPE
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewPath(float x, float y)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, int fillmode, FPDF_BOOL stroke)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObjMark_GetParamKey(FPDF_PAGEOBJECTMARK mark, unsigned long index, void *buffer, unsigned long buflen, unsigned long *out_buflen)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_GetImageMetadata(FPDF_PAGEOBJECT image_object, FPDF_PAGE page, FPDF_IMAGEOBJ_METADATA *metadata)
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPathSegment_GetPoint(FPDF_PATHSEGMENT segment, float *x, float *y)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFFont_GetDescent(FPDF_FONT font, float font_size, float *descent)
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFImageObj_GetRenderedBitmap(FPDF_DOCUMENT document, FPDF_PAGE page, FPDF_PAGEOBJECT image_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_Close(FPDF_PAGEOBJECT path)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, unsigned int R, unsigned int G, unsigned int B, unsigned int A)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFTextObj_SetTextRenderMode(FPDF_PAGEOBJECT text, FPDF_TEXT_RENDERMODE render_mode)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetDrawMode(FPDF_PAGEOBJECT path, int *fillmode, FPDF_BOOL *stroke)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFFont_GetItalicAngle(FPDF_FONT font, int *angle)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFImageObj_GetImageDataRaw(FPDF_PAGEOBJECT image_object, void *buffer, unsigned long buflen)
#define FPDF_FILLMODE_NONE
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFImageObj_GetImageFilter(FPDF_PAGEOBJECT image_object, int index, void *buffer, unsigned long buflen)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_GetFillColor(FPDF_PAGEOBJECT page_object, unsigned int *R, unsigned int *G, unsigned int *B, unsigned int *A)
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object)
FPDF_EXPORT int FPDF_CALLCONV FPDFPageObjMark_CountParams(FPDF_PAGEOBJECTMARK mark)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_RemoveMark(FPDF_PAGEOBJECT page_object, FPDF_PAGEOBJECTMARK mark)
FPDF_EXPORT int FPDF_CALLCONV FPDFFont_GetFlags(FPDF_FONT font)
#define FPDF_SEGMENT_MOVETO
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObjMark_GetParamStringValue(FPDF_PAGEOBJECTMARK mark, FPDF_BYTESTRING key, void *buffer, unsigned long buflen, unsigned long *out_buflen)
FPDF_EXPORT int FPDF_CALLCONV FPDFPageObj_CountMarks(FPDF_PAGEOBJECT page_object)
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x, float y, float w, float h)
#define FPDF_SEGMENT_UNKNOWN
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_TransformAnnots(FPDF_PAGE page, double a, double b, double c, double d, double e, double f)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_RemoveObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_LineTo(FPDF_PAGEOBJECT path, float x, float y)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObjMark_GetParamBlobValue(FPDF_PAGEOBJECTMARK mark, FPDF_BYTESTRING key, void *buffer, unsigned long buflen, unsigned long *out_buflen)
#define FPDF_SEGMENT_BEZIERTO
FPDF_EXPORT int FPDF_CALLCONV FPDFImageObj_GetImageFilterCount(FPDF_PAGEOBJECT image_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObjMark_RemoveParam(FPDF_PAGEOBJECT page_object, FPDF_PAGEOBJECTMARK mark, FPDF_BYTESTRING key)
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPage_GetObject(FPDF_PAGE page, int index)
FPDF_EXPORT FPDF_TEXT_RENDERMODE FPDF_CALLCONV FPDFTextObj_GetTextRenderMode(FPDF_PAGEOBJECT text)
FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV FPDFPageObjMark_GetParamValueType(FPDF_PAGEOBJECTMARK mark, FPDF_BYTESTRING key)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObjMark_GetParamIntValue(FPDF_PAGEOBJECTMARK mark, FPDF_BYTESTRING key, int *out_value)
FPDF_EXPORT FPDF_FONT FPDF_CALLCONV FPDFTextObj_GetFont(FPDF_PAGEOBJECT text)
FPDF_EXPORT FPDF_GLYPHPATH FPDF_CALLCONV FPDFFont_GetGlyphPath(FPDF_FONT font, uint32_t glyph, float font_size)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_BezierTo(FPDF_PAGEOBJECT path, float x1, float y1, float x2, float y2, float x3, float y3)
FPDF_EXPORT int FPDF_CALLCONV FPDFPageObj_GetType(FPDF_PAGEOBJECT page_object)
#define FPDF_PAGEOBJ_PATH
FPDF_EXPORT int FPDF_CALLCONV FPDFPath_CountSegments(FPDF_PAGEOBJECT path)
#define FPDF_PAGEOBJ_TEXT
#define FPDF_PAGEOBJ_IMAGE
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path, float x, float y)
#define FPDF_COLORSPACE_INDEXED
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_GetBounds(FPDF_PAGEOBJECT page_object, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text, float *size)
FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV FPDFPageObj_GetMark(FPDF_PAGEOBJECT page_object, unsigned long index)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_GetStrokeWidth(FPDF_PAGEOBJECT page_object, float *width)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetMatrix(FPDF_PAGEOBJECT page_object, const FS_MATRIX *matrix)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetStrokeWidth(FPDF_PAGEOBJECT page_object, float width)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_GetImagePixelSize(FPDF_PAGEOBJECT image_object, unsigned int *width, unsigned int *height)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFFont_GetAscent(FPDF_FONT font, float font_size, float *ascent)
#define FPDF_PAGEOBJ_FORM
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object, void *buffer, unsigned long buflen)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GenerateContent(FPDF_PAGE page)
FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV FPDFGlyphPath_GetGlyphPathSegment(FPDF_GLYPHPATH glyphpath, int index)
#define FPDF_COLORSPACE_DEVICERGB
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFTextObj_GetRenderedBitmap(FPDF_DOCUMENT document, FPDF_PAGE page, FPDF_PAGEOBJECT text_object, float scale)
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_CountObjects(FPDF_PAGE page)
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index)
FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV FPDFPageObj_AddMark(FPDF_PAGEOBJECT page_object, FPDF_BYTESTRING name)
#define FPDF_SEGMENT_LINETO
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObjMark_GetName(FPDF_PAGEOBJECTMARK mark, void *buffer, unsigned long buflen, unsigned long *out_buflen)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_GetMatrix(FPDF_PAGEOBJECT page_object, FS_MATRIX *matrix)
FPDF_EXPORT int FPDF_CALLCONV FPDFGlyphPath_CountGlyphSegments(FPDF_GLYPHPATH glyphpath)
FPDF_EXPORT void FPDF_CALLCONV FPDFPageObj_SetBlendMode(FPDF_PAGEOBJECT page_object, FPDF_BYTESTRING blend_mode)
FPDF_EXPORT void FPDF_CALLCONV FPDFPageObj_Transform(FPDF_PAGEOBJECT page_object, double a, double b, double c, double d, double e, double f)
FPDF_EXPORT void FPDF_CALLCONV FPDFPageObj_Destroy(FPDF_PAGEOBJECT page_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPathSegment_GetClose(FPDF_PATHSEGMENT segment)
#define FPDF_FILLMODE_WINDING
TEST_F(FPDFEditEmbedderTest, EmbedNotoSansSCFont)
TEST_F(FPDFEditEmbedderTest, GraphicsData)
void CheckMarkCounts(FPDF_PAGE page, int start_from, int expected_object_count, size_t expected_prime_count, size_t expected_square_count, size_t expected_greater_than_ten_count, size_t expected_bounds_count)
TEST_F(FPDFEditMoveEmbedderTest, MovePagesTest)
FPDF_EXPORT int FPDF_CALLCONV FPDFClipPath_CountPaths(FPDF_CLIPPATH clip_path)
FPDF_EXPORT FPDF_CLIPPATH FPDF_CALLCONV FPDFPageObj_GetClipPath(FPDF_PAGEOBJECT page_object)
FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV FPDFClipPath_GetPathSegment(FPDF_CLIPPATH clip_path, int path_index, int segment_index)
FPDF_EXPORT int FPDF_CALLCONV FPDFClipPath_CountPathSegments(FPDF_CLIPPATH clip_path, int path_index)
FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page)
#define FPDF_OBJECT_NUMBER
#define FPDF_OBJECT_STRING
#define FPDF_OBJECT_ARRAY
bool FontStyleIsNonSymbolic(uint32_t style)
bool FontStyleIsItalic(uint32_t style)
bool FontStyleIsForceBold(uint32_t style)
const char kBlankPage612By792Checksum[]
const char * HelloWorldChecksum()
const char * HelloWorldRemovedChecksum()
const char * ManyRectanglesChecksum()