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