Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 1 | // 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 Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 5 | #include <cwchar> |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 6 | #include <memory> |
| 7 | #include <string> |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 10 | #include "core/fxcrt/fx_system.h" |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 11 | #include "public/fpdf_annot.h" |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 12 | #include "public/fpdf_edit.h" |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 13 | #include "public/fpdfview.h" |
| 14 | #include "testing/embedder_test.h" |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 15 | #include "testing/gmock/include/gmock/gmock-matchers.h" |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 18 | static constexpr char kContentsKey[] = "Contents"; |
| 19 | |
Nicolas Pena | 3ff5400 | 2017-07-05 11:55:35 -0400 | [diff] [blame] | 20 | class FPDFAnnotEmbeddertest : public EmbedderTest {}; |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 21 | |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 22 | const std::wstring BufferToWString(std::vector<char>& buf) { |
| 23 | return GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())); |
| 24 | } |
| 25 | |
| 26 | const std::string BufferToString(std::vector<char>& buf) { |
| 27 | return GetPlatformString(reinterpret_cast<unsigned short*>(buf.data())); |
| 28 | } |
| 29 | |
Jane Liu | e17011d | 2017-06-21 12:18:37 -0400 | [diff] [blame] | 30 | TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) { |
| 31 | // Open a file with one annotation and load its first page. |
| 32 | ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf")); |
| 33 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 34 | ASSERT_TRUE(page); |
| 35 | |
| 36 | // This annotation has a malformed appearance stream, which does not have its |
| 37 | // normal appearance defined, only its rollover appearance. In this case, its |
| 38 | // normal appearance should be generated, allowing the highlight annotation to |
| 39 | // still display. |
Nicolas Pena | 3ff5400 | 2017-07-05 11:55:35 -0400 | [diff] [blame] | 40 | FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle(), FPDF_ANNOT); |
Jane Liu | e17011d | 2017-06-21 12:18:37 -0400 | [diff] [blame] | 41 | CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); |
| 42 | FPDFBitmap_Destroy(bitmap); |
| 43 | |
| 44 | UnloadPage(page); |
| 45 | } |
| 46 | |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 47 | TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) { |
| 48 | // Open a file with one annotation and load its first page. |
| 49 | ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); |
| 50 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 51 | ASSERT_TRUE(page); |
| 52 | |
| 53 | // Check that there is a total of 1 annotation on its first page. |
| 54 | EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); |
| 55 | |
| 56 | // Check that the annotation is of type "highlight". |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 57 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 58 | ASSERT_TRUE(annot); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 59 | EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); |
| 60 | |
| 61 | // Check that the annotation color is yellow. |
| 62 | unsigned int R; |
| 63 | unsigned int G; |
| 64 | unsigned int B; |
| 65 | unsigned int A; |
| 66 | EXPECT_TRUE( |
| 67 | FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)); |
| 68 | EXPECT_EQ(255u, R); |
| 69 | EXPECT_EQ(255u, G); |
| 70 | EXPECT_EQ(0u, B); |
| 71 | EXPECT_EQ(255u, A); |
| 72 | |
| 73 | // Check that the author is correct. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 74 | static constexpr char kAuthorKey[] = "T"; |
| 75 | EXPECT_EQ(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(annot, kAuthorKey)); |
| 76 | unsigned long len = FPDFAnnot_GetStringValue(annot, kAuthorKey, nullptr, 0); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 77 | std::vector<char> buf(len); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 78 | EXPECT_EQ(28u, FPDFAnnot_GetStringValue(annot, kAuthorKey, buf.data(), len)); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 79 | EXPECT_STREQ(L"Jae Hyun Park", BufferToWString(buf).c_str()); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 80 | |
| 81 | // Check that the content is correct. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 82 | EXPECT_EQ(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(annot, kContentsKey)); |
| 83 | len = FPDFAnnot_GetStringValue(annot, kContentsKey, nullptr, 0); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 84 | buf.clear(); |
| 85 | buf.resize(len); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 86 | EXPECT_EQ(2690u, |
| 87 | FPDFAnnot_GetStringValue(annot, kContentsKey, buf.data(), len)); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 88 | const wchar_t contents[] = |
| 89 | L"This is a note for that highlight annotation. Very long highlight " |
| 90 | "annotation. Long long long Long 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 longLong long longLong 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 long. END"; |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 109 | EXPECT_STREQ(contents, BufferToWString(buf).c_str()); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 110 | |
| 111 | // Check that the quadpoints are correct. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 112 | FS_QUADPOINTSF quadpoints; |
| 113 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 114 | EXPECT_EQ(115.802643f, quadpoints.x1); |
| 115 | EXPECT_EQ(718.913940f, quadpoints.y1); |
| 116 | EXPECT_EQ(157.211182f, quadpoints.x4); |
| 117 | EXPECT_EQ(706.264465f, quadpoints.y4); |
| 118 | |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 119 | FPDFPage_CloseAnnot(annot); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 120 | UnloadPage(page); |
| 121 | } |
| 122 | |
| 123 | TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) { |
| 124 | // Open a file with three annotations and load its first page. |
| 125 | ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); |
| 126 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 127 | ASSERT_TRUE(page); |
| 128 | |
| 129 | // Check that there is a total of 3 annotation on its first page. |
| 130 | EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); |
| 131 | |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 132 | // Check that the third annotation is of type "ink". |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 133 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 2); |
| 134 | ASSERT_TRUE(annot); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 135 | EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot)); |
| 136 | |
| 137 | // Check that the annotation color is blue with opacity. |
| 138 | unsigned int R; |
| 139 | unsigned int G; |
| 140 | unsigned int B; |
| 141 | unsigned int A; |
| 142 | EXPECT_TRUE( |
| 143 | FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)); |
| 144 | EXPECT_EQ(0u, R); |
| 145 | EXPECT_EQ(0u, G); |
| 146 | EXPECT_EQ(255u, B); |
| 147 | EXPECT_EQ(76u, A); |
| 148 | |
| 149 | // Check that there is no content. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 150 | EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot, kContentsKey, nullptr, 0)); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 151 | |
| 152 | // Check that the rectange coordinates are correct. |
| 153 | // Note that upon rendering, the rectangle coordinates will be adjusted. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 154 | FS_RECTF rect; |
| 155 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 156 | EXPECT_EQ(351.820404f, rect.left); |
| 157 | EXPECT_EQ(583.830688f, rect.bottom); |
| 158 | EXPECT_EQ(475.336090f, rect.right); |
| 159 | EXPECT_EQ(681.535034f, rect.top); |
| 160 | |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 161 | FPDFPage_CloseAnnot(annot); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 162 | UnloadPage(page); |
| 163 | } |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 164 | |
| 165 | TEST_F(FPDFAnnotEmbeddertest, AddIllegalSubtypeAnnotation) { |
| 166 | // Open a file with one annotation and load its first page. |
| 167 | ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); |
| 168 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 169 | ASSERT_TRUE(page); |
| 170 | |
| 171 | // Add an annotation with an illegal subtype. |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 172 | ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 173 | |
| 174 | UnloadPage(page); |
| 175 | } |
| 176 | |
Jane Liu | d321ef9 | 2017-06-14 09:56:22 -0400 | [diff] [blame] | 177 | TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 178 | // Open a file with no annotation and load its first page. |
| 179 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 180 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 181 | ASSERT_TRUE(page); |
| 182 | EXPECT_EQ(0, FPDFPage_GetAnnotCount(page)); |
| 183 | |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 184 | // Add a text annotation to the page. |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 185 | FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT); |
| 186 | ASSERT_TRUE(annot); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 187 | |
| 188 | // Check that there is now 1 annotations on this page. |
| 189 | EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); |
| 190 | |
| 191 | // Check that the subtype of the annotation is correct. |
| 192 | EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot)); |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 193 | FPDFPage_CloseAnnot(annot); |
| 194 | |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 195 | annot = FPDFPage_GetAnnot(page, 0); |
| 196 | ASSERT_TRUE(annot); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 197 | EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot)); |
| 198 | |
| 199 | // Set the color of the annotation. |
| 200 | ASSERT_TRUE( |
| 201 | FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 51, 102, 153, 204)); |
| 202 | // Check that the color has been set correctly. |
| 203 | unsigned int R; |
| 204 | unsigned int G; |
| 205 | unsigned int B; |
| 206 | unsigned int A; |
| 207 | EXPECT_TRUE( |
| 208 | FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)); |
| 209 | EXPECT_EQ(51u, R); |
| 210 | EXPECT_EQ(102u, G); |
| 211 | EXPECT_EQ(153u, B); |
| 212 | EXPECT_EQ(204u, A); |
| 213 | |
| 214 | // Change the color of the annotation. |
| 215 | ASSERT_TRUE( |
| 216 | FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 204, 153, 102, 51)); |
| 217 | // Check that the color has been set correctly. |
| 218 | EXPECT_TRUE( |
| 219 | FPDFAnnot_GetColor(annot, FPDFANNOT_COLORTYPE_Color, &R, &G, &B, &A)); |
| 220 | EXPECT_EQ(204u, R); |
| 221 | EXPECT_EQ(153u, G); |
| 222 | EXPECT_EQ(102u, B); |
| 223 | EXPECT_EQ(51u, A); |
| 224 | |
| 225 | // Set the annotation rectangle. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 226 | FS_RECTF rect; |
| 227 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 228 | EXPECT_EQ(0.f, rect.left); |
| 229 | EXPECT_EQ(0.f, rect.right); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 230 | rect.left = 35; |
| 231 | rect.bottom = 150; |
| 232 | rect.right = 53; |
| 233 | rect.top = 165; |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 234 | ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 235 | // Check that the annotation rectangle has been set correctly. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 236 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 237 | EXPECT_EQ(35.f, rect.left); |
| 238 | EXPECT_EQ(150.f, rect.bottom); |
| 239 | EXPECT_EQ(53.f, rect.right); |
| 240 | EXPECT_EQ(165.f, rect.top); |
| 241 | |
| 242 | // Set the content of the annotation. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 243 | static constexpr wchar_t contents[] = L"Hello! This is a customized content."; |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 244 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = |
| 245 | GetFPDFWideString(contents); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 246 | ASSERT_TRUE(FPDFAnnot_SetStringValue(annot, kContentsKey, text.get())); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 247 | // Check that the content has been set correctly. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 248 | unsigned long len = FPDFAnnot_GetStringValue(annot, kContentsKey, nullptr, 0); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 249 | std::vector<char> buf(len); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 250 | EXPECT_EQ(74u, |
| 251 | FPDFAnnot_GetStringValue(annot, kContentsKey, buf.data(), len)); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 252 | EXPECT_STREQ(contents, BufferToWString(buf).c_str()); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 253 | |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 254 | FPDFPage_CloseAnnot(annot); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 255 | UnloadPage(page); |
| 256 | } |
| 257 | |
| 258 | TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { |
| 259 | // Open a file with one annotation and load its first page. |
| 260 | ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); |
| 261 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 262 | ASSERT_TRUE(page); |
| 263 | |
| 264 | // Check that there is a total of one annotation on its first page, and verify |
| 265 | // its quadpoints. |
| 266 | EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 267 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 268 | ASSERT_TRUE(annot); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 269 | FS_QUADPOINTSF quadpoints; |
| 270 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 271 | EXPECT_EQ(115.802643f, quadpoints.x1); |
| 272 | EXPECT_EQ(718.913940f, quadpoints.y1); |
| 273 | EXPECT_EQ(157.211182f, quadpoints.x4); |
| 274 | EXPECT_EQ(706.264465f, quadpoints.y4); |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 275 | FPDFPage_CloseAnnot(annot); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 276 | |
| 277 | // Add an underline annotation to the page and set its quadpoints. |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 278 | annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE); |
| 279 | ASSERT_TRUE(annot); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 280 | quadpoints.x1 = 140.802643f; |
| 281 | quadpoints.x3 = 140.802643f; |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 282 | ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, &quadpoints)); |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 283 | FPDFPage_CloseAnnot(annot); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 284 | |
| 285 | // Save the document, closing the page and document. |
| 286 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 287 | FPDF_ClosePage(page); |
| 288 | |
| 289 | // Open the saved document. |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 290 | const char md5[] = "dba153419f67b7c0c0e3d22d3e8910d5"; |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 291 | |
| 292 | OpenSavedDocument(); |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 293 | page = LoadSavedPage(0); |
| 294 | VerifySavedRendering(page, 612, 792, md5); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 295 | |
| 296 | // Check that the saved document has 2 annotations on the first page |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 297 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 298 | |
| 299 | // Check that the second annotation is an underline annotation and verify |
| 300 | // its quadpoints. |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 301 | FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(page, 1); |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 302 | ASSERT_TRUE(new_annot); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 303 | EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot)); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 304 | FS_QUADPOINTSF new_quadpoints; |
| 305 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(new_annot, &new_quadpoints)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 306 | EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f); |
| 307 | EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f); |
| 308 | EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f); |
| 309 | EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f); |
| 310 | |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 311 | FPDFPage_CloseAnnot(new_annot); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 312 | |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 313 | CloseSavedPage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 314 | CloseSavedDocument(); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 315 | } |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 316 | |
| 317 | TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) { |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 318 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 319 | const char md5_original[] = "63af8432fab95a67cdebb7cd0e514941"; |
| 320 | const char md5_modified_highlight[] = "aec26075011349dec9bace891856b5f2"; |
| 321 | const char md5_modified_square[] = "057f57a32be95975775e5ec513fdcb56"; |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 322 | #elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 323 | const char md5_original[] = "0e27376094f11490f74c65f3dc3a42c5"; |
| 324 | const char md5_modified_highlight[] = "66f3caef3a7d488a4fa1ad37fc06310e"; |
| 325 | const char md5_modified_square[] = "a456dad0bc6801ee2d6408a4394af563"; |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 326 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 327 | const char md5_original[] = "0e27376094f11490f74c65f3dc3a42c5"; |
| 328 | const char md5_modified_highlight[] = "66f3caef3a7d488a4fa1ad37fc06310e"; |
| 329 | const char md5_modified_square[] = "a456dad0bc6801ee2d6408a4394af563"; |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 330 | #endif |
| 331 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 332 | // Open a file with four annotations and load its first page. |
| 333 | ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); |
| 334 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 335 | ASSERT_TRUE(page); |
| 336 | EXPECT_EQ(4, FPDFPage_GetAnnotCount(page)); |
| 337 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 338 | // Check that the original file renders correctly. |
| 339 | FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 340 | CompareBitmap(bitmap, 612, 792, md5_original); |
| 341 | FPDFBitmap_Destroy(bitmap); |
| 342 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 343 | // Retrieve the highlight annotation which has its AP stream already defined. |
| 344 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 345 | ASSERT_TRUE(annot); |
| 346 | EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); |
| 347 | |
| 348 | // Check that color cannot be set when an AP stream is defined already. |
| 349 | EXPECT_FALSE( |
| 350 | FPDFAnnot_SetColor(annot, FPDFANNOT_COLORTYPE_Color, 51, 102, 153, 204)); |
| 351 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 352 | // Verify its attachment points. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 353 | FS_QUADPOINTSF quadpoints; |
| 354 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)); |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 355 | EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f); |
| 356 | EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f); |
| 357 | EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f); |
| 358 | EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 359 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 360 | // Check that updating the attachment points would succeed. |
| 361 | quadpoints.x1 -= 50.f; |
| 362 | quadpoints.x2 -= 50.f; |
| 363 | quadpoints.x3 -= 50.f; |
| 364 | quadpoints.x4 -= 50.f; |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 365 | ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, &quadpoints)); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 366 | FS_QUADPOINTSF new_quadpoints; |
| 367 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &new_quadpoints)); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 368 | EXPECT_EQ(quadpoints.x1, new_quadpoints.x1); |
| 369 | EXPECT_EQ(quadpoints.y1, new_quadpoints.y1); |
| 370 | EXPECT_EQ(quadpoints.x4, new_quadpoints.x4); |
| 371 | EXPECT_EQ(quadpoints.y4, new_quadpoints.y4); |
| 372 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 373 | // Check that updating quadpoints does not change the annotation's position. |
| 374 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 375 | CompareBitmap(bitmap, 612, 792, md5_original); |
| 376 | FPDFBitmap_Destroy(bitmap); |
| 377 | |
| 378 | // Verify its annotation rectangle. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 379 | FS_RECTF rect; |
| 380 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 381 | EXPECT_NEAR(67.7299f, rect.left, 0.001f); |
| 382 | EXPECT_NEAR(704.296f, rect.bottom, 0.001f); |
| 383 | EXPECT_NEAR(136.325f, rect.right, 0.001f); |
| 384 | EXPECT_NEAR(721.292f, rect.top, 0.001f); |
| 385 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 386 | // Check that updating the rectangle would succeed. |
| 387 | rect.left -= 60.f; |
| 388 | rect.right -= 60.f; |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 389 | ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect)); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 390 | FS_RECTF new_rect; |
| 391 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect)); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 392 | EXPECT_EQ(rect.right, new_rect.right); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 393 | FPDFPage_CloseAnnot(annot); |
| 394 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 395 | // Check that updating the rectangle changes the annotation's position. |
| 396 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 397 | CompareBitmap(bitmap, 612, 792, md5_modified_highlight); |
| 398 | FPDFBitmap_Destroy(bitmap); |
| 399 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 400 | // Retrieve the square annotation which has its AP stream already defined. |
| 401 | annot = FPDFPage_GetAnnot(page, 2); |
| 402 | ASSERT_TRUE(annot); |
| 403 | EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot)); |
| 404 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 405 | // Check that updating the rectangle would succeed. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 406 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 407 | rect.left += 70.f; |
| 408 | rect.right += 70.f; |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 409 | ASSERT_TRUE(FPDFAnnot_SetRect(annot, &rect)); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 410 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect)); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 411 | EXPECT_EQ(rect.right, new_rect.right); |
| 412 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 413 | // Check that updating the rectangle changes the square annotation's position. |
| 414 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 415 | CompareBitmap(bitmap, 612, 792, md5_modified_square); |
| 416 | FPDFBitmap_Destroy(bitmap); |
| 417 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 418 | FPDFPage_CloseAnnot(annot); |
| 419 | UnloadPage(page); |
| 420 | } |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 421 | |
| 422 | TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) { |
| 423 | // Open a file with 3 annotations on its first page. |
| 424 | ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); |
| 425 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 426 | ASSERT_TRUE(page); |
| 427 | EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); |
| 428 | |
| 429 | // Check that the annotations have the expected rectangle coordinates. |
| 430 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 431 | FS_RECTF rect; |
| 432 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 433 | EXPECT_NEAR(86.1971f, rect.left, 0.001f); |
| 434 | FPDFPage_CloseAnnot(annot); |
| 435 | |
| 436 | annot = FPDFPage_GetAnnot(page, 1); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 437 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 438 | EXPECT_NEAR(149.8127f, rect.left, 0.001f); |
| 439 | FPDFPage_CloseAnnot(annot); |
| 440 | |
| 441 | annot = FPDFPage_GetAnnot(page, 2); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 442 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 443 | EXPECT_NEAR(351.8204f, rect.left, 0.001f); |
| 444 | FPDFPage_CloseAnnot(annot); |
| 445 | |
| 446 | // Check that nothing happens when attempting to remove an annotation with an |
| 447 | // out-of-bound index. |
| 448 | EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4)); |
| 449 | EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1)); |
| 450 | EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); |
| 451 | |
| 452 | // Remove the second annotation. |
| 453 | EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1)); |
| 454 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 455 | EXPECT_FALSE(FPDFPage_GetAnnot(page, 2)); |
| 456 | |
| 457 | // Save the document, closing the page and document. |
| 458 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 459 | FPDF_ClosePage(page); |
| 460 | |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 461 | // TODO(npm): VerifySavedRendering changes annot rect dimensions by 1?? |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 462 | // Open the saved document. |
| 463 | std::string new_file = GetString(); |
| 464 | FPDF_FILEACCESS file_access; |
| 465 | memset(&file_access, 0, sizeof(file_access)); |
| 466 | file_access.m_FileLen = new_file.size(); |
| 467 | file_access.m_GetBlock = GetBlockFromString; |
| 468 | file_access.m_Param = &new_file; |
| 469 | FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); |
| 470 | ASSERT_TRUE(new_doc); |
| 471 | FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); |
| 472 | ASSERT_TRUE(new_page); |
| 473 | |
| 474 | // Check that the saved document has 2 annotations on the first page. |
| 475 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page)); |
| 476 | |
| 477 | // Check that the remaining 2 annotations are the original 1st and 3rd ones by |
| 478 | // verifying their rectangle coordinates. |
| 479 | annot = FPDFPage_GetAnnot(new_page, 0); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 480 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 481 | EXPECT_NEAR(86.1971f, rect.left, 0.001f); |
| 482 | FPDFPage_CloseAnnot(annot); |
| 483 | |
| 484 | annot = FPDFPage_GetAnnot(new_page, 1); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 485 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 486 | EXPECT_NEAR(351.8204f, rect.left, 0.001f); |
| 487 | FPDFPage_CloseAnnot(annot); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 488 | FPDF_ClosePage(new_page); |
| 489 | FPDF_CloseDocument(new_doc); |
| 490 | } |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 491 | |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 492 | TEST_F(FPDFAnnotEmbeddertest, AddAndModifyPath) { |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 493 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 494 | const char md5_original[] = "c35408717759562d1f8bf33d317483d2"; |
| 495 | const char md5_modified_path[] = "cf3cea74bd46497520ff6c4d1ea228c8"; |
| 496 | const char md5_two_paths[] = "e8994452fc4385337bae5522354e10ff"; |
| 497 | const char md5_new_annot[] = "ee5372b31fede117fc83b9384598aa25"; |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 498 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 499 | const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e"; |
| 500 | const char md5_modified_path[] = "3f77b88ce6048e08e636c9a03921b2e5"; |
| 501 | const char md5_two_paths[] = "bffbf5ecd15862b9fe553c795400ff8e"; |
| 502 | const char md5_new_annot[] = "e020534c7eeea76be537c70d6e359a40"; |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 503 | #endif |
| 504 | |
| 505 | // Open a file with two annotations and load its first page. |
| 506 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
| 507 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 508 | ASSERT_TRUE(page); |
| 509 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 510 | |
| 511 | // Check that the page renders correctly. |
| 512 | FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 513 | CompareBitmap(bitmap, 595, 842, md5_original); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 514 | FPDFBitmap_Destroy(bitmap); |
| 515 | |
| 516 | // Retrieve the stamp annotation which has its AP stream already defined. |
| 517 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 518 | ASSERT_TRUE(annot); |
| 519 | |
| 520 | // Check that this annotation has one path object and retrieve it. |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 521 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); |
| 522 | FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot, 1); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 523 | EXPECT_FALSE(path); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 524 | path = FPDFAnnot_GetObject(annot, 0); |
| 525 | EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 526 | EXPECT_TRUE(path); |
| 527 | |
| 528 | // Modify the color of the path object. |
| 529 | EXPECT_TRUE(FPDFPath_SetStrokeColor(path, 0, 0, 0, 255)); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 530 | EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, path)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 531 | |
| 532 | // Check that the page with the modified annotation renders correctly. |
| 533 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 534 | CompareBitmap(bitmap, 595, 842, md5_modified_path); |
| 535 | FPDFBitmap_Destroy(bitmap); |
| 536 | |
| 537 | // Add a second path object to the same annotation. |
| 538 | FPDF_PAGEOBJECT dot = FPDFPageObj_CreateNewPath(7, 84); |
| 539 | EXPECT_TRUE(FPDFPath_BezierTo(dot, 9, 86, 10, 87, 11, 88)); |
| 540 | EXPECT_TRUE(FPDFPath_SetStrokeColor(dot, 255, 0, 0, 100)); |
| 541 | EXPECT_TRUE(FPDFPath_SetStrokeWidth(dot, 14)); |
| 542 | EXPECT_TRUE(FPDFPath_SetDrawMode(dot, 0, 1)); |
| 543 | EXPECT_TRUE(FPDFAnnot_AppendObject(annot, dot)); |
| 544 | EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot)); |
| 545 | |
| 546 | // Check that the page with an annotation with two paths renders correctly. |
| 547 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 548 | CompareBitmap(bitmap, 595, 842, md5_two_paths); |
| 549 | FPDFBitmap_Destroy(bitmap); |
| 550 | |
| 551 | // Delete the newly added path object. |
| 552 | EXPECT_TRUE(FPDFAnnot_RemoveObject(annot, 1)); |
| 553 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); |
| 554 | FPDFPage_CloseAnnot(annot); |
| 555 | |
| 556 | // Check that the page renders the same as before. |
| 557 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 558 | CompareBitmap(bitmap, 595, 842, md5_modified_path); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 559 | FPDFBitmap_Destroy(bitmap); |
| 560 | |
| 561 | // Create another stamp annotation and set its annotation rectangle. |
| 562 | annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP); |
| 563 | ASSERT_TRUE(annot); |
| 564 | FS_RECTF rect; |
| 565 | rect.left = 200.f; |
| 566 | rect.bottom = 400.f; |
| 567 | rect.right = 500.f; |
| 568 | rect.top = 600.f; |
| 569 | EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect)); |
| 570 | |
| 571 | // Add a new path to the annotation. |
| 572 | FPDF_PAGEOBJECT check = FPDFPageObj_CreateNewPath(200, 500); |
| 573 | EXPECT_TRUE(FPDFPath_LineTo(check, 300, 400)); |
| 574 | EXPECT_TRUE(FPDFPath_LineTo(check, 500, 600)); |
| 575 | EXPECT_TRUE(FPDFPath_MoveTo(check, 350, 550)); |
| 576 | EXPECT_TRUE(FPDFPath_LineTo(check, 450, 450)); |
| 577 | EXPECT_TRUE(FPDFPath_SetStrokeColor(check, 0, 255, 255, 180)); |
| 578 | EXPECT_TRUE(FPDFPath_SetStrokeWidth(check, 8.35f)); |
| 579 | EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1)); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 580 | EXPECT_TRUE(FPDFAnnot_AppendObject(annot, check)); |
| 581 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 582 | |
| 583 | // Check that the annotation's bounding box came from its rectangle. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 584 | FS_RECTF new_rect; |
| 585 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 586 | EXPECT_EQ(rect.left, new_rect.left); |
| 587 | EXPECT_EQ(rect.bottom, new_rect.bottom); |
| 588 | EXPECT_EQ(rect.right, new_rect.right); |
| 589 | EXPECT_EQ(rect.top, new_rect.top); |
| 590 | |
| 591 | // Save the document, closing the page and document. |
| 592 | FPDFPage_CloseAnnot(annot); |
| 593 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 594 | FPDF_ClosePage(page); |
| 595 | |
| 596 | // Open the saved document. |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 597 | OpenSavedDocument(); |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 598 | page = LoadSavedPage(0); |
| 599 | VerifySavedRendering(page, 595, 842, md5_new_annot); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 600 | |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 601 | // Check that the document has a correct count of annotations and objects. |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 602 | EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); |
| 603 | annot = FPDFPage_GetAnnot(page, 2); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 604 | ASSERT_TRUE(annot); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 605 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 606 | |
| 607 | // Check that the new annotation's rectangle is as defined. |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 608 | ASSERT_TRUE(FPDFAnnot_GetRect(annot, &new_rect)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 609 | EXPECT_EQ(rect.left, new_rect.left); |
| 610 | EXPECT_EQ(rect.bottom, new_rect.bottom); |
| 611 | EXPECT_EQ(rect.right, new_rect.right); |
| 612 | EXPECT_EQ(rect.top, new_rect.top); |
| 613 | |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 614 | FPDFPage_CloseAnnot(annot); |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 615 | CloseSavedPage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 616 | CloseSavedDocument(); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 617 | } |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 618 | |
| 619 | TEST_F(FPDFAnnotEmbeddertest, ModifyAnnotationFlags) { |
| 620 | // Open a file with an annotation and load its first page. |
| 621 | ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf")); |
| 622 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 623 | ASSERT_TRUE(page); |
| 624 | |
| 625 | // Check that the page renders correctly. |
| 626 | FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 627 | CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); |
| 628 | FPDFBitmap_Destroy(bitmap); |
| 629 | |
| 630 | // Retrieve the annotation. |
| 631 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 632 | ASSERT_TRUE(annot); |
| 633 | |
| 634 | // Check that the original flag values are as expected. |
| 635 | int flags = FPDFAnnot_GetFlags(annot); |
| 636 | EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN); |
| 637 | EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); |
| 638 | |
| 639 | // Set the HIDDEN flag. |
| 640 | flags |= FPDF_ANNOT_FLAG_HIDDEN; |
| 641 | EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags)); |
| 642 | flags = FPDFAnnot_GetFlags(annot); |
| 643 | EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_HIDDEN); |
| 644 | EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); |
| 645 | |
| 646 | // Check that the page renders correctly without rendering the annotation. |
| 647 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 648 | CompareBitmap(bitmap, 612, 792, "1940568c9ba33bac5d0b1ee9558c76b3"); |
| 649 | FPDFBitmap_Destroy(bitmap); |
| 650 | |
| 651 | // Unset the HIDDEN flag. |
| 652 | EXPECT_TRUE(FPDFAnnot_SetFlags(annot, FPDF_ANNOT_FLAG_NONE)); |
| 653 | EXPECT_FALSE(FPDFAnnot_GetFlags(annot)); |
| 654 | flags &= ~FPDF_ANNOT_FLAG_HIDDEN; |
| 655 | EXPECT_TRUE(FPDFAnnot_SetFlags(annot, flags)); |
| 656 | flags = FPDFAnnot_GetFlags(annot); |
| 657 | EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN); |
| 658 | EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); |
| 659 | |
| 660 | // Check that the page renders correctly as before. |
| 661 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
| 662 | CompareBitmap(bitmap, 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); |
| 663 | FPDFBitmap_Destroy(bitmap); |
| 664 | |
| 665 | FPDFPage_CloseAnnot(annot); |
| 666 | UnloadPage(page); |
| 667 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 668 | |
| 669 | TEST_F(FPDFAnnotEmbeddertest, AddAndModifyImage) { |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 670 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 671 | const char md5_original[] = "c35408717759562d1f8bf33d317483d2"; |
| 672 | const char md5_new_image[] = "ff012f5697436dfcaec25b32d1333596"; |
| 673 | const char md5_modified_image[] = "86cf8cb2755a7a2046a543e66d9c1e61"; |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 674 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 675 | const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e"; |
| 676 | const char md5_new_image[] = "9ea8732dc9d579f68853f16892856208"; |
| 677 | const char md5_modified_image[] = "74239d2a8c55c9de1dbb9cd8781895aa"; |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 678 | #endif |
| 679 | |
| 680 | // Open a file with two annotations and load its first page. |
| 681 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
| 682 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 683 | ASSERT_TRUE(page); |
| 684 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 685 | |
| 686 | // Check that the page renders correctly. |
| 687 | FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 688 | CompareBitmap(bitmap, 595, 842, md5_original); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 689 | FPDFBitmap_Destroy(bitmap); |
| 690 | |
| 691 | // Create a stamp annotation and set its annotation rectangle. |
| 692 | FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP); |
| 693 | ASSERT_TRUE(annot); |
| 694 | FS_RECTF rect; |
| 695 | rect.left = 200.f; |
| 696 | rect.bottom = 600.f; |
| 697 | rect.right = 400.f; |
| 698 | rect.top = 800.f; |
| 699 | EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect)); |
| 700 | |
| 701 | // Add a solid-color translucent image object to the new annotation. |
| 702 | constexpr int kBitmapSize = 200; |
| 703 | FPDF_BITMAP image_bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 1); |
| 704 | FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xeeeecccc); |
| 705 | EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap)); |
| 706 | EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap)); |
| 707 | FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document()); |
| 708 | ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap)); |
| 709 | ASSERT_TRUE(FPDFImageObj_SetMatrix(image_object, kBitmapSize, 0, 0, |
| 710 | kBitmapSize, 0, 0)); |
| 711 | FPDFPageObj_Transform(image_object, 1, 0, 0, 1, 200, 600); |
| 712 | EXPECT_TRUE(FPDFAnnot_AppendObject(annot, image_object)); |
| 713 | FPDFPage_CloseAnnot(annot); |
| 714 | |
| 715 | // Check that the page renders correctly with the new image object. |
| 716 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 717 | CompareBitmap(bitmap, 595, 842, md5_new_image); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 718 | FPDFBitmap_Destroy(bitmap); |
| 719 | |
| 720 | // Retrieve the newly added stamp annotation and its image object. |
| 721 | annot = FPDFPage_GetAnnot(page, 2); |
| 722 | ASSERT_TRUE(annot); |
| 723 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); |
| 724 | image_object = FPDFAnnot_GetObject(annot, 0); |
| 725 | EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image_object)); |
| 726 | |
| 727 | // Modify the image in the new annotation. |
| 728 | FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, 0xff000000); |
| 729 | ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap)); |
| 730 | EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, image_object)); |
| 731 | FPDFPage_CloseAnnot(annot); |
| 732 | |
| 733 | // Save the document, closing the page and document. |
| 734 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 735 | FPDF_ClosePage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 736 | FPDFBitmap_Destroy(image_bitmap); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 737 | |
| 738 | // Test that the saved document renders the modified image object correctly. |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 739 | VerifySavedDocument(595, 842, md5_modified_image); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | TEST_F(FPDFAnnotEmbeddertest, AddAndModifyText) { |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 743 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 744 | const char md5_original[] = "c35408717759562d1f8bf33d317483d2"; |
| 745 | const char md5_new_text[] = "e5680ed048c2cfd9a1d27212cdf41286"; |
| 746 | const char md5_modified_text[] = "79f5cfb0b07caaf936f65f6a7a57ce77"; |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 747 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 748 | const char md5_original[] = "964f89bbe8911e540a465cf1a64b7f7e"; |
| 749 | const char md5_new_text[] = "00b14fa2dc1c90d1b0d034e1608efef5"; |
| 750 | const char md5_modified_text[] = "076c8f24a09ddc0e49f7e758edead6f0"; |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 751 | #endif |
| 752 | |
| 753 | // Open a file with two annotations and load its first page. |
| 754 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
| 755 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 756 | ASSERT_TRUE(page); |
| 757 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 758 | |
| 759 | // Check that the page renders correctly. |
| 760 | FPDF_BITMAP bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 761 | CompareBitmap(bitmap, 595, 842, md5_original); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 762 | FPDFBitmap_Destroy(bitmap); |
| 763 | |
| 764 | // Create a stamp annotation and set its annotation rectangle. |
| 765 | FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP); |
| 766 | ASSERT_TRUE(annot); |
| 767 | FS_RECTF rect; |
| 768 | rect.left = 200.f; |
| 769 | rect.bottom = 550.f; |
| 770 | rect.right = 450.f; |
| 771 | rect.top = 650.f; |
| 772 | EXPECT_TRUE(FPDFAnnot_SetRect(annot, &rect)); |
| 773 | |
| 774 | // Add a translucent text object to the new annotation. |
| 775 | FPDF_PAGEOBJECT text_object = |
| 776 | FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); |
| 777 | EXPECT_TRUE(text_object); |
| 778 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = |
| 779 | GetFPDFWideString(L"I'm a translucent text laying on other text."); |
| 780 | EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); |
| 781 | EXPECT_TRUE(FPDFText_SetFillColor(text_object, 0, 0, 255, 150)); |
| 782 | FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 600); |
| 783 | EXPECT_TRUE(FPDFAnnot_AppendObject(annot, text_object)); |
| 784 | FPDFPage_CloseAnnot(annot); |
| 785 | |
| 786 | // Check that the page renders correctly with the new text object. |
| 787 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 788 | CompareBitmap(bitmap, 595, 842, md5_new_text); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 789 | FPDFBitmap_Destroy(bitmap); |
| 790 | |
| 791 | // Retrieve the newly added stamp annotation and its text object. |
| 792 | annot = FPDFPage_GetAnnot(page, 2); |
| 793 | ASSERT_TRUE(annot); |
| 794 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot)); |
| 795 | text_object = FPDFAnnot_GetObject(annot, 0); |
| 796 | EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object)); |
| 797 | |
| 798 | // Modify the text in the new annotation. |
| 799 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> new_text = |
| 800 | GetFPDFWideString(L"New text!"); |
| 801 | EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get())); |
| 802 | EXPECT_TRUE(FPDFAnnot_UpdateObject(annot, text_object)); |
| 803 | FPDFPage_CloseAnnot(annot); |
| 804 | |
| 805 | // Check that the page renders correctly with the modified text object. |
| 806 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 807 | CompareBitmap(bitmap, 595, 842, md5_modified_text); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 808 | FPDFBitmap_Destroy(bitmap); |
| 809 | |
| 810 | // Remove the new annotation, and check that the page renders as before. |
| 811 | EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2)); |
| 812 | bitmap = RenderPageWithFlags(page, form_handle_, FPDF_ANNOT); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 813 | CompareBitmap(bitmap, 595, 842, md5_original); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 814 | FPDFBitmap_Destroy(bitmap); |
| 815 | |
| 816 | UnloadPage(page); |
| 817 | } |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 818 | |
| 819 | TEST_F(FPDFAnnotEmbeddertest, GetSetStringValue) { |
| 820 | // Open a file with four annotations and load its first page. |
| 821 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
| 822 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 823 | ASSERT_TRUE(page); |
| 824 | |
| 825 | // Retrieve the first annotation. |
| 826 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 827 | ASSERT_TRUE(annot); |
| 828 | |
| 829 | // Check that a non-existent key does not exist. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 830 | EXPECT_FALSE(FPDFAnnot_HasKey(annot, "none")); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 831 | |
| 832 | // Check that the string value of a non-string dictionary entry is empty. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 833 | static constexpr char kApKey[] = "AP"; |
| 834 | EXPECT_TRUE(FPDFAnnot_HasKey(annot, kApKey)); |
| 835 | EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kApKey)); |
| 836 | EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot, kApKey, nullptr, 0)); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 837 | |
| 838 | // Check that the string value of the hash is correct. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 839 | static constexpr char kHashKey[] = "AAPL:Hash"; |
| 840 | EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, kHashKey)); |
| 841 | unsigned long len = FPDFAnnot_GetStringValue(annot, kHashKey, nullptr, 0); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 842 | std::vector<char> buf(len); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 843 | EXPECT_EQ(66u, FPDFAnnot_GetStringValue(annot, kHashKey, buf.data(), len)); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 844 | EXPECT_STREQ(L"395fbcb98d558681742f30683a62a2ad", |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 845 | BufferToWString(buf).c_str()); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 846 | |
| 847 | // Check that the string value of the modified date is correct. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 848 | static constexpr char kDateKey[] = "M"; |
| 849 | EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot, kHashKey)); |
| 850 | len = FPDFAnnot_GetStringValue(annot, kDateKey, nullptr, 0); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 851 | buf.clear(); |
| 852 | buf.resize(len); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 853 | EXPECT_EQ(44u, FPDFAnnot_GetStringValue(annot, kDateKey, buf.data(), len)); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 854 | EXPECT_STREQ(L"D:201706071721Z00'00'", BufferToWString(buf).c_str()); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 855 | |
| 856 | // Update the date entry for the annotation. |
| 857 | const wchar_t new_date[] = L"D:201706282359Z00'00'"; |
| 858 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = |
| 859 | GetFPDFWideString(new_date); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 860 | EXPECT_TRUE(FPDFAnnot_SetStringValue(annot, kDateKey, text.get())); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 861 | |
| 862 | // Save the document, closing the page and document. |
| 863 | FPDFPage_CloseAnnot(annot); |
| 864 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 865 | FPDF_ClosePage(page); |
| 866 | |
| 867 | // Open the saved annotation. |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 868 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Artem Strygin | d24b97e | 2017-08-09 18:50:59 +0300 | [diff] [blame] | 869 | const char md5[] = "4d64e61c9c0f8c60ab3cc3234bb73b1c"; |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 870 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 871 | const char md5[] = "c96ee1f316d7f5a1b154de9f9d467f01"; |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 872 | #endif |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 873 | OpenSavedDocument(); |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 874 | page = LoadSavedPage(0); |
| 875 | VerifySavedRendering(page, 595, 842, md5); |
| 876 | FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(page, 0); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 877 | |
| 878 | // Check that the string value of the modified date is the newly-set value. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 879 | EXPECT_EQ(FPDF_OBJECT_STRING, FPDFAnnot_GetValueType(new_annot, kDateKey)); |
| 880 | len = FPDFAnnot_GetStringValue(new_annot, kDateKey, nullptr, 0); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 881 | buf.clear(); |
| 882 | buf.resize(len); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 883 | EXPECT_EQ(44u, |
| 884 | FPDFAnnot_GetStringValue(new_annot, kDateKey, buf.data(), len)); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 885 | EXPECT_STREQ(new_date, BufferToWString(buf).c_str()); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 886 | |
| 887 | FPDFPage_CloseAnnot(new_annot); |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 888 | CloseSavedPage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 889 | CloseSavedDocument(); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 890 | } |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 891 | |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame^] | 892 | TEST_F(FPDFAnnotEmbeddertest, GetAP) { |
| 893 | // Open a file with four annotations and load its first page. |
| 894 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
| 895 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 896 | ASSERT_TRUE(page); |
| 897 | |
| 898 | // Retrieve the first annotation. |
| 899 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 900 | ASSERT_TRUE(annot); |
| 901 | |
| 902 | // Check that the string value of an AP returns the expected length. |
| 903 | unsigned long len = |
| 904 | FPDFAnnot_GetAP(annot, FPDF_ANNOT_APPEARANCEMODE_NORMAL, nullptr, 0); |
| 905 | EXPECT_EQ(73970u, len); |
| 906 | |
| 907 | // Check that the string value of an AP is not returned if the buffer is too |
| 908 | // small. The result buffer should be overwritten with an empty string. |
| 909 | std::vector<char> buf(len - 1); |
| 910 | // Write L"z" in the buffer to verify it's not overwritten. |
| 911 | wcscpy(reinterpret_cast<wchar_t*>(buf.data()), L"z"); |
| 912 | EXPECT_EQ(73970u, FPDFAnnot_GetAP(annot, FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
| 913 | buf.data(), len - 1)); |
| 914 | std::string ap = BufferToString(buf); |
| 915 | EXPECT_STREQ("z", ap.c_str()); |
| 916 | |
| 917 | // Check that the string value of an AP is returned through a buffer that is |
| 918 | // the right size. |
| 919 | buf.clear(); |
| 920 | buf.resize(len); |
| 921 | EXPECT_EQ(73970u, FPDFAnnot_GetAP(annot, FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
| 922 | buf.data(), len)); |
| 923 | ap = BufferToString(buf); |
| 924 | EXPECT_THAT(ap, testing::StartsWith("q Q q 7.442786 w 2 J")); |
| 925 | EXPECT_THAT(ap, testing::EndsWith("c 716.5381 327.7156 l S Q Q")); |
| 926 | |
| 927 | // Check that the string value of an AP is returned through a buffer that is |
| 928 | // larger than necessary. |
| 929 | buf.clear(); |
| 930 | buf.resize(len + 1); |
| 931 | EXPECT_EQ(73970u, FPDFAnnot_GetAP(annot, FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
| 932 | buf.data(), len + 1)); |
| 933 | ap = BufferToString(buf); |
| 934 | EXPECT_THAT(ap, testing::StartsWith("q Q q 7.442786 w 2 J")); |
| 935 | EXPECT_THAT(ap, testing::EndsWith("c 716.5381 327.7156 l S Q Q")); |
| 936 | |
| 937 | // Check that getting an AP for a mode that does not have an AP returns an |
| 938 | // empty string. |
| 939 | buf.clear(); |
| 940 | buf.resize(len); |
| 941 | EXPECT_EQ(2u, FPDFAnnot_GetAP(annot, FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, |
| 942 | buf.data(), len)); |
| 943 | ap = BufferToString(buf); |
| 944 | EXPECT_STREQ("", ap.c_str()); |
| 945 | |
| 946 | FPDFPage_CloseAnnot(annot); |
| 947 | FPDF_ClosePage(page); |
| 948 | } |
| 949 | |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 950 | TEST_F(FPDFAnnotEmbeddertest, ExtractLinkedAnnotations) { |
| 951 | // Open a file with annotations and load its first page. |
| 952 | ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); |
| 953 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 954 | ASSERT_TRUE(page); |
Jane Liu | d1ed1ce | 2017-08-24 12:31:10 -0400 | [diff] [blame] | 955 | EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr)); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 956 | |
| 957 | // Retrieve the highlight annotation which has its popup defined. |
| 958 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 959 | ASSERT_TRUE(annot); |
| 960 | EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); |
Jane Liu | d1ed1ce | 2017-08-24 12:31:10 -0400 | [diff] [blame] | 961 | EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot)); |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 962 | static constexpr char kPopupKey[] = "Popup"; |
| 963 | ASSERT_TRUE(FPDFAnnot_HasKey(annot, kPopupKey)); |
| 964 | ASSERT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kPopupKey)); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 965 | |
| 966 | // Retrieve and verify the popup of the highlight annotation. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 967 | FPDF_ANNOTATION popup = FPDFAnnot_GetLinkedAnnot(annot, kPopupKey); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 968 | ASSERT_TRUE(popup); |
| 969 | EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup)); |
Jane Liu | d1ed1ce | 2017-08-24 12:31:10 -0400 | [diff] [blame] | 970 | EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup)); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 971 | FS_RECTF rect; |
| 972 | ASSERT_TRUE(FPDFAnnot_GetRect(popup, &rect)); |
| 973 | EXPECT_NEAR(612.0f, rect.left, 0.001f); |
| 974 | EXPECT_NEAR(578.792, rect.bottom, 0.001f); |
| 975 | |
| 976 | // Attempting to retrieve |annot|'s "IRT"-linked annotation would fail, since |
| 977 | // "IRT" is not a key in |annot|'s dictionary. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 978 | static constexpr char kIRTKey[] = "IRT"; |
| 979 | ASSERT_FALSE(FPDFAnnot_HasKey(annot, kIRTKey)); |
| 980 | EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, kIRTKey)); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 981 | |
| 982 | // Attempting to retrieve |annot|'s parent dictionary as an annotation would |
| 983 | // fail, since its parent is not an annotation. |
Lei Zhang | df064df | 2017-08-31 02:33:27 -0700 | [diff] [blame] | 984 | static constexpr char kPKey[] = "P"; |
| 985 | ASSERT_TRUE(FPDFAnnot_HasKey(annot, kPKey)); |
| 986 | EXPECT_EQ(FPDF_OBJECT_REFERENCE, FPDFAnnot_GetValueType(annot, kPKey)); |
| 987 | EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot, kPKey)); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 988 | |
| 989 | FPDFPage_CloseAnnot(popup); |
| 990 | FPDFPage_CloseAnnot(annot); |
| 991 | UnloadPage(page); |
| 992 | } |
| 993 | |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 994 | TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsTextField) { |
| 995 | // Open file with form text fields. |
| 996 | ASSERT_TRUE(OpenDocument("text_form_multiple.pdf")); |
| 997 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 998 | ASSERT_TRUE(page); |
| 999 | |
| 1000 | // Retrieve the first annotation: user-editable text field. |
| 1001 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 1002 | ASSERT_TRUE(annot); |
| 1003 | |
| 1004 | // Check that the flag values are as expected. |
| 1005 | int flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1006 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1007 | FPDFPage_CloseAnnot(annot); |
| 1008 | |
| 1009 | // Retrieve the second annotation: read-only text field. |
| 1010 | annot = FPDFPage_GetAnnot(page, 1); |
| 1011 | ASSERT_TRUE(annot); |
| 1012 | |
| 1013 | // Check that the flag values are as expected. |
| 1014 | flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1015 | EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); |
| 1016 | FPDFPage_CloseAnnot(annot); |
| 1017 | |
| 1018 | UnloadPage(page); |
| 1019 | } |
| 1020 | |
| 1021 | TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) { |
| 1022 | // Open file with form text fields. |
| 1023 | ASSERT_TRUE(OpenDocument("combobox_form.pdf")); |
| 1024 | FPDF_PAGE page = FPDF_LoadPage(document(), 0); |
| 1025 | ASSERT_TRUE(page); |
| 1026 | |
| 1027 | // Retrieve the first annotation: user-editable combobox. |
| 1028 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 1029 | ASSERT_TRUE(annot); |
| 1030 | |
| 1031 | // Check that the flag values are as expected. |
| 1032 | int flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1033 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1034 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1035 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1036 | FPDFPage_CloseAnnot(annot); |
| 1037 | |
| 1038 | // Retrieve the second annotation: regular combobox. |
| 1039 | annot = FPDFPage_GetAnnot(page, 1); |
| 1040 | ASSERT_TRUE(annot); |
| 1041 | |
| 1042 | // Check that the flag values are as expected. |
| 1043 | flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1044 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1045 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1046 | EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1047 | FPDFPage_CloseAnnot(annot); |
| 1048 | |
| 1049 | // Retrieve the third annotation: read-only combobox. |
| 1050 | annot = FPDFPage_GetAnnot(page, 2); |
| 1051 | ASSERT_TRUE(annot); |
| 1052 | |
| 1053 | // Check that the flag values are as expected. |
| 1054 | flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1055 | EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); |
| 1056 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1057 | EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1058 | FPDFPage_CloseAnnot(annot); |
| 1059 | |
| 1060 | UnloadPage(page); |
| 1061 | } |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1062 | |
| 1063 | TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) { |
| 1064 | // Open file with form text fields. |
| 1065 | EXPECT_TRUE(OpenDocument("text_form.pdf")); |
| 1066 | FPDF_PAGE page = LoadPage(0); |
| 1067 | ASSERT_TRUE(page); |
| 1068 | |
| 1069 | // Attempt to get an annotation where no annotation exists on page. |
| 1070 | FPDF_ANNOTATION annot = |
| 1071 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0); |
| 1072 | EXPECT_FALSE(annot); |
| 1073 | |
| 1074 | UnloadPage(page); |
| 1075 | } |
| 1076 | |
| 1077 | TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) { |
| 1078 | // Open file with form text fields. |
| 1079 | EXPECT_TRUE(OpenDocument("text_form_multiple.pdf")); |
| 1080 | FPDF_PAGE page = LoadPage(0); |
| 1081 | ASSERT_TRUE(page); |
| 1082 | |
| 1083 | // Retrieve user-editable text field annotation. |
| 1084 | FPDF_ANNOTATION annot = |
| 1085 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118); |
| 1086 | ASSERT_TRUE(annot); |
| 1087 | |
| 1088 | // Check that interactive form annotation flag values are as expected. |
| 1089 | int flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1090 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1091 | FPDFPage_CloseAnnot(annot); |
| 1092 | |
| 1093 | // Retrieve read-only text field annotation. |
| 1094 | annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202); |
| 1095 | ASSERT_TRUE(annot); |
| 1096 | |
| 1097 | // Check that interactive form annotation flag values are as expected. |
| 1098 | flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1099 | EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); |
| 1100 | FPDFPage_CloseAnnot(annot); |
| 1101 | |
| 1102 | UnloadPage(page); |
| 1103 | } |
| 1104 | |
| 1105 | TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) { |
| 1106 | // Open file with form comboboxes. |
| 1107 | EXPECT_TRUE(OpenDocument("combobox_form.pdf")); |
| 1108 | FPDF_PAGE page = LoadPage(0); |
| 1109 | ASSERT_TRUE(page); |
| 1110 | |
| 1111 | // Retrieve user-editable combobox annotation. |
| 1112 | FPDF_ANNOTATION annot = |
| 1113 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 63); |
| 1114 | ASSERT_TRUE(annot); |
| 1115 | |
| 1116 | // Check that interactive form annotation flag values are as expected. |
| 1117 | int flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1118 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1119 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1120 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1121 | FPDFPage_CloseAnnot(annot); |
| 1122 | |
| 1123 | // Retrieve regular combobox annotation. |
| 1124 | annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 113); |
| 1125 | ASSERT_TRUE(annot); |
| 1126 | |
| 1127 | // Check that interactive form annotation flag values are as expected. |
| 1128 | flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1129 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1130 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1131 | EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1132 | FPDFPage_CloseAnnot(annot); |
| 1133 | |
| 1134 | // Retrieve read-only combobox annotation. |
| 1135 | annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 213); |
| 1136 | ASSERT_TRUE(annot); |
| 1137 | |
| 1138 | // Check that interactive form annotation flag values are as expected. |
| 1139 | flags = FPDFAnnot_GetFormFieldFlags(page, annot); |
| 1140 | EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); |
| 1141 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1142 | EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1143 | FPDFPage_CloseAnnot(annot); |
| 1144 | |
| 1145 | UnloadPage(page); |
| 1146 | } |