blob: 70e184dd410779c5526eb53c59f3f82358474237 [file] [log] [blame]
Jane Liu4fd9a472017-06-01 18:56:09 -04001// Copyright 2017 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00005#include <cwchar>
Jane Liu20eafda2017-06-07 10:33:24 -04006#include <memory>
7#include <string>
Jane Liu4fd9a472017-06-01 18:56:09 -04008#include <vector>
9
Jane Liubaa7ff42017-06-29 19:18:23 -040010#include "core/fxcrt/fx_system.h"
Lei Zhanga21d5932018-02-05 18:28:38 +000011#include "public/cpp/fpdf_deleters.h"
Jane Liu4fd9a472017-06-01 18:56:09 -040012#include "public/fpdf_annot.h"
Jane Liubaa7ff42017-06-29 19:18:23 -040013#include "public/fpdf_edit.h"
Jane Liu4fd9a472017-06-01 18:56:09 -040014#include "public/fpdfview.h"
15#include "testing/embedder_test.h"
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +000016#include "testing/gmock/include/gmock/gmock-matchers.h"
Jane Liu4fd9a472017-06-01 18:56:09 -040017#include "testing/gtest/include/gtest/gtest.h"
18
Lei Zhangdf064df2017-08-31 02:33:27 -070019static constexpr char kContentsKey[] = "Contents";
20
Nicolas Pena3ff54002017-07-05 11:55:35 -040021class FPDFAnnotEmbeddertest : public EmbedderTest {};
Jane Liu4fd9a472017-06-01 18:56:09 -040022
Lei Zhang4afee172018-01-10 20:57:15 +000023std::wstring BufferToWString(const std::vector<char>& buf) {
24 return GetPlatformWString(reinterpret_cast<FPDF_WIDESTRING>(buf.data()));
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +000025}
26
Lei Zhang4afee172018-01-10 20:57:15 +000027std::string BufferToString(const std::vector<char>& buf) {
28 return GetPlatformString(reinterpret_cast<FPDF_WIDESTRING>(buf.data()));
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +000029}
30
Jane Liue17011d2017-06-21 12:18:37 -040031TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) {
32 // Open a file with one annotation and load its first page.
33 ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +000034 FPDF_PAGE page = LoadPage(0);
Jane Liue17011d2017-06-21 12:18:37 -040035 ASSERT_TRUE(page);
36
37 // This annotation has a malformed appearance stream, which does not have its
38 // normal appearance defined, only its rollover appearance. In this case, its
39 // normal appearance should be generated, allowing the highlight annotation to
40 // still display.
Lei Zhanga98e3662018-02-07 20:28:35 +000041 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
42 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
43 CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
Jane Liue17011d2017-06-21 12:18:37 -040044
45 UnloadPage(page);
46}
47
Jane Liu4fd9a472017-06-01 18:56:09 -040048TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) {
49 // Open a file with one annotation and load its first page.
50 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +000051 // TODO(thestig): This test should use LoadPage() and UnloadPage(), but one of
52 // the FORM API calls in LoadPage() makes this test fail. So use
53 // FPDF_LoadPage() and FPDF_ClosePage() for now.
Jane Liu4fd9a472017-06-01 18:56:09 -040054 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
55 ASSERT_TRUE(page);
56
57 // Check that there is a total of 1 annotation on its first page.
58 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
59
60 // Check that the annotation is of type "highlight".
Lei Zhanga21d5932018-02-05 18:28:38 +000061 {
62 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
63 FPDFPage_GetAnnot(page, 0));
64 ASSERT_TRUE(annot);
65 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
Jane Liu4fd9a472017-06-01 18:56:09 -040066
Lei Zhanga21d5932018-02-05 18:28:38 +000067 // Check that the annotation color is yellow.
68 unsigned int R;
69 unsigned int G;
70 unsigned int B;
71 unsigned int A;
Lei Zhang75c81712018-02-08 17:22:39 +000072 ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R,
Lei Zhanga21d5932018-02-05 18:28:38 +000073 &G, &B, &A));
74 EXPECT_EQ(255u, R);
75 EXPECT_EQ(255u, G);
76 EXPECT_EQ(0u, B);
77 EXPECT_EQ(255u, A);
Jane Liu4fd9a472017-06-01 18:56:09 -040078
Lei Zhanga21d5932018-02-05 18:28:38 +000079 // Check that the author is correct.
80 static constexpr char kAuthorKey[] = "T";
81 EXPECT_EQ(FPDF_OBJECT_STRING,
82 FPDFAnnot_GetValueType(annot.get(), kAuthorKey));
83 unsigned long len =
84 FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, nullptr, 0);
85 std::vector<char> buf(len);
86 EXPECT_EQ(28u, FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, buf.data(),
87 len));
88 EXPECT_STREQ(L"Jae Hyun Park", BufferToWString(buf).c_str());
Jane Liu4fd9a472017-06-01 18:56:09 -040089
Lei Zhanga21d5932018-02-05 18:28:38 +000090 // Check that the content is correct.
91 EXPECT_EQ(FPDF_OBJECT_STRING,
92 FPDFAnnot_GetValueType(annot.get(), kContentsKey));
93 len = FPDFAnnot_GetStringValue(annot.get(), kContentsKey, nullptr, 0);
94 buf.clear();
95 buf.resize(len);
96 EXPECT_EQ(2690u, FPDFAnnot_GetStringValue(annot.get(), kContentsKey,
97 buf.data(), len));
98 const wchar_t contents[] =
99 L"This is a note for that highlight annotation. Very long highlight "
100 "annotation. Long long long Long long longLong long longLong long "
101 "longLong long longLong long longLong long longLong long longLong long "
102 "longLong long longLong long longLong long longLong long longLong long "
103 "longLong long longLong long longLong long longLong long longLong long "
104 "longLong long longLong long longLong long longLong long longLong long "
105 "longLong long longLong long longLong long longLong long longLong long "
106 "longLong long longLong long longLong long longLong long longLong long "
107 "longLong long longLong long longLong long longLong long longLong long "
108 "longLong long longLong long longLong long longLong long longLong long "
109 "longLong long longLong long longLong long longLong long longLong long "
110 "longLong long longLong long longLong long longLong long longLong long "
111 "longLong long longLong long longLong long longLong long longLong long "
112 "longLong long longLong long longLong long longLong long longLong long "
113 "longLong long longLong long longLong long longLong long longLong long "
114 "longLong long longLong long longLong long longLong long longLong long "
115 "longLong long longLong long longLong long longLong long longLong long "
116 "longLong long longLong long longLong long longLong long longLong long "
117 "longLong long longLong long longLong long longLong long longLong long "
118 "longLong long long. END";
119 EXPECT_STREQ(contents, BufferToWString(buf).c_str());
Jane Liu4fd9a472017-06-01 18:56:09 -0400120
Lei Zhanga21d5932018-02-05 18:28:38 +0000121 // Check that the quadpoints are correct.
122 FS_QUADPOINTSF quadpoints;
123 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
124 EXPECT_EQ(115.802643f, quadpoints.x1);
125 EXPECT_EQ(718.913940f, quadpoints.y1);
126 EXPECT_EQ(157.211182f, quadpoints.x4);
127 EXPECT_EQ(706.264465f, quadpoints.y4);
128 }
Lei Zhang75c81712018-02-08 17:22:39 +0000129 FPDF_ClosePage(page);
Jane Liu4fd9a472017-06-01 18:56:09 -0400130}
131
132TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) {
133 // Open a file with three annotations and load its first page.
134 ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000135 // TODO(thestig): This test should use LoadPage() and UnloadPage(), but one of
136 // the FORM API calls in LoadPage() makes this test fail. So use
137 // FPDF_LoadPage() and FPDF_ClosePage() for now.
Jane Liu4fd9a472017-06-01 18:56:09 -0400138 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
139 ASSERT_TRUE(page);
140
141 // Check that there is a total of 3 annotation on its first page.
142 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
143
Lei Zhanga21d5932018-02-05 18:28:38 +0000144 {
145 // Check that the third annotation is of type "ink".
146 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
147 FPDFPage_GetAnnot(page, 2));
148 ASSERT_TRUE(annot);
149 EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot.get()));
Jane Liu4fd9a472017-06-01 18:56:09 -0400150
Lei Zhanga21d5932018-02-05 18:28:38 +0000151 // Check that the annotation color is blue with opacity.
152 unsigned int R;
153 unsigned int G;
154 unsigned int B;
155 unsigned int A;
Lei Zhang75c81712018-02-08 17:22:39 +0000156 ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R,
Lei Zhanga21d5932018-02-05 18:28:38 +0000157 &G, &B, &A));
158 EXPECT_EQ(0u, R);
159 EXPECT_EQ(0u, G);
160 EXPECT_EQ(255u, B);
161 EXPECT_EQ(76u, A);
Jane Liu4fd9a472017-06-01 18:56:09 -0400162
Lei Zhanga21d5932018-02-05 18:28:38 +0000163 // Check that there is no content.
164 EXPECT_EQ(2u,
165 FPDFAnnot_GetStringValue(annot.get(), kContentsKey, nullptr, 0));
Jane Liu4fd9a472017-06-01 18:56:09 -0400166
Lei Zhanga21d5932018-02-05 18:28:38 +0000167 // Check that the rectange coordinates are correct.
168 // Note that upon rendering, the rectangle coordinates will be adjusted.
169 FS_RECTF rect;
170 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
171 EXPECT_EQ(351.820404f, rect.left);
172 EXPECT_EQ(583.830688f, rect.bottom);
173 EXPECT_EQ(475.336090f, rect.right);
174 EXPECT_EQ(681.535034f, rect.top);
175 }
Lei Zhang75c81712018-02-08 17:22:39 +0000176 FPDF_ClosePage(page);
Jane Liu4fd9a472017-06-01 18:56:09 -0400177}
Jane Liu20eafda2017-06-07 10:33:24 -0400178
179TEST_F(FPDFAnnotEmbeddertest, AddIllegalSubtypeAnnotation) {
180 // Open a file with one annotation and load its first page.
181 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000182 FPDF_PAGE page = LoadPage(0);
Jane Liu20eafda2017-06-07 10:33:24 -0400183 ASSERT_TRUE(page);
184
185 // Add an annotation with an illegal subtype.
Jane Liud60e9ad2017-06-26 11:28:36 -0400186 ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1));
Jane Liu20eafda2017-06-07 10:33:24 -0400187
188 UnloadPage(page);
189}
190
Jane Liud321ef92017-06-14 09:56:22 -0400191TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) {
Jane Liu20eafda2017-06-07 10:33:24 -0400192 // Open a file with no annotation and load its first page.
193 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000194 FPDF_PAGE page = LoadPage(0);
Jane Liu20eafda2017-06-07 10:33:24 -0400195 ASSERT_TRUE(page);
196 EXPECT_EQ(0, FPDFPage_GetAnnotCount(page));
197
Lei Zhanga21d5932018-02-05 18:28:38 +0000198 {
199 // Add a text annotation to the page.
200 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
201 FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT));
202 ASSERT_TRUE(annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400203
Lei Zhanga21d5932018-02-05 18:28:38 +0000204 // Check that there is now 1 annotations on this page.
205 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
Jane Liu20eafda2017-06-07 10:33:24 -0400206
Lei Zhanga21d5932018-02-05 18:28:38 +0000207 // Check that the subtype of the annotation is correct.
208 EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get()));
209 }
Jane Liue10509a2017-06-20 16:47:41 -0400210
Lei Zhanga21d5932018-02-05 18:28:38 +0000211 {
212 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
213 FPDFPage_GetAnnot(page, 0));
214 ASSERT_TRUE(annot);
215 EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get()));
Jane Liu20eafda2017-06-07 10:33:24 -0400216
Lei Zhanga21d5932018-02-05 18:28:38 +0000217 // Set the color of the annotation.
218 ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 51,
219 102, 153, 204));
220 // Check that the color has been set correctly.
221 unsigned int R;
222 unsigned int G;
223 unsigned int B;
224 unsigned int A;
Lei Zhang75c81712018-02-08 17:22:39 +0000225 ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R,
Lei Zhanga21d5932018-02-05 18:28:38 +0000226 &G, &B, &A));
227 EXPECT_EQ(51u, R);
228 EXPECT_EQ(102u, G);
229 EXPECT_EQ(153u, B);
230 EXPECT_EQ(204u, A);
Jane Liu20eafda2017-06-07 10:33:24 -0400231
Lei Zhanga21d5932018-02-05 18:28:38 +0000232 // Change the color of the annotation.
233 ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 204,
234 153, 102, 51));
235 // Check that the color has been set correctly.
Lei Zhang75c81712018-02-08 17:22:39 +0000236 ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R,
Lei Zhanga21d5932018-02-05 18:28:38 +0000237 &G, &B, &A));
238 EXPECT_EQ(204u, R);
239 EXPECT_EQ(153u, G);
240 EXPECT_EQ(102u, B);
241 EXPECT_EQ(51u, A);
Jane Liu20eafda2017-06-07 10:33:24 -0400242
Lei Zhanga21d5932018-02-05 18:28:38 +0000243 // Set the annotation rectangle.
244 FS_RECTF rect;
245 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
246 EXPECT_EQ(0.f, rect.left);
247 EXPECT_EQ(0.f, rect.right);
248 rect.left = 35;
249 rect.bottom = 150;
250 rect.right = 53;
251 rect.top = 165;
252 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
253 // Check that the annotation rectangle has been set correctly.
254 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
255 EXPECT_EQ(35.f, rect.left);
256 EXPECT_EQ(150.f, rect.bottom);
257 EXPECT_EQ(53.f, rect.right);
258 EXPECT_EQ(165.f, rect.top);
Jane Liu20eafda2017-06-07 10:33:24 -0400259
Lei Zhanga21d5932018-02-05 18:28:38 +0000260 // Set the content of the annotation.
261 static constexpr wchar_t kContents[] =
262 L"Hello! This is a customized content.";
263 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
264 GetFPDFWideString(kContents);
265 ASSERT_TRUE(
266 FPDFAnnot_SetStringValue(annot.get(), kContentsKey, text.get()));
267 // Check that the content has been set correctly.
268 unsigned long len =
269 FPDFAnnot_GetStringValue(annot.get(), kContentsKey, nullptr, 0);
270 std::vector<char> buf(len);
271 EXPECT_EQ(74u, FPDFAnnot_GetStringValue(annot.get(), kContentsKey,
272 buf.data(), len));
273 EXPECT_STREQ(kContents, BufferToWString(buf).c_str());
274 }
Jane Liu20eafda2017-06-07 10:33:24 -0400275 UnloadPage(page);
276}
277
278TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
279 // Open a file with one annotation and load its first page.
280 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000281 FPDF_PAGE page = LoadPage(0);
Jane Liu20eafda2017-06-07 10:33:24 -0400282 ASSERT_TRUE(page);
283
284 // Check that there is a total of one annotation on its first page, and verify
285 // its quadpoints.
286 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400287 FS_QUADPOINTSF quadpoints;
Lei Zhanga21d5932018-02-05 18:28:38 +0000288 {
289 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
290 FPDFPage_GetAnnot(page, 0));
291 ASSERT_TRUE(annot);
292 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
293 EXPECT_EQ(115.802643f, quadpoints.x1);
294 EXPECT_EQ(718.913940f, quadpoints.y1);
295 EXPECT_EQ(157.211182f, quadpoints.x4);
296 EXPECT_EQ(706.264465f, quadpoints.y4);
297 }
Jane Liu20eafda2017-06-07 10:33:24 -0400298
299 // Add an underline annotation to the page and set its quadpoints.
Lei Zhanga21d5932018-02-05 18:28:38 +0000300 {
301 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
302 FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE));
303 ASSERT_TRUE(annot);
304 quadpoints.x1 = 140.802643f;
305 quadpoints.x3 = 140.802643f;
306 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), &quadpoints));
307 }
Jane Liu20eafda2017-06-07 10:33:24 -0400308
309 // Save the document, closing the page and document.
310 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +0000311 UnloadPage(page);
Jane Liu20eafda2017-06-07 10:33:24 -0400312
313 // Open the saved document.
Henrique Nakashima09b41922017-10-27 20:39:29 +0000314 const char md5[] = "dba153419f67b7c0c0e3d22d3e8910d5";
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400315
316 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000317 page = LoadSavedPage(0);
318 VerifySavedRendering(page, 612, 792, md5);
Jane Liu20eafda2017-06-07 10:33:24 -0400319
320 // Check that the saved document has 2 annotations on the first page
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000321 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
Jane Liu20eafda2017-06-07 10:33:24 -0400322
Lei Zhanga21d5932018-02-05 18:28:38 +0000323 {
324 // Check that the second annotation is an underline annotation and verify
325 // its quadpoints.
326 std::unique_ptr<void, FPDFAnnotationDeleter> new_annot(
327 FPDFPage_GetAnnot(page, 1));
328 ASSERT_TRUE(new_annot);
329 EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot.get()));
330 FS_QUADPOINTSF new_quadpoints;
331 ASSERT_TRUE(
332 FPDFAnnot_GetAttachmentPoints(new_annot.get(), &new_quadpoints));
333 EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f);
334 EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f);
335 EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f);
336 EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f);
337 }
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400338
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000339 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400340 CloseSavedDocument();
Jane Liu20eafda2017-06-07 10:33:24 -0400341}
Jane Liu06462752017-06-27 16:41:14 -0400342
343TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400344#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liub370e5a2017-08-16 13:24:58 -0400345 const char md5_original[] = "63af8432fab95a67cdebb7cd0e514941";
346 const char md5_modified_highlight[] = "aec26075011349dec9bace891856b5f2";
347 const char md5_modified_square[] = "057f57a32be95975775e5ec513fdcb56";
Dan Sinclair698aed72017-09-26 16:24:49 -0400348#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Henrique Nakashima09b41922017-10-27 20:39:29 +0000349 const char md5_original[] = "0e27376094f11490f74c65f3dc3a42c5";
350 const char md5_modified_highlight[] = "66f3caef3a7d488a4fa1ad37fc06310e";
351 const char md5_modified_square[] = "a456dad0bc6801ee2d6408a4394af563";
Jane Liub370e5a2017-08-16 13:24:58 -0400352#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000353 const char md5_original[] = "0e27376094f11490f74c65f3dc3a42c5";
354 const char md5_modified_highlight[] = "66f3caef3a7d488a4fa1ad37fc06310e";
355 const char md5_modified_square[] = "a456dad0bc6801ee2d6408a4394af563";
Jane Liub370e5a2017-08-16 13:24:58 -0400356#endif
357
Jane Liu06462752017-06-27 16:41:14 -0400358 // Open a file with four annotations and load its first page.
359 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000360 FPDF_PAGE page = LoadPage(0);
Jane Liu06462752017-06-27 16:41:14 -0400361 ASSERT_TRUE(page);
362 EXPECT_EQ(4, FPDFPage_GetAnnotCount(page));
363
Jane Liub370e5a2017-08-16 13:24:58 -0400364 // Check that the original file renders correctly.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000365 {
366 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
367 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
368 CompareBitmap(bitmap.get(), 612, 792, md5_original);
369 }
Jane Liub370e5a2017-08-16 13:24:58 -0400370
Jane Liu0c6b07d2017-08-15 10:50:22 -0400371 FS_RECTF rect;
Jane Liu0c6b07d2017-08-15 10:50:22 -0400372 FS_RECTF new_rect;
Lei Zhanga21d5932018-02-05 18:28:38 +0000373
374 // Retrieve the highlight annotation which has its AP stream already defined.
375 {
376 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
377 FPDFPage_GetAnnot(page, 0));
378 ASSERT_TRUE(annot);
379 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
380
381 // Check that color cannot be set when an AP stream is defined already.
382 EXPECT_FALSE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 51,
383 102, 153, 204));
384
385 // Verify its attachment points.
386 FS_QUADPOINTSF quadpoints;
387 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
388 EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
389 EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
390 EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
391 EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
392
393 // Check that updating the attachment points would succeed.
394 quadpoints.x1 -= 50.f;
395 quadpoints.x2 -= 50.f;
396 quadpoints.x3 -= 50.f;
397 quadpoints.x4 -= 50.f;
398 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), &quadpoints));
399 FS_QUADPOINTSF new_quadpoints;
400 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &new_quadpoints));
401 EXPECT_EQ(quadpoints.x1, new_quadpoints.x1);
402 EXPECT_EQ(quadpoints.y1, new_quadpoints.y1);
403 EXPECT_EQ(quadpoints.x4, new_quadpoints.x4);
404 EXPECT_EQ(quadpoints.y4, new_quadpoints.y4);
405
406 // Check that updating quadpoints does not change the annotation's position.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000407 {
408 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
409 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
410 CompareBitmap(bitmap.get(), 612, 792, md5_original);
411 }
Lei Zhanga21d5932018-02-05 18:28:38 +0000412
413 // Verify its annotation rectangle.
414 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
415 EXPECT_NEAR(67.7299f, rect.left, 0.001f);
416 EXPECT_NEAR(704.296f, rect.bottom, 0.001f);
417 EXPECT_NEAR(136.325f, rect.right, 0.001f);
418 EXPECT_NEAR(721.292f, rect.top, 0.001f);
419
420 // Check that updating the rectangle would succeed.
421 rect.left -= 60.f;
422 rect.right -= 60.f;
423 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
424 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
425 EXPECT_EQ(rect.right, new_rect.right);
426 }
Jane Liu06462752017-06-27 16:41:14 -0400427
Jane Liub370e5a2017-08-16 13:24:58 -0400428 // Check that updating the rectangle changes the annotation's position.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000429 {
430 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
431 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
432 CompareBitmap(bitmap.get(), 612, 792, md5_modified_highlight);
433 }
Jane Liub370e5a2017-08-16 13:24:58 -0400434
Lei Zhanga21d5932018-02-05 18:28:38 +0000435 {
436 // Retrieve the square annotation which has its AP stream already defined.
437 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
438 FPDFPage_GetAnnot(page, 2));
439 ASSERT_TRUE(annot);
440 EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot.get()));
Jane Liu06462752017-06-27 16:41:14 -0400441
Lei Zhanga21d5932018-02-05 18:28:38 +0000442 // Check that updating the rectangle would succeed.
443 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
444 rect.left += 70.f;
445 rect.right += 70.f;
446 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
447 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
448 EXPECT_EQ(rect.right, new_rect.right);
Jane Liu06462752017-06-27 16:41:14 -0400449
Lei Zhanga21d5932018-02-05 18:28:38 +0000450 // Check that updating the rectangle changes the square annotation's
451 // position.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000452 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
453 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
454 CompareBitmap(bitmap.get(), 612, 792, md5_modified_square);
Lei Zhanga21d5932018-02-05 18:28:38 +0000455 }
Jane Liub370e5a2017-08-16 13:24:58 -0400456
Jane Liu06462752017-06-27 16:41:14 -0400457 UnloadPage(page);
458}
Jane Liu8ce58f52017-06-29 13:40:22 -0400459
460TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) {
461 // Open a file with 3 annotations on its first page.
462 ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000463 // TODO(thestig): This test should use LoadPage() and UnloadPage(), but one of
464 // the FORM API calls in LoadPage() makes this test fail. So use
465 // FPDF_LoadPage() and FPDF_ClosePage() for now.
Jane Liu8ce58f52017-06-29 13:40:22 -0400466 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
467 ASSERT_TRUE(page);
468 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
469
Jane Liu0c6b07d2017-08-15 10:50:22 -0400470 FS_RECTF rect;
Jane Liu8ce58f52017-06-29 13:40:22 -0400471
Lei Zhanga21d5932018-02-05 18:28:38 +0000472 // Check that the annotations have the expected rectangle coordinates.
473 {
474 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
475 FPDFPage_GetAnnot(page, 0));
476 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
477 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
478 }
Jane Liu8ce58f52017-06-29 13:40:22 -0400479
Lei Zhanga21d5932018-02-05 18:28:38 +0000480 {
481 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
482 FPDFPage_GetAnnot(page, 1));
483 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
484 EXPECT_NEAR(149.8127f, rect.left, 0.001f);
485 }
486
487 {
488 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
489 FPDFPage_GetAnnot(page, 2));
490 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
491 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
492 }
Jane Liu8ce58f52017-06-29 13:40:22 -0400493
494 // Check that nothing happens when attempting to remove an annotation with an
495 // out-of-bound index.
496 EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4));
497 EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1));
498 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
499
500 // Remove the second annotation.
501 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1));
502 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
503 EXPECT_FALSE(FPDFPage_GetAnnot(page, 2));
504
505 // Save the document, closing the page and document.
506 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
507 FPDF_ClosePage(page);
508
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400509 // TODO(npm): VerifySavedRendering changes annot rect dimensions by 1??
Jane Liu8ce58f52017-06-29 13:40:22 -0400510 // Open the saved document.
511 std::string new_file = GetString();
512 FPDF_FILEACCESS file_access;
513 memset(&file_access, 0, sizeof(file_access));
514 file_access.m_FileLen = new_file.size();
515 file_access.m_GetBlock = GetBlockFromString;
516 file_access.m_Param = &new_file;
517 FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
518 ASSERT_TRUE(new_doc);
519 FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
520 ASSERT_TRUE(new_page);
521
522 // Check that the saved document has 2 annotations on the first page.
523 EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page));
524
Lei Zhanga21d5932018-02-05 18:28:38 +0000525 // Check that the remaining 2 annotations are the original 1st and 3rd ones
526 // by verifying their rectangle coordinates.
527 {
528 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
529 FPDFPage_GetAnnot(new_page, 0));
530 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
531 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
532 }
Jane Liu8ce58f52017-06-29 13:40:22 -0400533
Lei Zhanga21d5932018-02-05 18:28:38 +0000534 {
535 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
536 FPDFPage_GetAnnot(new_page, 1));
537 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
538 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
539 }
Jane Liubaa7ff42017-06-29 19:18:23 -0400540 FPDF_ClosePage(new_page);
541 FPDF_CloseDocument(new_doc);
542}
Jane Liu8ce58f52017-06-29 13:40:22 -0400543
Jane Liubaa7ff42017-06-29 19:18:23 -0400544TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400545#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400546 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
Dan Sinclair844d79e2018-02-16 03:46:26 +0000547 const char md5_modified_path[] = "873b92ea83ccf006e58415d866ce145b";
548 const char md5_two_paths[] = "6f1f1c91f50240e9cc9d7c87c48b93a7";
549 const char md5_new_annot[] = "078bf58f939645ac305854f31ee9a828";
Jane Liubaa7ff42017-06-29 19:18:23 -0400550#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000551 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
Dan Sinclair844d79e2018-02-16 03:46:26 +0000552 const char md5_modified_path[] = "5a4a6091cff648a4ece3ce7e245e3e38";
553 const char md5_two_paths[] = "d6e4072a4415cfc6ec17201fb6be0ee0";
554 const char md5_new_annot[] = "fc338b97bf66a656916c6198697a8a28";
Jane Liubaa7ff42017-06-29 19:18:23 -0400555#endif
556
557 // Open a file with two annotations and load its first page.
558 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000559 FPDF_PAGE page = LoadPage(0);
Jane Liubaa7ff42017-06-29 19:18:23 -0400560 ASSERT_TRUE(page);
561 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
562
563 // Check that the page renders correctly.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000564 {
565 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
566 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
567 CompareBitmap(bitmap.get(), 595, 842, md5_original);
568 }
Jane Liubaa7ff42017-06-29 19:18:23 -0400569
Lei Zhanga21d5932018-02-05 18:28:38 +0000570 {
571 // Retrieve the stamp annotation which has its AP stream already defined.
572 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
573 FPDFPage_GetAnnot(page, 0));
574 ASSERT_TRUE(annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400575
Lei Zhanga21d5932018-02-05 18:28:38 +0000576 // Check that this annotation has one path object and retrieve it.
577 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
578 FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot.get(), 1);
579 EXPECT_FALSE(path);
580 path = FPDFAnnot_GetObject(annot.get(), 0);
581 EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
582 EXPECT_TRUE(path);
Jane Liubaa7ff42017-06-29 19:18:23 -0400583
Lei Zhanga21d5932018-02-05 18:28:38 +0000584 // Modify the color of the path object.
585 EXPECT_TRUE(FPDFPath_SetStrokeColor(path, 0, 0, 0, 255));
586 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), path));
Jane Liubaa7ff42017-06-29 19:18:23 -0400587
Lei Zhanga21d5932018-02-05 18:28:38 +0000588 // Check that the page with the modified annotation renders correctly.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000589 {
590 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
591 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
592 CompareBitmap(bitmap.get(), 595, 842, md5_modified_path);
593 }
Jane Liu7a9a38b2017-07-11 13:47:37 -0400594
Lei Zhanga21d5932018-02-05 18:28:38 +0000595 // Add a second path object to the same annotation.
596 FPDF_PAGEOBJECT dot = FPDFPageObj_CreateNewPath(7, 84);
597 EXPECT_TRUE(FPDFPath_BezierTo(dot, 9, 86, 10, 87, 11, 88));
598 EXPECT_TRUE(FPDFPath_SetStrokeColor(dot, 255, 0, 0, 100));
599 EXPECT_TRUE(FPDFPath_SetStrokeWidth(dot, 14));
600 EXPECT_TRUE(FPDFPath_SetDrawMode(dot, 0, 1));
601 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), dot));
602 EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot.get()));
Jane Liu7a9a38b2017-07-11 13:47:37 -0400603
Lei Zhanga21d5932018-02-05 18:28:38 +0000604 // Check that the page with an annotation with two paths renders correctly.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000605 {
606 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
607 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
608 CompareBitmap(bitmap.get(), 595, 842, md5_two_paths);
609 }
Jane Liu7a9a38b2017-07-11 13:47:37 -0400610
Lei Zhanga21d5932018-02-05 18:28:38 +0000611 // Delete the newly added path object.
612 EXPECT_TRUE(FPDFAnnot_RemoveObject(annot.get(), 1));
613 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
614 }
Jane Liu7a9a38b2017-07-11 13:47:37 -0400615
616 // Check that the page renders the same as before.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000617 {
618 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
619 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
620 CompareBitmap(bitmap.get(), 595, 842, md5_modified_path);
621 }
Jane Liubaa7ff42017-06-29 19:18:23 -0400622
Jane Liubaa7ff42017-06-29 19:18:23 -0400623 FS_RECTF rect;
Jane Liubaa7ff42017-06-29 19:18:23 -0400624
Lei Zhanga21d5932018-02-05 18:28:38 +0000625 {
626 // Create another stamp annotation and set its annotation rectangle.
627 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
628 FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
629 ASSERT_TRUE(annot);
630 rect.left = 200.f;
631 rect.bottom = 400.f;
632 rect.right = 500.f;
633 rect.top = 600.f;
634 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
Jane Liubaa7ff42017-06-29 19:18:23 -0400635
Lei Zhanga21d5932018-02-05 18:28:38 +0000636 // Add a new path to the annotation.
637 FPDF_PAGEOBJECT check = FPDFPageObj_CreateNewPath(200, 500);
638 EXPECT_TRUE(FPDFPath_LineTo(check, 300, 400));
639 EXPECT_TRUE(FPDFPath_LineTo(check, 500, 600));
640 EXPECT_TRUE(FPDFPath_MoveTo(check, 350, 550));
641 EXPECT_TRUE(FPDFPath_LineTo(check, 450, 450));
642 EXPECT_TRUE(FPDFPath_SetStrokeColor(check, 0, 255, 255, 180));
643 EXPECT_TRUE(FPDFPath_SetStrokeWidth(check, 8.35f));
644 EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1));
645 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), check));
646 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
647
648 // Check that the annotation's bounding box came from its rectangle.
649 FS_RECTF new_rect;
650 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
651 EXPECT_EQ(rect.left, new_rect.left);
652 EXPECT_EQ(rect.bottom, new_rect.bottom);
653 EXPECT_EQ(rect.right, new_rect.right);
654 EXPECT_EQ(rect.top, new_rect.top);
655 }
Jane Liubaa7ff42017-06-29 19:18:23 -0400656
657 // Save the document, closing the page and document.
Jane Liubaa7ff42017-06-29 19:18:23 -0400658 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +0000659 UnloadPage(page);
Jane Liubaa7ff42017-06-29 19:18:23 -0400660
661 // Open the saved document.
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400662 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000663 page = LoadSavedPage(0);
664 VerifySavedRendering(page, 595, 842, md5_new_annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400665
Jane Liu36567742017-07-06 11:13:35 -0400666 // Check that the document has a correct count of annotations and objects.
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000667 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
Jane Liubaa7ff42017-06-29 19:18:23 -0400668
Lei Zhanga21d5932018-02-05 18:28:38 +0000669 {
670 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
671 FPDFPage_GetAnnot(page, 2));
672 ASSERT_TRUE(annot);
673 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
Jane Liubaa7ff42017-06-29 19:18:23 -0400674
Lei Zhanga21d5932018-02-05 18:28:38 +0000675 // Check that the new annotation's rectangle is as defined.
676 FS_RECTF new_rect;
677 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
678 EXPECT_EQ(rect.left, new_rect.left);
679 EXPECT_EQ(rect.bottom, new_rect.bottom);
680 EXPECT_EQ(rect.right, new_rect.right);
681 EXPECT_EQ(rect.top, new_rect.top);
682 }
683
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000684 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400685 CloseSavedDocument();
Jane Liu8ce58f52017-06-29 13:40:22 -0400686}
Jane Liub137e752017-07-05 15:04:33 -0400687
688TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) {
689 // Open a file with an annotation and load its first page.
690 ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000691 FPDF_PAGE page = LoadPage(0);
Jane Liub137e752017-07-05 15:04:33 -0400692 ASSERT_TRUE(page);
693
694 // Check that the page renders correctly.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000695 {
696 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
697 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
698 CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
699 }
Jane Liub137e752017-07-05 15:04:33 -0400700
Lei Zhanga21d5932018-02-05 18:28:38 +0000701 {
702 // Retrieve the annotation.
703 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
704 FPDFPage_GetAnnot(page, 0));
705 ASSERT_TRUE(annot);
Jane Liub137e752017-07-05 15:04:33 -0400706
Lei Zhanga21d5932018-02-05 18:28:38 +0000707 // Check that the original flag values are as expected.
708 int flags = FPDFAnnot_GetFlags(annot.get());
709 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
710 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
Jane Liub137e752017-07-05 15:04:33 -0400711
Lei Zhanga21d5932018-02-05 18:28:38 +0000712 // Set the HIDDEN flag.
713 flags |= FPDF_ANNOT_FLAG_HIDDEN;
714 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags));
715 flags = FPDFAnnot_GetFlags(annot.get());
716 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_HIDDEN);
717 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
Jane Liub137e752017-07-05 15:04:33 -0400718
Lei Zhanga21d5932018-02-05 18:28:38 +0000719 // Check that the page renders correctly without rendering the annotation.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000720 {
721 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
722 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
723 CompareBitmap(bitmap.get(), 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
724 }
Jane Liub137e752017-07-05 15:04:33 -0400725
Lei Zhanga21d5932018-02-05 18:28:38 +0000726 // Unset the HIDDEN flag.
727 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), FPDF_ANNOT_FLAG_NONE));
728 EXPECT_FALSE(FPDFAnnot_GetFlags(annot.get()));
729 flags &= ~FPDF_ANNOT_FLAG_HIDDEN;
730 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags));
731 flags = FPDFAnnot_GetFlags(annot.get());
732 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
733 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
Jane Liub137e752017-07-05 15:04:33 -0400734
Lei Zhanga21d5932018-02-05 18:28:38 +0000735 // Check that the page renders correctly as before.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000736 {
737 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
738 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
739 CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
740 }
Lei Zhanga21d5932018-02-05 18:28:38 +0000741 }
Jane Liub137e752017-07-05 15:04:33 -0400742
Jane Liub137e752017-07-05 15:04:33 -0400743 UnloadPage(page);
744}
Jane Liu36567742017-07-06 11:13:35 -0400745
746TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400747#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400748 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
749 const char md5_new_image[] = "ff012f5697436dfcaec25b32d1333596";
750 const char md5_modified_image[] = "86cf8cb2755a7a2046a543e66d9c1e61";
Jane Liu36567742017-07-06 11:13:35 -0400751#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000752 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
753 const char md5_new_image[] = "9ea8732dc9d579f68853f16892856208";
754 const char md5_modified_image[] = "74239d2a8c55c9de1dbb9cd8781895aa";
Jane Liu36567742017-07-06 11:13:35 -0400755#endif
756
757 // Open a file with two annotations and load its first page.
758 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000759 FPDF_PAGE page = LoadPage(0);
Jane Liu36567742017-07-06 11:13:35 -0400760 ASSERT_TRUE(page);
761 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
762
763 // Check that the page renders correctly.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000764 {
765 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
766 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
767 CompareBitmap(bitmap.get(), 595, 842, md5_original);
768 }
Jane Liu36567742017-07-06 11:13:35 -0400769
Jane Liu36567742017-07-06 11:13:35 -0400770 constexpr int kBitmapSize = 200;
Lei Zhanga21d5932018-02-05 18:28:38 +0000771 FPDF_BITMAP image_bitmap;
772
773 {
774 // Create a stamp annotation and set its annotation rectangle.
775 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
776 FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
777 ASSERT_TRUE(annot);
778 FS_RECTF rect;
779 rect.left = 200.f;
780 rect.bottom = 600.f;
781 rect.right = 400.f;
782 rect.top = 800.f;
783 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
784
785 // Add a solid-color translucent image object to the new annotation.
786 image_bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 1);
787 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize,
788 0xeeeecccc);
789 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap));
790 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap));
791 FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document());
792 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
793 ASSERT_TRUE(FPDFImageObj_SetMatrix(image_object, kBitmapSize, 0, 0,
794 kBitmapSize, 0, 0));
795 FPDFPageObj_Transform(image_object, 1, 0, 0, 1, 200, 600);
796 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), image_object));
797 }
Jane Liu36567742017-07-06 11:13:35 -0400798
799 // Check that the page renders correctly with the new image object.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000800 {
801 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
802 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
803 CompareBitmap(bitmap.get(), 595, 842, md5_new_image);
804 }
Jane Liu36567742017-07-06 11:13:35 -0400805
Lei Zhanga21d5932018-02-05 18:28:38 +0000806 {
807 // Retrieve the newly added stamp annotation and its image object.
808 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
809 FPDFPage_GetAnnot(page, 2));
810 ASSERT_TRUE(annot);
811 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
812 FPDF_PAGEOBJECT image_object = FPDFAnnot_GetObject(annot.get(), 0);
813 EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image_object));
Jane Liu36567742017-07-06 11:13:35 -0400814
Lei Zhanga21d5932018-02-05 18:28:38 +0000815 // Modify the image in the new annotation.
816 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize,
817 0xff000000);
818 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
819 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), image_object));
820 }
Jane Liu36567742017-07-06 11:13:35 -0400821
822 // Save the document, closing the page and document.
823 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +0000824 UnloadPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400825 FPDFBitmap_Destroy(image_bitmap);
Jane Liu36567742017-07-06 11:13:35 -0400826
827 // Test that the saved document renders the modified image object correctly.
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400828 VerifySavedDocument(595, 842, md5_modified_image);
Jane Liu36567742017-07-06 11:13:35 -0400829}
830
831TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400832#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400833 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
834 const char md5_new_text[] = "e5680ed048c2cfd9a1d27212cdf41286";
835 const char md5_modified_text[] = "79f5cfb0b07caaf936f65f6a7a57ce77";
Jane Liu36567742017-07-06 11:13:35 -0400836#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000837 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
838 const char md5_new_text[] = "00b14fa2dc1c90d1b0d034e1608efef5";
839 const char md5_modified_text[] = "076c8f24a09ddc0e49f7e758edead6f0";
Jane Liu36567742017-07-06 11:13:35 -0400840#endif
841
842 // Open a file with two annotations and load its first page.
843 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000844 FPDF_PAGE page = LoadPage(0);
Jane Liu36567742017-07-06 11:13:35 -0400845 ASSERT_TRUE(page);
846 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
847
848 // Check that the page renders correctly.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000849 {
850 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
851 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
852 CompareBitmap(bitmap.get(), 595, 842, md5_original);
853 }
Jane Liu36567742017-07-06 11:13:35 -0400854
Lei Zhanga21d5932018-02-05 18:28:38 +0000855 {
856 // Create a stamp annotation and set its annotation rectangle.
857 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
858 FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
859 ASSERT_TRUE(annot);
860 FS_RECTF rect;
861 rect.left = 200.f;
862 rect.bottom = 550.f;
863 rect.right = 450.f;
864 rect.top = 650.f;
865 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
Jane Liu36567742017-07-06 11:13:35 -0400866
Lei Zhanga21d5932018-02-05 18:28:38 +0000867 // Add a translucent text object to the new annotation.
868 FPDF_PAGEOBJECT text_object =
869 FPDFPageObj_NewTextObj(document(), "Arial", 12.0f);
870 EXPECT_TRUE(text_object);
871 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
872 GetFPDFWideString(L"I'm a translucent text laying on other text.");
873 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
874 EXPECT_TRUE(FPDFText_SetFillColor(text_object, 0, 0, 255, 150));
875 FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 600);
876 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), text_object));
877 }
Jane Liu36567742017-07-06 11:13:35 -0400878
879 // Check that the page renders correctly with the new text object.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000880 {
881 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
882 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
883 CompareBitmap(bitmap.get(), 595, 842, md5_new_text);
884 }
Jane Liu36567742017-07-06 11:13:35 -0400885
Lei Zhanga21d5932018-02-05 18:28:38 +0000886 {
887 // Retrieve the newly added stamp annotation and its text object.
888 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
889 FPDFPage_GetAnnot(page, 2));
890 ASSERT_TRUE(annot);
891 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
892 FPDF_PAGEOBJECT text_object = FPDFAnnot_GetObject(annot.get(), 0);
893 EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
Jane Liu36567742017-07-06 11:13:35 -0400894
Lei Zhanga21d5932018-02-05 18:28:38 +0000895 // Modify the text in the new annotation.
896 std::unique_ptr<unsigned short, pdfium::FreeDeleter> new_text =
897 GetFPDFWideString(L"New text!");
898 EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get()));
899 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), text_object));
900 }
Jane Liu36567742017-07-06 11:13:35 -0400901
902 // Check that the page renders correctly with the modified text object.
Lei Zhangc113c7a2018-02-12 14:58:44 +0000903 {
904 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
905 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
906 CompareBitmap(bitmap.get(), 595, 842, md5_modified_text);
907 }
Jane Liu36567742017-07-06 11:13:35 -0400908
909 // Remove the new annotation, and check that the page renders as before.
910 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2));
Lei Zhangc113c7a2018-02-12 14:58:44 +0000911 {
912 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
913 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
914 CompareBitmap(bitmap.get(), 595, 842, md5_original);
915 }
Jane Liu36567742017-07-06 11:13:35 -0400916
917 UnloadPage(page);
918}
Jane Liu2e1a32b2017-07-06 12:01:25 -0400919
920TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) {
921 // Open a file with four annotations and load its first page.
922 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000923 FPDF_PAGE page = LoadPage(0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400924 ASSERT_TRUE(page);
925
Lei Zhangdf064df2017-08-31 02:33:27 -0700926 static constexpr char kDateKey[] = "M";
Lei Zhanga21d5932018-02-05 18:28:38 +0000927 static constexpr wchar_t kNewDate[] = L"D:201706282359Z00'00'";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400928
Lei Zhanga21d5932018-02-05 18:28:38 +0000929 {
930 // Retrieve the first annotation.
931 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
932 FPDFPage_GetAnnot(page, 0));
933 ASSERT_TRUE(annot);
934
935 // Check that a non-existent key does not exist.
936 EXPECT_FALSE(FPDFAnnot_HasKey(annot.get(), "none"));
937
938 // Check that the string value of a non-string dictionary entry is empty.
939 static constexpr char kApKey[] = "AP";
940 EXPECT_TRUE(FPDFAnnot_HasKey(annot.get(), kApKey));
941 EXPECT_EQ(FPDF_OBJECT_REFERENCE,
942 FPDFAnnot_GetValueType(annot.get(), kApKey));
943 EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot.get(), kApKey, nullptr, 0));
944
945 // Check that the string value of the hash is correct.
946 static constexpr char kHashKey[] = "AAPL:Hash";
947 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey));
948 unsigned long len =
949 FPDFAnnot_GetStringValue(annot.get(), kHashKey, nullptr, 0);
950 std::vector<char> buf(len);
951 EXPECT_EQ(66u,
952 FPDFAnnot_GetStringValue(annot.get(), kHashKey, buf.data(), len));
953 EXPECT_STREQ(L"395fbcb98d558681742f30683a62a2ad",
954 BufferToWString(buf).c_str());
955
956 // Check that the string value of the modified date is correct.
957 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey));
958 len = FPDFAnnot_GetStringValue(annot.get(), kDateKey, nullptr, 0);
959 buf.clear();
960 buf.resize(len);
961 EXPECT_EQ(44u,
962 FPDFAnnot_GetStringValue(annot.get(), kDateKey, buf.data(), len));
963 EXPECT_STREQ(L"D:201706071721Z00'00'", BufferToWString(buf).c_str());
964
965 // Update the date entry for the annotation.
966 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
967 GetFPDFWideString(kNewDate);
968 EXPECT_TRUE(FPDFAnnot_SetStringValue(annot.get(), kDateKey, text.get()));
969 }
Jane Liu2e1a32b2017-07-06 12:01:25 -0400970
971 // Save the document, closing the page and document.
Jane Liu2e1a32b2017-07-06 12:01:25 -0400972 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +0000973 UnloadPage(page);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400974
975 // Open the saved annotation.
Dan Sinclair698aed72017-09-26 16:24:49 -0400976#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Artem Strygind24b97e2017-08-09 18:50:59 +0300977 const char md5[] = "4d64e61c9c0f8c60ab3cc3234bb73b1c";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400978#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000979 const char md5[] = "c96ee1f316d7f5a1b154de9f9d467f01";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400980#endif
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400981 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000982 page = LoadSavedPage(0);
983 VerifySavedRendering(page, 595, 842, md5);
Lei Zhanga21d5932018-02-05 18:28:38 +0000984 {
985 std::unique_ptr<void, FPDFAnnotationDeleter> new_annot(
986 FPDFPage_GetAnnot(page, 0));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400987
Lei Zhanga21d5932018-02-05 18:28:38 +0000988 // Check that the string value of the modified date is the newly-set value.
989 EXPECT_EQ(FPDF_OBJECT_STRING,
990 FPDFAnnot_GetValueType(new_annot.get(), kDateKey));
991 unsigned long len =
992 FPDFAnnot_GetStringValue(new_annot.get(), kDateKey, nullptr, 0);
993 std::vector<char> buf(len);
994 EXPECT_EQ(44u, FPDFAnnot_GetStringValue(new_annot.get(), kDateKey,
995 buf.data(), len));
996 EXPECT_STREQ(kNewDate, BufferToWString(buf).c_str());
997 }
Jane Liu2e1a32b2017-07-06 12:01:25 -0400998
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000999 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -04001000 CloseSavedDocument();
Jane Liu2e1a32b2017-07-06 12:01:25 -04001001}
Diana Gage7e0c05d2017-07-19 17:33:33 -07001002
Henrique Nakashima5970a472018-01-11 22:40:59 +00001003TEST_F(FPDFAnnotEmbeddertest, GetSetAP) {
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001004 // Open a file with four annotations and load its first page.
1005 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001006 FPDF_PAGE page = LoadPage(0);
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001007 ASSERT_TRUE(page);
1008
Lei Zhanga21d5932018-02-05 18:28:38 +00001009 {
1010 // Retrieve the first annotation.
1011 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1012 FPDFPage_GetAnnot(page, 0));
1013 ASSERT_TRUE(annot);
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001014
Lei Zhanga21d5932018-02-05 18:28:38 +00001015 // Check that the string value of an AP returns the expected length.
1016 unsigned long normal_len = FPDFAnnot_GetAP(
1017 annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, nullptr, 0);
1018 EXPECT_EQ(73970u, normal_len);
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001019
Lei Zhanga21d5932018-02-05 18:28:38 +00001020 // Check that the string value of an AP is not returned if the buffer is too
1021 // small. The result buffer should be overwritten with an empty string.
1022 std::vector<char> buf(normal_len - 1);
1023 // Write L"z" in the buffer to verify it's not overwritten.
1024 wcscpy(reinterpret_cast<wchar_t*>(buf.data()), L"z");
1025 EXPECT_EQ(73970u,
1026 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1027 buf.data(), buf.size()));
1028 std::string ap = BufferToString(buf);
1029 EXPECT_STREQ("z", ap.c_str());
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001030
Lei Zhanga21d5932018-02-05 18:28:38 +00001031 // Check that the string value of an AP is returned through a buffer that is
1032 // the right size.
1033 buf.clear();
1034 buf.resize(normal_len);
1035 EXPECT_EQ(73970u,
1036 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1037 buf.data(), buf.size()));
1038 ap = BufferToString(buf);
1039 EXPECT_THAT(ap, testing::StartsWith("q Q q 7.442786 w 2 J"));
1040 EXPECT_THAT(ap, testing::EndsWith("c 716.5381 327.7156 l S Q Q"));
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001041
Lei Zhanga21d5932018-02-05 18:28:38 +00001042 // Check that the string value of an AP is returned through a buffer that is
1043 // larger than necessary.
1044 buf.clear();
1045 buf.resize(normal_len + 1);
1046 EXPECT_EQ(73970u,
1047 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1048 buf.data(), buf.size()));
1049 ap = BufferToString(buf);
1050 EXPECT_THAT(ap, testing::StartsWith("q Q q 7.442786 w 2 J"));
1051 EXPECT_THAT(ap, testing::EndsWith("c 716.5381 327.7156 l S Q Q"));
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001052
Lei Zhanga21d5932018-02-05 18:28:38 +00001053 // Check that getting an AP for a mode that does not have an AP returns an
1054 // empty string.
1055 unsigned long rollover_len = FPDFAnnot_GetAP(
1056 annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0);
1057 EXPECT_EQ(2u, rollover_len);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001058
Lei Zhanga21d5932018-02-05 18:28:38 +00001059 buf.clear();
1060 buf.resize(1000);
1061 EXPECT_EQ(2u,
1062 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
1063 buf.data(), buf.size()));
1064 EXPECT_STREQ("", BufferToString(buf).c_str());
Henrique Nakashima5970a472018-01-11 22:40:59 +00001065
Lei Zhanga21d5932018-02-05 18:28:38 +00001066 // Check that setting the AP for an invalid appearance mode fails.
1067 std::unique_ptr<unsigned short, pdfium::FreeDeleter> apText =
1068 GetFPDFWideString(L"new test ap");
1069 EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), -1, apText.get()));
1070 EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_COUNT,
1071 apText.get()));
1072 EXPECT_FALSE(FPDFAnnot_SetAP(
1073 annot.get(), FPDF_ANNOT_APPEARANCEMODE_COUNT + 1, apText.get()));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001074
Lei Zhanga21d5932018-02-05 18:28:38 +00001075 // Set the AP correctly now.
1076 EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
1077 apText.get()));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001078
Lei Zhanga21d5932018-02-05 18:28:38 +00001079 // Check that the new annotation value is equal to the value we just set.
1080 rollover_len = FPDFAnnot_GetAP(
1081 annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0);
1082 EXPECT_EQ(24u, rollover_len);
1083 buf.clear();
1084 buf.resize(rollover_len);
1085 EXPECT_EQ(24u,
1086 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
1087 buf.data(), buf.size()));
1088 EXPECT_STREQ(L"new test ap", BufferToWString(buf).c_str());
Henrique Nakashima5970a472018-01-11 22:40:59 +00001089
Lei Zhanga21d5932018-02-05 18:28:38 +00001090 // Check that the Normal AP was not touched when the Rollover AP was set.
1091 buf.clear();
1092 buf.resize(normal_len);
1093 EXPECT_EQ(73970u,
1094 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1095 buf.data(), buf.size()));
1096 ap = BufferToString(buf);
1097 EXPECT_THAT(ap, testing::StartsWith("q Q q 7.442786 w 2 J"));
1098 EXPECT_THAT(ap, testing::EndsWith("c 716.5381 327.7156 l S Q Q"));
1099 }
Henrique Nakashima5970a472018-01-11 22:40:59 +00001100
1101 // Save the modified document, then reopen it.
Henrique Nakashima5970a472018-01-11 22:40:59 +00001102 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +00001103 UnloadPage(page);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001104
1105 OpenSavedDocument();
1106 page = LoadSavedPage(0);
Lei Zhanga21d5932018-02-05 18:28:38 +00001107 {
1108 std::unique_ptr<void, FPDFAnnotationDeleter> new_annot(
1109 FPDFPage_GetAnnot(page, 0));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001110
Lei Zhanga21d5932018-02-05 18:28:38 +00001111 // Check that the new annotation value is equal to the value we set before
1112 // saving.
1113 unsigned long rollover_len = FPDFAnnot_GetAP(
1114 new_annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0);
1115 EXPECT_EQ(24u, rollover_len);
1116 std::vector<char> buf(rollover_len);
1117 EXPECT_EQ(24u, FPDFAnnot_GetAP(new_annot.get(),
1118 FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
1119 buf.data(), buf.size()));
1120 EXPECT_STREQ(L"new test ap", BufferToWString(buf).c_str());
1121 }
Henrique Nakashima5970a472018-01-11 22:40:59 +00001122
1123 // Close saved document.
Henrique Nakashima5970a472018-01-11 22:40:59 +00001124 CloseSavedPage(page);
1125 CloseSavedDocument();
1126}
1127
1128TEST_F(FPDFAnnotEmbeddertest, RemoveOptionalAP) {
1129 // Open a file with four annotations and load its first page.
1130 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001131 FPDF_PAGE page = LoadPage(0);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001132 ASSERT_TRUE(page);
1133
Lei Zhanga21d5932018-02-05 18:28:38 +00001134 {
1135 // Retrieve the first annotation.
1136 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1137 FPDFPage_GetAnnot(page, 0));
1138 ASSERT_TRUE(annot);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001139
Lei Zhanga21d5932018-02-05 18:28:38 +00001140 // Set Down AP. Normal AP is already set.
1141 std::unique_ptr<unsigned short, pdfium::FreeDeleter> apText =
1142 GetFPDFWideString(L"new test ap");
1143 EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1144 apText.get()));
1145 EXPECT_EQ(73970u,
1146 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1147 nullptr, 0));
1148 EXPECT_EQ(24u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1149 nullptr, 0));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001150
Lei Zhanga21d5932018-02-05 18:28:38 +00001151 // Check that setting the Down AP to null removes the Down entry but keeps
1152 // Normal intact.
1153 EXPECT_TRUE(
1154 FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, nullptr));
1155 EXPECT_EQ(73970u,
1156 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1157 nullptr, 0));
1158 EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1159 nullptr, 0));
1160 }
Henrique Nakashima5970a472018-01-11 22:40:59 +00001161
Lei Zhang75c81712018-02-08 17:22:39 +00001162 UnloadPage(page);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001163}
1164
1165TEST_F(FPDFAnnotEmbeddertest, RemoveRequiredAP) {
1166 // Open a file with four annotations and load its first page.
1167 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001168 FPDF_PAGE page = LoadPage(0);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001169 ASSERT_TRUE(page);
1170
Lei Zhanga21d5932018-02-05 18:28:38 +00001171 {
1172 // Retrieve the first annotation.
1173 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1174 FPDFPage_GetAnnot(page, 0));
1175 ASSERT_TRUE(annot);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001176
Lei Zhanga21d5932018-02-05 18:28:38 +00001177 // Set Down AP. Normal AP is already set.
1178 std::unique_ptr<unsigned short, pdfium::FreeDeleter> apText =
1179 GetFPDFWideString(L"new test ap");
1180 EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1181 apText.get()));
1182 EXPECT_EQ(73970u,
1183 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1184 nullptr, 0));
1185 EXPECT_EQ(24u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1186 nullptr, 0));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001187
Lei Zhanga21d5932018-02-05 18:28:38 +00001188 // Check that setting the Normal AP to null removes the whole AP dictionary.
1189 EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1190 nullptr));
1191 EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1192 nullptr, 0));
1193 EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1194 nullptr, 0));
1195 }
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001196
Lei Zhang75c81712018-02-08 17:22:39 +00001197 UnloadPage(page);
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001198}
1199
Jane Liu300bb272017-08-21 14:37:53 -04001200TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) {
1201 // Open a file with annotations and load its first page.
1202 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001203 FPDF_PAGE page = LoadPage(0);
Jane Liu300bb272017-08-21 14:37:53 -04001204 ASSERT_TRUE(page);
Jane Liud1ed1ce2017-08-24 12:31:10 -04001205 EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr));
Jane Liu300bb272017-08-21 14:37:53 -04001206
Lei Zhanga21d5932018-02-05 18:28:38 +00001207 {
1208 // Retrieve the highlight annotation which has its popup defined.
1209 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1210 FPDFPage_GetAnnot(page, 0));
1211 ASSERT_TRUE(annot);
1212 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
1213 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot.get()));
1214 static constexpr char kPopupKey[] = "Popup";
1215 ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), kPopupKey));
1216 ASSERT_EQ(FPDF_OBJECT_REFERENCE,
1217 FPDFAnnot_GetValueType(annot.get(), kPopupKey));
Jane Liu300bb272017-08-21 14:37:53 -04001218
Lei Zhanga21d5932018-02-05 18:28:38 +00001219 // Retrieve and verify the popup of the highlight annotation.
1220 std::unique_ptr<void, FPDFAnnotationDeleter> popup(
1221 FPDFAnnot_GetLinkedAnnot(annot.get(), kPopupKey));
1222 ASSERT_TRUE(popup);
1223 EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup.get()));
1224 EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup.get()));
1225 FS_RECTF rect;
1226 ASSERT_TRUE(FPDFAnnot_GetRect(popup.get(), &rect));
1227 EXPECT_NEAR(612.0f, rect.left, 0.001f);
1228 EXPECT_NEAR(578.792, rect.bottom, 0.001f);
Jane Liu300bb272017-08-21 14:37:53 -04001229
Lei Zhanga21d5932018-02-05 18:28:38 +00001230 // Attempting to retrieve |annot|'s "IRT"-linked annotation would fail,
1231 // since "IRT" is not a key in |annot|'s dictionary.
1232 static constexpr char kIRTKey[] = "IRT";
1233 ASSERT_FALSE(FPDFAnnot_HasKey(annot.get(), kIRTKey));
1234 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), kIRTKey));
Jane Liu300bb272017-08-21 14:37:53 -04001235
Lei Zhanga21d5932018-02-05 18:28:38 +00001236 // Attempting to retrieve |annot|'s parent dictionary as an annotation
1237 // would fail, since its parent is not an annotation.
1238 static constexpr char kPKey[] = "P";
1239 ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), kPKey));
1240 EXPECT_EQ(FPDF_OBJECT_REFERENCE,
1241 FPDFAnnot_GetValueType(annot.get(), kPKey));
1242 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), kPKey));
1243 }
Jane Liu300bb272017-08-21 14:37:53 -04001244
Jane Liu300bb272017-08-21 14:37:53 -04001245 UnloadPage(page);
1246}
1247
Diana Gage7e0c05d2017-07-19 17:33:33 -07001248TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) {
1249 // Open file with form text fields.
1250 ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001251 FPDF_PAGE page = LoadPage(0);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001252 ASSERT_TRUE(page);
1253
Lei Zhanga21d5932018-02-05 18:28:38 +00001254 {
1255 // Retrieve the first annotation: user-editable text field.
1256 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1257 FPDFPage_GetAnnot(page, 0));
1258 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001259
Lei Zhanga21d5932018-02-05 18:28:38 +00001260 // Check that the flag values are as expected.
1261 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1262 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1263 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001264
Lei Zhanga21d5932018-02-05 18:28:38 +00001265 {
1266 // Retrieve the second annotation: read-only text field.
1267 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1268 FPDFPage_GetAnnot(page, 1));
1269 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001270
Lei Zhanga21d5932018-02-05 18:28:38 +00001271 // Check that the flag values are as expected.
1272 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1273 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1274 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001275
1276 UnloadPage(page);
1277}
1278
1279TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) {
1280 // Open file with form text fields.
1281 ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001282 FPDF_PAGE page = LoadPage(0);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001283 ASSERT_TRUE(page);
1284
Lei Zhanga21d5932018-02-05 18:28:38 +00001285 {
1286 // Retrieve the first annotation: user-editable combobox.
1287 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1288 FPDFPage_GetAnnot(page, 0));
1289 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001290
Lei Zhanga21d5932018-02-05 18:28:38 +00001291 // Check that the flag values are as expected.
1292 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1293 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1294 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1295 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1296 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001297
Lei Zhanga21d5932018-02-05 18:28:38 +00001298 {
1299 // Retrieve the second annotation: regular combobox.
1300 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1301 FPDFPage_GetAnnot(page, 1));
1302 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001303
Lei Zhanga21d5932018-02-05 18:28:38 +00001304 // Check that the flag values are as expected.
1305 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1306 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1307 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1308 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1309 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001310
Lei Zhanga21d5932018-02-05 18:28:38 +00001311 {
1312 // Retrieve the third annotation: read-only combobox.
1313 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1314 FPDFPage_GetAnnot(page, 2));
1315 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001316
Lei Zhanga21d5932018-02-05 18:28:38 +00001317 // Check that the flag values are as expected.
1318 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1319 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1320 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1321 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1322 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001323
1324 UnloadPage(page);
1325}
Diana Gage40870db2017-07-19 18:16:03 -07001326
1327TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) {
1328 // Open file with form text fields.
1329 EXPECT_TRUE(OpenDocument("text_form.pdf"));
1330 FPDF_PAGE page = LoadPage(0);
1331 ASSERT_TRUE(page);
1332
1333 // Attempt to get an annotation where no annotation exists on page.
1334 FPDF_ANNOTATION annot =
1335 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0);
1336 EXPECT_FALSE(annot);
1337
1338 UnloadPage(page);
1339}
1340
1341TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) {
1342 // Open file with form text fields.
1343 EXPECT_TRUE(OpenDocument("text_form_multiple.pdf"));
1344 FPDF_PAGE page = LoadPage(0);
1345 ASSERT_TRUE(page);
1346
Lei Zhanga21d5932018-02-05 18:28:38 +00001347 {
1348 // Retrieve user-editable text field annotation.
1349 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1350 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118));
1351 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001352
Lei Zhanga21d5932018-02-05 18:28:38 +00001353 // Check that interactive form annotation flag values are as expected.
1354 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1355 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1356 }
Diana Gage40870db2017-07-19 18:16:03 -07001357
Lei Zhanga21d5932018-02-05 18:28:38 +00001358 {
1359 // Retrieve read-only text field annotation.
1360 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1361 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202));
1362 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001363
Lei Zhanga21d5932018-02-05 18:28:38 +00001364 // Check that interactive form annotation flag values are as expected.
1365 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1366 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1367 }
Diana Gage40870db2017-07-19 18:16:03 -07001368
1369 UnloadPage(page);
1370}
1371
1372TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) {
1373 // Open file with form comboboxes.
1374 EXPECT_TRUE(OpenDocument("combobox_form.pdf"));
1375 FPDF_PAGE page = LoadPage(0);
1376 ASSERT_TRUE(page);
1377
Lei Zhanga21d5932018-02-05 18:28:38 +00001378 {
1379 // Retrieve user-editable combobox annotation.
1380 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1381 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 63));
1382 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001383
Lei Zhanga21d5932018-02-05 18:28:38 +00001384 // Check that interactive form annotation flag values are as expected.
1385 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1386 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1387 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1388 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1389 }
Diana Gage40870db2017-07-19 18:16:03 -07001390
Lei Zhanga21d5932018-02-05 18:28:38 +00001391 {
1392 // Retrieve regular combobox annotation.
1393 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1394 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 113));
1395 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001396
Lei Zhanga21d5932018-02-05 18:28:38 +00001397 // Check that interactive form annotation flag values are as expected.
1398 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1399 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1400 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1401 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1402 }
Diana Gage40870db2017-07-19 18:16:03 -07001403
Lei Zhanga21d5932018-02-05 18:28:38 +00001404 {
1405 // Retrieve read-only combobox annotation.
1406 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1407 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 213));
1408 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001409
Lei Zhanga21d5932018-02-05 18:28:38 +00001410 // Check that interactive form annotation flag values are as expected.
1411 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1412 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1413 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1414 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1415 }
Diana Gage40870db2017-07-19 18:16:03 -07001416
1417 UnloadPage(page);
1418}