blob: dce658201c50018c1f110d448ef243865e8232fb [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
Jane Liu20eafda2017-06-07 10:33:24 -04005#include <memory>
6#include <string>
Jane Liu4fd9a472017-06-01 18:56:09 -04007#include <vector>
8
Jane Liubaa7ff42017-06-29 19:18:23 -04009#include "core/fxcrt/fx_system.h"
Jane Liu4fd9a472017-06-01 18:56:09 -040010#include "public/fpdf_annot.h"
Jane Liubaa7ff42017-06-29 19:18:23 -040011#include "public/fpdf_edit.h"
Jane Liu4fd9a472017-06-01 18:56:09 -040012#include "public/fpdfview.h"
13#include "testing/embedder_test.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
Lei Zhangdf064df2017-08-31 02:33:27 -070016static constexpr char kContentsKey[] = "Contents";
17
Nicolas Pena3ff54002017-07-05 11:55:35 -040018class FPDFAnnotEmbeddertest : public EmbedderTest {};
Jane Liu4fd9a472017-06-01 18:56:09 -040019
Jane Liue17011d2017-06-21 12:18:37 -040020TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) {
21 // Open a file with one annotation and load its first page.
22 ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
23 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
24 ASSERT_TRUE(page);
25
26 // This annotation has a malformed appearance stream, which does not have its
27 // normal appearance defined, only its rollover appearance. In this case, its
28 // normal appearance should be generated, allowing the highlight annotation to
29 // still display.
Nicolas Pena3ff54002017-07-05 11:55:35 -040030 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle(), FPDF_ANNOT);
Jane Liue17011d2017-06-21 12:18:37 -040031 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
32 FPDFBitmap_Destroy(bitmap);
33
34 UnloadPage(page);
35}
36
Jane Liu4fd9a472017-06-01 18:56:09 -040037TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) {
38 // Open a file with one annotation and load its first page.
39 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
40 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
41 ASSERT_TRUE(page);
42
43 // Check that there is a total of 1 annotation on its first page.
44 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
45
46 // Check that the annotation is of type "highlight".
Jane Liud60e9ad2017-06-26 11:28:36 -040047 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
48 ASSERT_TRUE(annot);
Jane Liu4fd9a472017-06-01 18:56:09 -040049 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
50
51 // Check that the annotation color is yellow.
52 unsigned int R;
53 unsigned int G;
54 unsigned int B;
55 unsigned int A;
56 EXPECT_TRUE(
57 FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A));
58 EXPECT_EQ(255u, R);
59 EXPECT_EQ(255u, G);
60 EXPECT_EQ(0u, B);
61 EXPECT_EQ(255u, A);
62
63 // Check that the author is correct.
Lei Zhangdf064df2017-08-31 02:33:27 -070064 static constexpr char kAuthorKey[] = "T";
65 EXPECT_EQ(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(annot, kAuthorKey));
66 unsigned long len = FPDFAnnot_GetStringValue(annot, kAuthorKey, nullptr, 0);
Jane Liu4fd9a472017-06-01 18:56:09 -040067 std::vector<char> buf(len);
Lei Zhangdf064df2017-08-31 02:33:27 -070068 EXPECT_EQ(28u, FPDFAnnot_GetStringValue(annot, kAuthorKey, buf.data(), len));
Jane Liu4fd9a472017-06-01 18:56:09 -040069 EXPECT_STREQ(L"Jae Hyun Park",
70 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
71 .c_str());
72
73 // Check that the content is correct.
Lei Zhangdf064df2017-08-31 02:33:27 -070074 EXPECT_EQ(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(annot, kContentsKey));
75 len = FPDFAnnot_GetStringValue(annot, kContentsKey, nullptr, 0);
Jane Liu4fd9a472017-06-01 18:56:09 -040076 buf.clear();
77 buf.resize(len);
Lei Zhangdf064df2017-08-31 02:33:27 -070078 EXPECT_EQ(2690u,
79 FPDFAnnot_GetStringValue(annot, kContentsKey, buf.data(), len));
Jane Liu4fd9a472017-06-01 18:56:09 -040080 const wchar_t contents[] =
81 L"This is a note for that highlight annotation. Very long highlight "
82 "annotation. Long long long Long long longLong long longLong long "
83 "longLong long longLong long longLong long longLong long longLong long "
84 "longLong long longLong long longLong long longLong long longLong long "
85 "longLong long longLong long longLong long longLong long longLong long "
86 "longLong long longLong long longLong long longLong long longLong long "
87 "longLong long longLong long longLong long longLong long longLong long "
88 "longLong long longLong long longLong long longLong long longLong long "
89 "longLong long longLong long longLong long longLong long longLong long "
90 "longLong long longLong long longLong long longLong long longLong long "
91 "longLong long longLong long longLong long longLong long longLong long "
92 "longLong long longLong long longLong long longLong long longLong long "
93 "longLong long longLong long longLong long longLong long longLong long "
94 "longLong long longLong long longLong long longLong long longLong long "
95 "longLong long longLong long longLong long longLong long longLong long "
96 "longLong long longLong long longLong long longLong long longLong long "
97 "longLong long longLong long longLong long longLong long longLong long "
98 "longLong long longLong long longLong long longLong long longLong long "
99 "longLong long longLong long longLong long longLong long longLong long "
100 "longLong long long. END";
101 EXPECT_STREQ(contents,
102 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
103 .c_str());
104
105 // Check that the quadpoints are correct.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400106 FS_QUADPOINTSF quadpoints;
107 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints));
Jane Liu4fd9a472017-06-01 18:56:09 -0400108 EXPECT_EQ(115.802643f, quadpoints.x1);
109 EXPECT_EQ(718.913940f, quadpoints.y1);
110 EXPECT_EQ(157.211182f, quadpoints.x4);
111 EXPECT_EQ(706.264465f, quadpoints.y4);
112
Jane Liue10509a2017-06-20 16:47:41 -0400113 FPDFPage_CloseAnnot(annot);
Jane Liu4fd9a472017-06-01 18:56:09 -0400114 UnloadPage(page);
115}
116
117TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) {
118 // Open a file with three annotations and load its first page.
119 ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
120 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
121 ASSERT_TRUE(page);
122
123 // Check that there is a total of 3 annotation on its first page.
124 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
125
Jane Liu20eafda2017-06-07 10:33:24 -0400126 // Check that the third annotation is of type "ink".
Jane Liud60e9ad2017-06-26 11:28:36 -0400127 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 2);
128 ASSERT_TRUE(annot);
Jane Liu4fd9a472017-06-01 18:56:09 -0400129 EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot));
130
131 // Check that the annotation color is blue with opacity.
132 unsigned int R;
133 unsigned int G;
134 unsigned int B;
135 unsigned int A;
136 EXPECT_TRUE(
137 FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A));
138 EXPECT_EQ(0u, R);
139 EXPECT_EQ(0u, G);
140 EXPECT_EQ(255u, B);
141 EXPECT_EQ(76u, A);
142
143 // Check that there is no content.
Lei Zhangdf064df2017-08-31 02:33:27 -0700144 EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot, kContentsKey, nullptr, 0));
Jane Liu4fd9a472017-06-01 18:56:09 -0400145
146 // Check that the rectange coordinates are correct.
147 // Note that upon rendering, the rectangle coordinates will be adjusted.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400148 FS_RECTF rect;
149 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu4fd9a472017-06-01 18:56:09 -0400150 EXPECT_EQ(351.820404f, rect.left);
151 EXPECT_EQ(583.830688f, rect.bottom);
152 EXPECT_EQ(475.336090f, rect.right);
153 EXPECT_EQ(681.535034f, rect.top);
154
Jane Liue10509a2017-06-20 16:47:41 -0400155 FPDFPage_CloseAnnot(annot);
Jane Liu4fd9a472017-06-01 18:56:09 -0400156 UnloadPage(page);
157}
Jane Liu20eafda2017-06-07 10:33:24 -0400158
159TEST_F(FPDFAnnotEmbeddertest, AddIllegalSubtypeAnnotation) {
160 // Open a file with one annotation and load its first page.
161 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
162 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
163 ASSERT_TRUE(page);
164
165 // Add an annotation with an illegal subtype.
Jane Liud60e9ad2017-06-26 11:28:36 -0400166 ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1));
Jane Liu20eafda2017-06-07 10:33:24 -0400167
168 UnloadPage(page);
169}
170
Jane Liud321ef92017-06-14 09:56:22 -0400171TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) {
Jane Liu20eafda2017-06-07 10:33:24 -0400172 // Open a file with no annotation and load its first page.
173 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
174 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
175 ASSERT_TRUE(page);
176 EXPECT_EQ(0, FPDFPage_GetAnnotCount(page));
177
Jane Liueda65252017-06-07 11:31:27 -0400178 // Add a text annotation to the page.
Jane Liud60e9ad2017-06-26 11:28:36 -0400179 FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT);
180 ASSERT_TRUE(annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400181
182 // Check that there is now 1 annotations on this page.
183 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
184
185 // Check that the subtype of the annotation is correct.
186 EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot));
Jane Liue10509a2017-06-20 16:47:41 -0400187 FPDFPage_CloseAnnot(annot);
188
Jane Liud60e9ad2017-06-26 11:28:36 -0400189 annot = FPDFPage_GetAnnot(page, 0);
190 ASSERT_TRUE(annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400191 EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot));
192
193 // Set the color of the annotation.
194 ASSERT_TRUE(
195 FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 51, 102, 153, 204));
196 // Check that the color has been set correctly.
197 unsigned int R;
198 unsigned int G;
199 unsigned int B;
200 unsigned int A;
201 EXPECT_TRUE(
202 FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A));
203 EXPECT_EQ(51u, R);
204 EXPECT_EQ(102u, G);
205 EXPECT_EQ(153u, B);
206 EXPECT_EQ(204u, A);
207
208 // Change the color of the annotation.
209 ASSERT_TRUE(
210 FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 204, 153, 102, 51));
211 // Check that the color has been set correctly.
212 EXPECT_TRUE(
213 FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A));
214 EXPECT_EQ(204u, R);
215 EXPECT_EQ(153u, G);
216 EXPECT_EQ(102u, B);
217 EXPECT_EQ(51u, A);
218
219 // Set the annotation rectangle.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400220 FS_RECTF rect;
221 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liud60e9ad2017-06-26 11:28:36 -0400222 EXPECT_EQ(0.f, rect.left);
223 EXPECT_EQ(0.f, rect.right);
Jane Liu20eafda2017-06-07 10:33:24 -0400224 rect.left = 35;
225 rect.bottom = 150;
226 rect.right = 53;
227 rect.top = 165;
Jane Liu06462752017-06-27 16:41:14 -0400228 ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect));
Jane Liu20eafda2017-06-07 10:33:24 -0400229 // Check that the annotation rectangle has been set correctly.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400230 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu20eafda2017-06-07 10:33:24 -0400231 EXPECT_EQ(35.f, rect.left);
232 EXPECT_EQ(150.f, rect.bottom);
233 EXPECT_EQ(53.f, rect.right);
234 EXPECT_EQ(165.f, rect.top);
235
236 // Set the content of the annotation.
Lei Zhangdf064df2017-08-31 02:33:27 -0700237 static constexpr wchar_t contents[] = L"Hello! This is a customized content.";
Jane Liu20eafda2017-06-07 10:33:24 -0400238 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
239 GetFPDFWideString(contents);
Lei Zhangdf064df2017-08-31 02:33:27 -0700240 ASSERT_TRUE(FPDFAnnot_SetStringValue(annot, kContentsKey, text.get()));
Jane Liu20eafda2017-06-07 10:33:24 -0400241 // Check that the content has been set correctly.
Lei Zhangdf064df2017-08-31 02:33:27 -0700242 unsigned long len = FPDFAnnot_GetStringValue(annot, kContentsKey, nullptr, 0);
Jane Liu20eafda2017-06-07 10:33:24 -0400243 std::vector<char> buf(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700244 EXPECT_EQ(74u,
245 FPDFAnnot_GetStringValue(annot, kContentsKey, buf.data(), len));
Jane Liu20eafda2017-06-07 10:33:24 -0400246 EXPECT_STREQ(contents,
247 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
248 .c_str());
249
Jane Liue10509a2017-06-20 16:47:41 -0400250 FPDFPage_CloseAnnot(annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400251 UnloadPage(page);
252}
253
254TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
255 // Open a file with one annotation and load its first page.
256 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
257 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
258 ASSERT_TRUE(page);
259
260 // Check that there is a total of one annotation on its first page, and verify
261 // its quadpoints.
262 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
Jane Liud60e9ad2017-06-26 11:28:36 -0400263 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
264 ASSERT_TRUE(annot);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400265 FS_QUADPOINTSF quadpoints;
266 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints));
Jane Liu20eafda2017-06-07 10:33:24 -0400267 EXPECT_EQ(115.802643f, quadpoints.x1);
268 EXPECT_EQ(718.913940f, quadpoints.y1);
269 EXPECT_EQ(157.211182f, quadpoints.x4);
270 EXPECT_EQ(706.264465f, quadpoints.y4);
Jane Liue10509a2017-06-20 16:47:41 -0400271 FPDFPage_CloseAnnot(annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400272
273 // Add an underline annotation to the page and set its quadpoints.
Jane Liud60e9ad2017-06-26 11:28:36 -0400274 annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE);
275 ASSERT_TRUE(annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400276 quadpoints.x1 = 140.802643f;
277 quadpoints.x3 = 140.802643f;
Jane Liu06462752017-06-27 16:41:14 -0400278 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, &quadpoints));
Jane Liue10509a2017-06-20 16:47:41 -0400279 FPDFPage_CloseAnnot(annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400280
281 // Save the document, closing the page and document.
282 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
283 FPDF_ClosePage(page);
284
285 // Open the saved document.
Henrique Nakashima09b41922017-10-27 20:39:29 +0000286 const char md5[] = "dba153419f67b7c0c0e3d22d3e8910d5";
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400287
288 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000289 page = LoadSavedPage(0);
290 VerifySavedRendering(page, 612, 792, md5);
Jane Liu20eafda2017-06-07 10:33:24 -0400291
292 // Check that the saved document has 2 annotations on the first page
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000293 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
Jane Liu20eafda2017-06-07 10:33:24 -0400294
295 // Check that the second annotation is an underline annotation and verify
296 // its quadpoints.
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000297 FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(page, 1);
Jane Liud60e9ad2017-06-26 11:28:36 -0400298 ASSERT_TRUE(new_annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400299 EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400300 FS_QUADPOINTSF new_quadpoints;
301 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(new_annot, &new_quadpoints));
Jane Liu20eafda2017-06-07 10:33:24 -0400302 EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f);
303 EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f);
304 EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f);
305 EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f);
306
Jane Liue10509a2017-06-20 16:47:41 -0400307 FPDFPage_CloseAnnot(new_annot);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400308
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000309 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400310 CloseSavedDocument();
Jane Liu20eafda2017-06-07 10:33:24 -0400311}
Jane Liu06462752017-06-27 16:41:14 -0400312
313TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400314#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liub370e5a2017-08-16 13:24:58 -0400315 const char md5_original[] = "63af8432fab95a67cdebb7cd0e514941";
316 const char md5_modified_highlight[] = "aec26075011349dec9bace891856b5f2";
317 const char md5_modified_square[] = "057f57a32be95975775e5ec513fdcb56";
Dan Sinclair698aed72017-09-26 16:24:49 -0400318#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Henrique Nakashima09b41922017-10-27 20:39:29 +0000319 const char md5_original[] = "0e27376094f11490f74c65f3dc3a42c5";
320 const char md5_modified_highlight[] = "66f3caef3a7d488a4fa1ad37fc06310e";
321 const char md5_modified_square[] = "a456dad0bc6801ee2d6408a4394af563";
Jane Liub370e5a2017-08-16 13:24:58 -0400322#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000323 const char md5_original[] = "0e27376094f11490f74c65f3dc3a42c5";
324 const char md5_modified_highlight[] = "66f3caef3a7d488a4fa1ad37fc06310e";
325 const char md5_modified_square[] = "a456dad0bc6801ee2d6408a4394af563";
Jane Liub370e5a2017-08-16 13:24:58 -0400326#endif
327
Jane Liu06462752017-06-27 16:41:14 -0400328 // Open a file with four annotations and load its first page.
329 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
330 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
331 ASSERT_TRUE(page);
332 EXPECT_EQ(4, FPDFPage_GetAnnotCount(page));
333
Jane Liub370e5a2017-08-16 13:24:58 -0400334 // Check that the original file renders correctly.
335 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
336 CompareBitmap(bitmap, 612, 792, md5_original);
337 FPDFBitmap_Destroy(bitmap);
338
Jane Liu06462752017-06-27 16:41:14 -0400339 // Retrieve the highlight annotation which has its AP stream already defined.
340 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
341 ASSERT_TRUE(annot);
342 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
343
344 // Check that color cannot be set when an AP stream is defined already.
345 EXPECT_FALSE(
346 FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 51, 102, 153, 204));
347
Jane Liub370e5a2017-08-16 13:24:58 -0400348 // Verify its attachment points.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400349 FS_QUADPOINTSF quadpoints;
350 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints));
Jane Liub370e5a2017-08-16 13:24:58 -0400351 EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
352 EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
353 EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
354 EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
Jane Liu06462752017-06-27 16:41:14 -0400355
Jane Liub370e5a2017-08-16 13:24:58 -0400356 // Check that updating the attachment points would succeed.
357 quadpoints.x1 -= 50.f;
358 quadpoints.x2 -= 50.f;
359 quadpoints.x3 -= 50.f;
360 quadpoints.x4 -= 50.f;
Jane Liu06462752017-06-27 16:41:14 -0400361 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, &quadpoints));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400362 FS_QUADPOINTSF new_quadpoints;
363 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &new_quadpoints));
Jane Liu06462752017-06-27 16:41:14 -0400364 EXPECT_EQ(quadpoints.x1, new_quadpoints.x1);
365 EXPECT_EQ(quadpoints.y1, new_quadpoints.y1);
366 EXPECT_EQ(quadpoints.x4, new_quadpoints.x4);
367 EXPECT_EQ(quadpoints.y4, new_quadpoints.y4);
368
Jane Liub370e5a2017-08-16 13:24:58 -0400369 // Check that updating quadpoints does not change the annotation's position.
370 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
371 CompareBitmap(bitmap, 612, 792, md5_original);
372 FPDFBitmap_Destroy(bitmap);
373
374 // Verify its annotation rectangle.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400375 FS_RECTF rect;
376 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu06462752017-06-27 16:41:14 -0400377 EXPECT_NEAR(67.7299f, rect.left, 0.001f);
378 EXPECT_NEAR(704.296f, rect.bottom, 0.001f);
379 EXPECT_NEAR(136.325f, rect.right, 0.001f);
380 EXPECT_NEAR(721.292f, rect.top, 0.001f);
381
Jane Liub370e5a2017-08-16 13:24:58 -0400382 // Check that updating the rectangle would succeed.
383 rect.left -= 60.f;
384 rect.right -= 60.f;
Jane Liu06462752017-06-27 16:41:14 -0400385 ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400386 FS_RECTF new_rect;
387 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liu06462752017-06-27 16:41:14 -0400388 EXPECT_EQ(rect.right, new_rect.right);
Jane Liu06462752017-06-27 16:41:14 -0400389 FPDFPage_CloseAnnot(annot);
390
Jane Liub370e5a2017-08-16 13:24:58 -0400391 // Check that updating the rectangle changes the annotation's position.
392 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
393 CompareBitmap(bitmap, 612, 792, md5_modified_highlight);
394 FPDFBitmap_Destroy(bitmap);
395
Jane Liu06462752017-06-27 16:41:14 -0400396 // Retrieve the square annotation which has its AP stream already defined.
397 annot = FPDFPage_GetAnnot(page, 2);
398 ASSERT_TRUE(annot);
399 EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot));
400
Jane Liub370e5a2017-08-16 13:24:58 -0400401 // Check that updating the rectangle would succeed.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400402 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liub370e5a2017-08-16 13:24:58 -0400403 rect.left += 70.f;
404 rect.right += 70.f;
Jane Liu06462752017-06-27 16:41:14 -0400405 ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400406 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liu06462752017-06-27 16:41:14 -0400407 EXPECT_EQ(rect.right, new_rect.right);
408
Jane Liub370e5a2017-08-16 13:24:58 -0400409 // Check that updating the rectangle changes the square annotation's position.
410 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
411 CompareBitmap(bitmap, 612, 792, md5_modified_square);
412 FPDFBitmap_Destroy(bitmap);
413
Jane Liu06462752017-06-27 16:41:14 -0400414 FPDFPage_CloseAnnot(annot);
415 UnloadPage(page);
416}
Jane Liu8ce58f52017-06-29 13:40:22 -0400417
418TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) {
419 // Open a file with 3 annotations on its first page.
420 ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
421 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
422 ASSERT_TRUE(page);
423 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
424
425 // Check that the annotations have the expected rectangle coordinates.
426 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400427 FS_RECTF rect;
428 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400429 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
430 FPDFPage_CloseAnnot(annot);
431
432 annot = FPDFPage_GetAnnot(page, 1);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400433 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400434 EXPECT_NEAR(149.8127f, rect.left, 0.001f);
435 FPDFPage_CloseAnnot(annot);
436
437 annot = FPDFPage_GetAnnot(page, 2);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400438 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400439 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
440 FPDFPage_CloseAnnot(annot);
441
442 // Check that nothing happens when attempting to remove an annotation with an
443 // out-of-bound index.
444 EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4));
445 EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1));
446 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
447
448 // Remove the second annotation.
449 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1));
450 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
451 EXPECT_FALSE(FPDFPage_GetAnnot(page, 2));
452
453 // Save the document, closing the page and document.
454 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
455 FPDF_ClosePage(page);
456
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400457 // TODO(npm): VerifySavedRendering changes annot rect dimensions by 1??
Jane Liu8ce58f52017-06-29 13:40:22 -0400458 // Open the saved document.
459 std::string new_file = GetString();
460 FPDF_FILEACCESS file_access;
461 memset(&file_access, 0, sizeof(file_access));
462 file_access.m_FileLen = new_file.size();
463 file_access.m_GetBlock = GetBlockFromString;
464 file_access.m_Param = &new_file;
465 FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
466 ASSERT_TRUE(new_doc);
467 FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
468 ASSERT_TRUE(new_page);
469
470 // Check that the saved document has 2 annotations on the first page.
471 EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page));
472
473 // Check that the remaining 2 annotations are the original 1st and 3rd ones by
474 // verifying their rectangle coordinates.
475 annot = FPDFPage_GetAnnot(new_page, 0);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400476 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400477 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
478 FPDFPage_CloseAnnot(annot);
479
480 annot = FPDFPage_GetAnnot(new_page, 1);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400481 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400482 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
483 FPDFPage_CloseAnnot(annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400484 FPDF_ClosePage(new_page);
485 FPDF_CloseDocument(new_doc);
486}
Jane Liu8ce58f52017-06-29 13:40:22 -0400487
Jane Liubaa7ff42017-06-29 19:18:23 -0400488TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400489#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400490 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
491 const char md5_modified_path[] = "cf3cea74bd46497520ff6c4d1ea228c8";
492 const char md5_two_paths[] = "e8994452fc4385337bae5522354e10ff";
493 const char md5_new_annot[] = "ee5372b31fede117fc83b9384598aa25";
Jane Liubaa7ff42017-06-29 19:18:23 -0400494#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000495 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
496 const char md5_modified_path[] = "3f77b88ce6048e08e636c9a03921b2e5";
497 const char md5_two_paths[] = "bffbf5ecd15862b9fe553c795400ff8e";
498 const char md5_new_annot[] = "e020534c7eeea76be537c70d6e359a40";
Jane Liubaa7ff42017-06-29 19:18:23 -0400499#endif
500
501 // Open a file with two annotations and load its first page.
502 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
503 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
504 ASSERT_TRUE(page);
505 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
506
507 // Check that the page renders correctly.
508 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400509 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liubaa7ff42017-06-29 19:18:23 -0400510 FPDFBitmap_Destroy(bitmap);
511
512 // Retrieve the stamp annotation which has its AP stream already defined.
513 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
514 ASSERT_TRUE(annot);
515
516 // Check that this annotation has one path object and retrieve it.
Jane Liu36567742017-07-06 11:13:35 -0400517 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
518 FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot, 1);
Jane Liubaa7ff42017-06-29 19:18:23 -0400519 EXPECT_FALSE(path);
Jane Liu36567742017-07-06 11:13:35 -0400520 path = FPDFAnnot_GetObject(annot, 0);
521 EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
Jane Liubaa7ff42017-06-29 19:18:23 -0400522 EXPECT_TRUE(path);
523
524 // Modify the color of the path object.
525 EXPECT_TRUE(FPDFPath_SetStrokeColor(path, 0, 0, 0, 255));
Jane Liu36567742017-07-06 11:13:35 -0400526 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, path));
Jane Liubaa7ff42017-06-29 19:18:23 -0400527
528 // Check that the page with the modified annotation renders correctly.
529 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400530 CompareBitmap(bitmap, 595, 842, md5_modified_path);
531 FPDFBitmap_Destroy(bitmap);
532
533 // Add a second path object to the same annotation.
534 FPDF_PAGEOBJECT dot = FPDFPageObj_CreateNewPath(7, 84);
535 EXPECT_TRUE(FPDFPath_BezierTo(dot, 9, 86, 10, 87, 11, 88));
536 EXPECT_TRUE(FPDFPath_SetStrokeColor(dot, 255, 0, 0, 100));
537 EXPECT_TRUE(FPDFPath_SetStrokeWidth(dot, 14));
538 EXPECT_TRUE(FPDFPath_SetDrawMode(dot, 0, 1));
539 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, dot));
540 EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot));
541
542 // Check that the page with an annotation with two paths renders correctly.
543 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
544 CompareBitmap(bitmap, 595, 842, md5_two_paths);
545 FPDFBitmap_Destroy(bitmap);
546
547 // Delete the newly added path object.
548 EXPECT_TRUE(FPDFAnnot_RemoveObject(annot, 1));
549 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
550 FPDFPage_CloseAnnot(annot);
551
552 // Check that the page renders the same as before.
553 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
554 CompareBitmap(bitmap, 595, 842, md5_modified_path);
Jane Liubaa7ff42017-06-29 19:18:23 -0400555 FPDFBitmap_Destroy(bitmap);
556
557 // Create another stamp annotation and set its annotation rectangle.
558 annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP);
559 ASSERT_TRUE(annot);
560 FS_RECTF rect;
561 rect.left = 200.f;
562 rect.bottom = 400.f;
563 rect.right = 500.f;
564 rect.top = 600.f;
565 EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect));
566
567 // Add a new path to the annotation.
568 FPDF_PAGEOBJECT check = FPDFPageObj_CreateNewPath(200, 500);
569 EXPECT_TRUE(FPDFPath_LineTo(check, 300, 400));
570 EXPECT_TRUE(FPDFPath_LineTo(check, 500, 600));
571 EXPECT_TRUE(FPDFPath_MoveTo(check, 350, 550));
572 EXPECT_TRUE(FPDFPath_LineTo(check, 450, 450));
573 EXPECT_TRUE(FPDFPath_SetStrokeColor(check, 0, 255, 255, 180));
574 EXPECT_TRUE(FPDFPath_SetStrokeWidth(check, 8.35f));
575 EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1));
Jane Liu36567742017-07-06 11:13:35 -0400576 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, check));
577 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
Jane Liubaa7ff42017-06-29 19:18:23 -0400578
579 // Check that the annotation's bounding box came from its rectangle.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400580 FS_RECTF new_rect;
581 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liubaa7ff42017-06-29 19:18:23 -0400582 EXPECT_EQ(rect.left, new_rect.left);
583 EXPECT_EQ(rect.bottom, new_rect.bottom);
584 EXPECT_EQ(rect.right, new_rect.right);
585 EXPECT_EQ(rect.top, new_rect.top);
586
587 // Save the document, closing the page and document.
588 FPDFPage_CloseAnnot(annot);
589 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
590 FPDF_ClosePage(page);
591
592 // Open the saved document.
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400593 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000594 page = LoadSavedPage(0);
595 VerifySavedRendering(page, 595, 842, md5_new_annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400596
Jane Liu36567742017-07-06 11:13:35 -0400597 // Check that the document has a correct count of annotations and objects.
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000598 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
599 annot = FPDFPage_GetAnnot(page, 2);
Jane Liubaa7ff42017-06-29 19:18:23 -0400600 ASSERT_TRUE(annot);
Jane Liu36567742017-07-06 11:13:35 -0400601 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
Jane Liubaa7ff42017-06-29 19:18:23 -0400602
603 // Check that the new annotation's rectangle is as defined.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400604 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liubaa7ff42017-06-29 19:18:23 -0400605 EXPECT_EQ(rect.left, new_rect.left);
606 EXPECT_EQ(rect.bottom, new_rect.bottom);
607 EXPECT_EQ(rect.right, new_rect.right);
608 EXPECT_EQ(rect.top, new_rect.top);
609
Jane Liubaa7ff42017-06-29 19:18:23 -0400610 FPDFPage_CloseAnnot(annot);
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000611 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400612 CloseSavedDocument();
Jane Liu8ce58f52017-06-29 13:40:22 -0400613}
Jane Liub137e752017-07-05 15:04:33 -0400614
615TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) {
616 // Open a file with an annotation and load its first page.
617 ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
618 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
619 ASSERT_TRUE(page);
620
621 // Check that the page renders correctly.
622 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
623 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
624 FPDFBitmap_Destroy(bitmap);
625
626 // Retrieve the annotation.
627 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
628 ASSERT_TRUE(annot);
629
630 // Check that the original flag values are as expected.
631 int flags = FPDFAnnot_GetFlags(annot);
632 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
633 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
634
635 // Set the HIDDEN flag.
636 flags |= FPDF_ANNOT_FLAG_HIDDEN;
637 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags));
638 flags = FPDFAnnot_GetFlags(annot);
639 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_HIDDEN);
640 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
641
642 // Check that the page renders correctly without rendering the annotation.
643 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
644 CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
645 FPDFBitmap_Destroy(bitmap);
646
647 // Unset the HIDDEN flag.
648 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, FPDF_ANNOT_FLAG_NONE));
649 EXPECT_FALSE(FPDFAnnot_GetFlags(annot));
650 flags &= ~FPDF_ANNOT_FLAG_HIDDEN;
651 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags));
652 flags = FPDFAnnot_GetFlags(annot);
653 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
654 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
655
656 // Check that the page renders correctly as before.
657 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
658 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
659 FPDFBitmap_Destroy(bitmap);
660
661 FPDFPage_CloseAnnot(annot);
662 UnloadPage(page);
663}
Jane Liu36567742017-07-06 11:13:35 -0400664
665TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400666#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400667 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
668 const char md5_new_image[] = "ff012f5697436dfcaec25b32d1333596";
669 const char md5_modified_image[] = "86cf8cb2755a7a2046a543e66d9c1e61";
Jane Liu36567742017-07-06 11:13:35 -0400670#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000671 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
672 const char md5_new_image[] = "9ea8732dc9d579f68853f16892856208";
673 const char md5_modified_image[] = "74239d2a8c55c9de1dbb9cd8781895aa";
Jane Liu36567742017-07-06 11:13:35 -0400674#endif
675
676 // Open a file with two annotations and load its first page.
677 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
678 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
679 ASSERT_TRUE(page);
680 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
681
682 // Check that the page renders correctly.
683 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400684 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400685 FPDFBitmap_Destroy(bitmap);
686
687 // Create a stamp annotation and set its annotation rectangle.
688 FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP);
689 ASSERT_TRUE(annot);
690 FS_RECTF rect;
691 rect.left = 200.f;
692 rect.bottom = 600.f;
693 rect.right = 400.f;
694 rect.top = 800.f;
695 EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect));
696
697 // Add a solid-color translucent image object to the new annotation.
698 constexpr int kBitmapSize = 200;
699 FPDF_BITMAP image_bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 1);
700 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xeeeecccc);
701 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap));
702 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap));
703 FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document());
704 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
705 ASSERT_TRUE(FPDFImageObj_SetMatrix(image_object, kBitmapSize, 0, 0,
706 kBitmapSize, 0, 0));
707 FPDFPageObj_Transform(image_object, 1, 0, 0, 1, 200, 600);
708 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, image_object));
709 FPDFPage_CloseAnnot(annot);
710
711 // Check that the page renders correctly with the new image object.
712 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400713 CompareBitmap(bitmap, 595, 842, md5_new_image);
Jane Liu36567742017-07-06 11:13:35 -0400714 FPDFBitmap_Destroy(bitmap);
715
716 // Retrieve the newly added stamp annotation and its image object.
717 annot = FPDFPage_GetAnnot(page, 2);
718 ASSERT_TRUE(annot);
719 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
720 image_object = FPDFAnnot_GetObject(annot, 0);
721 EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image_object));
722
723 // Modify the image in the new annotation.
724 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xff000000);
725 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
726 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, image_object));
727 FPDFPage_CloseAnnot(annot);
728
729 // Save the document, closing the page and document.
730 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
731 FPDF_ClosePage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400732 FPDFBitmap_Destroy(image_bitmap);
Jane Liu36567742017-07-06 11:13:35 -0400733
734 // Test that the saved document renders the modified image object correctly.
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400735 VerifySavedDocument(595, 842, md5_modified_image);
Jane Liu36567742017-07-06 11:13:35 -0400736}
737
738TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400739#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400740 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
741 const char md5_new_text[] = "e5680ed048c2cfd9a1d27212cdf41286";
742 const char md5_modified_text[] = "79f5cfb0b07caaf936f65f6a7a57ce77";
Jane Liu36567742017-07-06 11:13:35 -0400743#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000744 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
745 const char md5_new_text[] = "00b14fa2dc1c90d1b0d034e1608efef5";
746 const char md5_modified_text[] = "076c8f24a09ddc0e49f7e758edead6f0";
Jane Liu36567742017-07-06 11:13:35 -0400747#endif
748
749 // Open a file with two annotations and load its first page.
750 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
751 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
752 ASSERT_TRUE(page);
753 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
754
755 // Check that the page renders correctly.
756 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400757 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400758 FPDFBitmap_Destroy(bitmap);
759
760 // Create a stamp annotation and set its annotation rectangle.
761 FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP);
762 ASSERT_TRUE(annot);
763 FS_RECTF rect;
764 rect.left = 200.f;
765 rect.bottom = 550.f;
766 rect.right = 450.f;
767 rect.top = 650.f;
768 EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect));
769
770 // Add a translucent text object to the new annotation.
771 FPDF_PAGEOBJECT text_object =
772 FPDFPageObj_NewTextObj(document(), "Arial", 12.0f);
773 EXPECT_TRUE(text_object);
774 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
775 GetFPDFWideString(L"I'm a translucent text laying on other text.");
776 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
777 EXPECT_TRUE(FPDFText_SetFillColor(text_object, 0, 0, 255, 150));
778 FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 600);
779 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, text_object));
780 FPDFPage_CloseAnnot(annot);
781
782 // Check that the page renders correctly with the new text object.
783 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400784 CompareBitmap(bitmap, 595, 842, md5_new_text);
Jane Liu36567742017-07-06 11:13:35 -0400785 FPDFBitmap_Destroy(bitmap);
786
787 // Retrieve the newly added stamp annotation and its text object.
788 annot = FPDFPage_GetAnnot(page, 2);
789 ASSERT_TRUE(annot);
790 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
791 text_object = FPDFAnnot_GetObject(annot, 0);
792 EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
793
794 // Modify the text in the new annotation.
795 std::unique_ptr<unsigned short, pdfium::FreeDeleter> new_text =
796 GetFPDFWideString(L"New text!");
797 EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get()));
798 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, text_object));
799 FPDFPage_CloseAnnot(annot);
800
801 // Check that the page renders correctly with the modified text object.
802 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400803 CompareBitmap(bitmap, 595, 842, md5_modified_text);
Jane Liu36567742017-07-06 11:13:35 -0400804 FPDFBitmap_Destroy(bitmap);
805
806 // Remove the new annotation, and check that the page renders as before.
807 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2));
808 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400809 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400810 FPDFBitmap_Destroy(bitmap);
811
812 UnloadPage(page);
813}
Jane Liu2e1a32b2017-07-06 12:01:25 -0400814
815TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) {
816 // Open a file with four annotations and load its first page.
817 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
818 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
819 ASSERT_TRUE(page);
820
821 // Retrieve the first annotation.
822 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
823 ASSERT_TRUE(annot);
824
825 // Check that a non-existent key does not exist.
Lei Zhangdf064df2017-08-31 02:33:27 -0700826 EXPECT_FALSE(FPDFAnnot_HasKey(annot, "none"));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400827
828 // Check that the string value of a non-string dictionary entry is empty.
Lei Zhangdf064df2017-08-31 02:33:27 -0700829 static constexpr char kApKey[] = "AP";
830 EXPECT_TRUE(FPDFAnnot_HasKey(annot, kApKey));
831 EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kApKey));
832 EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot, kApKey, nullptr, 0));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400833
834 // Check that the string value of the hash is correct.
Lei Zhangdf064df2017-08-31 02:33:27 -0700835 static constexpr char kHashKey[] = "AAPL:Hash";
836 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, kHashKey));
837 unsigned long len = FPDFAnnot_GetStringValue(annot, kHashKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400838 std::vector<char> buf(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700839 EXPECT_EQ(66u, FPDFAnnot_GetStringValue(annot, kHashKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400840 EXPECT_STREQ(L"395fbcb98d558681742f30683a62a2ad",
841 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
842 .c_str());
843
844 // Check that the string value of the modified date is correct.
Lei Zhangdf064df2017-08-31 02:33:27 -0700845 static constexpr char kDateKey[] = "M";
846 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, kHashKey));
847 len = FPDFAnnot_GetStringValue(annot, kDateKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400848 buf.clear();
849 buf.resize(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700850 EXPECT_EQ(44u, FPDFAnnot_GetStringValue(annot, kDateKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400851 EXPECT_STREQ(L"D:201706071721Z00'00'",
852 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
853 .c_str());
854
855 // Update the date entry for the annotation.
856 const wchar_t new_date[] = L"D:201706282359Z00'00'";
857 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
858 GetFPDFWideString(new_date);
Lei Zhangdf064df2017-08-31 02:33:27 -0700859 EXPECT_TRUE(FPDFAnnot_SetStringValue(annot, kDateKey, text.get()));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400860
861 // Save the document, closing the page and document.
862 FPDFPage_CloseAnnot(annot);
863 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
864 FPDF_ClosePage(page);
865
866 // Open the saved annotation.
Dan Sinclair698aed72017-09-26 16:24:49 -0400867#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Artem Strygind24b97e2017-08-09 18:50:59 +0300868 const char md5[] = "4d64e61c9c0f8c60ab3cc3234bb73b1c";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400869#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000870 const char md5[] = "c96ee1f316d7f5a1b154de9f9d467f01";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400871#endif
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400872 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000873 page = LoadSavedPage(0);
874 VerifySavedRendering(page, 595, 842, md5);
875 FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(page, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400876
877 // Check that the string value of the modified date is the newly-set value.
Lei Zhangdf064df2017-08-31 02:33:27 -0700878 EXPECT_EQ(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(new_annot, kDateKey));
879 len = FPDFAnnot_GetStringValue(new_annot, kDateKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400880 buf.clear();
881 buf.resize(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700882 EXPECT_EQ(44u,
883 FPDFAnnot_GetStringValue(new_annot, kDateKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400884 EXPECT_STREQ(new_date,
885 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
886 .c_str());
887
888 FPDFPage_CloseAnnot(new_annot);
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000889 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400890 CloseSavedDocument();
Jane Liu2e1a32b2017-07-06 12:01:25 -0400891}
Diana Gage7e0c05d2017-07-19 17:33:33 -0700892
Jane Liu300bb272017-08-21 14:37:53 -0400893TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) {
894 // Open a file with annotations and load its first page.
895 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
896 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
897 ASSERT_TRUE(page);
Jane Liud1ed1ce2017-08-24 12:31:10 -0400898 EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr));
Jane Liu300bb272017-08-21 14:37:53 -0400899
900 // Retrieve the highlight annotation which has its popup defined.
901 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
902 ASSERT_TRUE(annot);
903 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
Jane Liud1ed1ce2017-08-24 12:31:10 -0400904 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot));
Lei Zhangdf064df2017-08-31 02:33:27 -0700905 static constexpr char kPopupKey[] = "Popup";
906 ASSERT_TRUE(FPDFAnnot_HasKey(annot, kPopupKey));
907 ASSERT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kPopupKey));
Jane Liu300bb272017-08-21 14:37:53 -0400908
909 // Retrieve and verify the popup of the highlight annotation.
Lei Zhangdf064df2017-08-31 02:33:27 -0700910 FPDF_ANNOTATION popup = FPDFAnnot_GetLinkedAnnot(annot, kPopupKey);
Jane Liu300bb272017-08-21 14:37:53 -0400911 ASSERT_TRUE(popup);
912 EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup));
Jane Liud1ed1ce2017-08-24 12:31:10 -0400913 EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup));
Jane Liu300bb272017-08-21 14:37:53 -0400914 FS_RECTF rect;
915 ASSERT_TRUE(FPDFAnnot_GetRect(popup, &rect));
916 EXPECT_NEAR(612.0f, rect.left, 0.001f);
917 EXPECT_NEAR(578.792, rect.bottom, 0.001f);
918
919 // Attempting to retrieve |annot|'s "IRT"-linked annotation would fail, since
920 // "IRT" is not a key in |annot|'s dictionary.
Lei Zhangdf064df2017-08-31 02:33:27 -0700921 static constexpr char kIRTKey[] = "IRT";
922 ASSERT_FALSE(FPDFAnnot_HasKey(annot, kIRTKey));
923 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, kIRTKey));
Jane Liu300bb272017-08-21 14:37:53 -0400924
925 // Attempting to retrieve |annot|'s parent dictionary as an annotation would
926 // fail, since its parent is not an annotation.
Lei Zhangdf064df2017-08-31 02:33:27 -0700927 static constexpr char kPKey[] = "P";
928 ASSERT_TRUE(FPDFAnnot_HasKey(annot, kPKey));
929 EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kPKey));
930 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, kPKey));
Jane Liu300bb272017-08-21 14:37:53 -0400931
932 FPDFPage_CloseAnnot(popup);
933 FPDFPage_CloseAnnot(annot);
934 UnloadPage(page);
935}
936
Diana Gage7e0c05d2017-07-19 17:33:33 -0700937TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) {
938 // Open file with form text fields.
939 ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
940 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
941 ASSERT_TRUE(page);
942
943 // Retrieve the first annotation: user-editable text field.
944 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
945 ASSERT_TRUE(annot);
946
947 // Check that the flag values are as expected.
948 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
949 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
950 FPDFPage_CloseAnnot(annot);
951
952 // Retrieve the second annotation: read-only text field.
953 annot = FPDFPage_GetAnnot(page, 1);
954 ASSERT_TRUE(annot);
955
956 // Check that the flag values are as expected.
957 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
958 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
959 FPDFPage_CloseAnnot(annot);
960
961 UnloadPage(page);
962}
963
964TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) {
965 // Open file with form text fields.
966 ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
967 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
968 ASSERT_TRUE(page);
969
970 // Retrieve the first annotation: user-editable combobox.
971 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
972 ASSERT_TRUE(annot);
973
974 // Check that the flag values are as expected.
975 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
976 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
977 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
978 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
979 FPDFPage_CloseAnnot(annot);
980
981 // Retrieve the second annotation: regular combobox.
982 annot = FPDFPage_GetAnnot(page, 1);
983 ASSERT_TRUE(annot);
984
985 // Check that the flag values are as expected.
986 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
987 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
988 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
989 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
990 FPDFPage_CloseAnnot(annot);
991
992 // Retrieve the third annotation: read-only combobox.
993 annot = FPDFPage_GetAnnot(page, 2);
994 ASSERT_TRUE(annot);
995
996 // Check that the flag values are as expected.
997 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
998 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
999 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1000 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1001 FPDFPage_CloseAnnot(annot);
1002
1003 UnloadPage(page);
1004}
Diana Gage40870db2017-07-19 18:16:03 -07001005
1006TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) {
1007 // Open file with form text fields.
1008 EXPECT_TRUE(OpenDocument("text_form.pdf"));
1009 FPDF_PAGE page = LoadPage(0);
1010 ASSERT_TRUE(page);
1011
1012 // Attempt to get an annotation where no annotation exists on page.
1013 FPDF_ANNOTATION annot =
1014 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0);
1015 EXPECT_FALSE(annot);
1016
1017 UnloadPage(page);
1018}
1019
1020TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) {
1021 // Open file with form text fields.
1022 EXPECT_TRUE(OpenDocument("text_form_multiple.pdf"));
1023 FPDF_PAGE page = LoadPage(0);
1024 ASSERT_TRUE(page);
1025
1026 // Retrieve user-editable text field annotation.
1027 FPDF_ANNOTATION annot =
1028 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118);
1029 ASSERT_TRUE(annot);
1030
1031 // Check that interactive form annotation flag values are as expected.
1032 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1033 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1034 FPDFPage_CloseAnnot(annot);
1035
1036 // Retrieve read-only text field annotation.
1037 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202);
1038 ASSERT_TRUE(annot);
1039
1040 // Check that interactive form annotation flag values are as expected.
1041 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1042 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1043 FPDFPage_CloseAnnot(annot);
1044
1045 UnloadPage(page);
1046}
1047
1048TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) {
1049 // Open file with form comboboxes.
1050 EXPECT_TRUE(OpenDocument("combobox_form.pdf"));
1051 FPDF_PAGE page = LoadPage(0);
1052 ASSERT_TRUE(page);
1053
1054 // Retrieve user-editable combobox annotation.
1055 FPDF_ANNOTATION annot =
1056 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 63);
1057 ASSERT_TRUE(annot);
1058
1059 // Check that interactive form annotation flag values are as expected.
1060 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1061 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1062 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1063 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1064 FPDFPage_CloseAnnot(annot);
1065
1066 // Retrieve regular combobox annotation.
1067 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 113);
1068 ASSERT_TRUE(annot);
1069
1070 // Check that interactive form annotation flag values are as expected.
1071 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1072 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1073 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1074 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1075 FPDFPage_CloseAnnot(annot);
1076
1077 // Retrieve read-only combobox annotation.
1078 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 213);
1079 ASSERT_TRUE(annot);
1080
1081 // Check that interactive form annotation flag values are as expected.
1082 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1083 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1084 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1085 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1086 FPDFPage_CloseAnnot(annot);
1087
1088 UnloadPage(page);
1089}