5#include "public/fpdf_annot.h"
14#include "build/build_config.h"
15#include "constants/annotation_common.h"
16#include "core/fpdfapi/page/cpdf_annotcontext.h"
17#include "core/fpdfapi/parser/cpdf_array.h"
18#include "core/fpdfapi/parser/cpdf_dictionary.h"
19#include "core/fxcrt/compiler_specific.h"
20#include "core/fxcrt/containers/contains.h"
21#include "core/fxcrt/fx_memcpy_wrappers.h"
22#include "core/fxcrt/fx_system.h"
23#include "core/fxcrt/span.h"
24#include "core/fxge/cfx_defaultrenderdevice.h"
25#include "fpdfsdk/cpdfsdk_helpers.h"
26#include "public/cpp/fpdf_scopers.h"
27#include "public/fpdf_attachment.h"
28#include "public/fpdf_edit.h"
29#include "public/fpdf_formfill.h"
30#include "public/fpdfview.h"
31#include "testing/embedder_test.h"
32#include "testing/embedder_test_constants.h"
33#include "testing/fx_string_testhelpers.h"
34#include "testing/gmock/include/gmock/gmock-matchers.h"
35#include "testing/gtest/include/gtest/gtest.h"
36#include "testing/utils/hash.h"
38using pdfium::AnnotationStampWithApChecksum;
42const wchar_t kStreamData[] =
43 L"/GS gs 0.0 0.0 0.0 RG 4 w 211.8 747.6 m 211.8 744.8 "
44 L"212.6 743.0 214.2 740.8 "
45 L"c 215.4 739.0 216.8 737.1 218.9 736.1 c 220.8 735.1 221.4 733.0 "
46 L"223.7 732.4 c 232.6 729.9 242.0 730.8 251.2 730.8 c 257.5 730.8 "
47 L"263.0 732.9 269.0 734.4 c S";
49void VerifyFocusableAnnotSubtypes(
50 FPDF_FORMHANDLE form_handle,
51 pdfium::span<
const FPDF_ANNOTATION_SUBTYPE> expected_subtypes) {
52 ASSERT_EQ(
static_cast<
int>(expected_subtypes.size()),
55 std::vector<FPDF_ANNOTATION_SUBTYPE> actual_subtypes(
56 expected_subtypes.size());
57 ASSERT_TRUE(FPDFAnnot_GetFocusableSubtypes(
58 form_handle, actual_subtypes.data(), actual_subtypes.size()));
59 for (size_t i = 0; i < expected_subtypes.size(); ++i)
60 ASSERT_EQ(expected_subtypes[i], actual_subtypes[i]);
63void SetAndVerifyFocusableAnnotSubtypes(
64 FPDF_FORMHANDLE form_handle,
65 pdfium::span<
const FPDF_ANNOTATION_SUBTYPE> subtypes) {
66 ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes(form_handle, subtypes.data(),
68 VerifyFocusableAnnotSubtypes(form_handle, subtypes);
71void VerifyAnnotationSubtypesAndFocusability(
72 FPDF_FORMHANDLE form_handle,
74 pdfium::span<
const FPDF_ANNOTATION_SUBTYPE> expected_subtypes,
75 pdfium::span<
const FPDF_ANNOTATION_SUBTYPE> expected_focusable_subtypes) {
76 ASSERT_EQ(
static_cast<
int>(expected_subtypes.size()),
78 for (size_t i = 0; i < expected_subtypes.size(); ++i) {
79 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i));
81 EXPECT_EQ(expected_subtypes[i], FPDFAnnot_GetSubtype(annot.get()));
83 bool expected_focusable =
84 pdfium::Contains(expected_focusable_subtypes, expected_subtypes[i]);
85 EXPECT_EQ(expected_focusable,
86 FORM_SetFocusedAnnot(form_handle, annot.get()));
93void VerifyUriActionInLink(FPDF_DOCUMENT doc,
95 const std::string& expected_uri) {
104 ASSERT_EQ(expected_uri.size() + 1, bufsize);
106 std::vector<
char> buffer(bufsize);
108 FPDFAction_GetURIPath(doc, action, buffer.data(), bufsize));
109 EXPECT_EQ(expected_uri, buffer.data());
119 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
122 ASSERT_TRUE(ap_stream);
124 ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page.get(),
FPDF_ANNOT_INK));
132 const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f};
133 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect));
143 ASSERT_TRUE(context);
145 ASSERT_TRUE(annot_dict);
147 annot_dict->GetDictFor(pdfium::annotation::kAP);
148 ASSERT_TRUE(ap_dict);
150 ASSERT_TRUE(stream_dict);
153 stream_dict->GetDictFor(
"Resources");
154 ASSERT_FALSE(resources_dict);
156 EXPECT_EQ(
"XObject", type);
159 EXPECT_EQ(
"Form", sub_type);
162 const uint32_t kStreamDataSize =
std::size(kStreamData) *
sizeof(FPDF_WCHAR);
163 unsigned long normal_length_bytes = FPDFAnnot_GetAP(
165 ASSERT_EQ(kStreamDataSize, normal_length_bytes);
166 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(normal_length_bytes);
167 EXPECT_EQ(kStreamDataSize,
169 buf.data(), normal_length_bytes));
170 EXPECT_EQ(kStreamData, GetPlatformWString(buf.data()));
176 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
179 ASSERT_TRUE(ap_stream);
181 ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page.get(),
FPDF_ANNOT_INK));
187 const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f};
188 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect));
194 ASSERT_TRUE(context);
196 ASSERT_TRUE(annot_dict);
198 annot_dict->GetDictFor(pdfium::annotation::kAP);
199 ASSERT_TRUE(ap_dict);
201 ASSERT_TRUE(stream_dict);
203 stream_dict->GetDictFor(
"Resources");
204 ASSERT_TRUE(stream_dict);
206 resources_dict->GetDictFor(
"ExtGState");
207 ASSERT_TRUE(extGState_dict);
209 ASSERT_TRUE(gs_dict);
211 EXPECT_EQ(
"ExtGState", type);
212 float opacity = gs_dict->GetFloatFor(
"CA");
214 EXPECT_FLOAT_EQ(0.4f, opacity);
215 ByteString blend_mode = gs_dict->GetByteStringFor(
"BM");
216 EXPECT_EQ(
"Normal", blend_mode);
217 bool alpha_source_flag = gs_dict->GetBooleanFor(
"AIS",
true);
218 EXPECT_FALSE(alpha_source_flag);
224 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
228 ScopedFPDFAnnotation ink_annot(
230 ASSERT_TRUE(ink_annot);
232 CPDFAnnotContextFromFPDFAnnotation(ink_annot.get());
233 ASSERT_TRUE(context);
235 ASSERT_TRUE(annot_dict);
237 static constexpr FS_POINTF kFirstInkStroke[] = {
238 {80.0f, 90.0f}, {81.0f, 91.0f}, {82.0f, 92.0f},
239 {83.0f, 93.0f}, {84.0f, 94.0f}, {85.0f, 95.0f}};
240 static constexpr size_t kFirstStrokePointCount =
std::size(kFirstInkStroke);
242 static constexpr FS_POINTF kSecondInkStroke[] = {
243 {70.0f, 90.0f}, {71.0f, 91.0f}, {72.0f, 92.0f}};
244 static constexpr size_t kSecondStrokePointCount =
std::size(kSecondInkStroke);
246 static constexpr FS_POINTF kThirdInkStroke[] = {{60.0f, 90.0f},
251 static constexpr size_t kThirdStrokePointCount =
std::size(kThirdInkStroke);
254 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(
nullptr, kFirstInkStroke,
255 kFirstStrokePointCount));
259 ScopedFPDFAnnotation highlight_annot(
261 ASSERT_TRUE(highlight_annot);
262 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(highlight_annot.get(), kFirstInkStroke,
263 kFirstStrokePointCount));
266 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), kFirstInkStroke, 0));
269 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(),
nullptr,
270 kFirstStrokePointCount));
273 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), kSecondInkStroke,
278 EXPECT_EQ(0, FPDFAnnot_AddInkStroke(ink_annot.get(), kFirstInkStroke,
279 kFirstStrokePointCount));
282 ASSERT_TRUE(inklist);
283 EXPECT_EQ(1u, inklist->size());
284 EXPECT_EQ(kFirstStrokePointCount * 2, inklist->GetArrayAt(0)->size());
288 EXPECT_EQ(1, FPDFAnnot_AddInkStroke(ink_annot.get(), kSecondInkStroke,
289 kSecondStrokePointCount));
290 EXPECT_EQ(2u, inklist->size());
291 EXPECT_EQ(kSecondStrokePointCount * 2, inklist->GetArrayAt(1)->size());
295 EXPECT_EQ(2, FPDFAnnot_AddInkStroke(ink_annot.get(), kThirdInkStroke,
296 kThirdStrokePointCount - 1));
297 EXPECT_EQ(3u, inklist->size());
298 EXPECT_EQ((kThirdStrokePointCount - 1) * 2, inklist->GetArrayAt(2)->size());
304 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
312 ScopedFPDFAnnotation highlight_annot(
314 ASSERT_TRUE(highlight_annot);
315 EXPECT_FALSE(FPDFAnnot_RemoveInkList(highlight_annot.get()));
318 ScopedFPDFAnnotation ink_annot(
320 ASSERT_TRUE(ink_annot);
322 CPDFAnnotContextFromFPDFAnnotation(ink_annot.get());
323 ASSERT_TRUE(context);
325 ASSERT_TRUE(annot_dict);
327 static constexpr FS_POINTF kInkStroke[] = {{80.0f, 90.0f}, {81.0f, 91.0f},
328 {82.0f, 92.0f}, {83.0f, 93.0f},
329 {84.0f, 94.0f}, {85.0f, 95.0f}};
330 static constexpr size_t kPointCount =
std::size(kInkStroke);
335 FPDFAnnot_AddInkStroke(ink_annot.get(), kInkStroke, kPointCount));
338 ASSERT_TRUE(inklist);
339 ASSERT_EQ(1u, inklist->size());
340 EXPECT_EQ(kPointCount * 2, inklist->GetArrayAt(0)->size());
343 EXPECT_TRUE(FPDFAnnot_RemoveInkList(ink_annot.get()));
348 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
349 FPDF_PAGE page = LoadPage(0);
370 static const wchar_t kContents[] = L"Bar";
372 EXPECT_FALSE(FPDFAnnot_SetStringValue(
nullptr,
"foo", text.get()));
374 FPDF_WCHAR buffer[64];
384 ASSERT_TRUE(OpenDocument(
"bad_annots_entry.pdf"));
385 FPDF_PAGE page = LoadPage(0);
396 ASSERT_TRUE(OpenDocument(
"annotation_highlight_rollover_ap.pdf"));
397 FPDF_PAGE page = LoadPage(0);
404 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
405 CompareBitmap(bitmap.get(), 612, 792,
"dc98f06da047bd8aabfa99562d2cbd1e");
411 const char* checksum = []() {
413 return "ec1f4ccbd0aecfdea6d53893387a0101";
415 return "76512832d88017668d9acc7aacd13dae";
419 ASSERT_TRUE(OpenDocument(
"annotation_markup_multiline_no_ap.pdf"));
420 FPDF_PAGE page = LoadPage(0);
423 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
424 CompareBitmap(bitmap.get(), 595, 842, checksum);
431 ASSERT_TRUE(OpenDocument(
"annotation_highlight_long_content.pdf"));
432 FPDF_PAGE page = LoadPageNoEvents(0);
457 static const char kAuthorKey[] =
"T";
459 FPDFAnnot_GetValueType(annot.get(), kAuthorKey));
460 unsigned long length_bytes =
461 FPDFAnnot_GetStringValue(annot.get(), kAuthorKey,
nullptr, 0);
462 ASSERT_EQ(28u, length_bytes);
463 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
464 EXPECT_EQ(28u, FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, buf.data(),
466 EXPECT_EQ(L"Jae Hyun Park", GetPlatformWString(buf.data()));
472 length_bytes = FPDFAnnot_GetStringValue(
474 ASSERT_EQ(2690u, length_bytes);
475 buf = GetFPDFWideStringBuffer(length_bytes);
476 EXPECT_EQ(2690u, FPDFAnnot_GetStringValue(annot.get(),
478 buf.data(), length_bytes));
479 static const wchar_t kContents[] =
480 L"This is a note for that highlight annotation. Very long highlight "
481 "annotation. Long long long Long long longLong long longLong long "
482 "longLong long longLong long longLong long longLong long longLong long "
483 "longLong long longLong long longLong long longLong long longLong long "
484 "longLong long longLong long longLong long longLong long longLong long "
485 "longLong long longLong long longLong long longLong long longLong long "
486 "longLong long longLong long longLong long longLong long longLong long "
487 "longLong long longLong long longLong long longLong long longLong long "
488 "longLong long longLong long longLong long longLong long longLong long "
489 "longLong long longLong long longLong long longLong long longLong long "
490 "longLong long longLong long longLong long longLong long longLong long "
491 "longLong long longLong long longLong long longLong long longLong long "
492 "longLong long longLong long longLong long longLong long longLong long "
493 "longLong long longLong long longLong long longLong long longLong long "
494 "longLong long longLong long longLong long longLong long longLong long "
495 "longLong long longLong long longLong long longLong long longLong long "
496 "longLong long longLong long longLong long longLong long longLong long "
497 "longLong long longLong long longLong long longLong long longLong long "
498 "longLong long longLong long longLong long longLong long longLong long "
499 "longLong long long. END";
500 EXPECT_EQ(kContents, GetPlatformWString(buf.data()));
503 FS_QUADPOINTSF quadpoints;
504 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
505 EXPECT_EQ(115.802643f, quadpoints.x1);
506 EXPECT_EQ(718.913940f, quadpoints.y1);
507 EXPECT_EQ(157.211182f, quadpoints.x4);
508 EXPECT_EQ(706.264465f, quadpoints.y4);
510 UnloadPageNoEvents(page);
515 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
516 FPDF_PAGE page = LoadPageNoEvents(0);
541 EXPECT_EQ(2u, FPDFAnnot_GetStringValue(
547 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
548 EXPECT_EQ(351.820404f, rect.left);
549 EXPECT_EQ(583.830688f, rect.bottom);
550 EXPECT_EQ(475.336090f, rect.right);
551 EXPECT_EQ(681.535034f, rect.top);
554 const char* expected_hash = []() {
557 return "b4698da8e2f9e8cb82b7bbb6e7d559a9";
558#elif BUILDFLAG(IS_APPLE)
559 return "e3da57011a3d66238d15be1bedcb6696";
561 return "c2404a7a9a86ee78487cd1993949c56d";
564 return "354002e1c4386d38fdde29ef8d61074a";
566 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
567 CompareBitmap(bitmap.get(), 612, 792, expected_hash);
569 UnloadPageNoEvents(page);
574 ASSERT_TRUE(OpenDocument(
"annotation_highlight_long_content.pdf"));
575 FPDF_PAGE page = LoadPage(0);
586 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
587 FPDF_PAGE page = LoadPage(0);
636 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
637 EXPECT_EQ(0.f, rect.left);
638 EXPECT_EQ(0.f, rect.right);
643 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
645 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
646 EXPECT_EQ(35.f, rect.left);
647 EXPECT_EQ(150.f, rect.bottom);
648 EXPECT_EQ(53.f, rect.right);
649 EXPECT_EQ(165.f, rect.top);
652 static const wchar_t kContents[] = L"Hello! This is a customized content.";
654 ASSERT_TRUE(FPDFAnnot_SetStringValue(
657 unsigned long length_bytes = FPDFAnnot_GetStringValue(
659 ASSERT_EQ(74u, length_bytes);
660 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
661 EXPECT_EQ(74u, FPDFAnnot_GetStringValue(annot.get(),
663 buf.data(), length_bytes));
664 EXPECT_EQ(kContents, GetPlatformWString(buf.data()));
670 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
671 FPDF_PAGE page = LoadPage(0);
674 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
679 constexpr char kUri[] =
"https://pdfium.org/";
687 EXPECT_TRUE(FPDFAnnot_SetURI(annot.get(), kUri));
688 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
692 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
693 EXPECT_FALSE(FPDFAnnot_SetURI(annot.get(),
nullptr));
694 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
696 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
699 const FS_RECTF kRect = {19.0f, 48.0f, 85.0f, 60.0f};
700 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &kRect));
701 EXPECT_TRUE(FPDFAnnot_SetBorder(annot.get(), 0.0f,
715 EXPECT_FALSE(FPDFAnnot_SetURI(annot.get(), kUri));
723 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
728 ASSERT_TRUE(OpenSavedDocument());
729 page = LoadSavedPage(0);
738 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
743 CloseSavedPage(page);
744 CloseSavedDocument();
749 ASSERT_TRUE(OpenDocument(
"annotation_highlight_long_content.pdf"));
750 FPDF_PAGE page = LoadPage(0);
756 FS_QUADPOINTSF quadpoints;
760 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
761 EXPECT_EQ(115.802643f, quadpoints.x1);
762 EXPECT_EQ(718.913940f, quadpoints.y1);
763 EXPECT_EQ(157.211182f, quadpoints.x4);
764 EXPECT_EQ(706.264465f, quadpoints.y4);
769 ScopedFPDFAnnotation annot(
772 quadpoints.x1 = 140.802643f;
773 quadpoints.x3 = 140.802643f;
774 ASSERT_TRUE(FPDFAnnot_AppendAttachmentPoints(annot.get(), &quadpoints));
778 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
782 const char* checksum = []() {
785 return "c50012ab122cd3706d39f371ca7462ee";
786#elif BUILDFLAG(IS_APPLE)
787 return "24994ad69aa612a66d183eaf9a92aa06";
789 return "798fa41303381c9ba6d99092f5cd4d2b";
792 return "dba153419f67b7c0c0e3d22d3e8910d5";
795 ASSERT_TRUE(OpenSavedDocument());
796 page = LoadSavedPage(0);
798 VerifySavedRendering(page, 612, 792, checksum);
807 ASSERT_TRUE(new_annot);
809 FS_QUADPOINTSF new_quadpoints;
811 FPDFAnnot_GetAttachmentPoints(new_annot.get(), 0, &new_quadpoints));
812 EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f);
813 EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f);
814 EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f);
815 EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f);
818 CloseSavedPage(page);
819 CloseSavedDocument();
824 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
825 FPDF_PAGE page = LoadPage(0);
834 FS_QUADPOINTSF quadpoints;
835 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 0, &quadpoints));
839 ASSERT_EQ(1u, FPDFAnnot_CountAttachmentPoints(annot));
841 EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
842 EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
843 EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
844 EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
849 FS_QUADPOINTSF new_quadpoints = quadpoints;
850 new_quadpoints.y1 -= 20.f;
851 new_quadpoints.y2 -= 20.f;
852 new_quadpoints.y3 -= 20.f;
853 new_quadpoints.y4 -= 20.f;
854 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, 0, &new_quadpoints));
857 ASSERT_EQ(1u, FPDFAnnot_CountAttachmentPoints(annot));
858 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 0, &quadpoints));
859 EXPECT_NEAR(new_quadpoints.x1, quadpoints.x1, 0.001f);
860 EXPECT_NEAR(new_quadpoints.y1, quadpoints.y1, 0.001f);
861 EXPECT_NEAR(new_quadpoints.x4, quadpoints.x4, 0.001f);
862 EXPECT_NEAR(new_quadpoints.y4, quadpoints.y4, 0.001f);
867 FS_QUADPOINTSF new_quadpoints = quadpoints;
868 new_quadpoints.y1 += 20.f;
869 new_quadpoints.y2 += 20.f;
870 new_quadpoints.y3 += 20.f;
871 new_quadpoints.y4 += 20.f;
875 ASSERT_EQ(2u, FPDFAnnot_CountAttachmentPoints(annot));
876 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 1, &quadpoints));
877 EXPECT_NEAR(new_quadpoints.x1, quadpoints.x1, 0.001f);
878 EXPECT_NEAR(new_quadpoints.y1, quadpoints.y1, 0.001f);
879 EXPECT_NEAR(new_quadpoints.x4, quadpoints.x4, 0.001f);
880 EXPECT_NEAR(new_quadpoints.y4, quadpoints.y4, 0.001f);
885 EXPECT_FALSE(FPDFAnnot_SetAttachmentPoints(annot, 300000, &quadpoints));
886 EXPECT_FALSE(FPDFAnnot_GetAttachmentPoints(annot, 300000, &quadpoints));
896 ASSERT_TRUE(squareAnnot);
898 EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(squareAnnot));
899 EXPECT_FALSE(FPDFAnnot_SetAttachmentPoints(squareAnnot, 0, &quadpoints));
907 const char* md5_original = []() {
910 return "3867f6e34e801abad4e98811f6d7b887";
911#elif BUILDFLAG(IS_APPLE)
912 return "32cd26430a31752e612475bf881cc597";
914 return "2a9d1df839d5ec81a49f982347d9656c";
917#if BUILDFLAG(IS_APPLE)
918 return "fc59468d154f397fd298c69f47ef565a";
920 return "0e27376094f11490f74c65f3dc3a42c5";
923 const char* md5_modified_highlight = []() {
926 return "a6f6df562dcf96b3670d40fa2999a582";
927#elif BUILDFLAG(IS_APPLE)
928 return "9a969b7089f49c029b10cf8c208b40dd";
930 return "0fb1653db0e8e8f7ce5d726bb0074bb5";
933#if BUILDFLAG(IS_APPLE)
934 return "e64bf648f6e9354d1f3eedb47a2c9498";
936 return "66f3caef3a7d488a4fa1ad37fc06310e";
939 const char* md5_modified_square = []() {
942 return "cebb3bd3209f63f6dfd15b8425229e90";
943#elif BUILDFLAG(IS_APPLE)
944 return "613102f8b6d74d6d9f95c8eacd17b756";
946 return "879c77a2cb9f79ba65ffe0bbdd720ce3";
949#if BUILDFLAG(IS_APPLE)
950 return "a66591662c8e7ad3c6059952e234bebf";
952 return "a456dad0bc6801ee2d6408a4394af563";
957 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
958 FPDF_PAGE page = LoadPage(0);
964 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
965 CompareBitmap(bitmap.get(), 612, 792, md5_original);
982 FS_QUADPOINTSF quadpoints;
983 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
984 EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
985 EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
986 EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
987 EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
990 quadpoints.x1 -= 50.f;
991 quadpoints.x2 -= 50.f;
992 quadpoints.x3 -= 50.f;
993 quadpoints.x4 -= 50.f;
994 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), 0, &quadpoints));
995 FS_QUADPOINTSF new_quadpoints;
996 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &new_quadpoints));
997 EXPECT_EQ(quadpoints.x1, new_quadpoints.x1);
998 EXPECT_EQ(quadpoints.y1, new_quadpoints.y1);
999 EXPECT_EQ(quadpoints.x4, new_quadpoints.x4);
1000 EXPECT_EQ(quadpoints.y4, new_quadpoints.y4);
1004 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1005 CompareBitmap(bitmap.get(), 612, 792, md5_original);
1009 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1010 EXPECT_NEAR(67.7299f, rect.left, 0.001f);
1011 EXPECT_NEAR(704.296f, rect.bottom, 0.001f);
1012 EXPECT_NEAR(136.325f, rect.right, 0.001f);
1013 EXPECT_NEAR(721.292f, rect.top, 0.001f);
1018 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1019 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
1020 EXPECT_EQ(rect.right, new_rect.right);
1025 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1026 CompareBitmap(bitmap.get(), 612, 792, md5_modified_highlight);
1036 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1039 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1040 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
1041 EXPECT_EQ(rect.right, new_rect.right);
1045 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1046 CompareBitmap(bitmap.get(), 612, 792, md5_modified_square);
1054 ASSERT_TRUE(OpenDocument(
"annotation_markup_multiline_no_ap.pdf"));
1055 FPDF_PAGE page = LoadPage(0);
1062 EXPECT_EQ(3u, FPDFAnnot_CountAttachmentPoints(annot.get()));
1067 EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(
nullptr));
1072 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
1073 FPDF_PAGE page = LoadPageNoEvents(0);
1082 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1083 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
1088 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1089 EXPECT_NEAR(149.8127f, rect.left, 0.001f);
1094 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1095 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
1110 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1111 UnloadPageNoEvents(page);
1115 std::string new_file = GetString();
1116 FPDF_FILEACCESS file_access = {};
1117 static_assert(std::is_aggregate_v<
decltype(file_access)>);
1118 file_access.m_FileLen = new_file.size();
1119 file_access.m_GetBlock = GetBlockFromString;
1120 file_access.m_Param = &new_file;
1122 ASSERT_TRUE(new_doc);
1123 ScopedFPDFPage new_page(FPDF_LoadPage(new_doc.get(), 0));
1124 ASSERT_TRUE(new_page);
1127 EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page.get()));
1132 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(new_page.get(), 0));
1133 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1134 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
1138 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(new_page.get(), 1));
1139 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1140 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
1145 const char* md5_modified_path = []() {
1147#if BUILDFLAG(IS_WIN)
1148 return "c8ae5b9ebd9982d9fde526f50f936971";
1149#elif BUILDFLAG(IS_APPLE)
1150 return "3adf48360ca55e8794a9fc9f1ea87df1";
1152 return "94f7f4568385c16498604ddc46f18be9";
1155#if BUILDFLAG(IS_APPLE)
1156 return "34614087e04b729b7b8c37739dcf9af9";
1158 return "31a94d22460171cd83169daf6a6956ee";
1161 const char* md5_two_paths = []() {
1163#if BUILDFLAG(IS_WIN)
1164 return "d29d4258bd9344abf20bb55e6679c065";
1165#elif BUILDFLAG(IS_APPLE)
1166 return "5f7d44d3a4ffaadb6bf20b4f1ac2a1f0";
1168 return "1052cd0fe1c3e73865fc842525245551";
1171#if BUILDFLAG(IS_APPLE)
1172 return "6cdaf6b3e5145f435d8ccae6db5cf9af";
1174 return "ed49fefef45f14121f8150cde10006c4";
1177 const char* md5_new_annot = []() {
1179#if BUILDFLAG(IS_WIN)
1180 return "9ca0a274d1ae0db09ad814ee455dd88c";
1181#elif BUILDFLAG(IS_APPLE)
1182 return "71c8fb8eee9720c19851c48745dde152";
1184 return "f522e1262f487cc1976bb3fc585ef469";
1187#if BUILDFLAG(IS_APPLE)
1188 return "e6015f42eb81ed6003224cb2f27dcb51";
1190 return "2e567a33390cd2ebad9dc33d82a8b054";
1195 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1196 FPDF_PAGE page = LoadPage(0);
1202 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1212 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1214 FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot.get(), 1);
1216 path = FPDFAnnot_GetObject(annot.get(), 0);
1222 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), path));
1226 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1227 CompareBitmap(bitmap.get(), 595, 842, md5_modified_path);
1236 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), dot));
1237 EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot.get()));
1245 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1246 CompareBitmap(bitmap.get(), 595, 842, md5_two_paths);
1250 EXPECT_TRUE(FPDFAnnot_RemoveObject(annot.get(), 1));
1251 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1257 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1258 CompareBitmap(bitmap.get(), 595, 842, md5_modified_path);
1268 rect.bottom = 400.f;
1271 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1282 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), check));
1283 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1287 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
1288 EXPECT_EQ(rect.left, new_rect.left);
1289 EXPECT_EQ(rect.bottom, new_rect.bottom);
1290 EXPECT_EQ(rect.right, new_rect.right);
1291 EXPECT_EQ(rect.top, new_rect.top);
1295 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1299 ASSERT_TRUE(OpenSavedDocument());
1300 page = LoadSavedPage(0);
1302 VerifySavedRendering(page, 595, 842, md5_new_annot);
1310 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1314 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
1315 EXPECT_EQ(rect.left, new_rect.left);
1316 EXPECT_EQ(rect.bottom, new_rect.bottom);
1317 EXPECT_EQ(rect.right, new_rect.right);
1318 EXPECT_EQ(rect.top, new_rect.top);
1321 CloseSavedPage(page);
1322 CloseSavedDocument();
1327 ASSERT_TRUE(OpenDocument(
"annotation_highlight_rollover_ap.pdf"));
1328 FPDF_PAGE page = LoadPage(0);
1333 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1334 CompareBitmap(bitmap.get(), 612, 792,
"dc98f06da047bd8aabfa99562d2cbd1e");
1343 int flags = FPDFAnnot_GetFlags(annot.get());
1356 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags));
1357 flags = FPDFAnnot_GetFlags(annot.get());
1363 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1369 EXPECT_FALSE(FPDFAnnot_GetFlags(annot.get()));
1371 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags));
1372 flags = FPDFAnnot_GetFlags(annot.get());
1378 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1379 CompareBitmap(bitmap.get(), 612, 792,
"dc98f06da047bd8aabfa99562d2cbd1e");
1387 const char* md5_new_image = []() {
1389#if BUILDFLAG(IS_WIN)
1390 return "3515dee02973f010516e4c6c774ee281";
1391#elif BUILDFLAG(IS_APPLE)
1392 return "f740480598ff3732fb31871634509eec";
1394 return "77bf1781c60370bfcd8d81cf91ab7b09";
1397#if BUILDFLAG(IS_APPLE)
1398 return "17ac49518eabbb6a7632a547269c40a3";
1400 return "e79446398d4508bc2cb47e6cf2a677ed";
1403 const char* md5_modified_image = []() {
1405#if BUILDFLAG(IS_WIN)
1406 return "aeb7cfb0bf6ac2bcdef4412276f3bad4";
1407#elif BUILDFLAG(IS_APPLE)
1408 return "5beae8949ee6b5c99fe17475e90aea02";
1410 return "cfa8aa132250a1c0fec505bd13c15916";
1413#if BUILDFLAG(IS_APPLE)
1414 return "25bf5ec7c197cf9ff3d12b41fc336b25";
1416 return "dcb492d8e32528dd81bb60fa5bc900f8";
1421 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1422 FPDF_PAGE page = LoadPage(0);
1428 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1432 constexpr int kBitmapSize = 200;
1433 FPDF_BITMAP image_bitmap;
1441 rect.bottom = 600.f;
1444 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1449 kBitmapSize
, 0xeeeecccc
));
1452 FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document());
1454 static constexpr FS_MATRIX kBitmapScaleMatrix{kBitmapSize, 0, 0,
1458 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), image_object));
1463 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1464 CompareBitmap(bitmap.get(), 595, 842, md5_new_image);
1471 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1472 FPDF_PAGEOBJECT image_object = FPDFAnnot_GetObject(annot.get(), 0);
1477 kBitmapSize
, 0xff000000
));
1479 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), image_object));
1483 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1488 VerifySavedDocument(595, 842, md5_modified_image);
1492 const char* md5_new_text = []() {
1494#if BUILDFLAG(IS_WIN)
1495 return "9fbad802120d58b2b8b7edd043eeaf55";
1496#elif BUILDFLAG(IS_APPLE)
1497 return "eefdf26393df536e7f125816e7d967ff";
1499 return "f89c413c7155ae9b4a0b7c8e4013613e";
1502#if BUILDFLAG(IS_APPLE) && defined(ARCH_CPU_ARM64)
1503 return "8eabf79dcdcfc6474c593bc60d996def";
1504#elif BUILDFLAG(IS_APPLE) && !defined(ARCH_CPU_ARM64)
1505 return "5d449d36926c9f212c6cdb6c276d18cc";
1507 return "a9532f555aca2fd099e2107fa40b61e6";
1510 const char* md5_modified_text = []() {
1512#if BUILDFLAG(IS_WIN)
1513 return "850564e273ad58f651af09d880103e82";
1514#elif BUILDFLAG(IS_APPLE)
1515 return "25c03a641c8a7cac9845f8d38e54f90b";
1517 return "707320c806ed846c73ca2be8b2328bcd";
1520#if BUILDFLAG(IS_APPLE) && defined(ARCH_CPU_ARM64)
1521 return "704f3eb56f82377753a816a43de250ea";
1522#elif BUILDFLAG(IS_APPLE) && !defined(ARCH_CPU_ARM64)
1523 return "8c992808db99dbe3d74006358a671f05";
1525 return "03cae68322d6a6ba120e738ab325408c";
1530 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1531 FPDF_PAGE page = LoadPage(0);
1537 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1547 rect.bottom = 550.f;
1550 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1553 FPDF_PAGEOBJECT text_object =
1554 FPDFPageObj_NewTextObj(document(),
"Arial", 12.0f);
1555 EXPECT_TRUE(text_object);
1557 GetFPDFWideString(L"I'm a translucent text laying on other text.");
1558 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
1561 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), text_object));
1566 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1567 CompareBitmap(bitmap.get(), 595, 842, md5_new_text);
1574 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1575 FPDF_PAGEOBJECT text_object = FPDFAnnot_GetObject(annot.get(), 0);
1580 EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get()));
1581 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), text_object));
1586 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1587 CompareBitmap(bitmap.get(), 595, 842, md5_modified_text);
1593 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1602 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1603 FPDF_PAGE page = LoadPage(0);
1606 static const wchar_t kNewDate[] = L"D:201706282359Z00'00'";
1614 EXPECT_FALSE(FPDFAnnot_HasKey(annot.get(),
"none"));
1624 static const char kHashKey[] =
"AAPL:Hash";
1625 EXPECT_EQ(
FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey));
1626 unsigned long length_bytes =
1627 FPDFAnnot_GetStringValue(annot.get(), kHashKey,
nullptr, 0);
1628 ASSERT_EQ(66u, length_bytes);
1629 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
1630 EXPECT_EQ(66u, FPDFAnnot_GetStringValue(annot.get(), kHashKey, buf.data(),
1632 EXPECT_EQ(L"395fbcb98d558681742f30683a62a2ad",
1633 GetPlatformWString(buf.data()));
1636 EXPECT_EQ(
FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey));
1639 ASSERT_EQ(44u, length_bytes);
1640 buf = GetFPDFWideStringBuffer(length_bytes);
1642 buf.data(), length_bytes));
1643 EXPECT_EQ(L"D:201706071721Z00'00'", GetPlatformWString(buf.data()));
1652 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1655 const char* md5 = []() {
1657#if BUILDFLAG(IS_WIN)
1658 return "25b2a610cab9d656b9ab5f72746c9e2e";
1659#elif BUILDFLAG(IS_APPLE)
1660 return "0f6501f8e22441630bdd535363c93e59";
1662 return "1814140b1a9a9776546af7894e21d17f";
1665#if BUILDFLAG(IS_APPLE)
1666 return "0521eaa52fe2aa43aafd3e4495f63f0b";
1668 return "5f19ddad9d48f5b7b87ee7d92f577db6";
1673 ASSERT_TRUE(OpenSavedDocument());
1674 page = LoadSavedPage(0);
1676 VerifySavedRendering(page, 595, 842, md5);
1684 unsigned long length_bytes = FPDFAnnot_GetStringValue(
1686 ASSERT_EQ(44u, length_bytes);
1687 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
1690 buf.data(), length_bytes));
1691 EXPECT_EQ(kNewDate, GetPlatformWString(buf.data()));
1694 CloseSavedPage(page);
1695 CloseSavedDocument();
1700 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
1701 FPDF_PAGE page = LoadPage(0);
1705 for (
int i = 0; i < 2; i++) {
1710 EXPECT_FALSE(FPDFAnnot_HasKey(annot.get(),
"MaxLen"));
1713 EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(),
"MaxLen", &value));
1721 EXPECT_TRUE(FPDFAnnot_HasKey(annot.get(),
"MaxLen"));
1724 EXPECT_TRUE(FPDFAnnot_GetNumberValue(annot.get(),
"MaxLen", &value));
1725 EXPECT_FLOAT_EQ(10.0f, value);
1729 EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(),
nullptr, &value));
1730 EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(),
"MaxLen",
nullptr));
1732 EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(),
"V", &value));
1740 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1741 FPDF_PAGE page = LoadPage(0);
1745 static const char kMd5NormalAP[] =
"be903df0343fd774fadab9c8900cdf4a";
1746 static constexpr size_t kExpectNormalAPLength = 73970;
1753 unsigned long normal_length_bytes = FPDFAnnot_GetAP(
1755 ASSERT_EQ(kExpectNormalAPLength, normal_length_bytes);
1759 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(normal_length_bytes);
1761 UNSAFE_TODO(FXSYS_memcpy(buf.data(),
"abcdefgh", 8));
1762 EXPECT_EQ(kExpectNormalAPLength,
1764 buf.data(), normal_length_bytes - 1));
1765 UNSAFE_TODO(EXPECT_EQ(0, memcmp(buf.data(),
"abcdefgh", 8)));
1769 EXPECT_EQ(kExpectNormalAPLength,
1771 buf.data(), normal_length_bytes));
1772 EXPECT_EQ(kMd5NormalAP, GenerateMD5Base16(pdfium::as_byte_span(buf).first(
1773 normal_length_bytes)));
1777 buf = GetFPDFWideStringBuffer(normal_length_bytes + 2);
1778 EXPECT_EQ(kExpectNormalAPLength,
1780 buf.data(), normal_length_bytes + 2));
1781 EXPECT_EQ(kMd5NormalAP, GenerateMD5Base16(pdfium::as_byte_span(buf).first(
1782 normal_length_bytes)));
1786 unsigned long rollover_length_bytes = FPDFAnnot_GetAP(
1788 ASSERT_EQ(2u, rollover_length_bytes);
1790 buf = GetFPDFWideStringBuffer(1000);
1794 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
1798 EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), -1, ap_text.get()));
1801 EXPECT_FALSE(FPDFAnnot_SetAP(
1809 rollover_length_bytes = FPDFAnnot_GetAP(
1811 ASSERT_EQ(24u, rollover_length_bytes);
1812 buf = GetFPDFWideStringBuffer(rollover_length_bytes);
1815 buf.data(), rollover_length_bytes));
1816 EXPECT_EQ(L"new test ap", GetPlatformWString(buf.data()));
1819 buf = GetFPDFWideStringBuffer(normal_length_bytes);
1820 EXPECT_EQ(kExpectNormalAPLength,
1822 buf.data(), normal_length_bytes));
1823 EXPECT_EQ(kMd5NormalAP, GenerateMD5Base16(pdfium::as_byte_span(buf).first(
1824 normal_length_bytes)));
1828 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1831 ASSERT_TRUE(OpenSavedDocument());
1832 page = LoadSavedPage(0);
1839 unsigned long rollover_length_bytes = FPDFAnnot_GetAP(
1841 ASSERT_EQ(24u, rollover_length_bytes);
1842 std::vector<FPDF_WCHAR> buf =
1843 GetFPDFWideStringBuffer(rollover_length_bytes);
1844 EXPECT_EQ(24u, FPDFAnnot_GetAP(new_annot.get(),
1846 buf.data(), rollover_length_bytes));
1847 EXPECT_EQ(L"new test ap", GetPlatformWString(buf.data()));
1851 CloseSavedPage(page);
1852 CloseSavedDocument();
1857 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1858 FPDF_PAGE page = LoadPage(0);
1892 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1893 FPDF_PAGE page = LoadPage(0);
1925 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
1926 FPDF_PAGE page = LoadPage(0);
1935 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot.get()));
1936 static const char kPopupKey[] =
"Popup";
1937 ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), kPopupKey));
1939 FPDFAnnot_GetValueType(annot.get(), kPopupKey));
1942 ScopedFPDFAnnotation popup(
1943 FPDFAnnot_GetLinkedAnnot(annot.get(), kPopupKey));
1946 EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup.get()));
1948 ASSERT_TRUE(FPDFAnnot_GetRect(popup.get(), &rect));
1949 EXPECT_NEAR(612.0f, rect.left, 0.001f);
1950 EXPECT_NEAR(578.792, rect.bottom, 0.001f);
1954 static const char kIRTKey[] =
"IRT";
1955 ASSERT_FALSE(FPDFAnnot_HasKey(annot.get(), kIRTKey));
1956 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), kIRTKey));
1971 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
1972 FPDF_PAGE page = LoadPage(0);
1981 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
1995 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2009 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2022 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2023 FPDF_PAGE page = LoadPage(0);
2032 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2047 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2062 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2076 ASSERT_TRUE(OpenDocument(
"text_form.pdf"));
2077 FPDF_PAGE page = LoadPage(0);
2081 static const FS_POINTF kOriginPoint = {0.0f, 0.0f};
2083 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kOriginPoint));
2085 static const FS_POINTF kValidPoint = {120.0f, 120.0f};
2088 ScopedFPDFAnnotation annot(
2089 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kValidPoint));
2097 FPDFAnnot_GetFormFieldAtPoint(form_handle(),
nullptr, &kValidPoint));
2104 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
2105 FPDF_PAGE page = LoadPage(0);
2110 static const FS_POINTF kPoint = {105.0f, 118.0f};
2111 ScopedFPDFAnnotation annot(
2112 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2116 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2124 static const FS_POINTF kPoint = {105.0f, 202.0f};
2125 ScopedFPDFAnnotation annot(
2126 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2130 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2141 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2142 FPDF_PAGE page = LoadPage(0);
2147 static const FS_POINTF kPoint = {102.0f, 363.0f};
2148 ScopedFPDFAnnotation annot(
2149 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2153 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2164 static const FS_POINTF kPoint = {102.0f, 413.0f};
2165 ScopedFPDFAnnotation annot(
2166 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2170 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2181 static const FS_POINTF kPoint = {102.0f, 513.0f};
2182 ScopedFPDFAnnotation annot(
2183 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2187 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2200 const char* expected_bitmap = []() {
2202 return "a1ea1ceebb26922fae576cb79ce63af0";
2204 return "0d9fc05c6762fd788bd23fd87a4967bc";
2206 static constexpr size_t kExpectedMinimumOriginalSize = 1601;
2208 ASSERT_TRUE(OpenDocument(
"bug_1206.pdf"));
2210 FPDF_PAGE page = LoadPage(0);
2213 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2214 const size_t original_size = GetString().size();
2215 EXPECT_LE(kExpectedMinimumOriginalSize, original_size);
2218 for (size_t i = 0; i < 10; ++i) {
2219 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
2220 CompareBitmap(bitmap.get(), 612, 792, expected_bitmap);
2222 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2225 EXPECT_GT(GetString().size(), original_size);
2233 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
2234 FPDF_PAGE page = LoadPage(0);
2238 static const char kTestKey[] =
"test";
2239 static const wchar_t kData[] = L"\xf6\xe4";
2240 static const size_t kBufSize = 12;
2241 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(kBufSize);
2251 std::fill(buf.begin(), buf.end(),
'x');
2252 ASSERT_EQ(2u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(),
2254 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
2257 EXPECT_TRUE(FPDFAnnot_SetStringValue(annot.get(), kTestKey, text.get()));
2259 std::fill(buf.begin(), buf.end(),
'x');
2260 ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(),
2262 EXPECT_EQ(kData, GetPlatformWString(buf.data()));
2268 const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f};
2269 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect));
2273 std::fill(buf.begin(), buf.end(),
'x');
2276 buf.data(), kBufSize));
2277 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
2283 std::fill(buf.begin(), buf.end(),
'x');
2286 buf.data(), kBufSize));
2287 EXPECT_EQ(kData, GetPlatformWString(buf.data()));
2295 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2296 ASSERT_TRUE(OpenSavedDocument());
2297 FPDF_PAGE saved_page = LoadSavedPage(0);
2298 ASSERT_TRUE(saved_page);
2306 std::fill(buf.begin(), buf.end(),
'x');
2307 ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(),
2309 EXPECT_EQ(kData, GetPlatformWString(buf.data()));
2318 std::fill(buf.begin(), buf.end(),
'x');
2319 ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(),
2321 EXPECT_EQ(kData, GetPlatformWString(buf.data()));
2324 CloseSavedPage(saved_page);
2325 CloseSavedDocument();
2331 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2332 FPDF_PAGE page = LoadPage(0);
2339 EXPECT_EQ(3, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2344 EXPECT_EQ(26, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2348 EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(),
nullptr));
2349 EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(
nullptr, annot.get()));
2357 ASSERT_TRUE(OpenDocument(
"listbox_form.pdf"));
2358 FPDF_PAGE page = LoadPage(0);
2365 EXPECT_EQ(3, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2370 EXPECT_EQ(26, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2378 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
2379 FPDF_PAGE page = LoadPage(0);
2387 EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2392 EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2400 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2401 FPDF_PAGE page = LoadPage(0);
2409 unsigned long length_bytes =
2410 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2411 ASSERT_EQ(8u, length_bytes);
2412 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
2413 EXPECT_EQ(8u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2414 buf.data(), length_bytes));
2415 EXPECT_EQ(L"Foo", GetPlatformWString(buf.data()));
2422 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2423 ASSERT_EQ(12u, length_bytes);
2424 buf = GetFPDFWideStringBuffer(length_bytes);
2425 EXPECT_EQ(12u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2426 buf.data(), length_bytes));
2427 EXPECT_EQ(L"Apple", GetPlatformWString(buf.data()));
2431 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2432 buf = GetFPDFWideStringBuffer(length_bytes);
2433 EXPECT_EQ(18u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2434 buf.data(), length_bytes));
2435 EXPECT_EQ(L"Zucchini", GetPlatformWString(buf.data()));
2438 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), -1,
2440 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 26,
2446 FPDFAnnot_GetOptionLabel(
nullptr, annot.get(), 0,
nullptr, 0));
2448 FPDFAnnot_GetOptionLabel(form_handle(),
nullptr, 0,
nullptr, 0));
2456 ASSERT_TRUE(OpenDocument(
"listbox_form.pdf"));
2457 FPDF_PAGE page = LoadPage(0);
2465 unsigned long length_bytes =
2466 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2467 ASSERT_EQ(8u, length_bytes);
2468 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
2469 EXPECT_EQ(8u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2470 buf.data(), length_bytes));
2471 EXPECT_EQ(L"Foo", GetPlatformWString(buf.data()));
2478 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2479 ASSERT_EQ(12u, length_bytes);
2480 buf = GetFPDFWideStringBuffer(length_bytes);
2481 EXPECT_EQ(12u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2482 buf.data(), length_bytes));
2483 EXPECT_EQ(L"Apple", GetPlatformWString(buf.data()));
2487 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2488 ASSERT_EQ(18u, length_bytes);
2489 buf = GetFPDFWideStringBuffer(length_bytes);
2490 EXPECT_EQ(18u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2491 buf.data(), length_bytes));
2492 EXPECT_EQ(L"Zucchini", GetPlatformWString(buf.data()));
2495 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), -1,
2497 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 26,
2506 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
2507 FPDF_PAGE page = LoadPage(0);
2515 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 0,
2521 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 0,
2530 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2531 FPDF_PAGE page = LoadPage(0);
2539 int count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2540 ASSERT_EQ(3, count);
2541 for (
int i = 0; i < count; i++) {
2542 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2549 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2550 ASSERT_EQ(26, count);
2551 for (
int i = 0; i < count; i++) {
2553 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2557 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
2560 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
2566 FPDFAnnot_IsOptionSelected(form_handle(),
nullptr, 0));
2567 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(
nullptr, annot.get(), 0));
2575 ASSERT_TRUE(OpenDocument(
"listbox_form.pdf"));
2576 FPDF_PAGE page = LoadPage(0);
2584 int count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2585 ASSERT_EQ(3, count);
2586 for (
int i = 0; i < count; i++) {
2587 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2594 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2595 ASSERT_EQ(26, count);
2596 for (
int i = 0; i < count; i++) {
2598 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2606 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2607 ASSERT_EQ(5, count);
2608 for (
int i = 0; i < count; i++) {
2609 bool expected = (i == 1 || i == 3);
2611 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2619 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2620 ASSERT_EQ(5, count);
2621 for (
int i = 0; i < count; i++) {
2622 bool expected = (i == 2 || i == 4);
2624 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2632 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2633 ASSERT_EQ(5, count);
2634 for (
int i = 0; i < count; i++) {
2635 bool expected = (i == 0 || i == 2);
2637 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2646 ASSERT_TRUE(OpenDocument(
"multiple_form_types.pdf"));
2647 FPDF_PAGE page = LoadPage(0);
2655 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
2662 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
2671 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2672 FPDF_PAGE page = LoadPage(0);
2681 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2682 EXPECT_EQ(12.0, value);
2688 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_two));
2689 EXPECT_EQ(12.0, value_two);
2696 FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_three));
2697 EXPECT_EQ(12.0, value_three);
2705 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
2706 FPDF_PAGE page = LoadPage(0);
2715 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2716 EXPECT_EQ(12.0, value);
2722 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_two));
2723 EXPECT_EQ(12.0, value_two);
2730 FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_three));
2731 EXPECT_EQ(12.0, value_three);
2734 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_four));
2735 EXPECT_EQ(12.0, value_four);
2743 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
2744 FPDF_PAGE page = LoadPage(0);
2753 ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2758 ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2766 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2767 FPDF_PAGE page = LoadPage(0);
2776 ASSERT_FALSE(FPDFAnnot_GetFontSize(
nullptr, annot.get(), &value));
2777 ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(),
nullptr, &value));
2786 ASSERT_TRUE(OpenDocument(
"text_form_negative_fontsize.pdf"));
2787 FPDF_PAGE page = LoadPage(0);
2796 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2797 EXPECT_EQ(-12.0, value);
2805 ASSERT_TRUE(OpenDocument(
"text_form_color.pdf"));
2806 FPDF_PAGE page = LoadPage(0);
2820 ASSERT_FALSE(FPDFAnnot_GetFontColor(form_handle(),
nullptr,
nullptr,
2822 ASSERT_FALSE(FPDFAnnot_GetFontColor(form_handle(), annot.get(),
nullptr,
2824 ASSERT_FALSE(FPDFAnnot_GetFontColor(form_handle(), annot.get(), &R,
nullptr,
2827 FPDFAnnot_GetFontColor(form_handle(), annot.get(), &R, &G,
nullptr));
2830 ASSERT_TRUE(FPDFAnnot_GetFontColor(form_handle(), annot.get(), &R, &G, &B));
2832 EXPECT_EQ(0xffU, R);
2833 EXPECT_EQ(0x80U, G);
2834 EXPECT_EQ(0x00U, B);
2843 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2844 FPDF_PAGE page = LoadPage(0);
2850 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2859 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2860 FPDF_PAGE page = LoadPage(0);
2866 ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2875 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2876 FPDF_PAGE page = LoadPage(0);
2882 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2885 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2888 ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2897 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2898 FPDF_PAGE page = LoadPage(0);
2904 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2907 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2910 ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2919 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2920 FPDF_PAGE page = LoadPage(0);
2926 ASSERT_FALSE(FPDFAnnot_IsChecked(
nullptr, annot.get()));
2927 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(),
nullptr));
2936 ASSERT_TRUE(OpenDocument(
"text_form.pdf"));
2937 FPDF_PAGE page = LoadPage(0);
2943 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2950 ASSERT_TRUE(OpenDocument(
"multiple_form_types.pdf"));
2951 FPDF_PAGE page = LoadPage(0);
2954 EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(form_handle(),
nullptr));
2959 EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(
nullptr, annot.get()));
2962 static const struct {
2965 } kTests[] = {{0, -1},
2971 for (
const auto& test : kTests) {
2974 EXPECT_EQ(test.output,
2975 FPDFAnnot_GetFormFieldType(form_handle(), annot.get()));
2981 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
2982 FPDF_PAGE page = LoadPage(0);
2987 FPDFAnnot_GetFormFieldValue(form_handle(),
nullptr,
nullptr, 0));
2993 FPDFAnnot_GetFormFieldValue(
nullptr, annot.get(),
nullptr, 0));
2995 unsigned long length_bytes =
2996 FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
nullptr, 0);
2997 ASSERT_EQ(2u, length_bytes);
2998 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
2999 EXPECT_EQ(2u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
3000 buf.data(), length_bytes));
3001 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
3007 unsigned long length_bytes =
3008 FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
nullptr, 0);
3009 ASSERT_EQ(18u, length_bytes);
3010 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3011 EXPECT_EQ(18u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
3012 buf.data(), length_bytes));
3013 EXPECT_EQ(L"Elephant", GetPlatformWString(buf.data()));
3019 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
3020 FPDF_PAGE page = LoadPage(0);
3027 unsigned long length_bytes =
3028 FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
nullptr, 0);
3029 ASSERT_EQ(2u, length_bytes);
3030 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3031 EXPECT_EQ(2u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
3032 buf.data(), length_bytes));
3033 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
3039 unsigned long length_bytes =
3040 FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
nullptr, 0);
3041 ASSERT_EQ(14u, length_bytes);
3042 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3043 EXPECT_EQ(14u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
3044 buf.data(), length_bytes));
3045 EXPECT_EQ(L"Banana", GetPlatformWString(buf.data()));
3051 ASSERT_TRUE(OpenDocument(
"text_form.pdf"));
3052 FPDF_PAGE page = LoadPage(0);
3057 FPDFAnnot_GetFormFieldName(form_handle(),
nullptr,
nullptr, 0));
3062 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldName(
nullptr, annot.get(),
nullptr, 0));
3064 unsigned long length_bytes =
3065 FPDFAnnot_GetFormFieldName(form_handle(), annot.get(),
nullptr, 0);
3066 ASSERT_EQ(18u, length_bytes);
3067 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3068 EXPECT_EQ(18u, FPDFAnnot_GetFormFieldName(form_handle(), annot.get(),
3069 buf.data(), length_bytes));
3070 EXPECT_EQ(L"Text Box", GetPlatformWString(buf.data()));
3076 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
3077 FPDF_PAGE page = LoadPage(0);
3084 unsigned long length_bytes =
3085 FPDFAnnot_GetFormFieldName(form_handle(), annot.get(),
nullptr, 0);
3086 ASSERT_EQ(30u, length_bytes);
3087 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3088 EXPECT_EQ(30u, FPDFAnnot_GetFormFieldName(form_handle(), annot.get(),
3089 buf.data(), length_bytes));
3090 EXPECT_EQ(L"Combo_Editable", GetPlatformWString(buf.data()));
3096 ASSERT_TRUE(OpenDocument(
"annots.pdf"));
3097 FPDF_PAGE page = LoadPage(0);
3102 VerifyFocusableAnnotSubtypes(form_handle(), kDefaultSubtypes);
3105 const FPDF_ANNOTATION_SUBTYPE kExpectedAnnotSubtypes[] = {
3111 const FPDF_ANNOTATION_SUBTYPE kExpectedDefaultFocusableSubtypes[] = {
3113 VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
3114 kExpectedAnnotSubtypes,
3115 kExpectedDefaultFocusableSubtypes);
3118 ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes(form_handle(),
nullptr, 0));
3119 ASSERT_EQ(0, FPDFAnnot_GetFocusableSubtypesCount(form_handle()));
3123 SetAndVerifyFocusableAnnotSubtypes(form_handle(), kDefaultSubtypes);
3125 FPDFAnnot_SetFocusableSubtypes(form_handle(), kDefaultSubtypes, 0));
3126 ASSERT_EQ(0, FPDFAnnot_GetFocusableSubtypesCount(form_handle()));
3128 VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
3129 kExpectedAnnotSubtypes, {});
3133 SetAndVerifyFocusableAnnotSubtypes(form_handle(), kLinkSubtypes);
3135 const FPDF_ANNOTATION_SUBTYPE kExpectedLinkocusableSubtypes[] = {
3137 VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
3138 kExpectedAnnotSubtypes,
3139 kExpectedLinkocusableSubtypes);
3142 EXPECT_FALSE(FPDFAnnot_SetFocusableSubtypes(
nullptr, kDefaultSubtypes,
3143 std::size(kDefaultSubtypes)));
3144 EXPECT_FALSE(FPDFAnnot_SetFocusableSubtypes(form_handle(),
nullptr,
3145 std::size(kDefaultSubtypes)));
3148 std::vector<FPDF_ANNOTATION_SUBTYPE> subtypes(1);
3149 EXPECT_FALSE(FPDFAnnot_GetFocusableSubtypes(
nullptr, subtypes.data(),
3152 FPDFAnnot_GetFocusableSubtypes(form_handle(),
nullptr, subtypes.size()));
3154 FPDFAnnot_GetFocusableSubtypes(form_handle(), subtypes.data(), 0));
3160 ASSERT_TRUE(OpenDocument(
"annots.pdf"));
3161 FPDF_PAGE page = LoadPage(0);
3165 const char* md5_sum = []() {
3167#if BUILDFLAG(IS_WIN)
3168 return "f8c17a0b11d5e152d9a90d6469c6be96";
3169#elif BUILDFLAG(IS_APPLE)
3170 return "cd02e06aeb6555ca7d03136cb8f2e336";
3172 return "a08901d205e54530e76f5fc81846eb6a";
3175#if BUILDFLAG(IS_APPLE)
3176 return "108a46c517c4eaace9982ee83e8e3296";
3178 return "5550d8dcb4d1af1f50e8b4bcaef2ee60";
3182 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3183 CompareBitmap(bitmap.get(), 612, 792, md5_sum);
3187 static constexpr FPDF_ANNOTATION_SUBTYPE kSubTypes[] = {
FPDF_ANNOT_LINK,
3189 constexpr int kSubTypesCount =
std::size(kSubTypes);
3191 FPDFAnnot_SetFocusableSubtypes(form_handle(), kSubTypes, kSubTypesCount));
3192 ASSERT_EQ(kSubTypesCount, FPDFAnnot_GetFocusableSubtypesCount(form_handle()));
3193 std::vector<FPDF_ANNOTATION_SUBTYPE> subtypes(kSubTypesCount);
3194 ASSERT_TRUE(FPDFAnnot_GetFocusableSubtypes(form_handle(), subtypes.data(),
3200 const char* md5_sum = []() {
3202#if BUILDFLAG(IS_WIN)
3203 return "29886792e8942117a291dee7acdbf39f";
3204#elif BUILDFLAG(IS_APPLE)
3205 return "7e85e4675adccb100fc2cf1037f65f4a";
3207 return "de2186f2f36169d0002257a810435648";
3210#if BUILDFLAG(IS_APPLE)
3211 return "eb3869335e7a219e1b5f25c1c6037b97";
3213 return "805fe7bb751ac4ed2b82bb66efe6db40";
3220 EXPECT_TRUE(FORM_SetFocusedAnnot(form_handle(), annot.get()));
3221 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3222 CompareBitmap(bitmap.get(), 612, 792, md5_sum);
3226 const char* md5_sum = []() {
3228#if BUILDFLAG(IS_WIN)
3229 return "651517d1a58558c6eae18ebb3ff90784";
3230#elif BUILDFLAG(IS_APPLE)
3231 return "96f271ee3f1520d174f887f33989bbcb";
3233 return "27bb036f3a507fce66a74a00daf558ec";
3236#if BUILDFLAG(IS_APPLE)
3237 return "d20b1978da2362d3942ea0fc6d230997";
3239 return "c5c5dcb462af3ef5f43b298ec048feef";
3246 EXPECT_TRUE(FORM_SetFocusedAnnot(form_handle(), annot.get()));
3247 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3248 CompareBitmap(bitmap.get(), 612, 792, md5_sum);
3255 ASSERT_TRUE(OpenDocument(
"annots.pdf"));
3256 FPDF_PAGE page = LoadPage(0);
3259 constexpr char kExpectedResult[] =
3260 "https://cs.chromium.org/chromium/src/third_party/pdfium/public/"
3266 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()),
3274 EXPECT_FALSE(FPDFAnnot_GetLink(annot.get()));
3284 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3285 FPDF_PAGE page = LoadPage(0);
3291 FPDFAnnot_GetFormControlCount(form_handle(),
nullptr));
3298 FPDFAnnot_GetFormControlCount(
nullptr, annot.get()));
3300 EXPECT_EQ(3, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
3308 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3309 FPDF_PAGE page = LoadPage(0);
3315 EXPECT_EQ(1, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
3323 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
3324 FPDF_PAGE page = LoadPage(0);
3330 EXPECT_EQ(-1, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
3338 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3339 FPDF_PAGE page = LoadPage(0);
3345 FPDFAnnot_GetFormControlIndex(form_handle(),
nullptr));
3352 FPDFAnnot_GetFormControlIndex(
nullptr, annot.get()));
3354 EXPECT_EQ(1, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
3362 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3363 FPDF_PAGE page = LoadPage(0);
3369 EXPECT_EQ(0, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
3377 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
3378 FPDF_PAGE page = LoadPage(0);
3384 EXPECT_EQ(-1, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
3392 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3393 FPDF_PAGE page = LoadPage(0);
3398 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue(
3399 form_handle(),
nullptr,
3406 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue(
3407 nullptr, annot.get(),
3410 unsigned long length_bytes =
3411 FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3413 ASSERT_EQ(14u, length_bytes);
3414 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3415 EXPECT_EQ(14u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3416 buf.data(), length_bytes));
3417 EXPECT_EQ(L"value2", GetPlatformWString(buf.data()));
3425 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3426 FPDF_PAGE page = LoadPage(0);
3433 unsigned long length_bytes =
3434 FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3436 ASSERT_EQ(8u, length_bytes);
3437 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3438 EXPECT_EQ(8u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3439 buf.data(), length_bytes));
3440 EXPECT_EQ(L"Yes", GetPlatformWString(buf.data()));
3448 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
3449 FPDF_PAGE page = LoadPage(0);
3455 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3464 ASSERT_TRUE(OpenDocument(
"redact_annot.pdf"));
3465 FPDF_PAGE page = LoadPage(0);
3479 ASSERT_TRUE(OpenDocument(
"polygon_annot.pdf"));
3480 FPDF_PAGE page = LoadPage(0);
3489 unsigned long size = FPDFAnnot_GetVertices(annot.get(),
nullptr, 0);
3490 const size_t kExpectedSize = 3;
3491 ASSERT_EQ(kExpectedSize, size);
3492 std::vector<FS_POINTF> vertices_buffer(size);
3494 FPDFAnnot_GetVertices(annot.get(), vertices_buffer.data(), size));
3495 EXPECT_FLOAT_EQ(159.0f, vertices_buffer[0].x);
3496 EXPECT_FLOAT_EQ(296.0f, vertices_buffer[0].y);
3497 EXPECT_FLOAT_EQ(350.0f, vertices_buffer[1].x);
3498 EXPECT_FLOAT_EQ(411.0f, vertices_buffer[1].y);
3499 EXPECT_FLOAT_EQ(472.0f, vertices_buffer[2].x);
3500 EXPECT_FLOAT_EQ(243.42f, vertices_buffer[2].y);
3506 vertices_buffer.resize(1);
3507 vertices_buffer[0].x = 42;
3508 vertices_buffer[0].y = 43;
3509 size = FPDFAnnot_GetVertices(annot.get(), vertices_buffer.data(),
3510 vertices_buffer.size());
3511 EXPECT_EQ(kExpectedSize, size);
3512 EXPECT_FLOAT_EQ(42, vertices_buffer[0].x);
3513 EXPECT_FLOAT_EQ(43, vertices_buffer[0].y);
3522 unsigned long size = FPDFAnnot_GetVertices(annot.get(),
nullptr, 0);
3523 const size_t kExpectedSize = 3;
3524 ASSERT_EQ(kExpectedSize, size);
3525 std::vector<FS_POINTF> vertices_buffer(size);
3527 FPDFAnnot_GetVertices(annot.get(), vertices_buffer.data(), size));
3528 EXPECT_FLOAT_EQ(259.0f, vertices_buffer[0].x);
3529 EXPECT_FLOAT_EQ(396.0f, vertices_buffer[0].y);
3530 EXPECT_FLOAT_EQ(450.0f, vertices_buffer[1].x);
3531 EXPECT_FLOAT_EQ(511.0f, vertices_buffer[1].y);
3532 EXPECT_FLOAT_EQ(572.0f, vertices_buffer[2].x);
3533 EXPECT_FLOAT_EQ(343.0f, vertices_buffer[2].y);
3539 EXPECT_EQ(0U, FPDFAnnot_GetVertices(ink_annot.get(),
nullptr, 0));
3546 ASSERT_TRUE(OpenDocument(
"ink_annot.pdf"));
3547 FPDF_PAGE page = LoadPage(0);
3557 unsigned long size = FPDFAnnot_GetInkListCount(annot.get());
3558 const size_t kExpectedSize = 1;
3559 ASSERT_EQ(kExpectedSize, size);
3560 const unsigned long kPathIndex = 0;
3561 unsigned long path_size =
3562 FPDFAnnot_GetInkListPath(annot.get(), kPathIndex,
nullptr, 0);
3563 const size_t kExpectedPathSize = 3;
3564 ASSERT_EQ(kExpectedPathSize, path_size);
3565 std::vector<FS_POINTF> path_buffer(path_size);
3566 EXPECT_EQ(path_size,
3567 FPDFAnnot_GetInkListPath(annot.get(), kPathIndex,
3568 path_buffer.data(), path_size));
3569 EXPECT_FLOAT_EQ(159.0f, path_buffer[0].x);
3570 EXPECT_FLOAT_EQ(296.0f, path_buffer[0].y);
3571 EXPECT_FLOAT_EQ(350.0f, path_buffer[1].x);
3572 EXPECT_FLOAT_EQ(411.0f, path_buffer[1].y);
3573 EXPECT_FLOAT_EQ(472.0f, path_buffer[2].x);
3574 EXPECT_FLOAT_EQ(243.42f, path_buffer[2].y);
3585 path_buffer.resize(1);
3586 path_buffer[0].x = 42;
3587 path_buffer[0].y = 43;
3588 path_size = FPDFAnnot_GetInkListPath(
3589 annot.get(), kPathIndex, path_buffer.data(), path_buffer.size());
3590 EXPECT_EQ(kExpectedPathSize, path_size);
3591 EXPECT_FLOAT_EQ(42, path_buffer[0].x);
3592 EXPECT_FLOAT_EQ(43, path_buffer[0].y);
3601 unsigned long size = FPDFAnnot_GetInkListCount(annot.get());
3602 const size_t kExpectedSize = 1;
3603 ASSERT_EQ(kExpectedSize, size);
3604 const unsigned long kPathIndex = 0;
3605 unsigned long path_size =
3606 FPDFAnnot_GetInkListPath(annot.get(), kPathIndex,
nullptr, 0);
3607 const size_t kExpectedPathSize = 3;
3608 ASSERT_EQ(kExpectedPathSize, path_size);
3609 std::vector<FS_POINTF> path_buffer(path_size);
3610 EXPECT_EQ(path_size,
3611 FPDFAnnot_GetInkListPath(annot.get(), kPathIndex,
3612 path_buffer.data(), path_size));
3613 EXPECT_FLOAT_EQ(259.0f, path_buffer[0].x);
3614 EXPECT_FLOAT_EQ(396.0f, path_buffer[0].y);
3615 EXPECT_FLOAT_EQ(450.0f, path_buffer[1].x);
3616 EXPECT_FLOAT_EQ(511.0f, path_buffer[1].y);
3617 EXPECT_FLOAT_EQ(572.0f, path_buffer[2].x);
3618 EXPECT_FLOAT_EQ(343.0f, path_buffer[2].y);
3623 ScopedFPDFAnnotation polygon_annot(
3625 EXPECT_EQ(0U, FPDFAnnot_GetInkListCount(polygon_annot.get()));
3626 const unsigned long kPathIndex = 0;
3627 EXPECT_EQ(0U, FPDFAnnot_GetInkListPath(polygon_annot.get(), kPathIndex,
3635 ASSERT_TRUE(OpenDocument(
"line_annot.pdf"));
3636 FPDF_PAGE page = LoadPage(0);
3647 ASSERT_TRUE(FPDFAnnot_GetLine(annot.get(), &start, &end));
3648 EXPECT_FLOAT_EQ(159.0f, start.x);
3649 EXPECT_FLOAT_EQ(296.0f, start.y);
3650 EXPECT_FLOAT_EQ(472.0f, end.x);
3651 EXPECT_FLOAT_EQ(243.42f, end.y);
3655 EXPECT_FALSE(FPDFAnnot_GetLine(annot.get(),
nullptr,
nullptr));
3665 EXPECT_FALSE(FPDFAnnot_GetLine(annot.get(), &start, &end));
3673 EXPECT_FALSE(FPDFAnnot_GetLine(ink_annot.get(), &start, &end));
3680 ASSERT_TRUE(OpenDocument(
"line_annot.pdf"));
3681 FPDF_PAGE page = LoadPage(0);
3690 float horizontal_radius;
3691 float vertical_radius;
3693 ASSERT_TRUE(FPDFAnnot_GetBorder(annot.get(), &horizontal_radius,
3694 &vertical_radius, &border_width));
3695 EXPECT_FLOAT_EQ(0.25f, horizontal_radius);
3696 EXPECT_FLOAT_EQ(0.5f, vertical_radius);
3697 EXPECT_FLOAT_EQ(2.0f, border_width);
3701 EXPECT_FALSE(FPDFAnnot_GetBorder(annot.get(),
nullptr,
nullptr,
nullptr));
3709 float horizontal_radius;
3710 float vertical_radius;
3712 EXPECT_FALSE(FPDFAnnot_GetBorder(annot.get(), &horizontal_radius,
3713 &vertical_radius, &border_width));
3716 EXPECT_TRUE(FPDFAnnot_SetBorder(annot.get(), 2.0f,
3720 EXPECT_TRUE(FPDFAnnot_GetBorder(annot.get(), &horizontal_radius,
3721 &vertical_radius, &border_width));
3722 EXPECT_FLOAT_EQ(2.0f, horizontal_radius);
3723 EXPECT_FLOAT_EQ(3.5f, vertical_radius);
3724 EXPECT_FLOAT_EQ(4.0f, border_width);
3736 ASSERT_TRUE(OpenDocument(
"annot_javascript.pdf"));
3737 FPDF_PAGE page = LoadPage(0);
3746 unsigned long length_bytes = FPDFAnnot_GetFormAdditionalActionJavaScript(
3748 ASSERT_EQ(62u, length_bytes);
3749 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3750 EXPECT_EQ(62u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3752 buf.data(), length_bytes));
3753 EXPECT_EQ(L"AFDate_FormatEx(\"yyyy-mm-dd\");",
3754 GetPlatformWString(buf.data()));
3757 EXPECT_EQ(0u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3758 form_handle(),
nullptr, 0,
nullptr, 0));
3759 EXPECT_EQ(0u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3760 nullptr, annot.get(), 0,
nullptr, 0));
3761 EXPECT_EQ(0u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3762 form_handle(), annot.get(), 0,
nullptr, 0));
3763 EXPECT_EQ(2u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3772 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3773 FPDF_PAGE page = LoadPage(0);
3782 unsigned long length_bytes = FPDFAnnot_GetFormFieldAlternateName(
3783 form_handle(), annot.get(),
nullptr, 0);
3784 ASSERT_EQ(34u, length_bytes);
3785 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3786 EXPECT_EQ(34u, FPDFAnnot_GetFormFieldAlternateName(
3787 form_handle(), annot.get(), buf.data(), length_bytes));
3788 EXPECT_EQ(L"readOnlyCheckbox", GetPlatformWString(buf.data()));
3791 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldAlternateName(form_handle(),
nullptr,
3793 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldAlternateName(
nullptr, annot.get(),
3804 ASSERT_TRUE(OpenDocument(
"annots.pdf"));
3805 FPDF_PAGE page = LoadPage(1);
3809 const char* original_checksum = []() {
3811#if BUILDFLAG(IS_WIN)
3812 return "36ab186e78c0b88eeb8f7aceea93b72c";
3813#elif BUILDFLAG(IS_APPLE)
3814 return "953b14259560aeca886ea44c9529892b";
3816 return "238dccc7df0ac61ac580c28e1109da3c";
3819#if BUILDFLAG(IS_APPLE)
3820 return "522a4a6b6c7eab5bf95ded1f21ea372e";
3822 return "12127303aecd80c6288460f7c0d79f3f";
3825 const char* modified_checksum = []() {
3827#if BUILDFLAG(IS_WIN)
3828 return "ece1ab24a0d9425ef3b06747c95d75ce";
3829#elif BUILDFLAG(IS_APPLE)
3830 return "bfc344e98798298bf7bb0953db75c686";
3832 return "0f326acb3eb583125ca584d703ccb13b";
3835#if BUILDFLAG(IS_APPLE)
3836 return "6844019e07b83cc01723415f58218d06";
3838 return "73d06ff4c665fe85029acef30240dcca";
3848 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3849 CompareBitmap(bitmap.get(), 612, 792, original_checksum);
3852 EXPECT_TRUE(FPDFAnnot_SetBorder(annot.get(), 2.0f,
3857 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3858 CompareBitmap(bitmap.get(), 612, 792, modified_checksum);
3863 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3866 ASSERT_TRUE(OpenSavedDocument());
3867 page = LoadSavedPage(1);
3869 VerifySavedRendering(page, 612, 792, modified_checksum);
3871 CloseSavedPage(page);
3872 CloseSavedDocument();
3876 ASSERT_TRUE(OpenDocument(
"annotation_fileattachment.pdf"));
3877 FPDF_PAGE page = LoadPage(0);
3886 FPDF_ATTACHMENT attachment = FPDFAnnot_GetFileAttachment(annot.get());
3887 ASSERT_TRUE(attachment);
3891 ASSERT_EQ(18u, length_bytes);
3892 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3894 FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
3895 EXPECT_EQ(L"test.txt", GetPlatformWString(buf.data()));
3899 std::vector<uint8_t> content_buf(length_bytes);
3900 unsigned long actual_length_bytes;
3901 ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(),
3902 length_bytes, &actual_length_bytes));
3903 ASSERT_THAT(content_buf, testing::ElementsAre(
't',
'e',
's',
't',
' ',
't',
3909 ScopedFPDFAnnotation annot(
3917 FPDF_ATTACHMENT attachment =
3918 FPDFAnnot_AddFileAttachment(annot.get(), file_name.get());
3919 ASSERT_TRUE(attachment);
3931 FPDF_ATTACHMENT attachment = FPDFAnnot_GetFileAttachment(annot.get());
3932 ASSERT_TRUE(attachment);
3936 ASSERT_EQ(12u, length_bytes);
3937 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3939 FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
3940 EXPECT_EQ(L"0.txt", GetPlatformWString(buf.data()));
3947 ASSERT_TRUE(OpenDocument(
"annotation_fileattachment.pdf"));
3948 FPDF_PAGE page = LoadPage(0);
3955 ScopedFPDFAnnotation text_annot(
3957 ASSERT_TRUE(text_annot);
3958 ASSERT_FALSE(FPDFAnnot_GetFileAttachment(text_annot.get()));
3960 ScopedFPDFAnnotation newly_file_annot(
3962 ASSERT_TRUE(newly_file_annot);
3963 ASSERT_FALSE(FPDFAnnot_GetFileAttachment(newly_file_annot.get()));
3971 ASSERT_FALSE(FPDFAnnot_AddFileAttachment(
nullptr, empty_name.get()));
3972 ASSERT_FALSE(FPDFAnnot_AddFileAttachment(
nullptr, not_empty_name.get()));
3977 ASSERT_FALSE(FPDFAnnot_AddFileAttachment(annot.get(),
nullptr));
3978 ASSERT_FALSE(FPDFAnnot_AddFileAttachment(annot.get(), empty_name.get()));
3980 FPDF_ATTACHMENT old_attachment = FPDFAnnot_GetFileAttachment(annot.get());
3981 EXPECT_NE(old_attachment,
3982 FPDFAnnot_AddFileAttachment(annot.get(), not_empty_name.get()));
fxcrt::ByteString ByteString
static bool UseSkiaRenderer()
const CPDF_Dictionary * GetAnnotDict() const
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
bool KeyExist(const ByteString &key) const
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetFontSize(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot, float *value)
#define FPDF_ANNOT_FILEATTACHMENT
#define FPDF_ANNOT_FLAG_INVISIBLE
#define FPDF_ANNOT_FLAG_NOROTATE
#define FPDF_ANNOT_FLAG_NOZOOM
#define FPDF_ANNOT_FLAG_HIDDEN
#define FPDF_ANNOT_FLAG_PRINT
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_RemoveAnnot(FPDF_PAGE page, int index)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetBorder(FPDF_ANNOTATION annot, float *horizontal_radius, float *vertical_radius, float *border_width)
#define FPDF_ANNOT_APPEARANCEMODE_COUNT
#define FPDF_ANNOT_APPEARANCEMODE_ROLLOVER
FPDF_EXPORT int FPDF_CALLCONV FPDFAnnot_GetFocusableSubtypesCount(FPDF_FORMHANDLE hHandle)
FPDF_EXPORT int FPDF_CALLCONV FPDFAnnot_GetOptionCount(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAnnot_GetVertices(FPDF_ANNOTATION annot, FS_POINTF *buffer, unsigned long length)
#define FPDF_ANNOT_UNDERLINE
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFAnnot_GetObject(FPDF_ANNOTATION annot, int index)
#define FPDF_ANNOT_UNKNOWN
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_HasKey(FPDF_ANNOTATION annot, FPDF_BYTESTRING key)
#define FPDF_FORMFLAG_TEXT_MULTILINE
FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV FPDFAnnot_AddFileAttachment(FPDF_ANNOTATION annot, FPDF_WIDESTRING name)
FPDF_EXPORT int FPDF_CALLCONV FPDFAnnot_GetObjectCount(FPDF_ANNOTATION annot)
#define FPDF_ANNOT_FLAG_READONLY
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetAnnotCount(FPDF_PAGE page)
FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype)
#define FPDF_FORMFLAG_NOEXPORT
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_IsChecked(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot)
FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFAnnot_GetLink(FPDF_ANNOTATION annot)
#define FPDF_FORMFLAG_CHOICE_COMBO
#define FPDF_FORMFLAG_CHOICE_EDIT
FPDF_EXPORT FPDF_ANNOTATION_SUBTYPE FPDF_CALLCONV FPDFAnnot_GetSubtype(FPDF_ANNOTATION annot)
#define FPDF_ANNOT_WIDGET
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_AppendAttachmentPoints(FPDF_ANNOTATION annot, const FS_QUADPOINTSF *quad_points)
#define FPDF_ANNOT_HIGHLIGHT
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetFontColor(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot, unsigned int *R, unsigned int *G, unsigned int *B)
#define FPDF_FORMFLAG_READONLY
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAnnot_GetOptionLabel(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot, int index, FPDF_WCHAR *buffer, unsigned long buflen)
#define FPDF_ANNOT_APPEARANCEMODE_NORMAL
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAnnot_GetInkListPath(FPDF_ANNOTATION annot, unsigned long path_index, FS_POINTF *buffer, unsigned long length)
#define FPDF_FORMFLAG_REQUIRED
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_IsOptionSelected(FPDF_FORMHANDLE handle, FPDF_ANNOTATION annot, int index)
FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFPage_GetAnnot(FPDF_PAGE page, int index)
#define FPDF_ANNOT_FLAG_LOCKED
#define FPDF_ANNOT_SQUARE
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAnnot_GetStringValue(FPDF_ANNOTATION annot, FPDF_BYTESTRING key, FPDF_WCHAR *buffer, unsigned long buflen)
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_CloseAnnot(FPDF_ANNOTATION annot)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetNumberValue(FPDF_ANNOTATION annot, FPDF_BYTESTRING key, float *value)
#define FPDF_ANNOT_AACTION_FORMAT
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetURI(FPDF_ANNOTATION annot, const char *uri)
#define FPDF_ANNOT_APPEARANCEMODE_DOWN
#define FPDF_ANNOT_FLAG_NONE
#define FPDF_ANNOT_FLAG_NOVIEW
#define FPDF_ANNOT_REDACT
#define FPDF_ANNOT_POLYGON
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetLine(FPDF_ANNOTATION annot, FS_POINTF *start, FS_POINTF *end)
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetAnnotIndex(FPDF_PAGE page, FPDF_ANNOTATION annot)
#define FPDF_FORMFLAG_TEXT_PASSWORD
FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFAnnot_GetFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, const FS_POINTF *point)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAnnot_GetInkListCount(FPDF_ANNOTATION annot)
#define FPDF_FORMFLAG_CHOICE_MULTI_SELECT
@ FPDFANNOT_COLORTYPE_Color
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_SetBorder(FPDF_ANNOTATION annot, float horizontal_radius, float vertical_radius, float border_width)
#define FPDF_ANNOT_FLAG_TOGGLENOVIEW
#define FPDF_ANNOT_AACTION_KEY_STROKE
FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV FPDFAnnot_GetFileAttachment(FPDF_ANNOTATION annot)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_RemoveInkList(FPDF_ANNOTATION annot)
TEST_F(FPDFAnnotEmbedderTest, SetAP)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAttachment_GetName(FPDF_ATTACHMENT attachment, FPDF_WCHAR *buffer, unsigned long buflen)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment, void *buffer, unsigned long buflen, unsigned long *out_buflen)
FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK link)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetType(FPDF_ACTION action)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_ACTION action, void *buffer, unsigned long buflen)
FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_SetBitmap(FPDF_PAGE *pages, int count, FPDF_PAGEOBJECT image_object, FPDF_BITMAP bitmap)
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 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_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument()
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 FPDFPath_LineTo(FPDF_PAGEOBJECT path, float x, float y)
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
#define FPDF_PAGEOBJ_TEXT
#define FPDF_PAGEOBJ_IMAGE
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path, float x, float y)
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 int FPDF_CALLCONV FPDFPage_CountObjects(FPDF_PAGE page)
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 FPDF_DOCUMENT FPDF_CALLCONV FPDF_LoadCustomDocument(FPDF_FILEACCESS *pFileAccess, FPDF_BYTESTRING password)
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetHeight(FPDF_BITMAP bitmap)
FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_Destroy(FPDF_BITMAP bitmap)
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_Create(int width, int height, int alpha)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFBitmap_FillRect(FPDF_BITMAP bitmap, int left, int top, int width, int height, FPDF_DWORD color)
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetWidth(FPDF_BITMAP bitmap)
#define FPDF_OBJECT_REFERENCE
#define FPDF_OBJECT_STRING
std::unique_ptr< FPDF_WCHAR, pdfium::FreeDeleter > ScopedFPDFWideString
const char kBlankPage612By792Checksum[]
const char * AnnotationStampWithApChecksum()
const char * HelloWorldChecksum()