blob: a569c1037b781bdaede3adf95ffdd78ab55bfbaf [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 Nakashima53d443f2017-10-26 11:12:09 -0400286 const char md5[] = "dba153419f67b7c0c0e3d22d3e8910d5";
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400287
288 OpenSavedDocument();
289 LoadSavedPage();
290 VerifySavedRendering(612, 792, md5);
Jane Liu20eafda2017-06-07 10:33:24 -0400291
292 // Check that the saved document has 2 annotations on the first page
Nicolas Pena3ff54002017-07-05 11:55:35 -0400293 EXPECT_EQ(2, FPDFPage_GetAnnotCount(m_SavedPage));
Jane Liu20eafda2017-06-07 10:33:24 -0400294
295 // Check that the second annotation is an underline annotation and verify
296 // its quadpoints.
Nicolas Pena3ff54002017-07-05 11:55:35 -0400297 FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(m_SavedPage, 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
309 CloseSavedPage();
310 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 Nakashima53d443f2017-10-26 11:12:09 -0400319 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 Nakashima53d443f2017-10-26 11:12:09 -0400323 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";
Dan Sinclair698aed72017-09-26 16:24:49 -0400494#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Henrique Nakashima53d443f2017-10-26 11:12:09 -0400495 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#else
Henrique Nakashima53d443f2017-10-26 11:12:09 -0400500 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
501 const char md5_modified_path[] = "3f77b88ce6048e08e636c9a03921b2e5";
502 const char md5_two_paths[] = "bffbf5ecd15862b9fe553c795400ff8e";
503 const char md5_new_annot[] = "e020534c7eeea76be537c70d6e359a40";
Jane Liubaa7ff42017-06-29 19:18:23 -0400504#endif
505
506 // Open a file with two annotations and load its first page.
507 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
508 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
509 ASSERT_TRUE(page);
510 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
511
512 // Check that the page renders correctly.
513 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400514 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liubaa7ff42017-06-29 19:18:23 -0400515 FPDFBitmap_Destroy(bitmap);
516
517 // Retrieve the stamp annotation which has its AP stream already defined.
518 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
519 ASSERT_TRUE(annot);
520
521 // Check that this annotation has one path object and retrieve it.
Jane Liu36567742017-07-06 11:13:35 -0400522 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
523 FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot, 1);
Jane Liubaa7ff42017-06-29 19:18:23 -0400524 EXPECT_FALSE(path);
Jane Liu36567742017-07-06 11:13:35 -0400525 path = FPDFAnnot_GetObject(annot, 0);
526 EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
Jane Liubaa7ff42017-06-29 19:18:23 -0400527 EXPECT_TRUE(path);
528
529 // Modify the color of the path object.
530 EXPECT_TRUE(FPDFPath_SetStrokeColor(path, 0, 0, 0, 255));
Jane Liu36567742017-07-06 11:13:35 -0400531 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, path));
Jane Liubaa7ff42017-06-29 19:18:23 -0400532
533 // Check that the page with the modified annotation renders correctly.
534 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400535 CompareBitmap(bitmap, 595, 842, md5_modified_path);
536 FPDFBitmap_Destroy(bitmap);
537
538 // Add a second path object to the same annotation.
539 FPDF_PAGEOBJECT dot = FPDFPageObj_CreateNewPath(7, 84);
540 EXPECT_TRUE(FPDFPath_BezierTo(dot, 9, 86, 10, 87, 11, 88));
541 EXPECT_TRUE(FPDFPath_SetStrokeColor(dot, 255, 0, 0, 100));
542 EXPECT_TRUE(FPDFPath_SetStrokeWidth(dot, 14));
543 EXPECT_TRUE(FPDFPath_SetDrawMode(dot, 0, 1));
544 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, dot));
545 EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot));
546
547 // Check that the page with an annotation with two paths renders correctly.
548 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
549 CompareBitmap(bitmap, 595, 842, md5_two_paths);
550 FPDFBitmap_Destroy(bitmap);
551
552 // Delete the newly added path object.
553 EXPECT_TRUE(FPDFAnnot_RemoveObject(annot, 1));
554 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
555 FPDFPage_CloseAnnot(annot);
556
557 // Check that the page renders the same as before.
558 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
559 CompareBitmap(bitmap, 595, 842, md5_modified_path);
Jane Liubaa7ff42017-06-29 19:18:23 -0400560 FPDFBitmap_Destroy(bitmap);
561
562 // Create another stamp annotation and set its annotation rectangle.
563 annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP);
564 ASSERT_TRUE(annot);
565 FS_RECTF rect;
566 rect.left = 200.f;
567 rect.bottom = 400.f;
568 rect.right = 500.f;
569 rect.top = 600.f;
570 EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect));
571
572 // Add a new path to the annotation.
573 FPDF_PAGEOBJECT check = FPDFPageObj_CreateNewPath(200, 500);
574 EXPECT_TRUE(FPDFPath_LineTo(check, 300, 400));
575 EXPECT_TRUE(FPDFPath_LineTo(check, 500, 600));
576 EXPECT_TRUE(FPDFPath_MoveTo(check, 350, 550));
577 EXPECT_TRUE(FPDFPath_LineTo(check, 450, 450));
578 EXPECT_TRUE(FPDFPath_SetStrokeColor(check, 0, 255, 255, 180));
579 EXPECT_TRUE(FPDFPath_SetStrokeWidth(check, 8.35f));
580 EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1));
Jane Liu36567742017-07-06 11:13:35 -0400581 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, check));
582 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
Jane Liubaa7ff42017-06-29 19:18:23 -0400583
584 // Check that the annotation's bounding box came from its rectangle.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400585 FS_RECTF new_rect;
586 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liubaa7ff42017-06-29 19:18:23 -0400587 EXPECT_EQ(rect.left, new_rect.left);
588 EXPECT_EQ(rect.bottom, new_rect.bottom);
589 EXPECT_EQ(rect.right, new_rect.right);
590 EXPECT_EQ(rect.top, new_rect.top);
591
592 // Save the document, closing the page and document.
593 FPDFPage_CloseAnnot(annot);
594 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
595 FPDF_ClosePage(page);
596
597 // Open the saved document.
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400598 OpenSavedDocument();
599 LoadSavedPage();
600 VerifySavedRendering(595, 842, md5_new_annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400601
Jane Liu36567742017-07-06 11:13:35 -0400602 // Check that the document has a correct count of annotations and objects.
Nicolas Pena3ff54002017-07-05 11:55:35 -0400603 EXPECT_EQ(3, FPDFPage_GetAnnotCount(m_SavedPage));
604 annot = FPDFPage_GetAnnot(m_SavedPage, 2);
Jane Liubaa7ff42017-06-29 19:18:23 -0400605 ASSERT_TRUE(annot);
Jane Liu36567742017-07-06 11:13:35 -0400606 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
Jane Liubaa7ff42017-06-29 19:18:23 -0400607
608 // Check that the new annotation's rectangle is as defined.
Jane Liu0c6b07d2017-08-15 10:50:22 -0400609 ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect));
Jane Liubaa7ff42017-06-29 19:18:23 -0400610 EXPECT_EQ(rect.left, new_rect.left);
611 EXPECT_EQ(rect.bottom, new_rect.bottom);
612 EXPECT_EQ(rect.right, new_rect.right);
613 EXPECT_EQ(rect.top, new_rect.top);
614
Jane Liubaa7ff42017-06-29 19:18:23 -0400615 FPDFPage_CloseAnnot(annot);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400616 CloseSavedPage();
617 CloseSavedDocument();
Jane Liu8ce58f52017-06-29 13:40:22 -0400618}
Jane Liub137e752017-07-05 15:04:33 -0400619
620TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) {
621 // Open a file with an annotation and load its first page.
622 ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
623 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
624 ASSERT_TRUE(page);
625
626 // Check that the page renders correctly.
627 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
628 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
629 FPDFBitmap_Destroy(bitmap);
630
631 // Retrieve the annotation.
632 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
633 ASSERT_TRUE(annot);
634
635 // Check that the original flag values are as expected.
636 int flags = FPDFAnnot_GetFlags(annot);
637 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
638 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
639
640 // Set the HIDDEN flag.
641 flags |= FPDF_ANNOT_FLAG_HIDDEN;
642 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags));
643 flags = FPDFAnnot_GetFlags(annot);
644 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_HIDDEN);
645 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
646
647 // Check that the page renders correctly without rendering the annotation.
648 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
649 CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
650 FPDFBitmap_Destroy(bitmap);
651
652 // Unset the HIDDEN flag.
653 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, FPDF_ANNOT_FLAG_NONE));
654 EXPECT_FALSE(FPDFAnnot_GetFlags(annot));
655 flags &= ~FPDF_ANNOT_FLAG_HIDDEN;
656 EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags));
657 flags = FPDFAnnot_GetFlags(annot);
658 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
659 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
660
661 // Check that the page renders correctly as before.
662 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
663 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
664 FPDFBitmap_Destroy(bitmap);
665
666 FPDFPage_CloseAnnot(annot);
667 UnloadPage(page);
668}
Jane Liu36567742017-07-06 11:13:35 -0400669
670TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400671#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400672 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
673 const char md5_new_image[] = "ff012f5697436dfcaec25b32d1333596";
674 const char md5_modified_image[] = "86cf8cb2755a7a2046a543e66d9c1e61";
Dan Sinclair698aed72017-09-26 16:24:49 -0400675#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Henrique Nakashima53d443f2017-10-26 11:12:09 -0400676 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
677 const char md5_new_image[] = "9ea8732dc9d579f68853f16892856208";
678 const char md5_modified_image[] = "74239d2a8c55c9de1dbb9cd8781895aa";
Jane Liu36567742017-07-06 11:13:35 -0400679#else
Henrique Nakashima53d443f2017-10-26 11:12:09 -0400680 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
681 const char md5_new_image[] = "9ea8732dc9d579f68853f16892856208";
682 const char md5_modified_image[] = "74239d2a8c55c9de1dbb9cd8781895aa";
Jane Liu36567742017-07-06 11:13:35 -0400683#endif
684
685 // Open a file with two annotations and load its first page.
686 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
687 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
688 ASSERT_TRUE(page);
689 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
690
691 // Check that the page renders correctly.
692 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400693 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400694 FPDFBitmap_Destroy(bitmap);
695
696 // Create a stamp annotation and set its annotation rectangle.
697 FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP);
698 ASSERT_TRUE(annot);
699 FS_RECTF rect;
700 rect.left = 200.f;
701 rect.bottom = 600.f;
702 rect.right = 400.f;
703 rect.top = 800.f;
704 EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect));
705
706 // Add a solid-color translucent image object to the new annotation.
707 constexpr int kBitmapSize = 200;
708 FPDF_BITMAP image_bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 1);
709 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xeeeecccc);
710 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap));
711 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap));
712 FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document());
713 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
714 ASSERT_TRUE(FPDFImageObj_SetMatrix(image_object, kBitmapSize, 0, 0,
715 kBitmapSize, 0, 0));
716 FPDFPageObj_Transform(image_object, 1, 0, 0, 1, 200, 600);
717 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, image_object));
718 FPDFPage_CloseAnnot(annot);
719
720 // Check that the page renders correctly with the new image object.
721 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400722 CompareBitmap(bitmap, 595, 842, md5_new_image);
Jane Liu36567742017-07-06 11:13:35 -0400723 FPDFBitmap_Destroy(bitmap);
724
725 // Retrieve the newly added stamp annotation and its image object.
726 annot = FPDFPage_GetAnnot(page, 2);
727 ASSERT_TRUE(annot);
728 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
729 image_object = FPDFAnnot_GetObject(annot, 0);
730 EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image_object));
731
732 // Modify the image in the new annotation.
733 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xff000000);
734 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
735 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, image_object));
736 FPDFPage_CloseAnnot(annot);
737
738 // Save the document, closing the page and document.
739 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
740 FPDF_ClosePage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400741 FPDFBitmap_Destroy(image_bitmap);
Jane Liu36567742017-07-06 11:13:35 -0400742
743 // Test that the saved document renders the modified image object correctly.
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400744 VerifySavedDocument(595, 842, md5_modified_image);
Jane Liu36567742017-07-06 11:13:35 -0400745}
746
747TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400748#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400749 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
750 const char md5_new_text[] = "e5680ed048c2cfd9a1d27212cdf41286";
751 const char md5_modified_text[] = "79f5cfb0b07caaf936f65f6a7a57ce77";
Dan Sinclair698aed72017-09-26 16:24:49 -0400752#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Henrique Nakashima53d443f2017-10-26 11:12:09 -0400753 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
754 const char md5_new_text[] = "00b14fa2dc1c90d1b0d034e1608efef5";
755 const char md5_modified_text[] = "076c8f24a09ddc0e49f7e758edead6f0";
Jane Liu36567742017-07-06 11:13:35 -0400756#else
Henrique Nakashima53d443f2017-10-26 11:12:09 -0400757 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
758 const char md5_new_text[] = "00b14fa2dc1c90d1b0d034e1608efef5";
759 const char md5_modified_text[] = "076c8f24a09ddc0e49f7e758edead6f0";
Jane Liu36567742017-07-06 11:13:35 -0400760#endif
761
762 // Open a file with two annotations and load its first page.
763 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
764 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
765 ASSERT_TRUE(page);
766 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
767
768 // Check that the page renders correctly.
769 FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400770 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400771 FPDFBitmap_Destroy(bitmap);
772
773 // Create a stamp annotation and set its annotation rectangle.
774 FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP);
775 ASSERT_TRUE(annot);
776 FS_RECTF rect;
777 rect.left = 200.f;
778 rect.bottom = 550.f;
779 rect.right = 450.f;
780 rect.top = 650.f;
781 EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect));
782
783 // Add a translucent text object to the new annotation.
784 FPDF_PAGEOBJECT text_object =
785 FPDFPageObj_NewTextObj(document(), "Arial", 12.0f);
786 EXPECT_TRUE(text_object);
787 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
788 GetFPDFWideString(L"I'm a translucent text laying on other text.");
789 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
790 EXPECT_TRUE(FPDFText_SetFillColor(text_object, 0, 0, 255, 150));
791 FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 600);
792 EXPECT_TRUE(FPDFAnnot_AppendObject(annot, text_object));
793 FPDFPage_CloseAnnot(annot);
794
795 // Check that the page renders correctly with the new text object.
796 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400797 CompareBitmap(bitmap, 595, 842, md5_new_text);
Jane Liu36567742017-07-06 11:13:35 -0400798 FPDFBitmap_Destroy(bitmap);
799
800 // Retrieve the newly added stamp annotation and its text object.
801 annot = FPDFPage_GetAnnot(page, 2);
802 ASSERT_TRUE(annot);
803 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot));
804 text_object = FPDFAnnot_GetObject(annot, 0);
805 EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
806
807 // Modify the text in the new annotation.
808 std::unique_ptr<unsigned short, pdfium::FreeDeleter> new_text =
809 GetFPDFWideString(L"New text!");
810 EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get()));
811 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, text_object));
812 FPDFPage_CloseAnnot(annot);
813
814 // Check that the page renders correctly with the modified text object.
815 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400816 CompareBitmap(bitmap, 595, 842, md5_modified_text);
Jane Liu36567742017-07-06 11:13:35 -0400817 FPDFBitmap_Destroy(bitmap);
818
819 // Remove the new annotation, and check that the page renders as before.
820 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2));
821 bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400822 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400823 FPDFBitmap_Destroy(bitmap);
824
825 UnloadPage(page);
826}
Jane Liu2e1a32b2017-07-06 12:01:25 -0400827
828TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) {
829 // Open a file with four annotations and load its first page.
830 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
831 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
832 ASSERT_TRUE(page);
833
834 // Retrieve the first annotation.
835 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
836 ASSERT_TRUE(annot);
837
838 // Check that a non-existent key does not exist.
Lei Zhangdf064df2017-08-31 02:33:27 -0700839 EXPECT_FALSE(FPDFAnnot_HasKey(annot, "none"));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400840
841 // Check that the string value of a non-string dictionary entry is empty.
Lei Zhangdf064df2017-08-31 02:33:27 -0700842 static constexpr char kApKey[] = "AP";
843 EXPECT_TRUE(FPDFAnnot_HasKey(annot, kApKey));
844 EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kApKey));
845 EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot, kApKey, nullptr, 0));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400846
847 // Check that the string value of the hash is correct.
Lei Zhangdf064df2017-08-31 02:33:27 -0700848 static constexpr char kHashKey[] = "AAPL:Hash";
849 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, kHashKey));
850 unsigned long len = FPDFAnnot_GetStringValue(annot, kHashKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400851 std::vector<char> buf(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700852 EXPECT_EQ(66u, FPDFAnnot_GetStringValue(annot, kHashKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400853 EXPECT_STREQ(L"395fbcb98d558681742f30683a62a2ad",
854 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
855 .c_str());
856
857 // Check that the string value of the modified date is correct.
Lei Zhangdf064df2017-08-31 02:33:27 -0700858 static constexpr char kDateKey[] = "M";
859 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, kHashKey));
860 len = FPDFAnnot_GetStringValue(annot, kDateKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400861 buf.clear();
862 buf.resize(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700863 EXPECT_EQ(44u, FPDFAnnot_GetStringValue(annot, kDateKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400864 EXPECT_STREQ(L"D:201706071721Z00'00'",
865 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
866 .c_str());
867
868 // Update the date entry for the annotation.
869 const wchar_t new_date[] = L"D:201706282359Z00'00'";
870 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
871 GetFPDFWideString(new_date);
Lei Zhangdf064df2017-08-31 02:33:27 -0700872 EXPECT_TRUE(FPDFAnnot_SetStringValue(annot, kDateKey, text.get()));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400873
874 // Save the document, closing the page and document.
875 FPDFPage_CloseAnnot(annot);
876 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
877 FPDF_ClosePage(page);
878
879 // Open the saved annotation.
Dan Sinclair698aed72017-09-26 16:24:49 -0400880#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Artem Strygind24b97e2017-08-09 18:50:59 +0300881 const char md5[] = "4d64e61c9c0f8c60ab3cc3234bb73b1c";
Dan Sinclair698aed72017-09-26 16:24:49 -0400882#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Henrique Nakashima53d443f2017-10-26 11:12:09 -0400883 const char md5[] = "c96ee1f316d7f5a1b154de9f9d467f01";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400884#else
Henrique Nakashima53d443f2017-10-26 11:12:09 -0400885 const char md5[] = "c96ee1f316d7f5a1b154de9f9d467f01";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400886#endif
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400887 OpenSavedDocument();
888 LoadSavedPage();
889 VerifySavedRendering(595, 842, md5);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400890 FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(m_SavedPage, 0);
891
892 // Check that the string value of the modified date is the newly-set value.
Lei Zhangdf064df2017-08-31 02:33:27 -0700893 EXPECT_EQ(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(new_annot, kDateKey));
894 len = FPDFAnnot_GetStringValue(new_annot, kDateKey, nullptr, 0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400895 buf.clear();
896 buf.resize(len);
Lei Zhangdf064df2017-08-31 02:33:27 -0700897 EXPECT_EQ(44u,
898 FPDFAnnot_GetStringValue(new_annot, kDateKey, buf.data(), len));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400899 EXPECT_STREQ(new_date,
900 GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
901 .c_str());
902
903 FPDFPage_CloseAnnot(new_annot);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400904 CloseSavedPage();
905 CloseSavedDocument();
Jane Liu2e1a32b2017-07-06 12:01:25 -0400906}
Diana Gage7e0c05d2017-07-19 17:33:33 -0700907
Jane Liu300bb272017-08-21 14:37:53 -0400908TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) {
909 // Open a file with annotations and load its first page.
910 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
911 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
912 ASSERT_TRUE(page);
Jane Liud1ed1ce2017-08-24 12:31:10 -0400913 EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr));
Jane Liu300bb272017-08-21 14:37:53 -0400914
915 // Retrieve the highlight annotation which has its popup defined.
916 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
917 ASSERT_TRUE(annot);
918 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot));
Jane Liud1ed1ce2017-08-24 12:31:10 -0400919 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot));
Lei Zhangdf064df2017-08-31 02:33:27 -0700920 static constexpr char kPopupKey[] = "Popup";
921 ASSERT_TRUE(FPDFAnnot_HasKey(annot, kPopupKey));
922 ASSERT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kPopupKey));
Jane Liu300bb272017-08-21 14:37:53 -0400923
924 // Retrieve and verify the popup of the highlight annotation.
Lei Zhangdf064df2017-08-31 02:33:27 -0700925 FPDF_ANNOTATION popup = FPDFAnnot_GetLinkedAnnot(annot, kPopupKey);
Jane Liu300bb272017-08-21 14:37:53 -0400926 ASSERT_TRUE(popup);
927 EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup));
Jane Liud1ed1ce2017-08-24 12:31:10 -0400928 EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup));
Jane Liu300bb272017-08-21 14:37:53 -0400929 FS_RECTF rect;
930 ASSERT_TRUE(FPDFAnnot_GetRect(popup, &rect));
931 EXPECT_NEAR(612.0f, rect.left, 0.001f);
932 EXPECT_NEAR(578.792, rect.bottom, 0.001f);
933
934 // Attempting to retrieve |annot|'s "IRT"-linked annotation would fail, since
935 // "IRT" is not a key in |annot|'s dictionary.
Lei Zhangdf064df2017-08-31 02:33:27 -0700936 static constexpr char kIRTKey[] = "IRT";
937 ASSERT_FALSE(FPDFAnnot_HasKey(annot, kIRTKey));
938 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, kIRTKey));
Jane Liu300bb272017-08-21 14:37:53 -0400939
940 // Attempting to retrieve |annot|'s parent dictionary as an annotation would
941 // fail, since its parent is not an annotation.
Lei Zhangdf064df2017-08-31 02:33:27 -0700942 static constexpr char kPKey[] = "P";
943 ASSERT_TRUE(FPDFAnnot_HasKey(annot, kPKey));
944 EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kPKey));
945 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, kPKey));
Jane Liu300bb272017-08-21 14:37:53 -0400946
947 FPDFPage_CloseAnnot(popup);
948 FPDFPage_CloseAnnot(annot);
949 UnloadPage(page);
950}
951
Diana Gage7e0c05d2017-07-19 17:33:33 -0700952TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) {
953 // Open file with form text fields.
954 ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
955 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
956 ASSERT_TRUE(page);
957
958 // Retrieve the first annotation: user-editable text field.
959 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
960 ASSERT_TRUE(annot);
961
962 // Check that the flag values are as expected.
963 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
964 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
965 FPDFPage_CloseAnnot(annot);
966
967 // Retrieve the second annotation: read-only text field.
968 annot = FPDFPage_GetAnnot(page, 1);
969 ASSERT_TRUE(annot);
970
971 // Check that the flag values are as expected.
972 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
973 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
974 FPDFPage_CloseAnnot(annot);
975
976 UnloadPage(page);
977}
978
979TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) {
980 // Open file with form text fields.
981 ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
982 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
983 ASSERT_TRUE(page);
984
985 // Retrieve the first annotation: user-editable combobox.
986 FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
987 ASSERT_TRUE(annot);
988
989 // Check that the flag values are as expected.
990 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
991 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
992 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
993 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
994 FPDFPage_CloseAnnot(annot);
995
996 // Retrieve the second annotation: regular combobox.
997 annot = FPDFPage_GetAnnot(page, 1);
998 ASSERT_TRUE(annot);
999
1000 // Check that the flag values are as expected.
1001 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1002 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1003 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1004 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1005 FPDFPage_CloseAnnot(annot);
1006
1007 // Retrieve the third annotation: read-only combobox.
1008 annot = FPDFPage_GetAnnot(page, 2);
1009 ASSERT_TRUE(annot);
1010
1011 // Check that the flag values are as expected.
1012 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1013 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1014 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1015 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1016 FPDFPage_CloseAnnot(annot);
1017
1018 UnloadPage(page);
1019}
Diana Gage40870db2017-07-19 18:16:03 -07001020
1021TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) {
1022 // Open file with form text fields.
1023 EXPECT_TRUE(OpenDocument("text_form.pdf"));
1024 FPDF_PAGE page = LoadPage(0);
1025 ASSERT_TRUE(page);
1026
1027 // Attempt to get an annotation where no annotation exists on page.
1028 FPDF_ANNOTATION annot =
1029 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0);
1030 EXPECT_FALSE(annot);
1031
1032 UnloadPage(page);
1033}
1034
1035TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) {
1036 // Open file with form text fields.
1037 EXPECT_TRUE(OpenDocument("text_form_multiple.pdf"));
1038 FPDF_PAGE page = LoadPage(0);
1039 ASSERT_TRUE(page);
1040
1041 // Retrieve user-editable text field annotation.
1042 FPDF_ANNOTATION annot =
1043 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118);
1044 ASSERT_TRUE(annot);
1045
1046 // Check that interactive form annotation flag values are as expected.
1047 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1048 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1049 FPDFPage_CloseAnnot(annot);
1050
1051 // Retrieve read-only text field annotation.
1052 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202);
1053 ASSERT_TRUE(annot);
1054
1055 // Check that interactive form annotation flag values are as expected.
1056 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1057 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1058 FPDFPage_CloseAnnot(annot);
1059
1060 UnloadPage(page);
1061}
1062
1063TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) {
1064 // Open file with form comboboxes.
1065 EXPECT_TRUE(OpenDocument("combobox_form.pdf"));
1066 FPDF_PAGE page = LoadPage(0);
1067 ASSERT_TRUE(page);
1068
1069 // Retrieve user-editable combobox annotation.
1070 FPDF_ANNOTATION annot =
1071 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 63);
1072 ASSERT_TRUE(annot);
1073
1074 // Check that interactive form annotation flag values are as expected.
1075 int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1076 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1077 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1078 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1079 FPDFPage_CloseAnnot(annot);
1080
1081 // Retrieve regular combobox annotation.
1082 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 113);
1083 ASSERT_TRUE(annot);
1084
1085 // Check that interactive form annotation flag values are as expected.
1086 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1087 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1088 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1089 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1090 FPDFPage_CloseAnnot(annot);
1091
1092 // Retrieve read-only combobox annotation.
1093 annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 213);
1094 ASSERT_TRUE(annot);
1095
1096 // Check that interactive form annotation flag values are as expected.
1097 flags = FPDFAnnot_GetFormFieldFlags(page, annot);
1098 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1099 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1100 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1101 FPDFPage_CloseAnnot(annot);
1102
1103 UnloadPage(page);
1104}