blob: 34643dfb48602bfab297bec3a80f0cff1fecf3e1 [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.
Nicolas Pena3ff54002017-07-05 11:55:35 -0400286 const char md5[] = "184b67b322edaee27994b3232544b8b3";
287 TestSaved(612, 792, md5);
Jane Liu20eafda2017-06-07 10:33:24 -0400288
289 // Check that the saved document has 2 annotations on the first page
Nicolas Pena3ff54002017-07-05 11:55:35 -0400290 EXPECT_EQ(2, FPDFPage_GetAnnotCount(m_SavedPage));
Jane Liu20eafda2017-06-07 10:33:24 -0400291
292 // Check that the second annotation is an underline annotation and verify
293 // its quadpoints.
Nicolas Pena3ff54002017-07-05 11:55:35 -0400294 FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(m_SavedPage, 1);
Jane Liud60e9ad2017-06-26 11:28:36 -0400295 ASSERT_TRUE(new_annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400296 EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400297 FS_QUADPOINTSF new_quadpoints;
298 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(new_annot, &new_quadpoints));
Jane Liu20eafda2017-06-07 10:33:24 -0400299 EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f);
300 EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f);
301 EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f);
302 EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f);
303
Jane Liue10509a2017-06-20 16:47:41 -0400304 FPDFPage_CloseAnnot(new_annot);
Nicolas Pena3ff54002017-07-05 11:55:35 -0400305 CloseSaved();
Jane Liu20eafda2017-06-07 10:33:24 -0400306}
Jane Liu06462752017-06-27 16:41:14 -0400307
308TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400309#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liub370e5a2017-08-16 13:24:58 -0400310 const char md5_original[] = "63af8432fab95a67cdebb7cd0e514941";
311 const char md5_modified_highlight[] = "aec26075011349dec9bace891856b5f2";
312 const char md5_modified_square[] = "057f57a32be95975775e5ec513fdcb56";
Dan Sinclair698aed72017-09-26 16:24:49 -0400313#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Jane Liub370e5a2017-08-16 13:24:58 -0400314 const char md5_original[] = "ade6762a70e85605546ce067e7d2148f";
315 const char md5_modified_highlight[] = "fb8440ed1a070b53ed5598ce7451cfad";
316 const char md5_modified_square[] = "7925f6726b343393f258e8b4e93dd65d";
317#else
318 const char md5_original[] = "ade6762a70e85605546ce067e7d2148f";
319 const char md5_modified_highlight[] = "fb8440ed1a070b53ed5598ce7451cfad";
320 const char md5_modified_square[] = "7925f6726b343393f258e8b4e93dd65d";
321#endif
322
Jane Liu06462752017-06-27 16:41:14 -0400323 // Open a file with four annotations and load its first page.
324 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
325 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
326 ASSERT_TRUE(page);
327 EXPECT_EQ(4, FPDFPage_GetAnnotCount(page));
328
Jane Liub370e5a2017-08-16 13:24:58 -0400329 // Check that the original file renders correctly.
330 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
331 CompareBitmap(bitmap, 612, 792, md5_original);
332 FPDFBitmap_Destroy(bitmap);
333
Jane Liu06462752017-06-27 16:41:14 -0400334 // Retrieve the highlight annotation which has its AP stream already defined.
335 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
336 ASSERT_TRUE(annot);
337 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
338
339 // Check that color cannot be set when an AP stream is defined already.
340 EXPECT_FALSE(
341 FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 51, 102, 153, 204));
342
Jane Liub370e5a2017-08-16 13:24:58 -0400343 // Verify its attachment points.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400344 FS_QUADPOINTSF quadpoints;
345 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints));
Jane Liub370e5a2017-08-16 13:24:58 -0400346 EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
347 EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
348 EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
349 EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
Jane Liu06462752017-06-27 16:41:14 -0400350
Jane Liub370e5a2017-08-16 13:24:58 -0400351 // Check that updating the attachment points would succeed.
352 quadpoints.x1 -= 50.f;
353 quadpoints.x2 -= 50.f;
354 quadpoints.x3 -= 50.f;
355 quadpoints.x4 -= 50.f;
Jane Liu06462752017-06-27 16:41:14 -0400356 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, &quadpoints));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400357 FS_QUADPOINTSF new_quadpoints;
358 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &new_quadpoints));
Jane Liu06462752017-06-27 16:41:14 -0400359 EXPECT_EQ(quadpoints.x1, new_quadpoints.x1);
360 EXPECT_EQ(quadpoints.y1, new_quadpoints.y1);
361 EXPECT_EQ(quadpoints.x4, new_quadpoints.x4);
362 EXPECT_EQ(quadpoints.y4, new_quadpoints.y4);
363
Jane Liub370e5a2017-08-16 13:24:58 -0400364 // Check that updating quadpoints does not change the annotation's position.
365 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
366 CompareBitmap(bitmap, 612, 792, md5_original);
367 FPDFBitmap_Destroy(bitmap);
368
369 // Verify its annotation rectangle.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400370 FS_RECTF rect;
371 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu06462752017-06-27 16:41:14 -0400372 EXPECT_NEAR(67.7299f, rect.left, 0.001f);
373 EXPECT_NEAR(704.296f, rect.bottom, 0.001f);
374 EXPECT_NEAR(136.325f, rect.right, 0.001f);
375 EXPECT_NEAR(721.292f, rect.top, 0.001f);
376
Jane Liub370e5a2017-08-16 13:24:58 -0400377 // Check that updating the rectangle would succeed.
378 rect.left -= 60.f;
379 rect.right -= 60.f;
Jane Liu06462752017-06-27 16:41:14 -0400380 ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400381 FS_RECTF new_rect;
382 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liu06462752017-06-27 16:41:14 -0400383 EXPECT_EQ(rect.right, new_rect.right);
Jane Liu06462752017-06-27 16:41:14 -0400384 FPDFPage_CloseAnnot(annot);
385
Jane Liub370e5a2017-08-16 13:24:58 -0400386 // Check that updating the rectangle changes the annotation's position.
387 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
388 CompareBitmap(bitmap, 612, 792, md5_modified_highlight);
389 FPDFBitmap_Destroy(bitmap);
390
Jane Liu06462752017-06-27 16:41:14 -0400391 // Retrieve the square annotation which has its AP stream already defined.
392 annot = FPDFPage_GetAnnot(page, 2);
393 ASSERT_TRUE(annot);
394 EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot));
395
Jane Liub370e5a2017-08-16 13:24:58 -0400396 // Check that updating the rectangle would succeed.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400397 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liub370e5a2017-08-16 13:24:58 -0400398 rect.left += 70.f;
399 rect.right += 70.f;
Jane Liu06462752017-06-27 16:41:14 -0400400 ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400401 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liu06462752017-06-27 16:41:14 -0400402 EXPECT_EQ(rect.right, new_rect.right);
403
Jane Liub370e5a2017-08-16 13:24:58 -0400404 // Check that updating the rectangle changes the square annotation's position.
405 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
406 CompareBitmap(bitmap, 612, 792, md5_modified_square);
407 FPDFBitmap_Destroy(bitmap);
408
Jane Liu06462752017-06-27 16:41:14 -0400409 FPDFPage_CloseAnnot(annot);
410 UnloadPage(page);
411}
Jane Liu8ce58f52017-06-29 13:40:22 -0400412
413TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) {
414 // Open a file with 3 annotations on its first page.
415 ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
416 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
417 ASSERT_TRUE(page);
418 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
419
420 // Check that the annotations have the expected rectangle coordinates.
421 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400422 FS_RECTF rect;
423 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400424 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
425 FPDFPage_CloseAnnot(annot);
426
427 annot = FPDFPage_GetAnnot(page, 1);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400428 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400429 EXPECT_NEAR(149.8127f, rect.left, 0.001f);
430 FPDFPage_CloseAnnot(annot);
431
432 annot = FPDFPage_GetAnnot(page, 2);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400433 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400434 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
435 FPDFPage_CloseAnnot(annot);
436
437 // Check that nothing happens when attempting to remove an annotation with an
438 // out-of-bound index.
439 EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4));
440 EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1));
441 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
442
443 // Remove the second annotation.
444 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1));
445 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
446 EXPECT_FALSE(FPDFPage_GetAnnot(page, 2));
447
448 // Save the document, closing the page and document.
449 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
450 FPDF_ClosePage(page);
451
Nicolas Pena3ff54002017-07-05 11:55:35 -0400452 // TODO(npm): TestSaved changes annot rect dimensions by 1??
Jane Liu8ce58f52017-06-29 13:40:22 -0400453 // Open the saved document.
454 std::string new_file = GetString();
455 FPDF_FILEACCESS file_access;
456 memset(&file_access, 0, sizeof(file_access));
457 file_access.m_FileLen = new_file.size();
458 file_access.m_GetBlock = GetBlockFromString;
459 file_access.m_Param = &new_file;
460 FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
461 ASSERT_TRUE(new_doc);
462 FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
463 ASSERT_TRUE(new_page);
464
465 // Check that the saved document has 2 annotations on the first page.
466 EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page));
467
468 // Check that the remaining 2 annotations are the original 1st and 3rd ones by
469 // verifying their rectangle coordinates.
470 annot = FPDFPage_GetAnnot(new_page, 0);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400471 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400472 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
473 FPDFPage_CloseAnnot(annot);
474
475 annot = FPDFPage_GetAnnot(new_page, 1);
Jane Liu0c6b07d2017-08-15 10:50:22 -0400476 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect));
Jane Liu8ce58f52017-06-29 13:40:22 -0400477 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
478 FPDFPage_CloseAnnot(annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400479 FPDF_ClosePage(new_page);
480 FPDF_CloseDocument(new_doc);
481}
Jane Liu8ce58f52017-06-29 13:40:22 -0400482
Jane Liubaa7ff42017-06-29 19:18:23 -0400483TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400484#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400485 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
486 const char md5_modified_path[] = "cf3cea74bd46497520ff6c4d1ea228c8";
487 const char md5_two_paths[] = "e8994452fc4385337bae5522354e10ff";
488 const char md5_new_annot[] = "ee5372b31fede117fc83b9384598aa25";
Dan Sinclair698aed72017-09-26 16:24:49 -0400489#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400490 const char md5_original[] = "4f64add0190ede63f7bb9eb1e2e83edb";
491 const char md5_modified_path[] = "681f0d0738dded0722e146f6c219bfac";
492 const char md5_two_paths[] = "67c7e90fc3b64e20f6b69a1744f7f4f0";
493 const char md5_new_annot[] = "262187984451bae2fe826067d68623ff";
Jane Liubaa7ff42017-06-29 19:18:23 -0400494#else
Jane Liu7a9a38b2017-07-11 13:47:37 -0400495 const char md5_original[] = "02e1c6adff8fee4aeabd91c2c2e4be43";
496 const char md5_modified_path[] = "87a78cbacd8509b961a67be56b5665a2";
497 const char md5_two_paths[] = "76e985c18b73ceacf409f77f978176d4";
498 const char md5_new_annot[] = "c95de7a9a1f61faca03d953961a319b9";
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.
Jane Liu7a9a38b2017-07-11 13:47:37 -0400593 TestSaved(595, 842, md5_new_annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400594
Jane Liu36567742017-07-06 11:13:35 -0400595 // Check that the document has a correct count of annotations and objects.
Nicolas Pena3ff54002017-07-05 11:55:35 -0400596 EXPECT_EQ(3, FPDFPage_GetAnnotCount(m_SavedPage));
597 annot = FPDFPage_GetAnnot(m_SavedPage, 2);
Jane Liubaa7ff42017-06-29 19:18:23 -0400598 ASSERT_TRUE(annot);
Jane Liu36567742017-07-06 11:13:35 -0400599 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
Jane Liubaa7ff42017-06-29 19:18:23 -0400600
601 // Check that the new annotation's rectangle is as defined.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400602 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liubaa7ff42017-06-29 19:18:23 -0400603 EXPECT_EQ(rect.left, new_rect.left);
604 EXPECT_EQ(rect.bottom, new_rect.bottom);
605 EXPECT_EQ(rect.right, new_rect.right);
606 EXPECT_EQ(rect.top, new_rect.top);
607
Jane Liubaa7ff42017-06-29 19:18:23 -0400608 FPDFPage_CloseAnnot(annot);
Nicolas Pena3ff54002017-07-05 11:55:35 -0400609 CloseSaved();
Jane Liu8ce58f52017-06-29 13:40:22 -0400610}
Jane Liub137e752017-07-05 15:04:33 -0400611
612TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) {
613 // Open a file with an annotation and load its first page.
614 ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
615 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
616 ASSERT_TRUE(page);
617
618 // Check that the page renders correctly.
619 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
620 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
621 FPDFBitmap_Destroy(bitmap);
622
623 // Retrieve the annotation.
624 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
625 ASSERT_TRUE(annot);
626
627 // Check that the original flag values are as expected.
628 int flags = FPDFAnnot_GetFlags(annot);
629 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
630 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
631
632 // Set the HIDDEN flag.
633 flags |= FPDF_ANNOT_FLAG_HIDDEN;
634 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags));
635 flags = FPDFAnnot_GetFlags(annot);
636 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_HIDDEN);
637 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
638
639 // Check that the page renders correctly without rendering the annotation.
640 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
641 CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
642 FPDFBitmap_Destroy(bitmap);
643
644 // Unset the HIDDEN flag.
645 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, FPDF_ANNOT_FLAG_NONE));
646 EXPECT_FALSE(FPDFAnnot_GetFlags(annot));
647 flags &= ~FPDF_ANNOT_FLAG_HIDDEN;
648 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags));
649 flags = FPDFAnnot_GetFlags(annot);
650 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
651 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
652
653 // Check that the page renders correctly as before.
654 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
655 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
656 FPDFBitmap_Destroy(bitmap);
657
658 FPDFPage_CloseAnnot(annot);
659 UnloadPage(page);
660}
Jane Liu36567742017-07-06 11:13:35 -0400661
662TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400663#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400664 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
665 const char md5_new_image[] = "ff012f5697436dfcaec25b32d1333596";
666 const char md5_modified_image[] = "86cf8cb2755a7a2046a543e66d9c1e61";
Dan Sinclair698aed72017-09-26 16:24:49 -0400667#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400668 const char md5_original[] = "4f64add0190ede63f7bb9eb1e2e83edb";
669 const char md5_new_image[] = "6fb176c20996cc554d0210d8c8b6138f";
670 const char md5_modified_image[] = "546959714dfb0dcd7e7b00259e8d178c";
Jane Liu36567742017-07-06 11:13:35 -0400671#else
Jane Liu7a9a38b2017-07-11 13:47:37 -0400672 const char md5_original[] = "02e1c6adff8fee4aeabd91c2c2e4be43";
673 const char md5_new_image[] = "e7658232abd8977cdc3367dd02aee04a";
674 const char md5_modified_image[] = "f393432b9a9b452ea69022f46c8b3f75";
Jane Liu36567742017-07-06 11:13:35 -0400675#endif
676
677 // Open a file with two annotations and load its first page.
678 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
679 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
680 ASSERT_TRUE(page);
681 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
682
683 // Check that the page renders correctly.
684 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400685 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400686 FPDFBitmap_Destroy(bitmap);
687
688 // Create a stamp annotation and set its annotation rectangle.
689 FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP);
690 ASSERT_TRUE(annot);
691 FS_RECTF rect;
692 rect.left = 200.f;
693 rect.bottom = 600.f;
694 rect.right = 400.f;
695 rect.top = 800.f;
696 EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect));
697
698 // Add a solid-color translucent image object to the new annotation.
699 constexpr int kBitmapSize = 200;
700 FPDF_BITMAP image_bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 1);
701 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xeeeecccc);
702 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap));
703 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap));
704 FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document());
705 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
706 ASSERT_TRUE(FPDFImageObj_SetMatrix(image_object, kBitmapSize, 0, 0,
707 kBitmapSize, 0, 0));
708 FPDFPageObj_Transform(image_object, 1, 0, 0, 1, 200, 600);
709 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, image_object));
710 FPDFPage_CloseAnnot(annot);
711
712 // Check that the page renders correctly with the new image object.
713 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400714 CompareBitmap(bitmap, 595, 842, md5_new_image);
Jane Liu36567742017-07-06 11:13:35 -0400715 FPDFBitmap_Destroy(bitmap);
716
717 // Retrieve the newly added stamp annotation and its image object.
718 annot = FPDFPage_GetAnnot(page, 2);
719 ASSERT_TRUE(annot);
720 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
721 image_object = FPDFAnnot_GetObject(annot, 0);
722 EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image_object));
723
724 // Modify the image in the new annotation.
725 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xff000000);
726 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
727 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, image_object));
728 FPDFPage_CloseAnnot(annot);
729
730 // Save the document, closing the page and document.
731 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
732 FPDF_ClosePage(page);
733
734 // Test that the saved document renders the modified image object correctly.
Jane Liu7a9a38b2017-07-11 13:47:37 -0400735 TestSaved(595, 842, md5_modified_image);
Jane Liu36567742017-07-06 11:13:35 -0400736
737 FPDFBitmap_Destroy(image_bitmap);
738 CloseSaved();
739}
740
741TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400742#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400743 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
744 const char md5_new_text[] = "e5680ed048c2cfd9a1d27212cdf41286";
745 const char md5_modified_text[] = "79f5cfb0b07caaf936f65f6a7a57ce77";
Dan Sinclair698aed72017-09-26 16:24:49 -0400746#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400747 const char md5_original[] = "4f64add0190ede63f7bb9eb1e2e83edb";
748 const char md5_new_text[] = "998abae4962f8f41e094e7612d8339fc";
749 const char md5_modified_text[] = "e89b82ca4589b8f0b45fff42ca3a96a4";
Jane Liu36567742017-07-06 11:13:35 -0400750#else
Jane Liu7a9a38b2017-07-11 13:47:37 -0400751 const char md5_original[] = "02e1c6adff8fee4aeabd91c2c2e4be43";
752 const char md5_new_text[] = "3fbbaec4d846ccf2be89e09daae0273d";
753 const char md5_modified_text[] = "2ad0acaf2d8990bcdf48e1d12e6c44ad";
Jane Liu36567742017-07-06 11:13:35 -0400754#endif
755
756 // Open a file with two annotations and load its first page.
757 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
758 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
759 ASSERT_TRUE(page);
760 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
761
762 // Check that the page renders correctly.
763 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400764 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400765 FPDFBitmap_Destroy(bitmap);
766
767 // Create a stamp annotation and set its annotation rectangle.
768 FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP);
769 ASSERT_TRUE(annot);
770 FS_RECTF rect;
771 rect.left = 200.f;
772 rect.bottom = 550.f;
773 rect.right = 450.f;
774 rect.top = 650.f;
775 EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect));
776
777 // Add a translucent text object to the new annotation.
778 FPDF_PAGEOBJECT text_object =
779 FPDFPageObj_NewTextObj(document(), "Arial", 12.0f);
780 EXPECT_TRUE(text_object);
781 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
782 GetFPDFWideString(L"I'm a translucent text laying on other text.");
783 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
784 EXPECT_TRUE(FPDFText_SetFillColor(text_object, 0, 0, 255, 150));
785 FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 600);
786 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, text_object));
787 FPDFPage_CloseAnnot(annot);
788
789 // Check that the page renders correctly with the new text object.
790 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400791 CompareBitmap(bitmap, 595, 842, md5_new_text);
Jane Liu36567742017-07-06 11:13:35 -0400792 FPDFBitmap_Destroy(bitmap);
793
794 // Retrieve the newly added stamp annotation and its text object.
795 annot = FPDFPage_GetAnnot(page, 2);
796 ASSERT_TRUE(annot);
797 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
798 text_object = FPDFAnnot_GetObject(annot, 0);
799 EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
800
801 // Modify the text in the new annotation.
802 std::unique_ptr<unsigned short, pdfium::FreeDeleter> new_text =
803 GetFPDFWideString(L"New text!");
804 EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get()));
805 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, text_object));
806 FPDFPage_CloseAnnot(annot);
807
808 // Check that the page renders correctly with the modified text object.
809 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400810 CompareBitmap(bitmap, 595, 842, md5_modified_text);
Jane Liu36567742017-07-06 11:13:35 -0400811 FPDFBitmap_Destroy(bitmap);
812
813 // Remove the new annotation, and check that the page renders as before.
814 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2));
815 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400816 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400817 FPDFBitmap_Destroy(bitmap);
818
819 UnloadPage(page);
820}
Jane Liu2e1a32b2017-07-06 12:01:25 -0400821
822TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) {
823 // Open a file with four annotations and load its first page.
824 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
825 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
826 ASSERT_TRUE(page);
827
828 // Retrieve the first annotation.
829 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
830 ASSERT_TRUE(annot);
831
832 // Check that a non-existent key does not exist.
Lei Zhangdf064df2017-08-31 02:33:27 -0700833 EXPECT_FALSE(FPDFAnnot_HasKey(annot, "none"));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400834
835 // Check that the string value of a non-string dictionary entry is empty.
Lei Zhangdf064df2017-08-31 02:33:27 -0700836 static constexpr char kApKey[] = "AP";
837 EXPECT_TRUE(FPDFAnnot_HasKey(annot, kApKey));
838 EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kApKey));
839 EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot, kApKey, nullptr, 0));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400840
841 // Check that the string value of the hash is correct.
Lei Zhangdf064df2017-08-31 02:33:27 -0700842 static constexpr char kHashKey[] = "AAPL:Hash";
843 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, kHashKey));
844 unsigned long len = FPDFAnnot_GetStringValue(annot, kHashKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400845 std::vector<char> buf(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700846 EXPECT_EQ(66u, FPDFAnnot_GetStringValue(annot, kHashKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400847 EXPECT_STREQ(L"395fbcb98d558681742f30683a62a2ad",
848 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
849 .c_str());
850
851 // Check that the string value of the modified date is correct.
Lei Zhangdf064df2017-08-31 02:33:27 -0700852 static constexpr char kDateKey[] = "M";
853 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, kHashKey));
854 len = FPDFAnnot_GetStringValue(annot, kDateKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400855 buf.clear();
856 buf.resize(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700857 EXPECT_EQ(44u, FPDFAnnot_GetStringValue(annot, kDateKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400858 EXPECT_STREQ(L"D:201706071721Z00'00'",
859 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
860 .c_str());
861
862 // Update the date entry for the annotation.
863 const wchar_t new_date[] = L"D:201706282359Z00'00'";
864 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
865 GetFPDFWideString(new_date);
Lei Zhangdf064df2017-08-31 02:33:27 -0700866 EXPECT_TRUE(FPDFAnnot_SetStringValue(annot, kDateKey, text.get()));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400867
868 // Save the document, closing the page and document.
869 FPDFPage_CloseAnnot(annot);
870 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
871 FPDF_ClosePage(page);
872
873 // Open the saved annotation.
Dan Sinclair698aed72017-09-26 16:24:49 -0400874#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Artem Strygind24b97e2017-08-09 18:50:59 +0300875 const char md5[] = "4d64e61c9c0f8c60ab3cc3234bb73b1c";
Dan Sinclair698aed72017-09-26 16:24:49 -0400876#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Artem Strygind24b97e2017-08-09 18:50:59 +0300877 const char md5[] = "0e3710ea6476f5bcba2cd39eb42d54e2";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400878#else
Artem Strygind24b97e2017-08-09 18:50:59 +0300879 const char md5[] = "831a3c465a56d2e0c89aef7bdf15306a";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400880#endif
881 TestSaved(595, 842, md5);
882 FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(m_SavedPage, 0);
883
884 // Check that the string value of the modified date is the newly-set value.
Lei Zhangdf064df2017-08-31 02:33:27 -0700885 EXPECT_EQ(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(new_annot, kDateKey));
886 len = FPDFAnnot_GetStringValue(new_annot, kDateKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400887 buf.clear();
888 buf.resize(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700889 EXPECT_EQ(44u,
890 FPDFAnnot_GetStringValue(new_annot, kDateKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400891 EXPECT_STREQ(new_date,
892 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
893 .c_str());
894
895 FPDFPage_CloseAnnot(new_annot);
896 CloseSaved();
897}
Diana Gage7e0c05d2017-07-19 17:33:33 -0700898
Jane Liu300bb272017-08-21 14:37:53 -0400899TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) {
900 // Open a file with annotations and load its first page.
901 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
902 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
903 ASSERT_TRUE(page);
Jane Liud1ed1ce2017-08-24 12:31:10 -0400904 EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr));
Jane Liu300bb272017-08-21 14:37:53 -0400905
906 // Retrieve the highlight annotation which has its popup defined.
907 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
908 ASSERT_TRUE(annot);
909 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
Jane Liud1ed1ce2017-08-24 12:31:10 -0400910 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot));
Lei Zhangdf064df2017-08-31 02:33:27 -0700911 static constexpr char kPopupKey[] = "Popup";
912 ASSERT_TRUE(FPDFAnnot_HasKey(annot, kPopupKey));
913 ASSERT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kPopupKey));
Jane Liu300bb272017-08-21 14:37:53 -0400914
915 // Retrieve and verify the popup of the highlight annotation.
Lei Zhangdf064df2017-08-31 02:33:27 -0700916 FPDF_ANNOTATION popup = FPDFAnnot_GetLinkedAnnot(annot, kPopupKey);
Jane Liu300bb272017-08-21 14:37:53 -0400917 ASSERT_TRUE(popup);
918 EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup));
Jane Liud1ed1ce2017-08-24 12:31:10 -0400919 EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup));
Jane Liu300bb272017-08-21 14:37:53 -0400920 FS_RECTF rect;
921 ASSERT_TRUE(FPDFAnnot_GetRect(popup, &rect));
922 EXPECT_NEAR(612.0f, rect.left, 0.001f);
923 EXPECT_NEAR(578.792, rect.bottom, 0.001f);
924
925 // Attempting to retrieve |annot|'s "IRT"-linked annotation would fail, since
926 // "IRT" is not a key in |annot|'s dictionary.
Lei Zhangdf064df2017-08-31 02:33:27 -0700927 static constexpr char kIRTKey[] = "IRT";
928 ASSERT_FALSE(FPDFAnnot_HasKey(annot, kIRTKey));
929 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, kIRTKey));
Jane Liu300bb272017-08-21 14:37:53 -0400930
931 // Attempting to retrieve |annot|'s parent dictionary as an annotation would
932 // fail, since its parent is not an annotation.
Lei Zhangdf064df2017-08-31 02:33:27 -0700933 static constexpr char kPKey[] = "P";
934 ASSERT_TRUE(FPDFAnnot_HasKey(annot, kPKey));
935 EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kPKey));
936 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, kPKey));
Jane Liu300bb272017-08-21 14:37:53 -0400937
938 FPDFPage_CloseAnnot(popup);
939 FPDFPage_CloseAnnot(annot);
940 UnloadPage(page);
941}
942
Diana Gage7e0c05d2017-07-19 17:33:33 -0700943TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) {
944 // Open file with form text fields.
945 ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
946 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
947 ASSERT_TRUE(page);
948
949 // Retrieve the first annotation: user-editable text field.
950 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
951 ASSERT_TRUE(annot);
952
953 // Check that the flag values are as expected.
954 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
955 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
956 FPDFPage_CloseAnnot(annot);
957
958 // Retrieve the second annotation: read-only text field.
959 annot = FPDFPage_GetAnnot(page, 1);
960 ASSERT_TRUE(annot);
961
962 // Check that the flag values are as expected.
963 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
964 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
965 FPDFPage_CloseAnnot(annot);
966
967 UnloadPage(page);
968}
969
970TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) {
971 // Open file with form text fields.
972 ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
973 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
974 ASSERT_TRUE(page);
975
976 // Retrieve the first annotation: user-editable combobox.
977 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
978 ASSERT_TRUE(annot);
979
980 // Check that the flag values are as expected.
981 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
982 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
983 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
984 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
985 FPDFPage_CloseAnnot(annot);
986
987 // Retrieve the second annotation: regular combobox.
988 annot = FPDFPage_GetAnnot(page, 1);
989 ASSERT_TRUE(annot);
990
991 // Check that the flag values are as expected.
992 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
993 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
994 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
995 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
996 FPDFPage_CloseAnnot(annot);
997
998 // Retrieve the third annotation: read-only combobox.
999 annot = FPDFPage_GetAnnot(page, 2);
1000 ASSERT_TRUE(annot);
1001
1002 // Check that the flag values are as expected.
1003 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1004 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1005 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1006 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1007 FPDFPage_CloseAnnot(annot);
1008
1009 UnloadPage(page);
1010}
Diana Gage40870db2017-07-19 18:16:03 -07001011
1012TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) {
1013 // Open file with form text fields.
1014 EXPECT_TRUE(OpenDocument("text_form.pdf"));
1015 FPDF_PAGE page = LoadPage(0);
1016 ASSERT_TRUE(page);
1017
1018 // Attempt to get an annotation where no annotation exists on page.
1019 FPDF_ANNOTATION annot =
1020 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0);
1021 EXPECT_FALSE(annot);
1022
1023 UnloadPage(page);
1024}
1025
1026TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) {
1027 // Open file with form text fields.
1028 EXPECT_TRUE(OpenDocument("text_form_multiple.pdf"));
1029 FPDF_PAGE page = LoadPage(0);
1030 ASSERT_TRUE(page);
1031
1032 // Retrieve user-editable text field annotation.
1033 FPDF_ANNOTATION annot =
1034 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118);
1035 ASSERT_TRUE(annot);
1036
1037 // Check that interactive form annotation flag values are as expected.
1038 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1039 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1040 FPDFPage_CloseAnnot(annot);
1041
1042 // Retrieve read-only text field annotation.
1043 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202);
1044 ASSERT_TRUE(annot);
1045
1046 // Check that interactive form annotation flag values are as expected.
1047 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1048 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1049 FPDFPage_CloseAnnot(annot);
1050
1051 UnloadPage(page);
1052}
1053
1054TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) {
1055 // Open file with form comboboxes.
1056 EXPECT_TRUE(OpenDocument("combobox_form.pdf"));
1057 FPDF_PAGE page = LoadPage(0);
1058 ASSERT_TRUE(page);
1059
1060 // Retrieve user-editable combobox annotation.
1061 FPDF_ANNOTATION annot =
1062 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 63);
1063 ASSERT_TRUE(annot);
1064
1065 // Check that interactive form annotation flag values are as expected.
1066 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1067 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1068 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1069 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1070 FPDFPage_CloseAnnot(annot);
1071
1072 // Retrieve regular combobox annotation.
1073 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 113);
1074 ASSERT_TRUE(annot);
1075
1076 // Check that interactive form annotation flag values are as expected.
1077 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1078 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1079 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1080 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1081 FPDFPage_CloseAnnot(annot);
1082
1083 // Retrieve read-only combobox annotation.
1084 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 213);
1085 ASSERT_TRUE(annot);
1086
1087 // Check that interactive form annotation flag values are as expected.
1088 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1089 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1090 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1091 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1092 FPDFPage_CloseAnnot(annot);
1093
1094 UnloadPage(page);
1095}