blob: 54063973759a9f510d8adfb6ca62b2ae7b8f86b4 [file] [log] [blame]
Jane Liu4fd9a472017-06-01 18:56:09 -04001// Copyright 2017 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00005#include <cwchar>
Jane Liu20eafda2017-06-07 10:33:24 -04006#include <memory>
7#include <string>
Jane Liu4fd9a472017-06-01 18:56:09 -04008#include <vector>
9
Jane Liubaa7ff42017-06-29 19:18:23 -040010#include "core/fxcrt/fx_system.h"
Lei Zhanga21d5932018-02-05 18:28:38 +000011#include "public/cpp/fpdf_deleters.h"
Jane Liu4fd9a472017-06-01 18:56:09 -040012#include "public/fpdf_annot.h"
Jane Liubaa7ff42017-06-29 19:18:23 -040013#include "public/fpdf_edit.h"
Jane Liu4fd9a472017-06-01 18:56:09 -040014#include "public/fpdfview.h"
15#include "testing/embedder_test.h"
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +000016#include "testing/gmock/include/gmock/gmock-matchers.h"
Jane Liu4fd9a472017-06-01 18:56:09 -040017#include "testing/gtest/include/gtest/gtest.h"
18
Lei Zhangdf064df2017-08-31 02:33:27 -070019static constexpr char kContentsKey[] = "Contents";
20
Nicolas Pena3ff54002017-07-05 11:55:35 -040021class FPDFAnnotEmbeddertest : public EmbedderTest {};
Jane Liu4fd9a472017-06-01 18:56:09 -040022
Lei Zhang4afee172018-01-10 20:57:15 +000023std::wstring BufferToWString(const std::vector<char>& buf) {
24 return GetPlatformWString(reinterpret_cast<FPDF_WIDESTRING>(buf.data()));
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +000025}
26
Lei Zhang4afee172018-01-10 20:57:15 +000027std::string BufferToString(const std::vector<char>& buf) {
28 return GetPlatformString(reinterpret_cast<FPDF_WIDESTRING>(buf.data()));
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +000029}
30
Jane Liue17011d2017-06-21 12:18:37 -040031TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) {
32 // Open a file with one annotation and load its first page.
33 ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +000034 FPDF_PAGE page = LoadPage(0);
Jane Liue17011d2017-06-21 12:18:37 -040035 ASSERT_TRUE(page);
36
37 // This annotation has a malformed appearance stream, which does not have its
38 // normal appearance defined, only its rollover appearance. In this case, its
39 // normal appearance should be generated, allowing the highlight annotation to
40 // still display.
Lei Zhanga98e3662018-02-07 20:28:35 +000041 std::unique_ptr<void, FPDFBitmapDeleter> bitmap =
42 RenderLoadedPageWithFlags(page, FPDF_ANNOT);
43 CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
Jane Liue17011d2017-06-21 12:18:37 -040044
45 UnloadPage(page);
46}
47
Jane Liu4fd9a472017-06-01 18:56:09 -040048TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) {
49 // Open a file with one annotation and load its first page.
50 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +000051 // TODO(thestig): This test should use LoadPage() and UnloadPage(), but one of
52 // the FORM API calls in LoadPage() makes this test fail. So use
53 // FPDF_LoadPage() and FPDF_ClosePage() for now.
Jane Liu4fd9a472017-06-01 18:56:09 -040054 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
55 ASSERT_TRUE(page);
56
57 // Check that there is a total of 1 annotation on its first page.
58 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
59
60 // Check that the annotation is of type "highlight".
Lei Zhanga21d5932018-02-05 18:28:38 +000061 {
62 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
63 FPDFPage_GetAnnot(page, 0));
64 ASSERT_TRUE(annot);
65 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
Jane Liu4fd9a472017-06-01 18:56:09 -040066
Lei Zhanga21d5932018-02-05 18:28:38 +000067 // Check that the annotation color is yellow.
68 unsigned int R;
69 unsigned int G;
70 unsigned int B;
71 unsigned int A;
Lei Zhang75c81712018-02-08 17:22:39 +000072 ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R,
Lei Zhanga21d5932018-02-05 18:28:38 +000073 &G, &B, &A));
74 EXPECT_EQ(255u, R);
75 EXPECT_EQ(255u, G);
76 EXPECT_EQ(0u, B);
77 EXPECT_EQ(255u, A);
Jane Liu4fd9a472017-06-01 18:56:09 -040078
Lei Zhanga21d5932018-02-05 18:28:38 +000079 // Check that the author is correct.
80 static constexpr char kAuthorKey[] = "T";
81 EXPECT_EQ(FPDF_OBJECT_STRING,
82 FPDFAnnot_GetValueType(annot.get(), kAuthorKey));
83 unsigned long len =
84 FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, nullptr, 0);
85 std::vector<char> buf(len);
86 EXPECT_EQ(28u, FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, buf.data(),
87 len));
88 EXPECT_STREQ(L"Jae Hyun Park", BufferToWString(buf).c_str());
Jane Liu4fd9a472017-06-01 18:56:09 -040089
Lei Zhanga21d5932018-02-05 18:28:38 +000090 // Check that the content is correct.
91 EXPECT_EQ(FPDF_OBJECT_STRING,
92 FPDFAnnot_GetValueType(annot.get(), kContentsKey));
93 len = FPDFAnnot_GetStringValue(annot.get(), kContentsKey, nullptr, 0);
94 buf.clear();
95 buf.resize(len);
96 EXPECT_EQ(2690u, FPDFAnnot_GetStringValue(annot.get(), kContentsKey,
97 buf.data(), len));
98 const wchar_t contents[] =
99 L"This is a note for that highlight annotation. Very long highlight "
100 "annotation. Long long long Long long longLong long longLong long "
101 "longLong long longLong long longLong long longLong long longLong long "
102 "longLong long longLong long longLong long longLong long longLong long "
103 "longLong long longLong long longLong long longLong long longLong long "
104 "longLong long longLong long longLong long longLong long longLong long "
105 "longLong long longLong long longLong long longLong long longLong long "
106 "longLong long longLong long longLong long longLong long longLong long "
107 "longLong long longLong long longLong long longLong long longLong long "
108 "longLong long longLong long longLong long longLong long longLong long "
109 "longLong long longLong long longLong long longLong long longLong long "
110 "longLong long longLong long longLong long longLong long longLong long "
111 "longLong long longLong long longLong long longLong long longLong long "
112 "longLong long longLong long longLong long longLong long longLong long "
113 "longLong long longLong long longLong long longLong long longLong long "
114 "longLong long longLong long longLong long longLong long longLong long "
115 "longLong long longLong long longLong long longLong long longLong long "
116 "longLong long longLong long longLong long longLong long longLong long "
117 "longLong long longLong long longLong long longLong long longLong long "
118 "longLong long long. END";
119 EXPECT_STREQ(contents, BufferToWString(buf).c_str());
Jane Liu4fd9a472017-06-01 18:56:09 -0400120
Lei Zhanga21d5932018-02-05 18:28:38 +0000121 // Check that the quadpoints are correct.
122 FS_QUADPOINTSF quadpoints;
123 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
124 EXPECT_EQ(115.802643f, quadpoints.x1);
125 EXPECT_EQ(718.913940f, quadpoints.y1);
126 EXPECT_EQ(157.211182f, quadpoints.x4);
127 EXPECT_EQ(706.264465f, quadpoints.y4);
128 }
Lei Zhang75c81712018-02-08 17:22:39 +0000129 FPDF_ClosePage(page);
Jane Liu4fd9a472017-06-01 18:56:09 -0400130}
131
132TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) {
133 // Open a file with three annotations and load its first page.
134 ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000135 // TODO(thestig): This test should use LoadPage() and UnloadPage(), but one of
136 // the FORM API calls in LoadPage() makes this test fail. So use
137 // FPDF_LoadPage() and FPDF_ClosePage() for now.
Jane Liu4fd9a472017-06-01 18:56:09 -0400138 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
139 ASSERT_TRUE(page);
140
141 // Check that there is a total of 3 annotation on its first page.
142 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
143
Lei Zhanga21d5932018-02-05 18:28:38 +0000144 {
145 // Check that the third annotation is of type "ink".
146 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
147 FPDFPage_GetAnnot(page, 2));
148 ASSERT_TRUE(annot);
149 EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot.get()));
Jane Liu4fd9a472017-06-01 18:56:09 -0400150
Lei Zhanga21d5932018-02-05 18:28:38 +0000151 // Check that the annotation color is blue with opacity.
152 unsigned int R;
153 unsigned int G;
154 unsigned int B;
155 unsigned int A;
Lei Zhang75c81712018-02-08 17:22:39 +0000156 ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R,
Lei Zhanga21d5932018-02-05 18:28:38 +0000157 &G, &B, &A));
158 EXPECT_EQ(0u, R);
159 EXPECT_EQ(0u, G);
160 EXPECT_EQ(255u, B);
161 EXPECT_EQ(76u, A);
Jane Liu4fd9a472017-06-01 18:56:09 -0400162
Lei Zhanga21d5932018-02-05 18:28:38 +0000163 // Check that there is no content.
164 EXPECT_EQ(2u,
165 FPDFAnnot_GetStringValue(annot.get(), kContentsKey, nullptr, 0));
Jane Liu4fd9a472017-06-01 18:56:09 -0400166
Lei Zhanga21d5932018-02-05 18:28:38 +0000167 // Check that the rectange coordinates are correct.
168 // Note that upon rendering, the rectangle coordinates will be adjusted.
169 FS_RECTF rect;
170 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
171 EXPECT_EQ(351.820404f, rect.left);
172 EXPECT_EQ(583.830688f, rect.bottom);
173 EXPECT_EQ(475.336090f, rect.right);
174 EXPECT_EQ(681.535034f, rect.top);
175 }
Lei Zhang75c81712018-02-08 17:22:39 +0000176 FPDF_ClosePage(page);
Jane Liu4fd9a472017-06-01 18:56:09 -0400177}
Jane Liu20eafda2017-06-07 10:33:24 -0400178
179TEST_F(FPDFAnnotEmbeddertest, AddIllegalSubtypeAnnotation) {
180 // Open a file with one annotation and load its first page.
181 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000182 FPDF_PAGE page = LoadPage(0);
Jane Liu20eafda2017-06-07 10:33:24 -0400183 ASSERT_TRUE(page);
184
185 // Add an annotation with an illegal subtype.
Jane Liud60e9ad2017-06-26 11:28:36 -0400186 ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1));
Jane Liu20eafda2017-06-07 10:33:24 -0400187
188 UnloadPage(page);
189}
190
Jane Liud321ef92017-06-14 09:56:22 -0400191TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) {
Jane Liu20eafda2017-06-07 10:33:24 -0400192 // Open a file with no annotation and load its first page.
193 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000194 FPDF_PAGE page = LoadPage(0);
Jane Liu20eafda2017-06-07 10:33:24 -0400195 ASSERT_TRUE(page);
196 EXPECT_EQ(0, FPDFPage_GetAnnotCount(page));
197
Lei Zhanga21d5932018-02-05 18:28:38 +0000198 {
199 // Add a text annotation to the page.
200 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
201 FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT));
202 ASSERT_TRUE(annot);
Jane Liu20eafda2017-06-07 10:33:24 -0400203
Lei Zhanga21d5932018-02-05 18:28:38 +0000204 // Check that there is now 1 annotations on this page.
205 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
Jane Liu20eafda2017-06-07 10:33:24 -0400206
Lei Zhanga21d5932018-02-05 18:28:38 +0000207 // Check that the subtype of the annotation is correct.
208 EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get()));
209 }
Jane Liue10509a2017-06-20 16:47:41 -0400210
Lei Zhanga21d5932018-02-05 18:28:38 +0000211 {
212 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
213 FPDFPage_GetAnnot(page, 0));
214 ASSERT_TRUE(annot);
215 EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get()));
Jane Liu20eafda2017-06-07 10:33:24 -0400216
Lei Zhanga21d5932018-02-05 18:28:38 +0000217 // Set the color of the annotation.
218 ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 51,
219 102, 153, 204));
220 // Check that the color has been set correctly.
221 unsigned int R;
222 unsigned int G;
223 unsigned int B;
224 unsigned int A;
Lei Zhang75c81712018-02-08 17:22:39 +0000225 ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R,
Lei Zhanga21d5932018-02-05 18:28:38 +0000226 &G, &B, &A));
227 EXPECT_EQ(51u, R);
228 EXPECT_EQ(102u, G);
229 EXPECT_EQ(153u, B);
230 EXPECT_EQ(204u, A);
Jane Liu20eafda2017-06-07 10:33:24 -0400231
Lei Zhanga21d5932018-02-05 18:28:38 +0000232 // Change the color of the annotation.
233 ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 204,
234 153, 102, 51));
235 // Check that the color has been set correctly.
Lei Zhang75c81712018-02-08 17:22:39 +0000236 ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R,
Lei Zhanga21d5932018-02-05 18:28:38 +0000237 &G, &B, &A));
238 EXPECT_EQ(204u, R);
239 EXPECT_EQ(153u, G);
240 EXPECT_EQ(102u, B);
241 EXPECT_EQ(51u, A);
Jane Liu20eafda2017-06-07 10:33:24 -0400242
Lei Zhanga21d5932018-02-05 18:28:38 +0000243 // Set the annotation rectangle.
244 FS_RECTF rect;
245 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
246 EXPECT_EQ(0.f, rect.left);
247 EXPECT_EQ(0.f, rect.right);
248 rect.left = 35;
249 rect.bottom = 150;
250 rect.right = 53;
251 rect.top = 165;
252 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
253 // Check that the annotation rectangle has been set correctly.
254 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
255 EXPECT_EQ(35.f, rect.left);
256 EXPECT_EQ(150.f, rect.bottom);
257 EXPECT_EQ(53.f, rect.right);
258 EXPECT_EQ(165.f, rect.top);
Jane Liu20eafda2017-06-07 10:33:24 -0400259
Lei Zhanga21d5932018-02-05 18:28:38 +0000260 // Set the content of the annotation.
261 static constexpr wchar_t kContents[] =
262 L"Hello! This is a customized content.";
263 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
264 GetFPDFWideString(kContents);
265 ASSERT_TRUE(
266 FPDFAnnot_SetStringValue(annot.get(), kContentsKey, text.get()));
267 // Check that the content has been set correctly.
268 unsigned long len =
269 FPDFAnnot_GetStringValue(annot.get(), kContentsKey, nullptr, 0);
270 std::vector<char> buf(len);
271 EXPECT_EQ(74u, FPDFAnnot_GetStringValue(annot.get(), kContentsKey,
272 buf.data(), len));
273 EXPECT_STREQ(kContents, BufferToWString(buf).c_str());
274 }
Jane Liu20eafda2017-06-07 10:33:24 -0400275 UnloadPage(page);
276}
277
278TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) {
279 // Open a file with one annotation and load its first page.
280 ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000281 FPDF_PAGE page = LoadPage(0);
Jane Liu20eafda2017-06-07 10:33:24 -0400282 ASSERT_TRUE(page);
283
284 // Check that there is a total of one annotation on its first page, and verify
285 // its quadpoints.
286 EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
Jane Liu0c6b07d2017-08-15 10:50:22 -0400287 FS_QUADPOINTSF quadpoints;
Lei Zhanga21d5932018-02-05 18:28:38 +0000288 {
289 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
290 FPDFPage_GetAnnot(page, 0));
291 ASSERT_TRUE(annot);
292 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
293 EXPECT_EQ(115.802643f, quadpoints.x1);
294 EXPECT_EQ(718.913940f, quadpoints.y1);
295 EXPECT_EQ(157.211182f, quadpoints.x4);
296 EXPECT_EQ(706.264465f, quadpoints.y4);
297 }
Jane Liu20eafda2017-06-07 10:33:24 -0400298
299 // Add an underline annotation to the page and set its quadpoints.
Lei Zhanga21d5932018-02-05 18:28:38 +0000300 {
301 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
302 FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE));
303 ASSERT_TRUE(annot);
304 quadpoints.x1 = 140.802643f;
305 quadpoints.x3 = 140.802643f;
306 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), &quadpoints));
307 }
Jane Liu20eafda2017-06-07 10:33:24 -0400308
309 // Save the document, closing the page and document.
310 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +0000311 UnloadPage(page);
Jane Liu20eafda2017-06-07 10:33:24 -0400312
313 // Open the saved document.
Henrique Nakashima09b41922017-10-27 20:39:29 +0000314 const char md5[] = "dba153419f67b7c0c0e3d22d3e8910d5";
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400315
316 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000317 page = LoadSavedPage(0);
318 VerifySavedRendering(page, 612, 792, md5);
Jane Liu20eafda2017-06-07 10:33:24 -0400319
320 // Check that the saved document has 2 annotations on the first page
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000321 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
Jane Liu20eafda2017-06-07 10:33:24 -0400322
Lei Zhanga21d5932018-02-05 18:28:38 +0000323 {
324 // Check that the second annotation is an underline annotation and verify
325 // its quadpoints.
326 std::unique_ptr<void, FPDFAnnotationDeleter> new_annot(
327 FPDFPage_GetAnnot(page, 1));
328 ASSERT_TRUE(new_annot);
329 EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot.get()));
330 FS_QUADPOINTSF new_quadpoints;
331 ASSERT_TRUE(
332 FPDFAnnot_GetAttachmentPoints(new_annot.get(), &new_quadpoints));
333 EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f);
334 EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f);
335 EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f);
336 EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f);
337 }
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400338
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000339 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400340 CloseSavedDocument();
Jane Liu20eafda2017-06-07 10:33:24 -0400341}
Jane Liu06462752017-06-27 16:41:14 -0400342
343TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400344#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liub370e5a2017-08-16 13:24:58 -0400345 const char md5_original[] = "63af8432fab95a67cdebb7cd0e514941";
346 const char md5_modified_highlight[] = "aec26075011349dec9bace891856b5f2";
347 const char md5_modified_square[] = "057f57a32be95975775e5ec513fdcb56";
Dan Sinclair698aed72017-09-26 16:24:49 -0400348#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
Henrique Nakashima09b41922017-10-27 20:39:29 +0000349 const char md5_original[] = "0e27376094f11490f74c65f3dc3a42c5";
350 const char md5_modified_highlight[] = "66f3caef3a7d488a4fa1ad37fc06310e";
351 const char md5_modified_square[] = "a456dad0bc6801ee2d6408a4394af563";
Jane Liub370e5a2017-08-16 13:24:58 -0400352#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000353 const char md5_original[] = "0e27376094f11490f74c65f3dc3a42c5";
354 const char md5_modified_highlight[] = "66f3caef3a7d488a4fa1ad37fc06310e";
355 const char md5_modified_square[] = "a456dad0bc6801ee2d6408a4394af563";
Jane Liub370e5a2017-08-16 13:24:58 -0400356#endif
357
Jane Liu06462752017-06-27 16:41:14 -0400358 // Open a file with four annotations and load its first page.
359 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000360 FPDF_PAGE page = LoadPage(0);
Jane Liu06462752017-06-27 16:41:14 -0400361 ASSERT_TRUE(page);
362 EXPECT_EQ(4, FPDFPage_GetAnnotCount(page));
363
Jane Liub370e5a2017-08-16 13:24:58 -0400364 // Check that the original file renders correctly.
Lei Zhanga98e3662018-02-07 20:28:35 +0000365 FPDF_BITMAP bitmap =
366 RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liub370e5a2017-08-16 13:24:58 -0400367 CompareBitmap(bitmap, 612, 792, md5_original);
368 FPDFBitmap_Destroy(bitmap);
369
Jane Liu0c6b07d2017-08-15 10:50:22 -0400370 FS_RECTF rect;
Jane Liu0c6b07d2017-08-15 10:50:22 -0400371 FS_RECTF new_rect;
Lei Zhanga21d5932018-02-05 18:28:38 +0000372
373 // Retrieve the highlight annotation which has its AP stream already defined.
374 {
375 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
376 FPDFPage_GetAnnot(page, 0));
377 ASSERT_TRUE(annot);
378 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
379
380 // Check that color cannot be set when an AP stream is defined already.
381 EXPECT_FALSE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 51,
382 102, 153, 204));
383
384 // Verify its attachment points.
385 FS_QUADPOINTSF quadpoints;
386 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &quadpoints));
387 EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f);
388 EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f);
389 EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f);
390 EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f);
391
392 // Check that updating the attachment points would succeed.
393 quadpoints.x1 -= 50.f;
394 quadpoints.x2 -= 50.f;
395 quadpoints.x3 -= 50.f;
396 quadpoints.x4 -= 50.f;
397 ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), &quadpoints));
398 FS_QUADPOINTSF new_quadpoints;
399 ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), &new_quadpoints));
400 EXPECT_EQ(quadpoints.x1, new_quadpoints.x1);
401 EXPECT_EQ(quadpoints.y1, new_quadpoints.y1);
402 EXPECT_EQ(quadpoints.x4, new_quadpoints.x4);
403 EXPECT_EQ(quadpoints.y4, new_quadpoints.y4);
404
405 // Check that updating quadpoints does not change the annotation's position.
Lei Zhanga98e3662018-02-07 20:28:35 +0000406 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Lei Zhanga21d5932018-02-05 18:28:38 +0000407 CompareBitmap(bitmap, 612, 792, md5_original);
408 FPDFBitmap_Destroy(bitmap);
409
410 // Verify its annotation rectangle.
411 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
412 EXPECT_NEAR(67.7299f, rect.left, 0.001f);
413 EXPECT_NEAR(704.296f, rect.bottom, 0.001f);
414 EXPECT_NEAR(136.325f, rect.right, 0.001f);
415 EXPECT_NEAR(721.292f, rect.top, 0.001f);
416
417 // Check that updating the rectangle would succeed.
418 rect.left -= 60.f;
419 rect.right -= 60.f;
420 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
421 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
422 EXPECT_EQ(rect.right, new_rect.right);
423 }
Jane Liu06462752017-06-27 16:41:14 -0400424
Jane Liub370e5a2017-08-16 13:24:58 -0400425 // Check that updating the rectangle changes the annotation's position.
Lei Zhanga98e3662018-02-07 20:28:35 +0000426 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liub370e5a2017-08-16 13:24:58 -0400427 CompareBitmap(bitmap, 612, 792, md5_modified_highlight);
428 FPDFBitmap_Destroy(bitmap);
429
Lei Zhanga21d5932018-02-05 18:28:38 +0000430 {
431 // Retrieve the square annotation which has its AP stream already defined.
432 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
433 FPDFPage_GetAnnot(page, 2));
434 ASSERT_TRUE(annot);
435 EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot.get()));
Jane Liu06462752017-06-27 16:41:14 -0400436
Lei Zhanga21d5932018-02-05 18:28:38 +0000437 // Check that updating the rectangle would succeed.
438 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
439 rect.left += 70.f;
440 rect.right += 70.f;
441 ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
442 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
443 EXPECT_EQ(rect.right, new_rect.right);
Jane Liu06462752017-06-27 16:41:14 -0400444
Lei Zhanga21d5932018-02-05 18:28:38 +0000445 // Check that updating the rectangle changes the square annotation's
446 // position.
Lei Zhanga98e3662018-02-07 20:28:35 +0000447 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Lei Zhanga21d5932018-02-05 18:28:38 +0000448 CompareBitmap(bitmap, 612, 792, md5_modified_square);
449 FPDFBitmap_Destroy(bitmap);
450 }
Jane Liub370e5a2017-08-16 13:24:58 -0400451
Jane Liu06462752017-06-27 16:41:14 -0400452 UnloadPage(page);
453}
Jane Liu8ce58f52017-06-29 13:40:22 -0400454
455TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) {
456 // Open a file with 3 annotations on its first page.
457 ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000458 // TODO(thestig): This test should use LoadPage() and UnloadPage(), but one of
459 // the FORM API calls in LoadPage() makes this test fail. So use
460 // FPDF_LoadPage() and FPDF_ClosePage() for now.
Jane Liu8ce58f52017-06-29 13:40:22 -0400461 FPDF_PAGE page = FPDF_LoadPage(document(), 0);
462 ASSERT_TRUE(page);
463 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
464
Jane Liu0c6b07d2017-08-15 10:50:22 -0400465 FS_RECTF rect;
Jane Liu8ce58f52017-06-29 13:40:22 -0400466
Lei Zhanga21d5932018-02-05 18:28:38 +0000467 // Check that the annotations have the expected rectangle coordinates.
468 {
469 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
470 FPDFPage_GetAnnot(page, 0));
471 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
472 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
473 }
Jane Liu8ce58f52017-06-29 13:40:22 -0400474
Lei Zhanga21d5932018-02-05 18:28:38 +0000475 {
476 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
477 FPDFPage_GetAnnot(page, 1));
478 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
479 EXPECT_NEAR(149.8127f, rect.left, 0.001f);
480 }
481
482 {
483 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
484 FPDFPage_GetAnnot(page, 2));
485 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
486 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
487 }
Jane Liu8ce58f52017-06-29 13:40:22 -0400488
489 // Check that nothing happens when attempting to remove an annotation with an
490 // out-of-bound index.
491 EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4));
492 EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1));
493 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
494
495 // Remove the second annotation.
496 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1));
497 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
498 EXPECT_FALSE(FPDFPage_GetAnnot(page, 2));
499
500 // Save the document, closing the page and document.
501 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
502 FPDF_ClosePage(page);
503
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400504 // TODO(npm): VerifySavedRendering changes annot rect dimensions by 1??
Jane Liu8ce58f52017-06-29 13:40:22 -0400505 // Open the saved document.
506 std::string new_file = GetString();
507 FPDF_FILEACCESS file_access;
508 memset(&file_access, 0, sizeof(file_access));
509 file_access.m_FileLen = new_file.size();
510 file_access.m_GetBlock = GetBlockFromString;
511 file_access.m_Param = &new_file;
512 FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
513 ASSERT_TRUE(new_doc);
514 FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
515 ASSERT_TRUE(new_page);
516
517 // Check that the saved document has 2 annotations on the first page.
518 EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page));
519
Lei Zhanga21d5932018-02-05 18:28:38 +0000520 // Check that the remaining 2 annotations are the original 1st and 3rd ones
521 // by verifying their rectangle coordinates.
522 {
523 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
524 FPDFPage_GetAnnot(new_page, 0));
525 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
526 EXPECT_NEAR(86.1971f, rect.left, 0.001f);
527 }
Jane Liu8ce58f52017-06-29 13:40:22 -0400528
Lei Zhanga21d5932018-02-05 18:28:38 +0000529 {
530 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
531 FPDFPage_GetAnnot(new_page, 1));
532 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect));
533 EXPECT_NEAR(351.8204f, rect.left, 0.001f);
534 }
Jane Liubaa7ff42017-06-29 19:18:23 -0400535 FPDF_ClosePage(new_page);
536 FPDF_CloseDocument(new_doc);
537}
Jane Liu8ce58f52017-06-29 13:40:22 -0400538
Jane Liubaa7ff42017-06-29 19:18:23 -0400539TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400540#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400541 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
542 const char md5_modified_path[] = "cf3cea74bd46497520ff6c4d1ea228c8";
543 const char md5_two_paths[] = "e8994452fc4385337bae5522354e10ff";
544 const char md5_new_annot[] = "ee5372b31fede117fc83b9384598aa25";
Jane Liubaa7ff42017-06-29 19:18:23 -0400545#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000546 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
547 const char md5_modified_path[] = "3f77b88ce6048e08e636c9a03921b2e5";
548 const char md5_two_paths[] = "bffbf5ecd15862b9fe553c795400ff8e";
549 const char md5_new_annot[] = "e020534c7eeea76be537c70d6e359a40";
Jane Liubaa7ff42017-06-29 19:18:23 -0400550#endif
551
552 // Open a file with two annotations and load its first page.
553 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000554 FPDF_PAGE page = LoadPage(0);
Jane Liubaa7ff42017-06-29 19:18:23 -0400555 ASSERT_TRUE(page);
556 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
557
558 // Check that the page renders correctly.
Lei Zhanga98e3662018-02-07 20:28:35 +0000559 FPDF_BITMAP bitmap =
560 RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400561 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liubaa7ff42017-06-29 19:18:23 -0400562 FPDFBitmap_Destroy(bitmap);
563
Lei Zhanga21d5932018-02-05 18:28:38 +0000564 {
565 // Retrieve the stamp annotation which has its AP stream already defined.
566 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
567 FPDFPage_GetAnnot(page, 0));
568 ASSERT_TRUE(annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400569
Lei Zhanga21d5932018-02-05 18:28:38 +0000570 // Check that this annotation has one path object and retrieve it.
571 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
572 FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot.get(), 1);
573 EXPECT_FALSE(path);
574 path = FPDFAnnot_GetObject(annot.get(), 0);
575 EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
576 EXPECT_TRUE(path);
Jane Liubaa7ff42017-06-29 19:18:23 -0400577
Lei Zhanga21d5932018-02-05 18:28:38 +0000578 // Modify the color of the path object.
579 EXPECT_TRUE(FPDFPath_SetStrokeColor(path, 0, 0, 0, 255));
580 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), path));
Jane Liubaa7ff42017-06-29 19:18:23 -0400581
Lei Zhanga21d5932018-02-05 18:28:38 +0000582 // Check that the page with the modified annotation renders correctly.
Lei Zhanga98e3662018-02-07 20:28:35 +0000583 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Lei Zhanga21d5932018-02-05 18:28:38 +0000584 CompareBitmap(bitmap, 595, 842, md5_modified_path);
585 FPDFBitmap_Destroy(bitmap);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400586
Lei Zhanga21d5932018-02-05 18:28:38 +0000587 // Add a second path object to the same annotation.
588 FPDF_PAGEOBJECT dot = FPDFPageObj_CreateNewPath(7, 84);
589 EXPECT_TRUE(FPDFPath_BezierTo(dot, 9, 86, 10, 87, 11, 88));
590 EXPECT_TRUE(FPDFPath_SetStrokeColor(dot, 255, 0, 0, 100));
591 EXPECT_TRUE(FPDFPath_SetStrokeWidth(dot, 14));
592 EXPECT_TRUE(FPDFPath_SetDrawMode(dot, 0, 1));
593 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), dot));
594 EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot.get()));
Jane Liu7a9a38b2017-07-11 13:47:37 -0400595
Lei Zhanga21d5932018-02-05 18:28:38 +0000596 // Check that the page with an annotation with two paths renders correctly.
Lei Zhanga98e3662018-02-07 20:28:35 +0000597 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Lei Zhanga21d5932018-02-05 18:28:38 +0000598 CompareBitmap(bitmap, 595, 842, md5_two_paths);
599 FPDFBitmap_Destroy(bitmap);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400600
Lei Zhanga21d5932018-02-05 18:28:38 +0000601 // Delete the newly added path object.
602 EXPECT_TRUE(FPDFAnnot_RemoveObject(annot.get(), 1));
603 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
604 }
Jane Liu7a9a38b2017-07-11 13:47:37 -0400605
606 // Check that the page renders the same as before.
Lei Zhanga98e3662018-02-07 20:28:35 +0000607 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400608 CompareBitmap(bitmap, 595, 842, md5_modified_path);
Jane Liubaa7ff42017-06-29 19:18:23 -0400609 FPDFBitmap_Destroy(bitmap);
610
Jane Liubaa7ff42017-06-29 19:18:23 -0400611 FS_RECTF rect;
Jane Liubaa7ff42017-06-29 19:18:23 -0400612
Lei Zhanga21d5932018-02-05 18:28:38 +0000613 {
614 // Create another stamp annotation and set its annotation rectangle.
615 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
616 FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
617 ASSERT_TRUE(annot);
618 rect.left = 200.f;
619 rect.bottom = 400.f;
620 rect.right = 500.f;
621 rect.top = 600.f;
622 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
Jane Liubaa7ff42017-06-29 19:18:23 -0400623
Lei Zhanga21d5932018-02-05 18:28:38 +0000624 // Add a new path to the annotation.
625 FPDF_PAGEOBJECT check = FPDFPageObj_CreateNewPath(200, 500);
626 EXPECT_TRUE(FPDFPath_LineTo(check, 300, 400));
627 EXPECT_TRUE(FPDFPath_LineTo(check, 500, 600));
628 EXPECT_TRUE(FPDFPath_MoveTo(check, 350, 550));
629 EXPECT_TRUE(FPDFPath_LineTo(check, 450, 450));
630 EXPECT_TRUE(FPDFPath_SetStrokeColor(check, 0, 255, 255, 180));
631 EXPECT_TRUE(FPDFPath_SetStrokeWidth(check, 8.35f));
632 EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1));
633 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), check));
634 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
635
636 // Check that the annotation's bounding box came from its rectangle.
637 FS_RECTF new_rect;
638 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
639 EXPECT_EQ(rect.left, new_rect.left);
640 EXPECT_EQ(rect.bottom, new_rect.bottom);
641 EXPECT_EQ(rect.right, new_rect.right);
642 EXPECT_EQ(rect.top, new_rect.top);
643 }
Jane Liubaa7ff42017-06-29 19:18:23 -0400644
645 // Save the document, closing the page and document.
Jane Liubaa7ff42017-06-29 19:18:23 -0400646 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +0000647 UnloadPage(page);
Jane Liubaa7ff42017-06-29 19:18:23 -0400648
649 // Open the saved document.
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400650 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000651 page = LoadSavedPage(0);
652 VerifySavedRendering(page, 595, 842, md5_new_annot);
Jane Liubaa7ff42017-06-29 19:18:23 -0400653
Jane Liu36567742017-07-06 11:13:35 -0400654 // Check that the document has a correct count of annotations and objects.
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000655 EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
Jane Liubaa7ff42017-06-29 19:18:23 -0400656
Lei Zhanga21d5932018-02-05 18:28:38 +0000657 {
658 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
659 FPDFPage_GetAnnot(page, 2));
660 ASSERT_TRUE(annot);
661 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
Jane Liubaa7ff42017-06-29 19:18:23 -0400662
Lei Zhanga21d5932018-02-05 18:28:38 +0000663 // Check that the new annotation's rectangle is as defined.
664 FS_RECTF new_rect;
665 ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect));
666 EXPECT_EQ(rect.left, new_rect.left);
667 EXPECT_EQ(rect.bottom, new_rect.bottom);
668 EXPECT_EQ(rect.right, new_rect.right);
669 EXPECT_EQ(rect.top, new_rect.top);
670 }
671
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000672 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400673 CloseSavedDocument();
Jane Liu8ce58f52017-06-29 13:40:22 -0400674}
Jane Liub137e752017-07-05 15:04:33 -0400675
676TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) {
677 // Open a file with an annotation and load its first page.
678 ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000679 FPDF_PAGE page = LoadPage(0);
Jane Liub137e752017-07-05 15:04:33 -0400680 ASSERT_TRUE(page);
681
682 // Check that the page renders correctly.
Lei Zhanga98e3662018-02-07 20:28:35 +0000683 FPDF_BITMAP bitmap =
684 RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liub137e752017-07-05 15:04:33 -0400685 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
686 FPDFBitmap_Destroy(bitmap);
687
Lei Zhanga21d5932018-02-05 18:28:38 +0000688 {
689 // Retrieve the annotation.
690 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
691 FPDFPage_GetAnnot(page, 0));
692 ASSERT_TRUE(annot);
Jane Liub137e752017-07-05 15:04:33 -0400693
Lei Zhanga21d5932018-02-05 18:28:38 +0000694 // Check that the original flag values are as expected.
695 int flags = FPDFAnnot_GetFlags(annot.get());
696 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
697 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
Jane Liub137e752017-07-05 15:04:33 -0400698
Lei Zhanga21d5932018-02-05 18:28:38 +0000699 // Set the HIDDEN flag.
700 flags |= FPDF_ANNOT_FLAG_HIDDEN;
701 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags));
702 flags = FPDFAnnot_GetFlags(annot.get());
703 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_HIDDEN);
704 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
Jane Liub137e752017-07-05 15:04:33 -0400705
Lei Zhanga21d5932018-02-05 18:28:38 +0000706 // Check that the page renders correctly without rendering the annotation.
Lei Zhanga98e3662018-02-07 20:28:35 +0000707 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Lei Zhanga21d5932018-02-05 18:28:38 +0000708 CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3");
709 FPDFBitmap_Destroy(bitmap);
Jane Liub137e752017-07-05 15:04:33 -0400710
Lei Zhanga21d5932018-02-05 18:28:38 +0000711 // Unset the HIDDEN flag.
712 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), FPDF_ANNOT_FLAG_NONE));
713 EXPECT_FALSE(FPDFAnnot_GetFlags(annot.get()));
714 flags &= ~FPDF_ANNOT_FLAG_HIDDEN;
715 EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags));
716 flags = FPDFAnnot_GetFlags(annot.get());
717 EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN);
718 EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT);
Jane Liub137e752017-07-05 15:04:33 -0400719
Lei Zhanga21d5932018-02-05 18:28:38 +0000720 // Check that the page renders correctly as before.
Lei Zhanga98e3662018-02-07 20:28:35 +0000721 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Lei Zhanga21d5932018-02-05 18:28:38 +0000722 CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e");
723 FPDFBitmap_Destroy(bitmap);
724 }
Jane Liub137e752017-07-05 15:04:33 -0400725
Jane Liub137e752017-07-05 15:04:33 -0400726 UnloadPage(page);
727}
Jane Liu36567742017-07-06 11:13:35 -0400728
729TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400730#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400731 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
732 const char md5_new_image[] = "ff012f5697436dfcaec25b32d1333596";
733 const char md5_modified_image[] = "86cf8cb2755a7a2046a543e66d9c1e61";
Jane Liu36567742017-07-06 11:13:35 -0400734#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000735 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
736 const char md5_new_image[] = "9ea8732dc9d579f68853f16892856208";
737 const char md5_modified_image[] = "74239d2a8c55c9de1dbb9cd8781895aa";
Jane Liu36567742017-07-06 11:13:35 -0400738#endif
739
740 // Open a file with two annotations and load its first page.
741 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000742 FPDF_PAGE page = LoadPage(0);
Jane Liu36567742017-07-06 11:13:35 -0400743 ASSERT_TRUE(page);
744 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
745
746 // Check that the page renders correctly.
Lei Zhanga98e3662018-02-07 20:28:35 +0000747 FPDF_BITMAP bitmap =
748 RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400749 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400750 FPDFBitmap_Destroy(bitmap);
751
Jane Liu36567742017-07-06 11:13:35 -0400752 constexpr int kBitmapSize = 200;
Lei Zhanga21d5932018-02-05 18:28:38 +0000753 FPDF_BITMAP image_bitmap;
754
755 {
756 // Create a stamp annotation and set its annotation rectangle.
757 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
758 FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
759 ASSERT_TRUE(annot);
760 FS_RECTF rect;
761 rect.left = 200.f;
762 rect.bottom = 600.f;
763 rect.right = 400.f;
764 rect.top = 800.f;
765 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
766
767 // Add a solid-color translucent image object to the new annotation.
768 image_bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 1);
769 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize,
770 0xeeeecccc);
771 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap));
772 EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap));
773 FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document());
774 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
775 ASSERT_TRUE(FPDFImageObj_SetMatrix(image_object, kBitmapSize, 0, 0,
776 kBitmapSize, 0, 0));
777 FPDFPageObj_Transform(image_object, 1, 0, 0, 1, 200, 600);
778 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), image_object));
779 }
Jane Liu36567742017-07-06 11:13:35 -0400780
781 // Check that the page renders correctly with the new image object.
Lei Zhanga98e3662018-02-07 20:28:35 +0000782 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400783 CompareBitmap(bitmap, 595, 842, md5_new_image);
Jane Liu36567742017-07-06 11:13:35 -0400784 FPDFBitmap_Destroy(bitmap);
785
Lei Zhanga21d5932018-02-05 18:28:38 +0000786 {
787 // Retrieve the newly added stamp annotation and its image object.
788 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
789 FPDFPage_GetAnnot(page, 2));
790 ASSERT_TRUE(annot);
791 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
792 FPDF_PAGEOBJECT image_object = FPDFAnnot_GetObject(annot.get(), 0);
793 EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image_object));
Jane Liu36567742017-07-06 11:13:35 -0400794
Lei Zhanga21d5932018-02-05 18:28:38 +0000795 // Modify the image in the new annotation.
796 FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize,
797 0xff000000);
798 ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap));
799 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), image_object));
800 }
Jane Liu36567742017-07-06 11:13:35 -0400801
802 // Save the document, closing the page and document.
803 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +0000804 UnloadPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400805 FPDFBitmap_Destroy(image_bitmap);
Jane Liu36567742017-07-06 11:13:35 -0400806
807 // Test that the saved document renders the modified image object correctly.
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400808 VerifySavedDocument(595, 842, md5_modified_image);
Jane Liu36567742017-07-06 11:13:35 -0400809}
810
811TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) {
Dan Sinclair698aed72017-09-26 16:24:49 -0400812#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Jane Liu7a9a38b2017-07-11 13:47:37 -0400813 const char md5_original[] = "c35408717759562d1f8bf33d317483d2";
814 const char md5_new_text[] = "e5680ed048c2cfd9a1d27212cdf41286";
815 const char md5_modified_text[] = "79f5cfb0b07caaf936f65f6a7a57ce77";
Jane Liu36567742017-07-06 11:13:35 -0400816#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000817 const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e";
818 const char md5_new_text[] = "00b14fa2dc1c90d1b0d034e1608efef5";
819 const char md5_modified_text[] = "076c8f24a09ddc0e49f7e758edead6f0";
Jane Liu36567742017-07-06 11:13:35 -0400820#endif
821
822 // Open a file with two annotations and load its first page.
823 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000824 FPDF_PAGE page = LoadPage(0);
Jane Liu36567742017-07-06 11:13:35 -0400825 ASSERT_TRUE(page);
826 EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
827
828 // Check that the page renders correctly.
Lei Zhanga98e3662018-02-07 20:28:35 +0000829 FPDF_BITMAP bitmap =
830 RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400831 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400832 FPDFBitmap_Destroy(bitmap);
833
Lei Zhanga21d5932018-02-05 18:28:38 +0000834 {
835 // Create a stamp annotation and set its annotation rectangle.
836 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
837 FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP));
838 ASSERT_TRUE(annot);
839 FS_RECTF rect;
840 rect.left = 200.f;
841 rect.bottom = 550.f;
842 rect.right = 450.f;
843 rect.top = 650.f;
844 EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect));
Jane Liu36567742017-07-06 11:13:35 -0400845
Lei Zhanga21d5932018-02-05 18:28:38 +0000846 // Add a translucent text object to the new annotation.
847 FPDF_PAGEOBJECT text_object =
848 FPDFPageObj_NewTextObj(document(), "Arial", 12.0f);
849 EXPECT_TRUE(text_object);
850 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
851 GetFPDFWideString(L"I'm a translucent text laying on other text.");
852 EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
853 EXPECT_TRUE(FPDFText_SetFillColor(text_object, 0, 0, 255, 150));
854 FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 600);
855 EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), text_object));
856 }
Jane Liu36567742017-07-06 11:13:35 -0400857
858 // Check that the page renders correctly with the new text object.
Lei Zhanga98e3662018-02-07 20:28:35 +0000859 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400860 CompareBitmap(bitmap, 595, 842, md5_new_text);
Jane Liu36567742017-07-06 11:13:35 -0400861 FPDFBitmap_Destroy(bitmap);
862
Lei Zhanga21d5932018-02-05 18:28:38 +0000863 {
864 // Retrieve the newly added stamp annotation and its text object.
865 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
866 FPDFPage_GetAnnot(page, 2));
867 ASSERT_TRUE(annot);
868 EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get()));
869 FPDF_PAGEOBJECT text_object = FPDFAnnot_GetObject(annot.get(), 0);
870 EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object));
Jane Liu36567742017-07-06 11:13:35 -0400871
Lei Zhanga21d5932018-02-05 18:28:38 +0000872 // Modify the text in the new annotation.
873 std::unique_ptr<unsigned short, pdfium::FreeDeleter> new_text =
874 GetFPDFWideString(L"New text!");
875 EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get()));
876 EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), text_object));
877 }
Jane Liu36567742017-07-06 11:13:35 -0400878
879 // Check that the page renders correctly with the modified text object.
Lei Zhanga98e3662018-02-07 20:28:35 +0000880 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400881 CompareBitmap(bitmap, 595, 842, md5_modified_text);
Jane Liu36567742017-07-06 11:13:35 -0400882 FPDFBitmap_Destroy(bitmap);
883
884 // Remove the new annotation, and check that the page renders as before.
885 EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2));
Lei Zhanga98e3662018-02-07 20:28:35 +0000886 bitmap = RenderPageWithFlagsDeprecated(page, form_handle_, FPDF_ANNOT);
Jane Liu7a9a38b2017-07-11 13:47:37 -0400887 CompareBitmap(bitmap, 595, 842, md5_original);
Jane Liu36567742017-07-06 11:13:35 -0400888 FPDFBitmap_Destroy(bitmap);
889
890 UnloadPage(page);
891}
Jane Liu2e1a32b2017-07-06 12:01:25 -0400892
893TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) {
894 // Open a file with four annotations and load its first page.
895 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000896 FPDF_PAGE page = LoadPage(0);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400897 ASSERT_TRUE(page);
898
Lei Zhangdf064df2017-08-31 02:33:27 -0700899 static constexpr char kDateKey[] = "M";
Lei Zhanga21d5932018-02-05 18:28:38 +0000900 static constexpr wchar_t kNewDate[] = L"D:201706282359Z00'00'";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400901
Lei Zhanga21d5932018-02-05 18:28:38 +0000902 {
903 // Retrieve the first annotation.
904 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
905 FPDFPage_GetAnnot(page, 0));
906 ASSERT_TRUE(annot);
907
908 // Check that a non-existent key does not exist.
909 EXPECT_FALSE(FPDFAnnot_HasKey(annot.get(), "none"));
910
911 // Check that the string value of a non-string dictionary entry is empty.
912 static constexpr char kApKey[] = "AP";
913 EXPECT_TRUE(FPDFAnnot_HasKey(annot.get(), kApKey));
914 EXPECT_EQ(FPDF_OBJECT_REFERENCE,
915 FPDFAnnot_GetValueType(annot.get(), kApKey));
916 EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot.get(), kApKey, nullptr, 0));
917
918 // Check that the string value of the hash is correct.
919 static constexpr char kHashKey[] = "AAPL:Hash";
920 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey));
921 unsigned long len =
922 FPDFAnnot_GetStringValue(annot.get(), kHashKey, nullptr, 0);
923 std::vector<char> buf(len);
924 EXPECT_EQ(66u,
925 FPDFAnnot_GetStringValue(annot.get(), kHashKey, buf.data(), len));
926 EXPECT_STREQ(L"395fbcb98d558681742f30683a62a2ad",
927 BufferToWString(buf).c_str());
928
929 // Check that the string value of the modified date is correct.
930 EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey));
931 len = FPDFAnnot_GetStringValue(annot.get(), kDateKey, nullptr, 0);
932 buf.clear();
933 buf.resize(len);
934 EXPECT_EQ(44u,
935 FPDFAnnot_GetStringValue(annot.get(), kDateKey, buf.data(), len));
936 EXPECT_STREQ(L"D:201706071721Z00'00'", BufferToWString(buf).c_str());
937
938 // Update the date entry for the annotation.
939 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
940 GetFPDFWideString(kNewDate);
941 EXPECT_TRUE(FPDFAnnot_SetStringValue(annot.get(), kDateKey, text.get()));
942 }
Jane Liu2e1a32b2017-07-06 12:01:25 -0400943
944 // Save the document, closing the page and document.
Jane Liu2e1a32b2017-07-06 12:01:25 -0400945 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +0000946 UnloadPage(page);
Jane Liu2e1a32b2017-07-06 12:01:25 -0400947
948 // Open the saved annotation.
Dan Sinclair698aed72017-09-26 16:24:49 -0400949#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
Artem Strygind24b97e2017-08-09 18:50:59 +0300950 const char md5[] = "4d64e61c9c0f8c60ab3cc3234bb73b1c";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400951#else
Henrique Nakashima09b41922017-10-27 20:39:29 +0000952 const char md5[] = "c96ee1f316d7f5a1b154de9f9d467f01";
Jane Liu2e1a32b2017-07-06 12:01:25 -0400953#endif
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400954 OpenSavedDocument();
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000955 page = LoadSavedPage(0);
956 VerifySavedRendering(page, 595, 842, md5);
Lei Zhanga21d5932018-02-05 18:28:38 +0000957 {
958 std::unique_ptr<void, FPDFAnnotationDeleter> new_annot(
959 FPDFPage_GetAnnot(page, 0));
Jane Liu2e1a32b2017-07-06 12:01:25 -0400960
Lei Zhanga21d5932018-02-05 18:28:38 +0000961 // Check that the string value of the modified date is the newly-set value.
962 EXPECT_EQ(FPDF_OBJECT_STRING,
963 FPDFAnnot_GetValueType(new_annot.get(), kDateKey));
964 unsigned long len =
965 FPDFAnnot_GetStringValue(new_annot.get(), kDateKey, nullptr, 0);
966 std::vector<char> buf(len);
967 EXPECT_EQ(44u, FPDFAnnot_GetStringValue(new_annot.get(), kDateKey,
968 buf.data(), len));
969 EXPECT_STREQ(kNewDate, BufferToWString(buf).c_str());
970 }
Jane Liu2e1a32b2017-07-06 12:01:25 -0400971
Henrique Nakashima8baea3c2017-11-10 20:27:23 +0000972 CloseSavedPage(page);
Dan Sinclair04e4dc82017-10-18 12:17:14 -0400973 CloseSavedDocument();
Jane Liu2e1a32b2017-07-06 12:01:25 -0400974}
Diana Gage7e0c05d2017-07-19 17:33:33 -0700975
Henrique Nakashima5970a472018-01-11 22:40:59 +0000976TEST_F(FPDFAnnotEmbeddertest, GetSetAP) {
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +0000977 // Open a file with four annotations and load its first page.
978 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +0000979 FPDF_PAGE page = LoadPage(0);
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +0000980 ASSERT_TRUE(page);
981
Lei Zhanga21d5932018-02-05 18:28:38 +0000982 {
983 // Retrieve the first annotation.
984 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
985 FPDFPage_GetAnnot(page, 0));
986 ASSERT_TRUE(annot);
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +0000987
Lei Zhanga21d5932018-02-05 18:28:38 +0000988 // Check that the string value of an AP returns the expected length.
989 unsigned long normal_len = FPDFAnnot_GetAP(
990 annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, nullptr, 0);
991 EXPECT_EQ(73970u, normal_len);
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +0000992
Lei Zhanga21d5932018-02-05 18:28:38 +0000993 // Check that the string value of an AP is not returned if the buffer is too
994 // small. The result buffer should be overwritten with an empty string.
995 std::vector<char> buf(normal_len - 1);
996 // Write L"z" in the buffer to verify it's not overwritten.
997 wcscpy(reinterpret_cast<wchar_t*>(buf.data()), L"z");
998 EXPECT_EQ(73970u,
999 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1000 buf.data(), buf.size()));
1001 std::string ap = BufferToString(buf);
1002 EXPECT_STREQ("z", ap.c_str());
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001003
Lei Zhanga21d5932018-02-05 18:28:38 +00001004 // Check that the string value of an AP is returned through a buffer that is
1005 // the right size.
1006 buf.clear();
1007 buf.resize(normal_len);
1008 EXPECT_EQ(73970u,
1009 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1010 buf.data(), buf.size()));
1011 ap = BufferToString(buf);
1012 EXPECT_THAT(ap, testing::StartsWith("q Q q 7.442786 w 2 J"));
1013 EXPECT_THAT(ap, testing::EndsWith("c 716.5381 327.7156 l S Q Q"));
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001014
Lei Zhanga21d5932018-02-05 18:28:38 +00001015 // Check that the string value of an AP is returned through a buffer that is
1016 // larger than necessary.
1017 buf.clear();
1018 buf.resize(normal_len + 1);
1019 EXPECT_EQ(73970u,
1020 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1021 buf.data(), buf.size()));
1022 ap = BufferToString(buf);
1023 EXPECT_THAT(ap, testing::StartsWith("q Q q 7.442786 w 2 J"));
1024 EXPECT_THAT(ap, testing::EndsWith("c 716.5381 327.7156 l S Q Q"));
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001025
Lei Zhanga21d5932018-02-05 18:28:38 +00001026 // Check that getting an AP for a mode that does not have an AP returns an
1027 // empty string.
1028 unsigned long rollover_len = FPDFAnnot_GetAP(
1029 annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0);
1030 EXPECT_EQ(2u, rollover_len);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001031
Lei Zhanga21d5932018-02-05 18:28:38 +00001032 buf.clear();
1033 buf.resize(1000);
1034 EXPECT_EQ(2u,
1035 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
1036 buf.data(), buf.size()));
1037 EXPECT_STREQ("", BufferToString(buf).c_str());
Henrique Nakashima5970a472018-01-11 22:40:59 +00001038
Lei Zhanga21d5932018-02-05 18:28:38 +00001039 // Check that setting the AP for an invalid appearance mode fails.
1040 std::unique_ptr<unsigned short, pdfium::FreeDeleter> apText =
1041 GetFPDFWideString(L"new test ap");
1042 EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), -1, apText.get()));
1043 EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_COUNT,
1044 apText.get()));
1045 EXPECT_FALSE(FPDFAnnot_SetAP(
1046 annot.get(), FPDF_ANNOT_APPEARANCEMODE_COUNT + 1, apText.get()));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001047
Lei Zhanga21d5932018-02-05 18:28:38 +00001048 // Set the AP correctly now.
1049 EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
1050 apText.get()));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001051
Lei Zhanga21d5932018-02-05 18:28:38 +00001052 // Check that the new annotation value is equal to the value we just set.
1053 rollover_len = FPDFAnnot_GetAP(
1054 annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0);
1055 EXPECT_EQ(24u, rollover_len);
1056 buf.clear();
1057 buf.resize(rollover_len);
1058 EXPECT_EQ(24u,
1059 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
1060 buf.data(), buf.size()));
1061 EXPECT_STREQ(L"new test ap", BufferToWString(buf).c_str());
Henrique Nakashima5970a472018-01-11 22:40:59 +00001062
Lei Zhanga21d5932018-02-05 18:28:38 +00001063 // Check that the Normal AP was not touched when the Rollover AP was set.
1064 buf.clear();
1065 buf.resize(normal_len);
1066 EXPECT_EQ(73970u,
1067 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1068 buf.data(), buf.size()));
1069 ap = BufferToString(buf);
1070 EXPECT_THAT(ap, testing::StartsWith("q Q q 7.442786 w 2 J"));
1071 EXPECT_THAT(ap, testing::EndsWith("c 716.5381 327.7156 l S Q Q"));
1072 }
Henrique Nakashima5970a472018-01-11 22:40:59 +00001073
1074 // Save the modified document, then reopen it.
Henrique Nakashima5970a472018-01-11 22:40:59 +00001075 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
Lei Zhang75c81712018-02-08 17:22:39 +00001076 UnloadPage(page);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001077
1078 OpenSavedDocument();
1079 page = LoadSavedPage(0);
Lei Zhanga21d5932018-02-05 18:28:38 +00001080 {
1081 std::unique_ptr<void, FPDFAnnotationDeleter> new_annot(
1082 FPDFPage_GetAnnot(page, 0));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001083
Lei Zhanga21d5932018-02-05 18:28:38 +00001084 // Check that the new annotation value is equal to the value we set before
1085 // saving.
1086 unsigned long rollover_len = FPDFAnnot_GetAP(
1087 new_annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0);
1088 EXPECT_EQ(24u, rollover_len);
1089 std::vector<char> buf(rollover_len);
1090 EXPECT_EQ(24u, FPDFAnnot_GetAP(new_annot.get(),
1091 FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
1092 buf.data(), buf.size()));
1093 EXPECT_STREQ(L"new test ap", BufferToWString(buf).c_str());
1094 }
Henrique Nakashima5970a472018-01-11 22:40:59 +00001095
1096 // Close saved document.
Henrique Nakashima5970a472018-01-11 22:40:59 +00001097 CloseSavedPage(page);
1098 CloseSavedDocument();
1099}
1100
1101TEST_F(FPDFAnnotEmbeddertest, RemoveOptionalAP) {
1102 // Open a file with four annotations and load its first page.
1103 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001104 FPDF_PAGE page = LoadPage(0);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001105 ASSERT_TRUE(page);
1106
Lei Zhanga21d5932018-02-05 18:28:38 +00001107 {
1108 // Retrieve the first annotation.
1109 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1110 FPDFPage_GetAnnot(page, 0));
1111 ASSERT_TRUE(annot);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001112
Lei Zhanga21d5932018-02-05 18:28:38 +00001113 // Set Down AP. Normal AP is already set.
1114 std::unique_ptr<unsigned short, pdfium::FreeDeleter> apText =
1115 GetFPDFWideString(L"new test ap");
1116 EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1117 apText.get()));
1118 EXPECT_EQ(73970u,
1119 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1120 nullptr, 0));
1121 EXPECT_EQ(24u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1122 nullptr, 0));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001123
Lei Zhanga21d5932018-02-05 18:28:38 +00001124 // Check that setting the Down AP to null removes the Down entry but keeps
1125 // Normal intact.
1126 EXPECT_TRUE(
1127 FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, nullptr));
1128 EXPECT_EQ(73970u,
1129 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1130 nullptr, 0));
1131 EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1132 nullptr, 0));
1133 }
Henrique Nakashima5970a472018-01-11 22:40:59 +00001134
Lei Zhang75c81712018-02-08 17:22:39 +00001135 UnloadPage(page);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001136}
1137
1138TEST_F(FPDFAnnotEmbeddertest, RemoveRequiredAP) {
1139 // Open a file with four annotations and load its first page.
1140 ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001141 FPDF_PAGE page = LoadPage(0);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001142 ASSERT_TRUE(page);
1143
Lei Zhanga21d5932018-02-05 18:28:38 +00001144 {
1145 // Retrieve the first annotation.
1146 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1147 FPDFPage_GetAnnot(page, 0));
1148 ASSERT_TRUE(annot);
Henrique Nakashima5970a472018-01-11 22:40:59 +00001149
Lei Zhanga21d5932018-02-05 18:28:38 +00001150 // Set Down AP. Normal AP is already set.
1151 std::unique_ptr<unsigned short, pdfium::FreeDeleter> apText =
1152 GetFPDFWideString(L"new test ap");
1153 EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1154 apText.get()));
1155 EXPECT_EQ(73970u,
1156 FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1157 nullptr, 0));
1158 EXPECT_EQ(24u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1159 nullptr, 0));
Henrique Nakashima5970a472018-01-11 22:40:59 +00001160
Lei Zhanga21d5932018-02-05 18:28:38 +00001161 // Check that setting the Normal AP to null removes the whole AP dictionary.
1162 EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1163 nullptr));
1164 EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL,
1165 nullptr, 0));
1166 EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN,
1167 nullptr, 0));
1168 }
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001169
Lei Zhang75c81712018-02-08 17:22:39 +00001170 UnloadPage(page);
Henrique Nakashimaa74e75d2018-01-10 18:06:55 +00001171}
1172
Jane Liu300bb272017-08-21 14:37:53 -04001173TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) {
1174 // Open a file with annotations and load its first page.
1175 ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001176 FPDF_PAGE page = LoadPage(0);
Jane Liu300bb272017-08-21 14:37:53 -04001177 ASSERT_TRUE(page);
Jane Liud1ed1ce2017-08-24 12:31:10 -04001178 EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr));
Jane Liu300bb272017-08-21 14:37:53 -04001179
Lei Zhanga21d5932018-02-05 18:28:38 +00001180 {
1181 // Retrieve the highlight annotation which has its popup defined.
1182 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1183 FPDFPage_GetAnnot(page, 0));
1184 ASSERT_TRUE(annot);
1185 EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get()));
1186 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot.get()));
1187 static constexpr char kPopupKey[] = "Popup";
1188 ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), kPopupKey));
1189 ASSERT_EQ(FPDF_OBJECT_REFERENCE,
1190 FPDFAnnot_GetValueType(annot.get(), kPopupKey));
Jane Liu300bb272017-08-21 14:37:53 -04001191
Lei Zhanga21d5932018-02-05 18:28:38 +00001192 // Retrieve and verify the popup of the highlight annotation.
1193 std::unique_ptr<void, FPDFAnnotationDeleter> popup(
1194 FPDFAnnot_GetLinkedAnnot(annot.get(), kPopupKey));
1195 ASSERT_TRUE(popup);
1196 EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup.get()));
1197 EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup.get()));
1198 FS_RECTF rect;
1199 ASSERT_TRUE(FPDFAnnot_GetRect(popup.get(), &rect));
1200 EXPECT_NEAR(612.0f, rect.left, 0.001f);
1201 EXPECT_NEAR(578.792, rect.bottom, 0.001f);
Jane Liu300bb272017-08-21 14:37:53 -04001202
Lei Zhanga21d5932018-02-05 18:28:38 +00001203 // Attempting to retrieve |annot|'s "IRT"-linked annotation would fail,
1204 // since "IRT" is not a key in |annot|'s dictionary.
1205 static constexpr char kIRTKey[] = "IRT";
1206 ASSERT_FALSE(FPDFAnnot_HasKey(annot.get(), kIRTKey));
1207 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), kIRTKey));
Jane Liu300bb272017-08-21 14:37:53 -04001208
Lei Zhanga21d5932018-02-05 18:28:38 +00001209 // Attempting to retrieve |annot|'s parent dictionary as an annotation
1210 // would fail, since its parent is not an annotation.
1211 static constexpr char kPKey[] = "P";
1212 ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), kPKey));
1213 EXPECT_EQ(FPDF_OBJECT_REFERENCE,
1214 FPDFAnnot_GetValueType(annot.get(), kPKey));
1215 EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), kPKey));
1216 }
Jane Liu300bb272017-08-21 14:37:53 -04001217
Jane Liu300bb272017-08-21 14:37:53 -04001218 UnloadPage(page);
1219}
1220
Diana Gage7e0c05d2017-07-19 17:33:33 -07001221TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) {
1222 // Open file with form text fields.
1223 ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001224 FPDF_PAGE page = LoadPage(0);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001225 ASSERT_TRUE(page);
1226
Lei Zhanga21d5932018-02-05 18:28:38 +00001227 {
1228 // Retrieve the first annotation: user-editable text field.
1229 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1230 FPDFPage_GetAnnot(page, 0));
1231 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001232
Lei Zhanga21d5932018-02-05 18:28:38 +00001233 // Check that the flag values are as expected.
1234 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1235 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1236 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001237
Lei Zhanga21d5932018-02-05 18:28:38 +00001238 {
1239 // Retrieve the second annotation: read-only text field.
1240 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1241 FPDFPage_GetAnnot(page, 1));
1242 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001243
Lei Zhanga21d5932018-02-05 18:28:38 +00001244 // Check that the flag values are as expected.
1245 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1246 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1247 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001248
1249 UnloadPage(page);
1250}
1251
1252TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) {
1253 // Open file with form text fields.
1254 ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
Lei Zhang75c81712018-02-08 17:22:39 +00001255 FPDF_PAGE page = LoadPage(0);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001256 ASSERT_TRUE(page);
1257
Lei Zhanga21d5932018-02-05 18:28:38 +00001258 {
1259 // Retrieve the first annotation: user-editable combobox.
1260 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1261 FPDFPage_GetAnnot(page, 0));
1262 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001263
Lei Zhanga21d5932018-02-05 18:28:38 +00001264 // Check that the flag values are as expected.
1265 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1266 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1267 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1268 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1269 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001270
Lei Zhanga21d5932018-02-05 18:28:38 +00001271 {
1272 // Retrieve the second annotation: regular combobox.
1273 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1274 FPDFPage_GetAnnot(page, 1));
1275 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001276
Lei Zhanga21d5932018-02-05 18:28:38 +00001277 // Check that the flag values are as expected.
1278 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1279 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1280 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1281 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1282 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001283
Lei Zhanga21d5932018-02-05 18:28:38 +00001284 {
1285 // Retrieve the third annotation: read-only combobox.
1286 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1287 FPDFPage_GetAnnot(page, 2));
1288 ASSERT_TRUE(annot);
Diana Gage7e0c05d2017-07-19 17:33:33 -07001289
Lei Zhanga21d5932018-02-05 18:28:38 +00001290 // Check that the flag values are as expected.
1291 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1292 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1293 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1294 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1295 }
Diana Gage7e0c05d2017-07-19 17:33:33 -07001296
1297 UnloadPage(page);
1298}
Diana Gage40870db2017-07-19 18:16:03 -07001299
1300TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) {
1301 // Open file with form text fields.
1302 EXPECT_TRUE(OpenDocument("text_form.pdf"));
1303 FPDF_PAGE page = LoadPage(0);
1304 ASSERT_TRUE(page);
1305
1306 // Attempt to get an annotation where no annotation exists on page.
1307 FPDF_ANNOTATION annot =
1308 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0);
1309 EXPECT_FALSE(annot);
1310
1311 UnloadPage(page);
1312}
1313
1314TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) {
1315 // Open file with form text fields.
1316 EXPECT_TRUE(OpenDocument("text_form_multiple.pdf"));
1317 FPDF_PAGE page = LoadPage(0);
1318 ASSERT_TRUE(page);
1319
Lei Zhanga21d5932018-02-05 18:28:38 +00001320 {
1321 // Retrieve user-editable text field annotation.
1322 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1323 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118));
1324 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001325
Lei Zhanga21d5932018-02-05 18:28:38 +00001326 // Check that interactive form annotation flag values are as expected.
1327 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1328 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1329 }
Diana Gage40870db2017-07-19 18:16:03 -07001330
Lei Zhanga21d5932018-02-05 18:28:38 +00001331 {
1332 // Retrieve read-only text field annotation.
1333 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1334 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202));
1335 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001336
Lei Zhanga21d5932018-02-05 18:28:38 +00001337 // Check that interactive form annotation flag values are as expected.
1338 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1339 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1340 }
Diana Gage40870db2017-07-19 18:16:03 -07001341
1342 UnloadPage(page);
1343}
1344
1345TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) {
1346 // Open file with form comboboxes.
1347 EXPECT_TRUE(OpenDocument("combobox_form.pdf"));
1348 FPDF_PAGE page = LoadPage(0);
1349 ASSERT_TRUE(page);
1350
Lei Zhanga21d5932018-02-05 18:28:38 +00001351 {
1352 // Retrieve user-editable combobox annotation.
1353 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1354 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 63));
1355 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001356
Lei Zhanga21d5932018-02-05 18:28:38 +00001357 // Check that interactive form annotation flag values are as expected.
1358 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1359 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1360 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1361 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1362 }
Diana Gage40870db2017-07-19 18:16:03 -07001363
Lei Zhanga21d5932018-02-05 18:28:38 +00001364 {
1365 // Retrieve regular combobox annotation.
1366 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1367 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 113));
1368 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001369
Lei Zhanga21d5932018-02-05 18:28:38 +00001370 // Check that interactive form annotation flag values are as expected.
1371 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1372 EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
1373 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1374 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1375 }
Diana Gage40870db2017-07-19 18:16:03 -07001376
Lei Zhanga21d5932018-02-05 18:28:38 +00001377 {
1378 // Retrieve read-only combobox annotation.
1379 std::unique_ptr<void, FPDFAnnotationDeleter> annot(
1380 FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 213));
1381 ASSERT_TRUE(annot);
Diana Gage40870db2017-07-19 18:16:03 -07001382
Lei Zhanga21d5932018-02-05 18:28:38 +00001383 // Check that interactive form annotation flag values are as expected.
1384 int flags = FPDFAnnot_GetFormFieldFlags(page, annot.get());
1385 EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
1386 EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
1387 EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
1388 }
Diana Gage40870db2017-07-19 18:16:03 -07001389
1390 UnloadPage(page);
1391}