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