5#include "public/fpdf_annot.h"
13#include "build/build_config.h"
14#include "constants/annotation_common.h"
15#include "core/fpdfapi/page/cpdf_annotcontext.h"
16#include "core/fpdfapi/parser/cpdf_array.h"
17#include "core/fpdfapi/parser/cpdf_dictionary.h"
18#include "core/fxcrt/fx_system.h"
19#include "core/fxge/cfx_defaultrenderdevice.h"
20#include "fpdfsdk/cpdfsdk_helpers.h"
21#include "public/cpp/fpdf_scopers.h"
22#include "public/fpdf_edit.h"
23#include "public/fpdf_formfill.h"
24#include "public/fpdfview.h"
25#include "testing/embedder_test.h"
26#include "testing/embedder_test_constants.h"
27#include "testing/fx_string_testhelpers.h"
28#include "testing/gmock/include/gmock/gmock-matchers.h"
29#include "testing/gtest/include/gtest/gtest.h"
30#include "testing/utils/hash.h"
31#include "third_party/base/containers/contains.h"
32#include "third_party/base/containers/span.h"
34using pdfium::AnnotationStampWithApChecksum;
38const wchar_t kStreamData[] =
39 L"/GS gs 0.0 0.0 0.0 RG 4 w 211.8 747.6 m 211.8 744.8 "
40 L"212.6 743.0 214.2 740.8 "
41 L"c 215.4 739.0 216.8 737.1 218.9 736.1 c 220.8 735.1 221.4 733.0 "
42 L"223.7 732.4 c 232.6 729.9 242.0 730.8 251.2 730.8 c 257.5 730.8 "
43 L"263.0 732.9 269.0 734.4 c S";
45void VerifyFocusableAnnotSubtypes(
46 FPDF_FORMHANDLE form_handle,
47 pdfium::span<
const FPDF_ANNOTATION_SUBTYPE> expected_subtypes) {
48 ASSERT_EQ(
static_cast<
int>(expected_subtypes.size()),
51 std::vector<FPDF_ANNOTATION_SUBTYPE> actual_subtypes(
52 expected_subtypes.size());
53 ASSERT_TRUE(FPDFAnnot_GetFocusableSubtypes(
54 form_handle, actual_subtypes.data(), actual_subtypes.size()));
55 for (size_t i = 0; i < expected_subtypes.size(); ++i)
56 ASSERT_EQ(expected_subtypes[i], actual_subtypes[i]);
59void SetAndVerifyFocusableAnnotSubtypes(
60 FPDF_FORMHANDLE form_handle,
61 pdfium::span<
const FPDF_ANNOTATION_SUBTYPE> subtypes) {
62 ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes(form_handle, subtypes.data(),
64 VerifyFocusableAnnotSubtypes(form_handle, subtypes);
67void VerifyAnnotationSubtypesAndFocusability(
68 FPDF_FORMHANDLE form_handle,
70 pdfium::span<
const FPDF_ANNOTATION_SUBTYPE> expected_subtypes,
71 pdfium::span<
const FPDF_ANNOTATION_SUBTYPE> expected_focusable_subtypes) {
72 ASSERT_EQ(
static_cast<
int>(expected_subtypes.size()),
74 for (size_t i = 0; i < expected_subtypes.size(); ++i) {
75 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i));
77 EXPECT_EQ(expected_subtypes[i], FPDFAnnot_GetSubtype(annot.get()));
79 bool expected_focusable =
80 pdfium::Contains(expected_focusable_subtypes, expected_subtypes[i]);
81 EXPECT_EQ(expected_focusable,
82 FORM_SetFocusedAnnot(form_handle, annot.get()));
89void VerifyUriActionInLink(FPDF_DOCUMENT doc,
91 const std::string& expected_uri) {
100 ASSERT_EQ(expected_uri.size() + 1, bufsize);
102 std::vector<
char> buffer(bufsize);
104 FPDFAction_GetURIPath(doc, action, buffer.data(), bufsize));
105 EXPECT_STREQ(expected_uri.c_str(), buffer.data());
113 ScopedFPDFDocument doc(FPDF_CreateNewDocument());
115 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
117 ScopedFPDFWideString ap_stream = GetFPDFWideString(kStreamData);
118 ASSERT_TRUE(ap_stream);
120 ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page.get(),
FPDF_ANNOT_INK));
128 const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f};
129 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect));
139 ASSERT_TRUE(context);
141 ASSERT_TRUE(annot_dict);
142 RetainPtr<
const CPDF_Dictionary> ap_dict =
143 annot_dict->GetDictFor(pdfium::annotation::kAP);
144 ASSERT_TRUE(ap_dict);
145 RetainPtr<
const CPDF_Dictionary> stream_dict = ap_dict->GetDictFor(
"N");
146 ASSERT_TRUE(stream_dict);
148 RetainPtr<
const CPDF_Dictionary> resources_dict =
149 stream_dict->GetDictFor(
"Resources");
150 ASSERT_FALSE(resources_dict);
152 EXPECT_EQ(
"XObject", type);
153 ByteString sub_type =
155 EXPECT_EQ(
"Form", sub_type);
158 const uint32_t kStreamDataSize =
std::size(kStreamData) *
sizeof(FPDF_WCHAR);
159 unsigned long normal_length_bytes = FPDFAnnot_GetAP(
161 ASSERT_EQ(kStreamDataSize, normal_length_bytes);
162 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(normal_length_bytes);
163 EXPECT_EQ(kStreamDataSize,
165 buf.data(), normal_length_bytes));
166 EXPECT_EQ(kStreamData, GetPlatformWString(buf.data()));
170 ScopedFPDFDocument doc(FPDF_CreateNewDocument());
172 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
174 ScopedFPDFWideString ap_stream = GetFPDFWideString(kStreamData);
175 ASSERT_TRUE(ap_stream);
177 ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page.get(),
FPDF_ANNOT_INK));
183 const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f};
184 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect));
190 ASSERT_TRUE(context);
192 ASSERT_TRUE(annot_dict);
193 RetainPtr<
const CPDF_Dictionary> ap_dict =
194 annot_dict->GetDictFor(pdfium::annotation::kAP);
195 ASSERT_TRUE(ap_dict);
196 RetainPtr<
const CPDF_Dictionary> stream_dict = ap_dict->GetDictFor(
"N");
197 ASSERT_TRUE(stream_dict);
198 RetainPtr<
const CPDF_Dictionary> resources_dict =
199 stream_dict->GetDictFor(
"Resources");
200 ASSERT_TRUE(stream_dict);
201 RetainPtr<
const CPDF_Dictionary> extGState_dict =
202 resources_dict->GetDictFor(
"ExtGState");
203 ASSERT_TRUE(extGState_dict);
204 RetainPtr<
const CPDF_Dictionary> gs_dict = extGState_dict->GetDictFor(
"GS");
205 ASSERT_TRUE(gs_dict);
207 EXPECT_EQ(
"ExtGState", type);
208 float opacity = gs_dict->GetFloatFor(
"CA");
210 EXPECT_FLOAT_EQ(0.4f, opacity);
211 ByteString blend_mode = gs_dict->GetByteStringFor(
"BM");
212 EXPECT_EQ(
"Normal", blend_mode);
213 bool alpha_source_flag = gs_dict->GetBooleanFor(
"AIS",
true);
214 EXPECT_FALSE(alpha_source_flag);
218 ScopedFPDFDocument doc(FPDF_CreateNewDocument());
220 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
224 ScopedFPDFAnnotation ink_annot(
226 ASSERT_TRUE(ink_annot);
228 CPDFAnnotContextFromFPDFAnnotation(ink_annot.get());
229 ASSERT_TRUE(context);
231 ASSERT_TRUE(annot_dict);
233 static constexpr FS_POINTF kFirstInkStroke[] = {
234 {80.0f, 90.0f}, {81.0f, 91.0f}, {82.0f, 92.0f},
235 {83.0f, 93.0f}, {84.0f, 94.0f}, {85.0f, 95.0f}};
236 static constexpr size_t kFirstStrokePointCount = std::size(kFirstInkStroke);
238 static constexpr FS_POINTF kSecondInkStroke[] = {
239 {70.0f, 90.0f}, {71.0f, 91.0f}, {72.0f, 92.0f}};
240 static constexpr size_t kSecondStrokePointCount = std::size(kSecondInkStroke);
242 static constexpr FS_POINTF kThirdInkStroke[] = {{60.0f, 90.0f},
247 static constexpr size_t kThirdStrokePointCount = std::size(kThirdInkStroke);
250 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(
nullptr, kFirstInkStroke,
251 kFirstStrokePointCount));
255 ScopedFPDFAnnotation highlight_annot(
257 ASSERT_TRUE(highlight_annot);
258 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(highlight_annot.get(), kFirstInkStroke,
259 kFirstStrokePointCount));
262 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), kFirstInkStroke, 0));
265 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(),
nullptr,
266 kFirstStrokePointCount));
269 EXPECT_EQ(-1, FPDFAnnot_AddInkStroke(ink_annot.get(), kSecondInkStroke,
274 EXPECT_EQ(0, FPDFAnnot_AddInkStroke(ink_annot.get(), kFirstInkStroke,
275 kFirstStrokePointCount));
277 RetainPtr<
const CPDF_Array> inklist = annot_dict->GetArrayFor(
"InkList");
278 ASSERT_TRUE(inklist);
279 EXPECT_EQ(1u, inklist->size());
280 EXPECT_EQ(kFirstStrokePointCount * 2, inklist->GetArrayAt(0)->size());
284 EXPECT_EQ(1, FPDFAnnot_AddInkStroke(ink_annot.get(), kSecondInkStroke,
285 kSecondStrokePointCount));
286 EXPECT_EQ(2u, inklist->size());
287 EXPECT_EQ(kSecondStrokePointCount * 2, inklist->GetArrayAt(1)->size());
291 EXPECT_EQ(2, FPDFAnnot_AddInkStroke(ink_annot.get(), kThirdInkStroke,
292 kThirdStrokePointCount - 1));
293 EXPECT_EQ(3u, inklist->size());
294 EXPECT_EQ((kThirdStrokePointCount - 1) * 2, inklist->GetArrayAt(2)->size());
298 ScopedFPDFDocument doc(FPDF_CreateNewDocument());
300 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 100, 100));
308 ScopedFPDFAnnotation highlight_annot(
310 ASSERT_TRUE(highlight_annot);
311 EXPECT_FALSE(FPDFAnnot_RemoveInkList(highlight_annot.get()));
314 ScopedFPDFAnnotation ink_annot(
316 ASSERT_TRUE(ink_annot);
318 CPDFAnnotContextFromFPDFAnnotation(ink_annot.get());
319 ASSERT_TRUE(context);
321 ASSERT_TRUE(annot_dict);
323 static constexpr FS_POINTF kInkStroke[] = {{80.0f, 90.0f}, {81.0f, 91.0f},
324 {82.0f, 92.0f}, {83.0f, 93.0f},
325 {84.0f, 94.0f}, {85.0f, 95.0f}};
326 static constexpr size_t kPointCount = std::size(kInkStroke);
331 FPDFAnnot_AddInkStroke(ink_annot.get(), kInkStroke, kPointCount));
333 RetainPtr<
const CPDF_Array> inklist = annot_dict->GetArrayFor(
"InkList");
334 ASSERT_TRUE(inklist);
335 ASSERT_EQ(1u, inklist->size());
336 EXPECT_EQ(kPointCount * 2, inklist->GetArrayAt(0)->size());
339 EXPECT_TRUE(FPDFAnnot_RemoveInkList(ink_annot.get()));
344 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
345 FPDF_PAGE page = LoadPage(0);
366 static const wchar_t kContents[] = L"Bar";
367 ScopedFPDFWideString text = GetFPDFWideString(kContents);
368 EXPECT_FALSE(FPDFAnnot_SetStringValue(
nullptr,
"foo", text.get()));
370 FPDF_WCHAR buffer[64];
380 ASSERT_TRUE(OpenDocument(
"bad_annots_entry.pdf"));
381 FPDF_PAGE page = LoadPage(0);
392 ASSERT_TRUE(OpenDocument(
"annotation_highlight_rollover_ap.pdf"));
393 FPDF_PAGE page = LoadPage(0);
400 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
401 CompareBitmap(bitmap.get(), 612, 792,
"dc98f06da047bd8aabfa99562d2cbd1e");
407 const char* checksum = []() {
409 return "ec1f4ccbd0aecfdea6d53893387a0101";
411 return "76512832d88017668d9acc7aacd13dae";
415 ASSERT_TRUE(OpenDocument(
"annotation_markup_multiline_no_ap.pdf"));
416 FPDF_PAGE page = LoadPage(0);
419 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
420 CompareBitmap(bitmap.get(), 595, 842, checksum);
427 ASSERT_TRUE(OpenDocument(
"annotation_highlight_long_content.pdf"));
428 FPDF_PAGE page = LoadPageNoEvents(0);
436 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
453 static const char kAuthorKey[] =
"T";
455 FPDFAnnot_GetValueType(annot.get(), kAuthorKey));
456 unsigned long length_bytes =
457 FPDFAnnot_GetStringValue(annot.get(), kAuthorKey,
nullptr, 0);
458 ASSERT_EQ(28u, length_bytes);
459 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
460 EXPECT_EQ(28u, FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, buf.data(),
462 EXPECT_EQ(L"Jae Hyun Park", GetPlatformWString(buf.data()));
468 length_bytes = FPDFAnnot_GetStringValue(
470 ASSERT_EQ(2690u, length_bytes);
471 buf = GetFPDFWideStringBuffer(length_bytes);
472 EXPECT_EQ(2690u, FPDFAnnot_GetStringValue(annot.get(),
474 buf.data(), length_bytes));
475 static const wchar_t kContents[] =
476 L"This is a note for that highlight annotation. Very long highlight "
477 "annotation. Long long long Long long longLong long longLong long "
478 "longLong long longLong long longLong long longLong long longLong long "
479 "longLong long longLong long longLong long longLong long longLong long "
480 "longLong long longLong long longLong long longLong long longLong long "
481 "longLong long longLong long longLong 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 long. END";
496 EXPECT_EQ(kContents, GetPlatformWString(buf.data()));
499 FS_QUADPOINTSF quadpoints;
500 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
501 EXPECT_EQ(115.802643f, quadpoints.x1);
502 EXPECT_EQ(718.913940f, quadpoints.y1);
503 EXPECT_EQ(157.211182f, quadpoints.x4);
504 EXPECT_EQ(706.264465f, quadpoints.y4);
506 UnloadPageNoEvents(page);
511 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
512 FPDF_PAGE page = LoadPageNoEvents(0);
520 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
537 EXPECT_EQ(2u, FPDFAnnot_GetStringValue(
543 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
544 EXPECT_EQ(351.820404f, rect.left);
545 EXPECT_EQ(583.830688f, rect.bottom);
546 EXPECT_EQ(475.336090f, rect.right);
547 EXPECT_EQ(681.535034f, rect.top);
550 const char* expected_hash = []() {
553 return "d9411907a883f25ba51e71c8359c10fe";
554#elif BUILDFLAG(IS_APPLE)
555 return "6e00cc75639c5314c8273072915d8f92";
557 return "1fb0dd8dd5f0b9bb8d076e48eb59296d";
560 return "354002e1c4386d38fdde29ef8d61074a";
562 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
563 CompareBitmap(bitmap.get(), 612, 792, expected_hash);
565 UnloadPageNoEvents(page);
570 ASSERT_TRUE(OpenDocument(
"annotation_highlight_long_content.pdf"));
571 FPDF_PAGE page = LoadPage(0);
582 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
583 FPDF_PAGE page = LoadPage(0);
589 ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page,
FPDF_ANNOT_TEXT));
600 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
632 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
633 EXPECT_EQ(0.f, rect.left);
634 EXPECT_EQ(0.f, rect.right);
639 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
641 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
642 EXPECT_EQ(35.f, rect.left);
643 EXPECT_EQ(150.f, rect.bottom);
644 EXPECT_EQ(53.f, rect.right);
645 EXPECT_EQ(165.f, rect.top);
648 static const wchar_t kContents[] = L"Hello! This is a customized content.";
649 ScopedFPDFWideString text = GetFPDFWideString(kContents);
650 ASSERT_TRUE(FPDFAnnot_SetStringValue(
653 unsigned long length_bytes = FPDFAnnot_GetStringValue(
655 ASSERT_EQ(74u, length_bytes);
656 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
657 EXPECT_EQ(74u, FPDFAnnot_GetStringValue(annot.get(),
659 buf.data(), length_bytes));
660 EXPECT_EQ(kContents, GetPlatformWString(buf.data()));
666 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
667 FPDF_PAGE page = LoadPage(0);
670 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
675 constexpr char kUri[] =
"https://pdfium.org/";
679 ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page,
FPDF_ANNOT_LINK));
683 EXPECT_TRUE(FPDFAnnot_SetURI(annot.get(), kUri));
684 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
688 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
689 EXPECT_FALSE(FPDFAnnot_SetURI(annot.get(),
nullptr));
690 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
692 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
695 const FS_RECTF kRect = {19.0f, 48.0f, 85.0f, 60.0f};
696 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &kRect));
697 EXPECT_TRUE(FPDFAnnot_SetBorder(annot.get(), 0.0f,
707 ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page,
FPDF_ANNOT_INK));
711 EXPECT_FALSE(FPDFAnnot_SetURI(annot.get(), kUri));
719 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
724 ASSERT_TRUE(OpenSavedDocument());
725 page = LoadSavedPage(0);
731 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
734 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()), kUri);
739 CloseSavedPage(page);
740 CloseSavedDocument();
745 ASSERT_TRUE(OpenDocument(
"annotation_highlight_long_content.pdf"));
746 FPDF_PAGE page = LoadPage(0);
752 FS_QUADPOINTSF quadpoints;
754 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
756 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
757 EXPECT_EQ(115.802643f, quadpoints.x1);
758 EXPECT_EQ(718.913940f, quadpoints.y1);
759 EXPECT_EQ(157.211182f, quadpoints.x4);
760 EXPECT_EQ(706.264465f, quadpoints.y4);
765 ScopedFPDFAnnotation annot(
768 quadpoints.x1 = 140.802643f;
769 quadpoints.x3 = 140.802643f;
770 ASSERT_TRUE(FPDFAnnot_AppendAttachmentPoints(annot.get(), &quadpoints));
774 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
778 const char* checksum = []() {
781 return "c50012ab122cd3706d39f371ca7462ee";
782#elif BUILDFLAG(IS_APPLE)
783 return "24994ad69aa612a66d183eaf9a92aa06";
785 return "798fa41303381c9ba6d99092f5cd4d2b";
788 return "dba153419f67b7c0c0e3d22d3e8910d5";
791 ASSERT_TRUE(OpenSavedDocument());
792 page = LoadSavedPage(0);
794 VerifySavedRendering(page, 612, 792, checksum);
802 ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 1));
803 ASSERT_TRUE(new_annot);
805 FS_QUADPOINTSF new_quadpoints;
807 FPDFAnnot_GetAttachmentPoints(new_annot.get(), 0, &new_quadpoints));
808 EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f);
809 EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f);
810 EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f);
811 EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f);
814 CloseSavedPage(page);
815 CloseSavedDocument();
820 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
821 FPDF_PAGE page = LoadPage(0);
830 FS_QUADPOINTSF quadpoints;
831 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 0, &quadpoints));
835 ASSERT_EQ(1u, FPDFAnnot_CountAttachmentPoints(annot));
837 EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
838 EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
839 EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
840 EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
845 FS_QUADPOINTSF new_quadpoints = quadpoints;
846 new_quadpoints.y1 -= 20.f;
847 new_quadpoints.y2 -= 20.f;
848 new_quadpoints.y3 -= 20.f;
849 new_quadpoints.y4 -= 20.f;
850 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, 0, &new_quadpoints));
853 ASSERT_EQ(1u, FPDFAnnot_CountAttachmentPoints(annot));
854 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 0, &quadpoints));
855 EXPECT_NEAR(new_quadpoints.x1, quadpoints.x1, 0.001f);
856 EXPECT_NEAR(new_quadpoints.y1, quadpoints.y1, 0.001f);
857 EXPECT_NEAR(new_quadpoints.x4, quadpoints.x4, 0.001f);
858 EXPECT_NEAR(new_quadpoints.y4, quadpoints.y4, 0.001f);
863 FS_QUADPOINTSF new_quadpoints = quadpoints;
864 new_quadpoints.y1 += 20.f;
865 new_quadpoints.y2 += 20.f;
866 new_quadpoints.y3 += 20.f;
867 new_quadpoints.y4 += 20.f;
871 ASSERT_EQ(2u, FPDFAnnot_CountAttachmentPoints(annot));
872 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 1, &quadpoints));
873 EXPECT_NEAR(new_quadpoints.x1, quadpoints.x1, 0.001f);
874 EXPECT_NEAR(new_quadpoints.y1, quadpoints.y1, 0.001f);
875 EXPECT_NEAR(new_quadpoints.x4, quadpoints.x4, 0.001f);
876 EXPECT_NEAR(new_quadpoints.y4, quadpoints.y4, 0.001f);
881 EXPECT_FALSE(FPDFAnnot_SetAttachmentPoints(annot, 300000, &quadpoints));
882 EXPECT_FALSE(FPDFAnnot_GetAttachmentPoints(annot, 300000, &quadpoints));
892 ASSERT_TRUE(squareAnnot);
894 EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(squareAnnot));
895 EXPECT_FALSE(FPDFAnnot_SetAttachmentPoints(squareAnnot, 0, &quadpoints));
903 const char* md5_original = []() {
906 return "3867f6e34e801abad4e98811f6d7b887";
907#elif BUILDFLAG(IS_APPLE)
908 return "32cd26430a31752e612475bf881cc597";
910 return "2a9d1df839d5ec81a49f982347d9656c";
913#if BUILDFLAG(IS_APPLE)
914 return "fc59468d154f397fd298c69f47ef565a";
916 return "0e27376094f11490f74c65f3dc3a42c5";
919 const char* md5_modified_highlight = []() {
922 return "a6f6df562dcf96b3670d40fa2999a582";
923#elif BUILDFLAG(IS_APPLE)
924 return "9a969b7089f49c029b10cf8c208b40dd";
926 return "0fb1653db0e8e8f7ce5d726bb0074bb5";
929#if BUILDFLAG(IS_APPLE)
930 return "e64bf648f6e9354d1f3eedb47a2c9498";
932 return "66f3caef3a7d488a4fa1ad37fc06310e";
935 const char* md5_modified_square = []() {
938 return "cebb3bd3209f63f6dfd15b8425229e90";
939#elif BUILDFLAG(IS_APPLE)
940 return "613102f8b6d74d6d9f95c8eacd17b756";
942 return "879c77a2cb9f79ba65ffe0bbdd720ce3";
945#if BUILDFLAG(IS_APPLE)
946 return "a66591662c8e7ad3c6059952e234bebf";
948 return "a456dad0bc6801ee2d6408a4394af563";
953 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
954 FPDF_PAGE page = LoadPage(0);
960 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
961 CompareBitmap(bitmap.get(), 612, 792, md5_original);
969 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
978 FS_QUADPOINTSF quadpoints;
979 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints));
980 EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
981 EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
982 EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
983 EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
986 quadpoints.x1 -= 50.f;
987 quadpoints.x2 -= 50.f;
988 quadpoints.x3 -= 50.f;
989 quadpoints.x4 -= 50.f;
990 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), 0, &quadpoints));
991 FS_QUADPOINTSF new_quadpoints;
992 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &new_quadpoints));
993 EXPECT_EQ(quadpoints.x1, new_quadpoints.x1);
994 EXPECT_EQ(quadpoints.y1, new_quadpoints.y1);
995 EXPECT_EQ(quadpoints.x4, new_quadpoints.x4);
996 EXPECT_EQ(quadpoints.y4, new_quadpoints.y4);
1000 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1001 CompareBitmap(bitmap.get(), 612, 792, md5_original);
1005 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1006 EXPECT_NEAR(67.7299f, rect.left, 0.001f);
1007 EXPECT_NEAR(704.296f, rect.bottom, 0.001f);
1008 EXPECT_NEAR(136.325f, rect.right, 0.001f);
1009 EXPECT_NEAR(721.292f, rect.top, 0.001f);
1014 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1015 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
1016 EXPECT_EQ(rect.right, new_rect.right);
1021 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1022 CompareBitmap(bitmap.get(), 612, 792, md5_modified_highlight);
1027 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
1032 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1035 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1036 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
1037 EXPECT_EQ(rect.right, new_rect.right);
1041 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1042 CompareBitmap(bitmap.get(), 612, 792, md5_modified_square);
1050 ASSERT_TRUE(OpenDocument(
"annotation_markup_multiline_no_ap.pdf"));
1051 FPDF_PAGE page = LoadPage(0);
1054 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1058 EXPECT_EQ(3u, FPDFAnnot_CountAttachmentPoints(annot.get()));
1063 EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(
nullptr));
1068 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
1069 FPDF_PAGE page = LoadPageNoEvents(0);
1077 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1078 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1079 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
1083 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
1084 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1085 EXPECT_NEAR(149.8127f, rect.left, 0.001f);
1089 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
1090 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1091 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
1106 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1107 UnloadPageNoEvents(page);
1111 std::string new_file = GetString();
1112 FPDF_FILEACCESS file_access;
1113 memset(&file_access, 0,
sizeof(file_access));
1114 file_access.m_FileLen = new_file.size();
1115 file_access.m_GetBlock = GetBlockFromString;
1116 file_access.m_Param = &new_file;
1117 ScopedFPDFDocument new_doc(FPDF_LoadCustomDocument(&file_access,
nullptr));
1118 ASSERT_TRUE(new_doc);
1119 ScopedFPDFPage new_page(FPDF_LoadPage(new_doc.get(), 0));
1120 ASSERT_TRUE(new_page);
1123 EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page.get()));
1128 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(new_page.get(), 0));
1129 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1130 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
1134 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(new_page.get(), 1));
1135 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
1136 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
1141 const char* md5_modified_path = []() {
1143#if BUILDFLAG(IS_WIN)
1144 return "ab475e8230c6aab366073bdb70eb6953";
1145#elif BUILDFLAG(IS_APPLE)
1146 return "6d9247e3a0ecdf5627f365eded71307c";
1148 return "fb4d5fac05f7eb5d84a4100898c11197";
1151#if BUILDFLAG(IS_APPLE)
1152 return "34614087e04b729b7b8c37739dcf9af9";
1154 return "31a94d22460171cd83169daf6a6956ee";
1157 const char* md5_two_paths = []() {
1159#if BUILDFLAG(IS_WIN)
1160 return "ce7f5271ff51096a15861619fb789d5b";
1161#elif BUILDFLAG(IS_APPLE)
1162 return "d8a7ac6a292fbf1403effb0788599ee2";
1164 return "fcf3e79b2a91d1294b9bbccff727d3c2";
1167#if BUILDFLAG(IS_APPLE)
1168 return "6cdaf6b3e5145f435d8ccae6db5cf9af";
1170 return "ed49fefef45f14121f8150cde10006c4";
1173 const char* md5_new_annot = []() {
1175#if BUILDFLAG(IS_WIN)
1176 return "b627d1be207a1f090db9cf122bc198ae";
1177#elif BUILDFLAG(IS_APPLE)
1178 return "8f537dae2460736988530430b904bb55";
1180 return "7db6321c8ffe502f4e60622aa16d5417";
1183#if BUILDFLAG(IS_APPLE)
1184 return "55dab4f158fdc284e439b88c4306373c";
1186 return "cc08493b1f079803930388ecc703be9d";
1191 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1192 FPDF_PAGE page = LoadPage(0);
1198 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1204 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1208 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1210 FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot.get(), 1);
1212 path = FPDFAnnot_GetObject(annot.get(), 0);
1218 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), path));
1222 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1223 CompareBitmap(bitmap.get(), 595, 842, md5_modified_path);
1232 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), dot));
1233 EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot.get()));
1241 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1242 CompareBitmap(bitmap.get(), 595, 842, md5_two_paths);
1246 EXPECT_TRUE(FPDFAnnot_RemoveObject(annot.get(), 1));
1247 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1253 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1254 CompareBitmap(bitmap.get(), 595, 842, md5_modified_path);
1264 rect.bottom = 400.f;
1267 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1278 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), check));
1279 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1283 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
1284 EXPECT_EQ(rect.left, new_rect.left);
1285 EXPECT_EQ(rect.bottom, new_rect.bottom);
1286 EXPECT_EQ(rect.right, new_rect.right);
1287 EXPECT_EQ(rect.top, new_rect.top);
1291 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1295 ASSERT_TRUE(OpenSavedDocument());
1296 page = LoadSavedPage(0);
1298 VerifySavedRendering(page, 595, 842, md5_new_annot);
1304 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
1306 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1310 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
1311 EXPECT_EQ(rect.left, new_rect.left);
1312 EXPECT_EQ(rect.bottom, new_rect.bottom);
1313 EXPECT_EQ(rect.right, new_rect.right);
1314 EXPECT_EQ(rect.top, new_rect.top);
1317 CloseSavedPage(page);
1318 CloseSavedDocument();
1323 ASSERT_TRUE(OpenDocument(
"annotation_highlight_rollover_ap.pdf"));
1324 FPDF_PAGE page = LoadPage(0);
1329 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1330 CompareBitmap(bitmap.get(), 612, 792,
"dc98f06da047bd8aabfa99562d2cbd1e");
1335 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1339 int flags = FPDFAnnot_GetFlags(annot.get());
1352 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags));
1353 flags = FPDFAnnot_GetFlags(annot.get());
1359 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1365 EXPECT_FALSE(FPDFAnnot_GetFlags(annot.get()));
1367 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags));
1368 flags = FPDFAnnot_GetFlags(annot.get());
1374 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1375 CompareBitmap(bitmap.get(), 612, 792,
"dc98f06da047bd8aabfa99562d2cbd1e");
1383 const char* md5_new_image = []() {
1385#if BUILDFLAG(IS_WIN)
1386 return "5b7ce251f51f50c1c76d3b09c47a87f9";
1387#elif BUILDFLAG(IS_APPLE)
1388 return "d1f632f3a8bf0917eeece36e23dc3708";
1390 return "476596330c0e7daa31f115005c1d36eb";
1393#if BUILDFLAG(IS_APPLE)
1394 return "17ac49518eabbb6a7632a547269c40a3";
1396 return "e79446398d4508bc2cb47e6cf2a677ed";
1399 const char* md5_modified_image = []() {
1401#if BUILDFLAG(IS_WIN)
1402 return "f9af241702961e8ed59306a7084548bf";
1403#elif BUILDFLAG(IS_APPLE)
1404 return "1a86f152a7ef8ac6bf8d8e5aee09bd65";
1406 return "0047c3e7ea7658e1a963fc339f1c587d";
1409#if BUILDFLAG(IS_APPLE)
1410 return "ce68959f74242d588af7fb82be5ba0ab";
1412 return "425646a517a23104b9ef22881a19b3e2";
1417 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1418 FPDF_PAGE page = LoadPage(0);
1424 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1428 constexpr int kBitmapSize = 200;
1429 FPDF_BITMAP image_bitmap;
1437 rect.bottom = 600.f;
1440 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1448 FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document());
1450 static constexpr FS_MATRIX kBitmapScaleMatrix{kBitmapSize, 0, 0,
1454 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), image_object));
1459 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1460 CompareBitmap(bitmap.get(), 595, 842, md5_new_image);
1465 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
1467 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1468 FPDF_PAGEOBJECT image_object = FPDFAnnot_GetObject(annot.get(), 0);
1475 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), image_object));
1479 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1484 VerifySavedDocument(595, 842, md5_modified_image);
1488 const char* md5_new_text = []() {
1490#if BUILDFLAG(IS_WIN)
1491 return "2752b71ff3373a8a427fbc4145018ee8";
1492#elif BUILDFLAG(IS_APPLE)
1493 return "660063559c20b80e66c2702d44400eb2";
1495 return "1e7f98c18775d6e0f4f454747b77cc1a";
1498#if BUILDFLAG(IS_APPLE) && defined(ARCH_CPU_ARM64)
1499 return "0c3448974a4e8da2395da917935e5de1";
1500#elif BUILDFLAG(IS_APPLE) && !defined(ARCH_CPU_ARM64)
1501 return "5d449d36926c9f212c6cdb6c276d18cc";
1503 return "a9532f555aca2fd099e2107fa40b61e6";
1506 const char* md5_modified_text = []() {
1508#if BUILDFLAG(IS_WIN)
1509 return "064468521e40694712422c9a1b5212c4";
1510#elif BUILDFLAG(IS_APPLE)
1511 return "1e93d904e7a6f6d72062e014c58c8df2";
1513 return "37e35705946806f8f98c51e4e25647a2";
1516#if BUILDFLAG(IS_APPLE) && defined(ARCH_CPU_ARM64)
1517 return "9cf1c024a9d2d356bcdd14cb71a32324";
1518#elif BUILDFLAG(IS_APPLE) && !defined(ARCH_CPU_ARM64)
1519 return "8c992808db99dbe3d74006358a671f05";
1521 return "03cae68322d6a6ba120e738ab325408c";
1526 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1527 FPDF_PAGE page = LoadPage(0);
1533 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1543 rect.bottom = 550.f;
1546 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
1549 FPDF_PAGEOBJECT text_object =
1550 FPDFPageObj_NewTextObj(document(),
"Arial", 12.0f);
1551 EXPECT_TRUE(text_object);
1552 ScopedFPDFWideString text =
1553 GetFPDFWideString(L"I'm a translucent text laying on other text.");
1554 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
1557 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), text_object));
1562 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1563 CompareBitmap(bitmap.get(), 595, 842, md5_new_text);
1568 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
1570 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
1571 FPDF_PAGEOBJECT text_object = FPDFAnnot_GetObject(annot.get(), 0);
1575 ScopedFPDFWideString new_text = GetFPDFWideString(L"New text!");
1576 EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get()));
1577 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), text_object));
1582 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1583 CompareBitmap(bitmap.get(), 595, 842, md5_modified_text);
1589 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
1598 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1599 FPDF_PAGE page = LoadPage(0);
1602 static const wchar_t kNewDate[] = L"D:201706282359Z00'00'";
1606 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1610 EXPECT_FALSE(FPDFAnnot_HasKey(annot.get(),
"none"));
1620 static const char kHashKey[] =
"AAPL:Hash";
1621 EXPECT_EQ(
FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey));
1622 unsigned long length_bytes =
1623 FPDFAnnot_GetStringValue(annot.get(), kHashKey,
nullptr, 0);
1624 ASSERT_EQ(66u, length_bytes);
1625 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
1626 EXPECT_EQ(66u, FPDFAnnot_GetStringValue(annot.get(), kHashKey, buf.data(),
1628 EXPECT_EQ(L"395fbcb98d558681742f30683a62a2ad",
1629 GetPlatformWString(buf.data()));
1632 EXPECT_EQ(
FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey));
1633 length_bytes = FPDFAnnot_GetStringValue(annot.get(), pdfium
::annotation::kM,
1635 ASSERT_EQ(44u, length_bytes);
1636 buf = GetFPDFWideStringBuffer(length_bytes);
1637 EXPECT_EQ(44u, FPDFAnnot_GetStringValue(annot.get(), pdfium
::annotation::kM,
1638 buf.data(), length_bytes));
1639 EXPECT_EQ(L"D:201706071721Z00'00'", GetPlatformWString(buf.data()));
1642 ScopedFPDFWideString text = GetFPDFWideString(kNewDate);
1648 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1651 const char* md5 = []() {
1653#if BUILDFLAG(IS_WIN)
1654 return "5060b231fef2504446a5d44474869326";
1655#elif BUILDFLAG(IS_APPLE)
1656 return "88528466e6e6da2915ae024b497e3d4a";
1658 return "a95a65d109eda5671c793ff5f7d2a2df";
1661#if BUILDFLAG(IS_APPLE)
1662 return "52e93c54796f7f7167edf64e81d12bd7";
1664 return "5143f9a98beb7b00ff40b89110a1089f";
1669 ASSERT_TRUE(OpenSavedDocument());
1670 page = LoadSavedPage(0);
1672 VerifySavedRendering(page, 595, 842, md5);
1674 ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 0));
1680 unsigned long length_bytes = FPDFAnnot_GetStringValue(
1682 ASSERT_EQ(44u, length_bytes);
1683 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
1686 buf.data(), length_bytes));
1687 EXPECT_EQ(kNewDate, GetPlatformWString(buf.data()));
1690 CloseSavedPage(page);
1691 CloseSavedDocument();
1696 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
1697 FPDF_PAGE page = LoadPage(0);
1701 for (
int i = 0; i < 2; i++) {
1702 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i));
1706 EXPECT_FALSE(FPDFAnnot_HasKey(annot.get(),
"MaxLen"));
1709 EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(),
"MaxLen", &value));
1713 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
1717 EXPECT_TRUE(FPDFAnnot_HasKey(annot.get(),
"MaxLen"));
1720 EXPECT_TRUE(FPDFAnnot_GetNumberValue(annot.get(),
"MaxLen", &value));
1721 EXPECT_FLOAT_EQ(10.0f, value);
1725 EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(),
nullptr, &value));
1726 EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(),
"MaxLen",
nullptr));
1728 EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(),
"V", &value));
1736 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1737 FPDF_PAGE page = LoadPage(0);
1741 static const char kMd5NormalAP[] =
"be903df0343fd774fadab9c8900cdf4a";
1742 static constexpr size_t kExpectNormalAPLength = 73970;
1745 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1749 unsigned long normal_length_bytes = FPDFAnnot_GetAP(
1751 ASSERT_EQ(kExpectNormalAPLength, normal_length_bytes);
1755 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(normal_length_bytes);
1757 memcpy(buf.data(),
"abcdefgh", 8);
1758 EXPECT_EQ(kExpectNormalAPLength,
1760 buf.data(), normal_length_bytes - 1));
1761 EXPECT_EQ(0, memcmp(buf.data(),
"abcdefgh", 8));
1765 EXPECT_EQ(kExpectNormalAPLength,
1767 buf.data(), normal_length_bytes));
1768 EXPECT_EQ(kMd5NormalAP,
1769 GenerateMD5Base16({
reinterpret_cast<uint8_t*>(buf.data()),
1770 normal_length_bytes}));
1774 buf = GetFPDFWideStringBuffer(normal_length_bytes + 2);
1775 EXPECT_EQ(kExpectNormalAPLength,
1777 buf.data(), normal_length_bytes + 2));
1778 EXPECT_EQ(kMd5NormalAP,
1779 GenerateMD5Base16({
reinterpret_cast<uint8_t*>(buf.data()),
1780 normal_length_bytes}));
1784 unsigned long rollover_length_bytes = FPDFAnnot_GetAP(
1786 ASSERT_EQ(2u, rollover_length_bytes);
1788 buf = GetFPDFWideStringBuffer(1000);
1792 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
1795 ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap");
1796 EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), -1, ap_text.get()));
1799 EXPECT_FALSE(FPDFAnnot_SetAP(
1807 rollover_length_bytes = FPDFAnnot_GetAP(
1809 ASSERT_EQ(24u, rollover_length_bytes);
1810 buf = GetFPDFWideStringBuffer(rollover_length_bytes);
1813 buf.data(), rollover_length_bytes));
1814 EXPECT_EQ(L"new test ap", GetPlatformWString(buf.data()));
1817 buf = GetFPDFWideStringBuffer(normal_length_bytes);
1818 EXPECT_EQ(kExpectNormalAPLength,
1820 buf.data(), normal_length_bytes));
1821 EXPECT_EQ(kMd5NormalAP,
1822 GenerateMD5Base16({
reinterpret_cast<uint8_t*>(buf.data()),
1823 normal_length_bytes}));
1827 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
1830 ASSERT_TRUE(OpenSavedDocument());
1831 page = LoadSavedPage(0);
1834 ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 0));
1838 unsigned long rollover_length_bytes = FPDFAnnot_GetAP(
1840 ASSERT_EQ(24u, rollover_length_bytes);
1841 std::vector<FPDF_WCHAR> buf =
1842 GetFPDFWideStringBuffer(rollover_length_bytes);
1843 EXPECT_EQ(24u, FPDFAnnot_GetAP(new_annot.get(),
1845 buf.data(), rollover_length_bytes));
1846 EXPECT_EQ(L"new test ap", GetPlatformWString(buf.data()));
1850 CloseSavedPage(page);
1851 CloseSavedDocument();
1856 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1857 FPDF_PAGE page = LoadPage(0);
1862 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1866 ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap");
1891 ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"));
1892 FPDF_PAGE page = LoadPage(0);
1897 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1901 ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap");
1924 ASSERT_TRUE(OpenDocument(
"annotation_highlight_square_with_ap.pdf"));
1925 FPDF_PAGE page = LoadPage(0);
1931 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1934 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot.get()));
1935 static const char kPopupKey[] =
"Popup";
1936 ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), kPopupKey));
1938 FPDFAnnot_GetValueType(annot.get(), kPopupKey));
1941 ScopedFPDFAnnotation popup(
1942 FPDFAnnot_GetLinkedAnnot(annot.get(), kPopupKey));
1945 EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup.get()));
1947 ASSERT_TRUE(FPDFAnnot_GetRect(popup.get(), &rect));
1948 EXPECT_NEAR(612.0f, rect.left, 0.001f);
1949 EXPECT_NEAR(578.792, rect.bottom, 0.001f);
1953 static const char kIRTKey[] =
"IRT";
1954 ASSERT_FALSE(FPDFAnnot_HasKey(annot.get(), kIRTKey));
1955 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), kIRTKey));
1962 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), pdfium
::annotation::kP));
1970 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
1971 FPDF_PAGE page = LoadPage(0);
1976 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
1980 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
1990 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
1994 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2004 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
2008 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2021 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2022 FPDF_PAGE page = LoadPage(0);
2027 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2031 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2042 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
2046 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2057 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
2061 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2075 ASSERT_TRUE(OpenDocument(
"text_form.pdf"));
2076 FPDF_PAGE page = LoadPage(0);
2080 static const FS_POINTF kOriginPoint = {0.0f, 0.0f};
2082 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kOriginPoint));
2084 static const FS_POINTF kValidPoint = {120.0f, 120.0f};
2087 ScopedFPDFAnnotation annot(
2088 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kValidPoint));
2096 FPDFAnnot_GetFormFieldAtPoint(form_handle(),
nullptr, &kValidPoint));
2103 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
2104 FPDF_PAGE page = LoadPage(0);
2109 static const FS_POINTF kPoint = {105.0f, 118.0f};
2110 ScopedFPDFAnnotation annot(
2111 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2115 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2123 static const FS_POINTF kPoint = {105.0f, 202.0f};
2124 ScopedFPDFAnnotation annot(
2125 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2129 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2140 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2141 FPDF_PAGE page = LoadPage(0);
2146 static const FS_POINTF kPoint = {102.0f, 363.0f};
2147 ScopedFPDFAnnotation annot(
2148 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2152 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2163 static const FS_POINTF kPoint = {102.0f, 413.0f};
2164 ScopedFPDFAnnotation annot(
2165 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2169 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2180 static const FS_POINTF kPoint = {102.0f, 513.0f};
2181 ScopedFPDFAnnotation annot(
2182 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint));
2186 int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
2199 const char* expected_bitmap = []() {
2201 return "a1ea1ceebb26922fae576cb79ce63af0";
2203 return "0d9fc05c6762fd788bd23fd87a4967bc";
2205 static constexpr size_t kExpectedSize = 1601;
2207 ASSERT_TRUE(OpenDocument(
"bug_1206.pdf"));
2209 FPDF_PAGE page = LoadPage(0);
2212 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2213 EXPECT_EQ(kExpectedSize, GetString().size());
2216 for (size_t i = 0; i < 10; ++i) {
2217 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
2218 CompareBitmap(bitmap.get(), 612, 792, expected_bitmap);
2220 ASSERT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2223 EXPECT_LT(kExpectedSize, GetString().size());
2231 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
2232 FPDF_PAGE page = LoadPage(0);
2236 static const char kTestKey[] =
"test";
2237 static const wchar_t kData[] = L"\xf6\xe4";
2238 static const size_t kBufSize = 12;
2239 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(kBufSize);
2243 ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page,
FPDF_ANNOT_TEXT));
2249 std::fill(buf.begin(), buf.end(),
'x');
2250 ASSERT_EQ(2u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(),
2252 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
2254 ScopedFPDFWideString text = GetFPDFWideString(kData);
2255 EXPECT_TRUE(FPDFAnnot_SetStringValue(annot.get(), kTestKey, text.get()));
2257 std::fill(buf.begin(), buf.end(),
'x');
2258 ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(),
2260 EXPECT_EQ(kData, GetPlatformWString(buf.data()));
2266 const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f};
2267 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect));
2271 std::fill(buf.begin(), buf.end(),
'x');
2274 buf.data(), kBufSize));
2275 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
2277 ScopedFPDFWideString text = GetFPDFWideString(kData);
2281 std::fill(buf.begin(), buf.end(),
'x');
2284 buf.data(), kBufSize));
2285 EXPECT_EQ(kData, GetPlatformWString(buf.data()));
2293 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
2294 ASSERT_TRUE(OpenSavedDocument());
2295 FPDF_PAGE saved_page = LoadSavedPage(0);
2296 ASSERT_TRUE(saved_page);
2300 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(saved_page, 0));
2304 std::fill(buf.begin(), buf.end(),
'x');
2305 ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(),
2307 EXPECT_EQ(kData, GetPlatformWString(buf.data()));
2311 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(saved_page, 0));
2316 std::fill(buf.begin(), buf.end(),
'x');
2317 ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(),
2319 EXPECT_EQ(kData, GetPlatformWString(buf.data()));
2322 CloseSavedPage(saved_page);
2323 CloseSavedDocument();
2329 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2330 FPDF_PAGE page = LoadPage(0);
2334 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2337 EXPECT_EQ(3, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2342 EXPECT_EQ(26, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2346 EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(),
nullptr));
2347 EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(
nullptr, annot.get()));
2355 ASSERT_TRUE(OpenDocument(
"listbox_form.pdf"));
2356 FPDF_PAGE page = LoadPage(0);
2360 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2363 EXPECT_EQ(3, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2368 EXPECT_EQ(26, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2376 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
2377 FPDF_PAGE page = LoadPage(0);
2382 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2385 EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2390 EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), annot.get()));
2398 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2399 FPDF_PAGE page = LoadPage(0);
2403 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2407 unsigned long length_bytes =
2408 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2409 ASSERT_EQ(8u, length_bytes);
2410 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
2411 EXPECT_EQ(8u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2412 buf.data(), length_bytes));
2413 EXPECT_EQ(L"Foo", GetPlatformWString(buf.data()));
2420 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2421 ASSERT_EQ(12u, length_bytes);
2422 buf = GetFPDFWideStringBuffer(length_bytes);
2423 EXPECT_EQ(12u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2424 buf.data(), length_bytes));
2425 EXPECT_EQ(L"Apple", GetPlatformWString(buf.data()));
2429 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2430 buf = GetFPDFWideStringBuffer(length_bytes);
2431 EXPECT_EQ(18u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2432 buf.data(), length_bytes));
2433 EXPECT_EQ(L"Zucchini", GetPlatformWString(buf.data()));
2436 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), -1,
2438 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 26,
2444 FPDFAnnot_GetOptionLabel(
nullptr, annot.get(), 0,
nullptr, 0));
2446 FPDFAnnot_GetOptionLabel(form_handle(),
nullptr, 0,
nullptr, 0));
2454 ASSERT_TRUE(OpenDocument(
"listbox_form.pdf"));
2455 FPDF_PAGE page = LoadPage(0);
2459 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2463 unsigned long length_bytes =
2464 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2465 ASSERT_EQ(8u, length_bytes);
2466 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
2467 EXPECT_EQ(8u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2468 buf.data(), length_bytes));
2469 EXPECT_EQ(L"Foo", GetPlatformWString(buf.data()));
2476 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2477 ASSERT_EQ(12u, length_bytes);
2478 buf = GetFPDFWideStringBuffer(length_bytes);
2479 EXPECT_EQ(12u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2480 buf.data(), length_bytes));
2481 EXPECT_EQ(L"Apple", GetPlatformWString(buf.data()));
2485 FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
nullptr, 0);
2486 ASSERT_EQ(18u, length_bytes);
2487 buf = GetFPDFWideStringBuffer(length_bytes);
2488 EXPECT_EQ(18u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index,
2489 buf.data(), length_bytes));
2490 EXPECT_EQ(L"Zucchini", GetPlatformWString(buf.data()));
2493 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), -1,
2495 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 26,
2504 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
2505 FPDF_PAGE page = LoadPage(0);
2510 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2513 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 0,
2519 EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 0,
2528 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2529 FPDF_PAGE page = LoadPage(0);
2533 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2537 int count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2538 ASSERT_EQ(3, count);
2539 for (
int i = 0; i < count; i++) {
2540 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2547 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2548 ASSERT_EQ(26, count);
2549 for (
int i = 0; i < count; i++) {
2551 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2555 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
2558 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
2564 FPDFAnnot_IsOptionSelected(form_handle(),
nullptr, 0));
2565 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(
nullptr, annot.get(), 0));
2573 ASSERT_TRUE(OpenDocument(
"listbox_form.pdf"));
2574 FPDF_PAGE page = LoadPage(0);
2578 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2582 int count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2583 ASSERT_EQ(3, count);
2584 for (
int i = 0; i < count; i++) {
2585 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2592 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2593 ASSERT_EQ(26, count);
2594 for (
int i = 0; i < count; i++) {
2596 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2604 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2605 ASSERT_EQ(5, count);
2606 for (
int i = 0; i < count; i++) {
2607 bool expected = (i == 1 || i == 3);
2609 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2617 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2618 ASSERT_EQ(5, count);
2619 for (
int i = 0; i < count; i++) {
2620 bool expected = (i == 2 || i == 4);
2622 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2630 count = FPDFAnnot_GetOptionCount(form_handle(), annot.get());
2631 ASSERT_EQ(5, count);
2632 for (
int i = 0; i < count; i++) {
2633 bool expected = (i == 0 || i == 2);
2635 FPDFAnnot_IsOptionSelected(form_handle(), annot.get(), i));
2644 ASSERT_TRUE(OpenDocument(
"multiple_form_types.pdf"));
2645 FPDF_PAGE page = LoadPage(0);
2649 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2653 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
2660 EXPECT_FALSE(FPDFAnnot_IsOptionSelected(form_handle(), annot.get(),
2669 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2670 FPDF_PAGE page = LoadPage(0);
2675 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2679 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2680 EXPECT_EQ(12.0, value);
2686 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_two));
2687 EXPECT_EQ(12.0, value_two);
2694 FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_three));
2695 EXPECT_EQ(12.0, value_three);
2703 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
2704 FPDF_PAGE page = LoadPage(0);
2709 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2713 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2714 EXPECT_EQ(12.0, value);
2720 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_two));
2721 EXPECT_EQ(12.0, value_two);
2728 FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_three));
2729 EXPECT_EQ(12.0, value_three);
2732 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_four));
2733 EXPECT_EQ(12.0, value_four);
2741 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
2742 FPDF_PAGE page = LoadPage(0);
2747 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2751 ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2756 ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2764 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2765 FPDF_PAGE page = LoadPage(0);
2769 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2774 ASSERT_FALSE(FPDFAnnot_GetFontSize(
nullptr, annot.get(), &value));
2775 ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(),
nullptr, &value));
2784 ASSERT_TRUE(OpenDocument(
"text_form_negative_fontsize.pdf"));
2785 FPDF_PAGE page = LoadPage(0);
2790 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2794 ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value));
2795 EXPECT_EQ(-12.0, value);
2804 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2805 FPDF_PAGE page = LoadPage(0);
2809 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
2811 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2820 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2821 FPDF_PAGE page = LoadPage(0);
2825 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2827 ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2836 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2837 FPDF_PAGE page = LoadPage(0);
2841 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 5));
2843 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2846 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2849 ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2858 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2859 FPDF_PAGE page = LoadPage(0);
2863 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
2865 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2868 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2871 ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2880 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
2881 FPDF_PAGE page = LoadPage(0);
2885 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2887 ASSERT_FALSE(FPDFAnnot_IsChecked(
nullptr, annot.get()));
2888 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(),
nullptr));
2897 ASSERT_TRUE(OpenDocument(
"text_form.pdf"));
2898 FPDF_PAGE page = LoadPage(0);
2902 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2904 ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get()));
2911 ASSERT_TRUE(OpenDocument(
"multiple_form_types.pdf"));
2912 FPDF_PAGE page = LoadPage(0);
2915 EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(form_handle(),
nullptr));
2918 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
2920 EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(
nullptr, annot.get()));
2923 constexpr int kExpectedAnnotTypes[] = {-1,
2930 for (size_t i = 0; i <
std::size(kExpectedAnnotTypes); ++i) {
2931 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i));
2933 EXPECT_EQ(kExpectedAnnotTypes[i],
2934 FPDFAnnot_GetFormFieldType(form_handle(), annot.get()));
2940 ASSERT_TRUE(OpenDocument(
"text_form_multiple.pdf"));
2941 FPDF_PAGE page = LoadPage(0);
2946 FPDFAnnot_GetFormFieldValue(form_handle(),
nullptr,
nullptr, 0));
2948 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2952 FPDFAnnot_GetFormFieldValue(
nullptr, annot.get(),
nullptr, 0));
2954 unsigned long length_bytes =
2955 FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
nullptr, 0);
2956 ASSERT_EQ(2u, length_bytes);
2957 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
2958 EXPECT_EQ(2u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
2959 buf.data(), length_bytes));
2960 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
2963 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
2966 unsigned long length_bytes =
2967 FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
nullptr, 0);
2968 ASSERT_EQ(18u, length_bytes);
2969 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
2970 EXPECT_EQ(18u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
2971 buf.data(), length_bytes));
2972 EXPECT_EQ(L"Elephant", GetPlatformWString(buf.data()));
2978 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
2979 FPDF_PAGE page = LoadPage(0);
2983 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
2986 unsigned long length_bytes =
2987 FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
nullptr, 0);
2988 ASSERT_EQ(2u, length_bytes);
2989 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
2990 EXPECT_EQ(2u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
2991 buf.data(), length_bytes));
2992 EXPECT_EQ(L"", GetPlatformWString(buf.data()));
2995 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
2998 unsigned long length_bytes =
2999 FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
nullptr, 0);
3000 ASSERT_EQ(14u, length_bytes);
3001 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3002 EXPECT_EQ(14u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(),
3003 buf.data(), length_bytes));
3004 EXPECT_EQ(L"Banana", GetPlatformWString(buf.data()));
3010 ASSERT_TRUE(OpenDocument(
"text_form.pdf"));
3011 FPDF_PAGE page = LoadPage(0);
3016 FPDFAnnot_GetFormFieldName(form_handle(),
nullptr,
nullptr, 0));
3018 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3021 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldName(
nullptr, annot.get(),
nullptr, 0));
3023 unsigned long length_bytes =
3024 FPDFAnnot_GetFormFieldName(form_handle(), annot.get(),
nullptr, 0);
3025 ASSERT_EQ(18u, length_bytes);
3026 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3027 EXPECT_EQ(18u, FPDFAnnot_GetFormFieldName(form_handle(), annot.get(),
3028 buf.data(), length_bytes));
3029 EXPECT_EQ(L"Text Box", GetPlatformWString(buf.data()));
3035 ASSERT_TRUE(OpenDocument(
"combobox_form.pdf"));
3036 FPDF_PAGE page = LoadPage(0);
3040 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3043 unsigned long length_bytes =
3044 FPDFAnnot_GetFormFieldName(form_handle(), annot.get(),
nullptr, 0);
3045 ASSERT_EQ(30u, length_bytes);
3046 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3047 EXPECT_EQ(30u, FPDFAnnot_GetFormFieldName(form_handle(), annot.get(),
3048 buf.data(), length_bytes));
3049 EXPECT_EQ(L"Combo_Editable", GetPlatformWString(buf.data()));
3055 ASSERT_TRUE(OpenDocument(
"annots.pdf"));
3056 FPDF_PAGE page = LoadPage(0);
3061 VerifyFocusableAnnotSubtypes(form_handle(), kDefaultSubtypes);
3064 const FPDF_ANNOTATION_SUBTYPE kExpectedAnnotSubtypes[] = {
3070 const FPDF_ANNOTATION_SUBTYPE kExpectedDefaultFocusableSubtypes[] = {
3072 VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
3073 kExpectedAnnotSubtypes,
3074 kExpectedDefaultFocusableSubtypes);
3077 ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes(form_handle(),
nullptr, 0));
3078 ASSERT_EQ(0, FPDFAnnot_GetFocusableSubtypesCount(form_handle()));
3082 SetAndVerifyFocusableAnnotSubtypes(form_handle(), kDefaultSubtypes);
3084 FPDFAnnot_SetFocusableSubtypes(form_handle(), kDefaultSubtypes, 0));
3085 ASSERT_EQ(0, FPDFAnnot_GetFocusableSubtypesCount(form_handle()));
3087 VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
3088 kExpectedAnnotSubtypes, {});
3092 SetAndVerifyFocusableAnnotSubtypes(form_handle(), kLinkSubtypes);
3094 const FPDF_ANNOTATION_SUBTYPE kExpectedLinkocusableSubtypes[] = {
3096 VerifyAnnotationSubtypesAndFocusability(form_handle(), page,
3097 kExpectedAnnotSubtypes,
3098 kExpectedLinkocusableSubtypes);
3101 EXPECT_FALSE(FPDFAnnot_SetFocusableSubtypes(
nullptr, kDefaultSubtypes,
3102 std::size(kDefaultSubtypes)));
3103 EXPECT_FALSE(FPDFAnnot_SetFocusableSubtypes(form_handle(),
nullptr,
3104 std::size(kDefaultSubtypes)));
3107 std::vector<FPDF_ANNOTATION_SUBTYPE> subtypes(1);
3108 EXPECT_FALSE(FPDFAnnot_GetFocusableSubtypes(
nullptr, subtypes.data(),
3111 FPDFAnnot_GetFocusableSubtypes(form_handle(),
nullptr, subtypes.size()));
3113 FPDFAnnot_GetFocusableSubtypes(form_handle(), subtypes.data(), 0));
3119 ASSERT_TRUE(OpenDocument(
"annots.pdf"));
3120 FPDF_PAGE page = LoadPage(0);
3124 const char* md5_sum = []() {
3126#if BUILDFLAG(IS_WIN)
3127 return "911a6dbe2209b5e9e7e0a09b98c12d2e";
3128#elif BUILDFLAG(IS_APPLE)
3129 return "be6dcf7a2129469020ec60e56c905a6e";
3131 return "c09b129c071ec1569deb003676b617b0";
3134#if BUILDFLAG(IS_APPLE)
3135 return "108a46c517c4eaace9982ee83e8e3296";
3137 return "5550d8dcb4d1af1f50e8b4bcaef2ee60";
3141 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3142 CompareBitmap(bitmap.get(), 612, 792, md5_sum);
3146 static constexpr FPDF_ANNOTATION_SUBTYPE kSubTypes[] = {
FPDF_ANNOT_LINK,
3148 constexpr int kSubTypesCount =
std::size(kSubTypes);
3150 FPDFAnnot_SetFocusableSubtypes(form_handle(), kSubTypes, kSubTypesCount));
3151 ASSERT_EQ(kSubTypesCount, FPDFAnnot_GetFocusableSubtypesCount(form_handle()));
3152 std::vector<FPDF_ANNOTATION_SUBTYPE> subtypes(kSubTypesCount);
3153 ASSERT_TRUE(FPDFAnnot_GetFocusableSubtypes(form_handle(), subtypes.data(),
3159 const char* md5_sum = []() {
3161#if BUILDFLAG(IS_WIN)
3162 return "27777b11ea1498200b42d00a083a598f";
3163#elif BUILDFLAG(IS_APPLE)
3164 return "6b820388ace6004e83cd17392dddf32e";
3166 return "277f1b9e70031539d034d22bc6064838";
3169#if BUILDFLAG(IS_APPLE)
3170 return "eb3869335e7a219e1b5f25c1c6037b97";
3172 return "805fe7bb751ac4ed2b82bb66efe6db40";
3176 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3179 EXPECT_TRUE(FORM_SetFocusedAnnot(form_handle(), annot.get()));
3180 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3181 CompareBitmap(bitmap.get(), 612, 792, md5_sum);
3185 const char* md5_sum = []() {
3187#if BUILDFLAG(IS_WIN)
3188 return "61594e370efd7cb9097d8036b168ff1f";
3189#elif BUILDFLAG(IS_APPLE)
3190 return "4d41eddb0aadc3db440cb83877bd52e4";
3192 return "d980005939cd4ae0a199d8600a0abdf3";
3195#if BUILDFLAG(IS_APPLE)
3196 return "d20b1978da2362d3942ea0fc6d230997";
3198 return "c5c5dcb462af3ef5f43b298ec048feef";
3202 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 4));
3205 EXPECT_TRUE(FORM_SetFocusedAnnot(form_handle(), annot.get()));
3206 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3207 CompareBitmap(bitmap.get(), 612, 792, md5_sum);
3214 ASSERT_TRUE(OpenDocument(
"annots.pdf"));
3215 FPDF_PAGE page = LoadPage(0);
3218 constexpr char kExpectedResult[] =
3219 "https://cs.chromium.org/chromium/src/third_party/pdfium/public/"
3222 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
3225 VerifyUriActionInLink(document(), FPDFAnnot_GetLink(annot.get()),
3230 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 4));
3233 EXPECT_FALSE(FPDFAnnot_GetLink(annot.get()));
3243 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3244 FPDF_PAGE page = LoadPage(0);
3250 FPDFAnnot_GetFormControlCount(form_handle(),
nullptr));
3252 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
3257 FPDFAnnot_GetFormControlCount(
nullptr, annot.get()));
3259 EXPECT_EQ(3, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
3267 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3268 FPDF_PAGE page = LoadPage(0);
3272 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3274 EXPECT_EQ(1, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
3282 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
3283 FPDF_PAGE page = LoadPage(0);
3287 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3289 EXPECT_EQ(-1, FPDFAnnot_GetFormControlCount(form_handle(), annot.get()));
3297 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3298 FPDF_PAGE page = LoadPage(0);
3304 FPDFAnnot_GetFormControlIndex(form_handle(),
nullptr));
3306 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
3311 FPDFAnnot_GetFormControlIndex(
nullptr, annot.get()));
3313 EXPECT_EQ(1, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
3321 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3322 FPDF_PAGE page = LoadPage(0);
3326 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3328 EXPECT_EQ(0, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
3336 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
3337 FPDF_PAGE page = LoadPage(0);
3341 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3343 EXPECT_EQ(-1, FPDFAnnot_GetFormControlIndex(form_handle(), annot.get()));
3351 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3352 FPDF_PAGE page = LoadPage(0);
3357 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue(
3358 form_handle(),
nullptr,
3361 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 6));
3365 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue(
3366 nullptr, annot.get(),
3369 unsigned long length_bytes =
3370 FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3372 ASSERT_EQ(14u, length_bytes);
3373 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3374 EXPECT_EQ(14u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3375 buf.data(), length_bytes));
3376 EXPECT_EQ(L"value2", GetPlatformWString(buf.data()));
3384 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3385 FPDF_PAGE page = LoadPage(0);
3389 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3392 unsigned long length_bytes =
3393 FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3395 ASSERT_EQ(8u, length_bytes);
3396 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3397 EXPECT_EQ(8u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3398 buf.data(), length_bytes));
3399 EXPECT_EQ(L"Yes", GetPlatformWString(buf.data()));
3407 ASSERT_TRUE(OpenDocument(
"annotation_ink_multiple.pdf"));
3408 FPDF_PAGE page = LoadPage(0);
3412 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3414 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldExportValue(form_handle(), annot.get(),
3423 ASSERT_TRUE(OpenDocument(
"redact_annot.pdf"));
3424 FPDF_PAGE page = LoadPage(0);
3429 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3438 ASSERT_TRUE(OpenDocument(
"polygon_annot.pdf"));
3439 FPDF_PAGE page = LoadPage(0);
3444 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3448 unsigned long size = FPDFAnnot_GetVertices(annot.get(),
nullptr, 0);
3449 const size_t kExpectedSize = 3;
3450 ASSERT_EQ(kExpectedSize, size);
3451 std::vector<FS_POINTF> vertices_buffer(size);
3453 FPDFAnnot_GetVertices(annot.get(), vertices_buffer.data(), size));
3454 EXPECT_FLOAT_EQ(159.0f, vertices_buffer[0].x);
3455 EXPECT_FLOAT_EQ(296.0f, vertices_buffer[0].y);
3456 EXPECT_FLOAT_EQ(350.0f, vertices_buffer[1].x);
3457 EXPECT_FLOAT_EQ(411.0f, vertices_buffer[1].y);
3458 EXPECT_FLOAT_EQ(472.0f, vertices_buffer[2].x);
3459 EXPECT_FLOAT_EQ(243.42f, vertices_buffer[2].y);
3465 vertices_buffer.resize(1);
3466 vertices_buffer[0].x = 42;
3467 vertices_buffer[0].y = 43;
3468 size = FPDFAnnot_GetVertices(annot.get(), vertices_buffer.data(),
3469 vertices_buffer.size());
3470 EXPECT_EQ(kExpectedSize, size);
3471 EXPECT_FLOAT_EQ(42, vertices_buffer[0].x);
3472 EXPECT_FLOAT_EQ(43, vertices_buffer[0].y);
3476 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
3481 unsigned long size = FPDFAnnot_GetVertices(annot.get(),
nullptr, 0);
3482 const size_t kExpectedSize = 3;
3483 ASSERT_EQ(kExpectedSize, size);
3484 std::vector<FS_POINTF> vertices_buffer(size);
3486 FPDFAnnot_GetVertices(annot.get(), vertices_buffer.data(), size));
3487 EXPECT_FLOAT_EQ(259.0f, vertices_buffer[0].x);
3488 EXPECT_FLOAT_EQ(396.0f, vertices_buffer[0].y);
3489 EXPECT_FLOAT_EQ(450.0f, vertices_buffer[1].x);
3490 EXPECT_FLOAT_EQ(511.0f, vertices_buffer[1].y);
3491 EXPECT_FLOAT_EQ(572.0f, vertices_buffer[2].x);
3492 EXPECT_FLOAT_EQ(343.0f, vertices_buffer[2].y);
3497 ScopedFPDFAnnotation ink_annot(FPDFPage_CreateAnnot(page,
FPDF_ANNOT_INK));
3498 EXPECT_EQ(0U, FPDFAnnot_GetVertices(ink_annot.get(),
nullptr, 0));
3505 ASSERT_TRUE(OpenDocument(
"ink_annot.pdf"));
3506 FPDF_PAGE page = LoadPage(0);
3511 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3516 unsigned long size = FPDFAnnot_GetInkListCount(annot.get());
3517 const size_t kExpectedSize = 1;
3518 ASSERT_EQ(kExpectedSize, size);
3519 const unsigned long kPathIndex = 0;
3520 unsigned long path_size =
3521 FPDFAnnot_GetInkListPath(annot.get(), kPathIndex,
nullptr, 0);
3522 const size_t kExpectedPathSize = 3;
3523 ASSERT_EQ(kExpectedPathSize, path_size);
3524 std::vector<FS_POINTF> path_buffer(path_size);
3525 EXPECT_EQ(path_size,
3526 FPDFAnnot_GetInkListPath(annot.get(), kPathIndex,
3527 path_buffer.data(), path_size));
3528 EXPECT_FLOAT_EQ(159.0f, path_buffer[0].x);
3529 EXPECT_FLOAT_EQ(296.0f, path_buffer[0].y);
3530 EXPECT_FLOAT_EQ(350.0f, path_buffer[1].x);
3531 EXPECT_FLOAT_EQ(411.0f, path_buffer[1].y);
3532 EXPECT_FLOAT_EQ(472.0f, path_buffer[2].x);
3533 EXPECT_FLOAT_EQ(243.42f, path_buffer[2].y);
3544 path_buffer.resize(1);
3545 path_buffer[0].x = 42;
3546 path_buffer[0].y = 43;
3547 path_size = FPDFAnnot_GetInkListPath(
3548 annot.get(), kPathIndex, path_buffer.data(), path_buffer.size());
3549 EXPECT_EQ(kExpectedPathSize, path_size);
3550 EXPECT_FLOAT_EQ(42, path_buffer[0].x);
3551 EXPECT_FLOAT_EQ(43, path_buffer[0].y);
3555 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
3560 unsigned long size = FPDFAnnot_GetInkListCount(annot.get());
3561 const size_t kExpectedSize = 1;
3562 ASSERT_EQ(kExpectedSize, size);
3563 const unsigned long kPathIndex = 0;
3564 unsigned long path_size =
3565 FPDFAnnot_GetInkListPath(annot.get(), kPathIndex,
nullptr, 0);
3566 const size_t kExpectedPathSize = 3;
3567 ASSERT_EQ(kExpectedPathSize, path_size);
3568 std::vector<FS_POINTF> path_buffer(path_size);
3569 EXPECT_EQ(path_size,
3570 FPDFAnnot_GetInkListPath(annot.get(), kPathIndex,
3571 path_buffer.data(), path_size));
3572 EXPECT_FLOAT_EQ(259.0f, path_buffer[0].x);
3573 EXPECT_FLOAT_EQ(396.0f, path_buffer[0].y);
3574 EXPECT_FLOAT_EQ(450.0f, path_buffer[1].x);
3575 EXPECT_FLOAT_EQ(511.0f, path_buffer[1].y);
3576 EXPECT_FLOAT_EQ(572.0f, path_buffer[2].x);
3577 EXPECT_FLOAT_EQ(343.0f, path_buffer[2].y);
3582 ScopedFPDFAnnotation polygon_annot(
3584 EXPECT_EQ(0U, FPDFAnnot_GetInkListCount(polygon_annot.get()));
3585 const unsigned long kPathIndex = 0;
3586 EXPECT_EQ(0U, FPDFAnnot_GetInkListPath(polygon_annot.get(), kPathIndex,
3594 ASSERT_TRUE(OpenDocument(
"line_annot.pdf"));
3595 FPDF_PAGE page = LoadPage(0);
3600 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3606 ASSERT_TRUE(FPDFAnnot_GetLine(annot.get(), &start, &end));
3607 EXPECT_FLOAT_EQ(159.0f, start.x);
3608 EXPECT_FLOAT_EQ(296.0f, start.y);
3609 EXPECT_FLOAT_EQ(472.0f, end.x);
3610 EXPECT_FLOAT_EQ(243.42f, end.y);
3614 EXPECT_FALSE(FPDFAnnot_GetLine(annot.get(),
nullptr,
nullptr));
3618 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
3624 EXPECT_FALSE(FPDFAnnot_GetLine(annot.get(), &start, &end));
3629 ScopedFPDFAnnotation ink_annot(FPDFPage_CreateAnnot(page,
FPDF_ANNOT_INK));
3632 EXPECT_FALSE(FPDFAnnot_GetLine(ink_annot.get(), &start, &end));
3639 ASSERT_TRUE(OpenDocument(
"line_annot.pdf"));
3640 FPDF_PAGE page = LoadPage(0);
3645 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3649 float horizontal_radius;
3650 float vertical_radius;
3652 ASSERT_TRUE(FPDFAnnot_GetBorder(annot.get(), &horizontal_radius,
3653 &vertical_radius, &border_width));
3654 EXPECT_FLOAT_EQ(0.25f, horizontal_radius);
3655 EXPECT_FLOAT_EQ(0.5f, vertical_radius);
3656 EXPECT_FLOAT_EQ(2.0f, border_width);
3660 EXPECT_FALSE(FPDFAnnot_GetBorder(annot.get(),
nullptr,
nullptr,
nullptr));
3664 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
3668 float horizontal_radius;
3669 float vertical_radius;
3671 EXPECT_FALSE(FPDFAnnot_GetBorder(annot.get(), &horizontal_radius,
3672 &vertical_radius, &border_width));
3675 EXPECT_TRUE(FPDFAnnot_SetBorder(annot.get(), 2.0f,
3679 EXPECT_TRUE(FPDFAnnot_GetBorder(annot.get(), &horizontal_radius,
3680 &vertical_radius, &border_width));
3681 EXPECT_FLOAT_EQ(2.0f, horizontal_radius);
3682 EXPECT_FLOAT_EQ(3.5f, vertical_radius);
3683 EXPECT_FLOAT_EQ(4.0f, border_width);
3695 ASSERT_TRUE(OpenDocument(
"annot_javascript.pdf"));
3696 FPDF_PAGE page = LoadPage(0);
3701 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3705 unsigned long length_bytes = FPDFAnnot_GetFormAdditionalActionJavaScript(
3707 ASSERT_EQ(62u, length_bytes);
3708 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3709 EXPECT_EQ(62u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3711 buf.data(), length_bytes));
3712 EXPECT_EQ(L"AFDate_FormatEx(\"yyyy-mm-dd\");",
3713 GetPlatformWString(buf.data()));
3716 EXPECT_EQ(0u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3717 form_handle(),
nullptr, 0,
nullptr, 0));
3718 EXPECT_EQ(0u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3719 nullptr, annot.get(), 0,
nullptr, 0));
3720 EXPECT_EQ(0u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3721 form_handle(), annot.get(), 0,
nullptr, 0));
3722 EXPECT_EQ(2u, FPDFAnnot_GetFormAdditionalActionJavaScript(
3731 ASSERT_TRUE(OpenDocument(
"click_form.pdf"));
3732 FPDF_PAGE page = LoadPage(0);
3737 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
3741 unsigned long length_bytes = FPDFAnnot_GetFormFieldAlternateName(
3742 form_handle(), annot.get(),
nullptr, 0);
3743 ASSERT_EQ(34u, length_bytes);
3744 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
3745 EXPECT_EQ(34u, FPDFAnnot_GetFormFieldAlternateName(
3746 form_handle(), annot.get(), buf.data(), length_bytes));
3747 EXPECT_EQ(L"readOnlyCheckbox", GetPlatformWString(buf.data()));
3750 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldAlternateName(form_handle(),
nullptr,
3752 EXPECT_EQ(0u, FPDFAnnot_GetFormFieldAlternateName(
nullptr, annot.get(),
3763 ASSERT_TRUE(OpenDocument(
"annots.pdf"));
3764 FPDF_PAGE page = LoadPage(1);
3768 const char* original_checksum = []() {
3770#if BUILDFLAG(IS_WIN)
3771 return "36ab186e78c0b88eeb8f7aceea93b72c";
3772#elif BUILDFLAG(IS_APPLE)
3773 return "953b14259560aeca886ea44c9529892b";
3775 return "238dccc7df0ac61ac580c28e1109da3c";
3778#if BUILDFLAG(IS_APPLE)
3779 return "522a4a6b6c7eab5bf95ded1f21ea372e";
3781 return "12127303aecd80c6288460f7c0d79f3f";
3784 const char* modified_checksum = []() {
3786#if BUILDFLAG(IS_WIN)
3787 return "ece1ab24a0d9425ef3b06747c95d75ce";
3788#elif BUILDFLAG(IS_APPLE)
3789 return "bfc344e98798298bf7bb0953db75c686";
3791 return "0f326acb3eb583125ca584d703ccb13b";
3794#if BUILDFLAG(IS_APPLE)
3795 return "6844019e07b83cc01723415f58218d06";
3797 return "73d06ff4c665fe85029acef30240dcca";
3802 ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2));
3807 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3808 CompareBitmap(bitmap.get(), 612, 792, original_checksum);
3811 EXPECT_TRUE(FPDFAnnot_SetBorder(annot.get(), 2.0f,
3816 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT);
3817 CompareBitmap(bitmap.get(), 612, 792, modified_checksum);
3822 EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this, 0));
3825 ASSERT_TRUE(OpenSavedDocument());
3826 page = LoadSavedPage(1);
3828 VerifySavedRendering(page, 612, 792, modified_checksum);
3830 CloseSavedPage(page);
3831 CloseSavedDocument();
static bool UseSkiaRenderer()
const CPDF_Dictionary * GetAnnotDict() const
bool KeyExist(const ByteString &key) const
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetFontSize(FPDF_FORMHANDLE hHandle, FPDF_ANNOTATION annot, float *value)
#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 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
#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_BOOL FPDF_CALLCONV FPDFAnnot_RemoveInkList(FPDF_ANNOTATION annot)
TEST_F(FPDFAnnotEmbedderTest, SetAP)
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_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 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 void 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
const char kBlankPage612By792Checksum[]
const char * AnnotationStampWithApChecksum()
const char * HelloWorldChecksum()