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