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 | |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 5 | #include <algorithm> |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 6 | #include <cwchar> |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 7 | #include <memory> |
| 8 | #include <string> |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Lei Zhang | e4cdac5 | 2019-04-30 16:45:57 +0000 | [diff] [blame] | 11 | #include "build/build_config.h" |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 12 | #include "constants/annotation_common.h" |
Ankit Kumar | 8c7e4ad | 2020-02-07 08:56:49 +0000 | [diff] [blame] | 13 | #include "core/fxcrt/fx_memory.h" |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 14 | #include "core/fxcrt/fx_system.h" |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 15 | #include "public/cpp/fpdf_scopers.h" |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 16 | #include "public/fpdf_annot.h" |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 17 | #include "public/fpdf_edit.h" |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 18 | #include "public/fpdf_formfill.h" |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 19 | #include "public/fpdfview.h" |
| 20 | #include "testing/embedder_test.h" |
Hui Yingst | b4baceb | 2020-04-28 23:46:10 +0000 | [diff] [blame] | 21 | #include "testing/embedder_test_constants.h" |
Lei Zhang | b6992dd | 2019-02-05 23:30:20 +0000 | [diff] [blame] | 22 | #include "testing/fx_string_testhelpers.h" |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 23 | #include "testing/gmock/include/gmock/gmock-matchers.h" |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 24 | #include "testing/gtest/include/gtest/gtest.h" |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 25 | #include "testing/utils/hash.h" |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 26 | #include "third_party/base/span.h" |
Lei Zhang | c9b7299 | 2020-04-22 01:03:52 +0000 | [diff] [blame] | 27 | #include "third_party/base/stl_util.h" |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 28 | |
| 29 | namespace { |
| 30 | |
Hui Yingst | b4baceb | 2020-04-28 23:46:10 +0000 | [diff] [blame] | 31 | #if defined(OS_WIN) |
| 32 | const char kAnnotationStampWithApChecksum[] = |
| 33 | "6aa001a77ec05d0f1b0d1d22e28744d4"; |
| 34 | #elif defined(OS_MACOSX) |
| 35 | const char kAnnotationStampWithApChecksum[] = |
| 36 | "80d7b6cc7b13a78d77a6151bc846e80b"; |
| 37 | #else |
| 38 | const char kAnnotationStampWithApChecksum[] = |
| 39 | "b42cef463483e668eaf4055a65e4f1f5"; |
| 40 | #endif |
| 41 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 42 | void VerifyFocusableAnnotSubtypes( |
| 43 | FPDF_FORMHANDLE form_handle, |
| 44 | pdfium::span<const FPDF_ANNOTATION_SUBTYPE> expected_subtypes) { |
| 45 | ASSERT_EQ(static_cast<int>(expected_subtypes.size()), |
| 46 | FPDFAnnot_GetFocusableSubtypesCount(form_handle)); |
| 47 | |
| 48 | std::vector<FPDF_ANNOTATION_SUBTYPE> actual_subtypes( |
| 49 | expected_subtypes.size()); |
| 50 | ASSERT_TRUE(FPDFAnnot_GetFocusableSubtypes( |
| 51 | form_handle, actual_subtypes.data(), actual_subtypes.size())); |
| 52 | for (size_t i = 0; i < expected_subtypes.size(); ++i) |
| 53 | ASSERT_EQ(expected_subtypes[i], actual_subtypes[i]); |
| 54 | } |
| 55 | |
| 56 | void SetAndVerifyFocusableAnnotSubtypes( |
| 57 | FPDF_FORMHANDLE form_handle, |
| 58 | pdfium::span<const FPDF_ANNOTATION_SUBTYPE> subtypes) { |
| 59 | ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes(form_handle, subtypes.data(), |
| 60 | subtypes.size())); |
| 61 | VerifyFocusableAnnotSubtypes(form_handle, subtypes); |
| 62 | } |
| 63 | |
| 64 | void VerifyAnnotationSubtypesAndFocusability( |
| 65 | FPDF_FORMHANDLE form_handle, |
| 66 | FPDF_PAGE page, |
| 67 | pdfium::span<const FPDF_ANNOTATION_SUBTYPE> expected_subtypes, |
| 68 | pdfium::span<const FPDF_ANNOTATION_SUBTYPE> expected_focusable_subtypes) { |
| 69 | ASSERT_EQ(static_cast<int>(expected_subtypes.size()), |
| 70 | FPDFPage_GetAnnotCount(page)); |
| 71 | for (size_t i = 0; i < expected_subtypes.size(); ++i) { |
| 72 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i)); |
| 73 | ASSERT_TRUE(annot); |
| 74 | EXPECT_EQ(expected_subtypes[i], FPDFAnnot_GetSubtype(annot.get())); |
| 75 | |
| 76 | bool expected_focusable = pdfium::ContainsValue(expected_focusable_subtypes, |
| 77 | expected_subtypes[i]); |
| 78 | EXPECT_EQ(expected_focusable, |
| 79 | FORM_SetFocusedAnnot(form_handle, annot.get())); |
| 80 | |
| 81 | // Kill the focus so the next test starts in an unfocused state. |
| 82 | FORM_ForceToKillFocus(form_handle); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | } // namespace |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 87 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 88 | class FPDFAnnotEmbedderTest : public EmbedderTest {}; |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 89 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 90 | TEST_F(FPDFAnnotEmbedderTest, BadParams) { |
Lei Zhang | 7557e7b | 2018-09-14 17:02:40 +0000 | [diff] [blame] | 91 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 92 | FPDF_PAGE page = LoadPage(0); |
| 93 | ASSERT_TRUE(page); |
| 94 | |
| 95 | EXPECT_EQ(0, FPDFPage_GetAnnotCount(nullptr)); |
| 96 | |
| 97 | EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, 0)); |
| 98 | EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, -1)); |
| 99 | EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, 1)); |
| 100 | EXPECT_FALSE(FPDFPage_GetAnnot(page, -1)); |
| 101 | EXPECT_FALSE(FPDFPage_GetAnnot(page, 1)); |
| 102 | |
| 103 | EXPECT_EQ(FPDF_ANNOT_UNKNOWN, FPDFAnnot_GetSubtype(nullptr)); |
| 104 | |
| 105 | EXPECT_EQ(0, FPDFAnnot_GetObjectCount(nullptr)); |
| 106 | |
| 107 | EXPECT_FALSE(FPDFAnnot_GetObject(nullptr, 0)); |
| 108 | EXPECT_FALSE(FPDFAnnot_GetObject(nullptr, -1)); |
| 109 | EXPECT_FALSE(FPDFAnnot_GetObject(nullptr, 1)); |
| 110 | |
| 111 | EXPECT_FALSE(FPDFAnnot_HasKey(nullptr, "foo")); |
| 112 | |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 113 | static const wchar_t kContents[] = L"Bar"; |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 114 | ScopedFPDFWideString text = GetFPDFWideString(kContents); |
Lei Zhang | 7557e7b | 2018-09-14 17:02:40 +0000 | [diff] [blame] | 115 | EXPECT_FALSE(FPDFAnnot_SetStringValue(nullptr, "foo", text.get())); |
| 116 | |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 117 | FPDF_WCHAR buffer[64]; |
Lei Zhang | 7557e7b | 2018-09-14 17:02:40 +0000 | [diff] [blame] | 118 | EXPECT_EQ(0u, FPDFAnnot_GetStringValue(nullptr, "foo", nullptr, 0)); |
| 119 | EXPECT_EQ(0u, FPDFAnnot_GetStringValue(nullptr, "foo", buffer, 0)); |
| 120 | EXPECT_EQ(0u, |
| 121 | FPDFAnnot_GetStringValue(nullptr, "foo", buffer, sizeof(buffer))); |
| 122 | |
| 123 | UnloadPage(page); |
| 124 | } |
| 125 | |
Lei Zhang | 3d9a097 | 2019-03-04 19:34:09 +0000 | [diff] [blame] | 126 | TEST_F(FPDFAnnotEmbedderTest, BadAnnotsEntry) { |
| 127 | ASSERT_TRUE(OpenDocument("bad_annots_entry.pdf")); |
| 128 | FPDF_PAGE page = LoadPage(0); |
| 129 | ASSERT_TRUE(page); |
| 130 | |
| 131 | EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); |
Lei Zhang | 98dc8c0 | 2019-03-04 19:40:30 +0000 | [diff] [blame] | 132 | EXPECT_FALSE(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | 3d9a097 | 2019-03-04 19:34:09 +0000 | [diff] [blame] | 133 | |
| 134 | UnloadPage(page); |
| 135 | } |
| 136 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 137 | TEST_F(FPDFAnnotEmbedderTest, RenderAnnotWithOnlyRolloverAP) { |
Jane Liu | e17011d | 2017-06-21 12:18:37 -0400 | [diff] [blame] | 138 | // Open a file with one annotation and load its first page. |
| 139 | ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 140 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | e17011d | 2017-06-21 12:18:37 -0400 | [diff] [blame] | 141 | ASSERT_TRUE(page); |
| 142 | |
| 143 | // This annotation has a malformed appearance stream, which does not have its |
| 144 | // normal appearance defined, only its rollover appearance. In this case, its |
| 145 | // normal appearance should be generated, allowing the highlight annotation to |
| 146 | // still display. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 147 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | a98e366 | 2018-02-07 20:28:35 +0000 | [diff] [blame] | 148 | CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); |
Jane Liu | e17011d | 2017-06-21 12:18:37 -0400 | [diff] [blame] | 149 | |
| 150 | UnloadPage(page); |
| 151 | } |
| 152 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 153 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 154 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 155 | #define MAYBE_RenderMultilineMarkupAnnotWithoutAP \ |
| 156 | DISABLED_RenderMultilineMarkupAnnotWithoutAP |
| 157 | #else |
| 158 | #define MAYBE_RenderMultilineMarkupAnnotWithoutAP \ |
| 159 | RenderMultilineMarkupAnnotWithoutAP |
| 160 | #endif |
| 161 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_RenderMultilineMarkupAnnotWithoutAP) { |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 162 | static const char kMd5[] = "76512832d88017668d9acc7aacd13dae"; |
Henrique Nakashima | 5098b25 | 2018-03-26 21:46:00 +0000 | [diff] [blame] | 163 | // Open a file with multiline markup annotations. |
Ralf Sippl | b3a5240 | 2018-03-19 23:30:28 +0000 | [diff] [blame] | 164 | ASSERT_TRUE(OpenDocument("annotation_markup_multiline_no_ap.pdf")); |
| 165 | FPDF_PAGE page = LoadPage(0); |
| 166 | ASSERT_TRUE(page); |
| 167 | |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 168 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 169 | CompareBitmap(bitmap.get(), 595, 842, kMd5); |
Ralf Sippl | b3a5240 | 2018-03-19 23:30:28 +0000 | [diff] [blame] | 170 | |
| 171 | UnloadPage(page); |
| 172 | } |
| 173 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 174 | TEST_F(FPDFAnnotEmbedderTest, ExtractHighlightLongContent) { |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 175 | // Open a file with one annotation and load its first page. |
| 176 | ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); |
Tom Sepez | 507d019 | 2018-11-07 16:37:51 +0000 | [diff] [blame] | 177 | FPDF_PAGE page = LoadPageNoEvents(0); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 178 | ASSERT_TRUE(page); |
| 179 | |
| 180 | // Check that there is a total of 1 annotation on its first page. |
| 181 | EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); |
| 182 | |
| 183 | // Check that the annotation is of type "highlight". |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 184 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 185 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 186 | ASSERT_TRUE(annot); |
| 187 | EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get())); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 188 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 189 | // Check that the annotation color is yellow. |
| 190 | unsigned int R; |
| 191 | unsigned int G; |
| 192 | unsigned int B; |
| 193 | unsigned int A; |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 194 | ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R, |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 195 | &G, &B, &A)); |
| 196 | EXPECT_EQ(255u, R); |
| 197 | EXPECT_EQ(255u, G); |
| 198 | EXPECT_EQ(0u, B); |
| 199 | EXPECT_EQ(255u, A); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 200 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 201 | // Check that the author is correct. |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 202 | static const char kAuthorKey[] = "T"; |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 203 | EXPECT_EQ(FPDF_OBJECT_STRING, |
| 204 | FPDFAnnot_GetValueType(annot.get(), kAuthorKey)); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 205 | unsigned long length_bytes = |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 206 | FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 207 | ASSERT_EQ(28u, length_bytes); |
| 208 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 209 | EXPECT_EQ(28u, FPDFAnnot_GetStringValue(annot.get(), kAuthorKey, buf.data(), |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 210 | length_bytes)); |
| 211 | EXPECT_EQ(L"Jae Hyun Park", GetPlatformWString(buf.data())); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 212 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 213 | // Check that the content is correct. |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 214 | EXPECT_EQ( |
| 215 | FPDF_OBJECT_STRING, |
| 216 | FPDFAnnot_GetValueType(annot.get(), pdfium::annotation::kContents)); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 217 | length_bytes = FPDFAnnot_GetStringValue( |
| 218 | annot.get(), pdfium::annotation::kContents, nullptr, 0); |
| 219 | ASSERT_EQ(2690u, length_bytes); |
| 220 | buf = GetFPDFWideStringBuffer(length_bytes); |
| 221 | EXPECT_EQ(2690u, FPDFAnnot_GetStringValue(annot.get(), |
| 222 | pdfium::annotation::kContents, |
| 223 | buf.data(), length_bytes)); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 224 | static const wchar_t kContents[] = |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 225 | L"This is a note for that highlight annotation. Very long highlight " |
| 226 | "annotation. Long long long Long long longLong long longLong long " |
| 227 | "longLong long longLong long longLong long longLong long longLong long " |
| 228 | "longLong long longLong long longLong long longLong long longLong long " |
| 229 | "longLong long longLong long longLong long longLong long longLong long " |
| 230 | "longLong long longLong long longLong long longLong long longLong long " |
| 231 | "longLong long longLong long longLong long longLong long longLong long " |
| 232 | "longLong long longLong long longLong long longLong long longLong long " |
| 233 | "longLong long longLong long longLong long longLong long longLong long " |
| 234 | "longLong long longLong long longLong long longLong long longLong long " |
| 235 | "longLong long longLong long longLong long longLong long longLong long " |
| 236 | "longLong long longLong long longLong long longLong long longLong long " |
| 237 | "longLong long longLong long longLong long longLong long longLong long " |
| 238 | "longLong long longLong long longLong long longLong long longLong long " |
| 239 | "longLong long longLong long longLong long longLong long longLong long " |
| 240 | "longLong long longLong long longLong long longLong long longLong long " |
| 241 | "longLong long longLong long longLong long longLong long longLong long " |
| 242 | "longLong long longLong long longLong long longLong long longLong long " |
| 243 | "longLong long longLong long longLong long longLong long longLong long " |
| 244 | "longLong long long. END"; |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 245 | EXPECT_EQ(kContents, GetPlatformWString(buf.data())); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 246 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 247 | // Check that the quadpoints are correct. |
| 248 | FS_QUADPOINTSF quadpoints; |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 249 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 250 | EXPECT_EQ(115.802643f, quadpoints.x1); |
| 251 | EXPECT_EQ(718.913940f, quadpoints.y1); |
| 252 | EXPECT_EQ(157.211182f, quadpoints.x4); |
| 253 | EXPECT_EQ(706.264465f, quadpoints.y4); |
| 254 | } |
Tom Sepez | 507d019 | 2018-11-07 16:37:51 +0000 | [diff] [blame] | 255 | UnloadPageNoEvents(page); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 258 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 259 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 260 | #define MAYBE_ExtractInkMultiple DISABLED_ExtractInkMultiple |
| 261 | #else |
| 262 | #define MAYBE_ExtractInkMultiple ExtractInkMultiple |
| 263 | #endif |
| 264 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_ExtractInkMultiple) { |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 265 | // Open a file with three annotations and load its first page. |
| 266 | ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); |
Tom Sepez | 507d019 | 2018-11-07 16:37:51 +0000 | [diff] [blame] | 267 | FPDF_PAGE page = LoadPageNoEvents(0); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 268 | ASSERT_TRUE(page); |
| 269 | |
| 270 | // Check that there is a total of 3 annotation on its first page. |
| 271 | EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); |
| 272 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 273 | { |
| 274 | // Check that the third annotation is of type "ink". |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 275 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 276 | ASSERT_TRUE(annot); |
| 277 | EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot.get())); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 278 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 279 | // Check that the annotation color is blue with opacity. |
| 280 | unsigned int R; |
| 281 | unsigned int G; |
| 282 | unsigned int B; |
| 283 | unsigned int A; |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 284 | ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R, |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 285 | &G, &B, &A)); |
| 286 | EXPECT_EQ(0u, R); |
| 287 | EXPECT_EQ(0u, G); |
| 288 | EXPECT_EQ(255u, B); |
| 289 | EXPECT_EQ(76u, A); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 290 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 291 | // Check that there is no content. |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 292 | EXPECT_EQ(2u, FPDFAnnot_GetStringValue( |
| 293 | annot.get(), pdfium::annotation::kContents, nullptr, 0)); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 294 | |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 295 | // Check that the rectangle coordinates are correct. |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 296 | // Note that upon rendering, the rectangle coordinates will be adjusted. |
| 297 | FS_RECTF rect; |
| 298 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 299 | EXPECT_EQ(351.820404f, rect.left); |
| 300 | EXPECT_EQ(583.830688f, rect.bottom); |
| 301 | EXPECT_EQ(475.336090f, rect.right); |
| 302 | EXPECT_EQ(681.535034f, rect.top); |
| 303 | } |
Tom Sepez | ef43c26 | 2018-11-07 16:41:32 +0000 | [diff] [blame] | 304 | { |
| 305 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
| 306 | CompareBitmap(bitmap.get(), 612, 792, "354002e1c4386d38fdde29ef8d61074a"); |
| 307 | } |
Tom Sepez | 507d019 | 2018-11-07 16:37:51 +0000 | [diff] [blame] | 308 | UnloadPageNoEvents(page); |
Jane Liu | 4fd9a47 | 2017-06-01 18:56:09 -0400 | [diff] [blame] | 309 | } |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 310 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 311 | TEST_F(FPDFAnnotEmbedderTest, AddIllegalSubtypeAnnotation) { |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 312 | // Open a file with one annotation and load its first page. |
| 313 | ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 314 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 315 | ASSERT_TRUE(page); |
| 316 | |
| 317 | // Add an annotation with an illegal subtype. |
Jane Liu | d60e9ad | 2017-06-26 11:28:36 -0400 | [diff] [blame] | 318 | ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 319 | |
| 320 | UnloadPage(page); |
| 321 | } |
| 322 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 323 | TEST_F(FPDFAnnotEmbedderTest, AddFirstTextAnnotation) { |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 324 | // Open a file with no annotation and load its first page. |
| 325 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 326 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 327 | ASSERT_TRUE(page); |
| 328 | EXPECT_EQ(0, FPDFPage_GetAnnotCount(page)); |
| 329 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 330 | { |
| 331 | // Add a text annotation to the page. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 332 | ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 333 | ASSERT_TRUE(annot); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 334 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 335 | // Check that there is now 1 annotations on this page. |
| 336 | EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 337 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 338 | // Check that the subtype of the annotation is correct. |
| 339 | EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get())); |
| 340 | } |
Jane Liu | e10509a | 2017-06-20 16:47:41 -0400 | [diff] [blame] | 341 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 342 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 343 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 344 | ASSERT_TRUE(annot); |
| 345 | EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get())); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 346 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 347 | // Set the color of the annotation. |
| 348 | ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 51, |
| 349 | 102, 153, 204)); |
| 350 | // Check that the color has been set correctly. |
| 351 | unsigned int R; |
| 352 | unsigned int G; |
| 353 | unsigned int B; |
| 354 | unsigned int A; |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 355 | ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R, |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 356 | &G, &B, &A)); |
| 357 | EXPECT_EQ(51u, R); |
| 358 | EXPECT_EQ(102u, G); |
| 359 | EXPECT_EQ(153u, B); |
| 360 | EXPECT_EQ(204u, A); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 361 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 362 | // Change the color of the annotation. |
| 363 | ASSERT_TRUE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 204, |
| 364 | 153, 102, 51)); |
| 365 | // Check that the color has been set correctly. |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 366 | ASSERT_TRUE(FPDFAnnot_GetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, &R, |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 367 | &G, &B, &A)); |
| 368 | EXPECT_EQ(204u, R); |
| 369 | EXPECT_EQ(153u, G); |
| 370 | EXPECT_EQ(102u, B); |
| 371 | EXPECT_EQ(51u, A); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 372 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 373 | // Set the annotation rectangle. |
| 374 | FS_RECTF rect; |
| 375 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 376 | EXPECT_EQ(0.f, rect.left); |
| 377 | EXPECT_EQ(0.f, rect.right); |
| 378 | rect.left = 35; |
| 379 | rect.bottom = 150; |
| 380 | rect.right = 53; |
| 381 | rect.top = 165; |
| 382 | ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect)); |
| 383 | // Check that the annotation rectangle has been set correctly. |
| 384 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 385 | EXPECT_EQ(35.f, rect.left); |
| 386 | EXPECT_EQ(150.f, rect.bottom); |
| 387 | EXPECT_EQ(53.f, rect.right); |
| 388 | EXPECT_EQ(165.f, rect.top); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 389 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 390 | // Set the content of the annotation. |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 391 | static const wchar_t kContents[] = L"Hello! This is a customized content."; |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 392 | ScopedFPDFWideString text = GetFPDFWideString(kContents); |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 393 | ASSERT_TRUE(FPDFAnnot_SetStringValue( |
| 394 | annot.get(), pdfium::annotation::kContents, text.get())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 395 | // Check that the content has been set correctly. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 396 | unsigned long length_bytes = FPDFAnnot_GetStringValue( |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 397 | annot.get(), pdfium::annotation::kContents, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 398 | ASSERT_EQ(74u, length_bytes); |
| 399 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
| 400 | EXPECT_EQ(74u, FPDFAnnot_GetStringValue(annot.get(), |
| 401 | pdfium::annotation::kContents, |
| 402 | buf.data(), length_bytes)); |
| 403 | EXPECT_EQ(kContents, GetPlatformWString(buf.data())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 404 | } |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 405 | UnloadPage(page); |
| 406 | } |
| 407 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 408 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 409 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 410 | #define MAYBE_AddAndSaveUnderlineAnnotation \ |
| 411 | DISABLED_AddAndSaveUnderlineAnnotation |
| 412 | #else |
| 413 | #define MAYBE_AddAndSaveUnderlineAnnotation AddAndSaveUnderlineAnnotation |
| 414 | #endif |
| 415 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndSaveUnderlineAnnotation) { |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 416 | // Open a file with one annotation and load its first page. |
| 417 | ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 418 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 419 | ASSERT_TRUE(page); |
| 420 | |
| 421 | // Check that there is a total of one annotation on its first page, and verify |
| 422 | // its quadpoints. |
| 423 | EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 424 | FS_QUADPOINTSF quadpoints; |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 425 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 426 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 427 | ASSERT_TRUE(annot); |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 428 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 429 | EXPECT_EQ(115.802643f, quadpoints.x1); |
| 430 | EXPECT_EQ(718.913940f, quadpoints.y1); |
| 431 | EXPECT_EQ(157.211182f, quadpoints.x4); |
| 432 | EXPECT_EQ(706.264465f, quadpoints.y4); |
| 433 | } |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 434 | |
| 435 | // Add an underline annotation to the page and set its quadpoints. |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 436 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 437 | ScopedFPDFAnnotation annot( |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 438 | FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE)); |
| 439 | ASSERT_TRUE(annot); |
| 440 | quadpoints.x1 = 140.802643f; |
| 441 | quadpoints.x3 = 140.802643f; |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 442 | ASSERT_TRUE(FPDFAnnot_AppendAttachmentPoints(annot.get(), &quadpoints)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 443 | } |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 444 | |
| 445 | // Save the document, closing the page and document. |
| 446 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 447 | UnloadPage(page); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 448 | |
| 449 | // Open the saved document. |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 450 | static const char kMd5[] = "dba153419f67b7c0c0e3d22d3e8910d5"; |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 451 | |
Lei Zhang | 0b49405 | 2019-01-31 21:41:15 +0000 | [diff] [blame] | 452 | ASSERT_TRUE(OpenSavedDocument()); |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 453 | page = LoadSavedPage(0); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 454 | VerifySavedRendering(page, 612, 792, kMd5); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 455 | |
| 456 | // Check that the saved document has 2 annotations on the first page |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 457 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 458 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 459 | { |
| 460 | // Check that the second annotation is an underline annotation and verify |
| 461 | // its quadpoints. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 462 | ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 1)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 463 | ASSERT_TRUE(new_annot); |
| 464 | EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot.get())); |
| 465 | FS_QUADPOINTSF new_quadpoints; |
| 466 | ASSERT_TRUE( |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 467 | FPDFAnnot_GetAttachmentPoints(new_annot.get(), 0, &new_quadpoints)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 468 | EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f); |
| 469 | EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f); |
| 470 | EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f); |
| 471 | EXPECT_NEAR(quadpoints.y4, new_quadpoints.y4, 0.001f); |
| 472 | } |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 473 | |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 474 | CloseSavedPage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 475 | CloseSavedDocument(); |
Jane Liu | 20eafda | 2017-06-07 10:33:24 -0400 | [diff] [blame] | 476 | } |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 477 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 478 | TEST_F(FPDFAnnotEmbedderTest, GetAndSetQuadPoints) { |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 479 | // Open a file with four annotations and load its first page. |
| 480 | ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); |
| 481 | FPDF_PAGE page = LoadPage(0); |
| 482 | ASSERT_TRUE(page); |
| 483 | EXPECT_EQ(4, FPDFPage_GetAnnotCount(page)); |
| 484 | |
| 485 | // Retrieve the highlight annotation. |
| 486 | FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); |
| 487 | ASSERT_TRUE(annot); |
| 488 | ASSERT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); |
| 489 | |
| 490 | FS_QUADPOINTSF quadpoints; |
| 491 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 0, &quadpoints)); |
| 492 | |
| 493 | { |
| 494 | // Verify the current one set of quadpoints. |
| 495 | ASSERT_EQ(1u, FPDFAnnot_CountAttachmentPoints(annot)); |
| 496 | |
| 497 | EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f); |
| 498 | EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f); |
| 499 | EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f); |
| 500 | EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f); |
| 501 | } |
| 502 | |
| 503 | { |
| 504 | // Update the quadpoints. |
| 505 | FS_QUADPOINTSF new_quadpoints = quadpoints; |
| 506 | new_quadpoints.y1 -= 20.f; |
| 507 | new_quadpoints.y2 -= 20.f; |
| 508 | new_quadpoints.y3 -= 20.f; |
| 509 | new_quadpoints.y4 -= 20.f; |
| 510 | ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, 0, &new_quadpoints)); |
| 511 | |
| 512 | // Verify added quadpoint set |
| 513 | ASSERT_EQ(1u, FPDFAnnot_CountAttachmentPoints(annot)); |
| 514 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 0, &quadpoints)); |
| 515 | EXPECT_NEAR(new_quadpoints.x1, quadpoints.x1, 0.001f); |
| 516 | EXPECT_NEAR(new_quadpoints.y1, quadpoints.y1, 0.001f); |
| 517 | EXPECT_NEAR(new_quadpoints.x4, quadpoints.x4, 0.001f); |
| 518 | EXPECT_NEAR(new_quadpoints.y4, quadpoints.y4, 0.001f); |
| 519 | } |
| 520 | |
| 521 | { |
| 522 | // Append a new set of quadpoints. |
| 523 | FS_QUADPOINTSF new_quadpoints = quadpoints; |
| 524 | new_quadpoints.y1 += 20.f; |
| 525 | new_quadpoints.y2 += 20.f; |
| 526 | new_quadpoints.y3 += 20.f; |
| 527 | new_quadpoints.y4 += 20.f; |
| 528 | ASSERT_TRUE(FPDFAnnot_AppendAttachmentPoints(annot, &new_quadpoints)); |
| 529 | |
| 530 | // Verify added quadpoint set |
| 531 | ASSERT_EQ(2u, FPDFAnnot_CountAttachmentPoints(annot)); |
| 532 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, 1, &quadpoints)); |
| 533 | EXPECT_NEAR(new_quadpoints.x1, quadpoints.x1, 0.001f); |
| 534 | EXPECT_NEAR(new_quadpoints.y1, quadpoints.y1, 0.001f); |
| 535 | EXPECT_NEAR(new_quadpoints.x4, quadpoints.x4, 0.001f); |
| 536 | EXPECT_NEAR(new_quadpoints.y4, quadpoints.y4, 0.001f); |
| 537 | } |
| 538 | |
| 539 | { |
| 540 | // Setting and getting quadpoints at out-of-bound index should fail |
| 541 | EXPECT_FALSE(FPDFAnnot_SetAttachmentPoints(annot, 300000, &quadpoints)); |
| 542 | EXPECT_FALSE(FPDFAnnot_GetAttachmentPoints(annot, 300000, &quadpoints)); |
| 543 | } |
| 544 | |
| 545 | FPDFPage_CloseAnnot(annot); |
| 546 | |
| 547 | // Retrieve the square annotation |
| 548 | FPDF_ANNOTATION squareAnnot = FPDFPage_GetAnnot(page, 2); |
| 549 | |
| 550 | { |
| 551 | // Check that attempting to set its quadpoints would fail |
| 552 | ASSERT_TRUE(squareAnnot); |
| 553 | EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(squareAnnot)); |
| 554 | EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(squareAnnot)); |
| 555 | EXPECT_FALSE(FPDFAnnot_SetAttachmentPoints(squareAnnot, 0, &quadpoints)); |
| 556 | } |
| 557 | |
| 558 | FPDFPage_CloseAnnot(squareAnnot); |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 559 | UnloadPage(page); |
| 560 | } |
| 561 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 562 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 563 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 564 | #define MAYBE_ModifyRectQuadpointsWithAP DISABLED_ModifyRectQuadpointsWithAP |
| 565 | #else |
| 566 | #define MAYBE_ModifyRectQuadpointsWithAP ModifyRectQuadpointsWithAP |
| 567 | #endif |
| 568 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_ModifyRectQuadpointsWithAP) { |
Lei Zhang | e4cdac5 | 2019-04-30 16:45:57 +0000 | [diff] [blame] | 569 | #if defined(OS_MACOSX) |
Lei Zhang | 0f6b434 | 2020-02-25 20:00:39 +0000 | [diff] [blame] | 570 | static const char kMd5Original[] = "fc59468d154f397fd298c69f47ef565a"; |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 571 | static const char kMd5ModifiedHighlight[] = |
Lei Zhang | 0f6b434 | 2020-02-25 20:00:39 +0000 | [diff] [blame] | 572 | "e64bf648f6e9354d1f3eedb47a2c9498"; |
| 573 | static const char kMd5ModifiedSquare[] = "a66591662c8e7ad3c6059952e234bebf"; |
Lei Zhang | e67bcc7 | 2019-04-30 18:55:58 +0000 | [diff] [blame] | 574 | #elif defined(OS_WIN) |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 575 | static const char kMd5Original[] = "0e27376094f11490f74c65f3dc3a42c5"; |
| 576 | static const char kMd5ModifiedHighlight[] = |
| 577 | "66f3caef3a7d488a4fa1ad37fc06310e"; |
| 578 | static const char kMd5ModifiedSquare[] = "a456dad0bc6801ee2d6408a4394af563"; |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 579 | #else |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 580 | static const char kMd5Original[] = "0e27376094f11490f74c65f3dc3a42c5"; |
| 581 | static const char kMd5ModifiedHighlight[] = |
| 582 | "66f3caef3a7d488a4fa1ad37fc06310e"; |
| 583 | static const char kMd5ModifiedSquare[] = "a456dad0bc6801ee2d6408a4394af563"; |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 584 | #endif |
| 585 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 586 | // Open a file with four annotations and load its first page. |
| 587 | ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 588 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 589 | ASSERT_TRUE(page); |
| 590 | EXPECT_EQ(4, FPDFPage_GetAnnotCount(page)); |
| 591 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 592 | // Check that the original file renders correctly. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 593 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 594 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 595 | CompareBitmap(bitmap.get(), 612, 792, kMd5Original); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 596 | } |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 597 | |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 598 | FS_RECTF rect; |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 599 | FS_RECTF new_rect; |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 600 | |
| 601 | // Retrieve the highlight annotation which has its AP stream already defined. |
| 602 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 603 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 604 | ASSERT_TRUE(annot); |
| 605 | EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get())); |
| 606 | |
| 607 | // Check that color cannot be set when an AP stream is defined already. |
| 608 | EXPECT_FALSE(FPDFAnnot_SetColor(annot.get(), FPDFANNOT_COLORTYPE_Color, 51, |
| 609 | 102, 153, 204)); |
| 610 | |
| 611 | // Verify its attachment points. |
| 612 | FS_QUADPOINTSF quadpoints; |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 613 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &quadpoints)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 614 | EXPECT_NEAR(72.0000f, quadpoints.x1, 0.001f); |
| 615 | EXPECT_NEAR(720.792f, quadpoints.y1, 0.001f); |
| 616 | EXPECT_NEAR(132.055f, quadpoints.x4, 0.001f); |
| 617 | EXPECT_NEAR(704.796f, quadpoints.y4, 0.001f); |
| 618 | |
| 619 | // Check that updating the attachment points would succeed. |
| 620 | quadpoints.x1 -= 50.f; |
| 621 | quadpoints.x2 -= 50.f; |
| 622 | quadpoints.x3 -= 50.f; |
| 623 | quadpoints.x4 -= 50.f; |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 624 | ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot.get(), 0, &quadpoints)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 625 | FS_QUADPOINTSF new_quadpoints; |
Ralf Sippl | 1638179 | 2018-04-12 21:20:26 +0000 | [diff] [blame] | 626 | ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot.get(), 0, &new_quadpoints)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 627 | EXPECT_EQ(quadpoints.x1, new_quadpoints.x1); |
| 628 | EXPECT_EQ(quadpoints.y1, new_quadpoints.y1); |
| 629 | EXPECT_EQ(quadpoints.x4, new_quadpoints.x4); |
| 630 | EXPECT_EQ(quadpoints.y4, new_quadpoints.y4); |
| 631 | |
| 632 | // Check that updating quadpoints does not change the annotation's position. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 633 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 634 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 635 | CompareBitmap(bitmap.get(), 612, 792, kMd5Original); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 636 | } |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 637 | |
| 638 | // Verify its annotation rectangle. |
| 639 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 640 | EXPECT_NEAR(67.7299f, rect.left, 0.001f); |
| 641 | EXPECT_NEAR(704.296f, rect.bottom, 0.001f); |
| 642 | EXPECT_NEAR(136.325f, rect.right, 0.001f); |
| 643 | EXPECT_NEAR(721.292f, rect.top, 0.001f); |
| 644 | |
| 645 | // Check that updating the rectangle would succeed. |
| 646 | rect.left -= 60.f; |
| 647 | rect.right -= 60.f; |
| 648 | ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect)); |
| 649 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect)); |
| 650 | EXPECT_EQ(rect.right, new_rect.right); |
| 651 | } |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 652 | |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 653 | // Check that updating the rectangle changes the annotation's position. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 654 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 655 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 656 | CompareBitmap(bitmap.get(), 612, 792, kMd5ModifiedHighlight); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 657 | } |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 658 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 659 | { |
| 660 | // Retrieve the square annotation which has its AP stream already defined. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 661 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 662 | ASSERT_TRUE(annot); |
| 663 | EXPECT_EQ(FPDF_ANNOT_SQUARE, FPDFAnnot_GetSubtype(annot.get())); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 664 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 665 | // Check that updating the rectangle would succeed. |
| 666 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 667 | rect.left += 70.f; |
| 668 | rect.right += 70.f; |
| 669 | ASSERT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect)); |
| 670 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect)); |
| 671 | EXPECT_EQ(rect.right, new_rect.right); |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 672 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 673 | // Check that updating the rectangle changes the square annotation's |
| 674 | // position. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 675 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 676 | CompareBitmap(bitmap.get(), 612, 792, kMd5ModifiedSquare); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 677 | } |
Jane Liu | b370e5a | 2017-08-16 13:24:58 -0400 | [diff] [blame] | 678 | |
Jane Liu | 0646275 | 2017-06-27 16:41:14 -0400 | [diff] [blame] | 679 | UnloadPage(page); |
| 680 | } |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 681 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 682 | TEST_F(FPDFAnnotEmbedderTest, CountAttachmentPoints) { |
Henrique Nakashima | 5098b25 | 2018-03-26 21:46:00 +0000 | [diff] [blame] | 683 | // Open a file with multiline markup annotations. |
| 684 | ASSERT_TRUE(OpenDocument("annotation_markup_multiline_no_ap.pdf")); |
| 685 | FPDF_PAGE page = LoadPage(0); |
| 686 | ASSERT_TRUE(page); |
| 687 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 688 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Henrique Nakashima | 5098b25 | 2018-03-26 21:46:00 +0000 | [diff] [blame] | 689 | ASSERT_TRUE(annot); |
| 690 | |
| 691 | // This is a three line annotation. |
| 692 | EXPECT_EQ(3u, FPDFAnnot_CountAttachmentPoints(annot.get())); |
| 693 | } |
| 694 | UnloadPage(page); |
| 695 | |
| 696 | // null annotation should return 0 |
| 697 | EXPECT_EQ(0u, FPDFAnnot_CountAttachmentPoints(nullptr)); |
| 698 | } |
| 699 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 700 | TEST_F(FPDFAnnotEmbedderTest, RemoveAnnotation) { |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 701 | // Open a file with 3 annotations on its first page. |
| 702 | ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); |
Tom Sepez | 507d019 | 2018-11-07 16:37:51 +0000 | [diff] [blame] | 703 | FPDF_PAGE page = LoadPageNoEvents(0); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 704 | ASSERT_TRUE(page); |
| 705 | EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); |
| 706 | |
Jane Liu | 0c6b07d | 2017-08-15 10:50:22 -0400 | [diff] [blame] | 707 | FS_RECTF rect; |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 708 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 709 | // Check that the annotations have the expected rectangle coordinates. |
| 710 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 711 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 712 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 713 | EXPECT_NEAR(86.1971f, rect.left, 0.001f); |
| 714 | } |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 715 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 716 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 717 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 718 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 719 | EXPECT_NEAR(149.8127f, rect.left, 0.001f); |
| 720 | } |
| 721 | |
| 722 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 723 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 724 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 725 | EXPECT_NEAR(351.8204f, rect.left, 0.001f); |
| 726 | } |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 727 | |
| 728 | // Check that nothing happens when attempting to remove an annotation with an |
| 729 | // out-of-bound index. |
| 730 | EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4)); |
| 731 | EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1)); |
| 732 | EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); |
| 733 | |
| 734 | // Remove the second annotation. |
| 735 | EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1)); |
| 736 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 737 | EXPECT_FALSE(FPDFPage_GetAnnot(page, 2)); |
| 738 | |
| 739 | // Save the document, closing the page and document. |
| 740 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Tom Sepez | 507d019 | 2018-11-07 16:37:51 +0000 | [diff] [blame] | 741 | UnloadPageNoEvents(page); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 742 | |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 743 | // TODO(npm): VerifySavedRendering changes annot rect dimensions by 1?? |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 744 | // Open the saved document. |
| 745 | std::string new_file = GetString(); |
| 746 | FPDF_FILEACCESS file_access; |
| 747 | memset(&file_access, 0, sizeof(file_access)); |
| 748 | file_access.m_FileLen = new_file.size(); |
| 749 | file_access.m_GetBlock = GetBlockFromString; |
| 750 | file_access.m_Param = &new_file; |
| 751 | FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr); |
| 752 | ASSERT_TRUE(new_doc); |
| 753 | FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); |
| 754 | ASSERT_TRUE(new_page); |
| 755 | |
| 756 | // Check that the saved document has 2 annotations on the first page. |
| 757 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page)); |
| 758 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 759 | // Check that the remaining 2 annotations are the original 1st and 3rd ones |
| 760 | // by verifying their rectangle coordinates. |
| 761 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 762 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(new_page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 763 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 764 | EXPECT_NEAR(86.1971f, rect.left, 0.001f); |
| 765 | } |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 766 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 767 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 768 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(new_page, 1)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 769 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &rect)); |
| 770 | EXPECT_NEAR(351.8204f, rect.left, 0.001f); |
| 771 | } |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 772 | FPDF_ClosePage(new_page); |
| 773 | FPDF_CloseDocument(new_doc); |
| 774 | } |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 775 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 776 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 777 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 778 | #define MAYBE_AddAndModifyPath DISABLED_AddAndModifyPath |
| 779 | #else |
| 780 | #define MAYBE_AddAndModifyPath AddAndModifyPath |
| 781 | #endif |
| 782 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndModifyPath) { |
Lei Zhang | e4cdac5 | 2019-04-30 16:45:57 +0000 | [diff] [blame] | 783 | #if defined(OS_MACOSX) |
Lei Zhang | 0f6b434 | 2020-02-25 20:00:39 +0000 | [diff] [blame] | 784 | static const char kMd5ModifiedPath[] = "8cfae6d547fc5d6702f5f1ac631beb5e"; |
| 785 | static const char kMd5TwoPaths[] = "9677e4892bb02950d3e4dbe74470578f"; |
| 786 | static const char kMd5NewAnnot[] = "e8ebddac4db8c0a4b556ddf79aa1a26d"; |
Lei Zhang | e67bcc7 | 2019-04-30 18:55:58 +0000 | [diff] [blame] | 787 | #elif defined(OS_WIN) |
Lei Zhang | a2b7073 | 2019-06-25 08:34:22 +0000 | [diff] [blame] | 788 | static const char kMd5ModifiedPath[] = "a7a8d675a6ddbcbdfecee65a33ba19e1"; |
| 789 | static const char kMd5TwoPaths[] = "7c0bdd4552329704c47a7cce47edbbd6"; |
| 790 | static const char kMd5NewAnnot[] = "3c48d492b4f62941fed0fb62f729f31e"; |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 791 | #else |
Lei Zhang | a2b7073 | 2019-06-25 08:34:22 +0000 | [diff] [blame] | 792 | static const char kMd5ModifiedPath[] = "6ff77d6d1fec4ea571fabe0c7a19b517"; |
| 793 | static const char kMd5TwoPaths[] = "ca37ad549e74ac5b359a055708f3e7b6"; |
| 794 | static const char kMd5NewAnnot[] = "0d7a0e33fbf41ff7fa5d732ab2c5edff"; |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 795 | #endif |
| 796 | |
| 797 | // Open a file with two annotations and load its first page. |
| 798 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 799 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 800 | ASSERT_TRUE(page); |
| 801 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 802 | |
| 803 | // Check that the page renders correctly. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 804 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 805 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Hui Yingst | b4baceb | 2020-04-28 23:46:10 +0000 | [diff] [blame] | 806 | CompareBitmap(bitmap.get(), 595, 842, kAnnotationStampWithApChecksum); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 807 | } |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 808 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 809 | { |
| 810 | // Retrieve the stamp annotation which has its AP stream already defined. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 811 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 812 | ASSERT_TRUE(annot); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 813 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 814 | // Check that this annotation has one path object and retrieve it. |
| 815 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); |
Henrique Nakashima | 35841fa | 2018-03-15 15:25:16 +0000 | [diff] [blame] | 816 | ASSERT_EQ(32, FPDFPage_CountObjects(page)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 817 | FPDF_PAGEOBJECT path = FPDFAnnot_GetObject(annot.get(), 1); |
| 818 | EXPECT_FALSE(path); |
| 819 | path = FPDFAnnot_GetObject(annot.get(), 0); |
| 820 | EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path)); |
| 821 | EXPECT_TRUE(path); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 822 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 823 | // Modify the color of the path object. |
Lei Zhang | 3475b48 | 2019-05-13 18:30:57 +0000 | [diff] [blame] | 824 | EXPECT_TRUE(FPDFPageObj_SetStrokeColor(path, 0, 0, 0, 255)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 825 | EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), path)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 826 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 827 | // Check that the page with the modified annotation renders correctly. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 828 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 829 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 830 | CompareBitmap(bitmap.get(), 595, 842, kMd5ModifiedPath); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 831 | } |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 832 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 833 | // Add a second path object to the same annotation. |
| 834 | FPDF_PAGEOBJECT dot = FPDFPageObj_CreateNewPath(7, 84); |
| 835 | EXPECT_TRUE(FPDFPath_BezierTo(dot, 9, 86, 10, 87, 11, 88)); |
Lei Zhang | 3475b48 | 2019-05-13 18:30:57 +0000 | [diff] [blame] | 836 | EXPECT_TRUE(FPDFPageObj_SetStrokeColor(dot, 255, 0, 0, 100)); |
| 837 | EXPECT_TRUE(FPDFPageObj_SetStrokeWidth(dot, 14)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 838 | EXPECT_TRUE(FPDFPath_SetDrawMode(dot, 0, 1)); |
| 839 | EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), dot)); |
| 840 | EXPECT_EQ(2, FPDFAnnot_GetObjectCount(annot.get())); |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 841 | |
Henrique Nakashima | 35841fa | 2018-03-15 15:25:16 +0000 | [diff] [blame] | 842 | // The object is in the annontation, not in the page, so the page object |
| 843 | // array should not change. |
| 844 | ASSERT_EQ(32, FPDFPage_CountObjects(page)); |
| 845 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 846 | // Check that the page with an annotation with two paths renders correctly. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 847 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 848 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 849 | CompareBitmap(bitmap.get(), 595, 842, kMd5TwoPaths); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 850 | } |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 851 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 852 | // Delete the newly added path object. |
| 853 | EXPECT_TRUE(FPDFAnnot_RemoveObject(annot.get(), 1)); |
| 854 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); |
Henrique Nakashima | 35841fa | 2018-03-15 15:25:16 +0000 | [diff] [blame] | 855 | ASSERT_EQ(32, FPDFPage_CountObjects(page)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 856 | } |
Jane Liu | 7a9a38b | 2017-07-11 13:47:37 -0400 | [diff] [blame] | 857 | |
| 858 | // Check that the page renders the same as before. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 859 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 860 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 861 | CompareBitmap(bitmap.get(), 595, 842, kMd5ModifiedPath); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 862 | } |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 863 | |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 864 | FS_RECTF rect; |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 865 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 866 | { |
| 867 | // Create another stamp annotation and set its annotation rectangle. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 868 | ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 869 | ASSERT_TRUE(annot); |
| 870 | rect.left = 200.f; |
| 871 | rect.bottom = 400.f; |
| 872 | rect.right = 500.f; |
| 873 | rect.top = 600.f; |
| 874 | EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 875 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 876 | // Add a new path to the annotation. |
| 877 | FPDF_PAGEOBJECT check = FPDFPageObj_CreateNewPath(200, 500); |
| 878 | EXPECT_TRUE(FPDFPath_LineTo(check, 300, 400)); |
| 879 | EXPECT_TRUE(FPDFPath_LineTo(check, 500, 600)); |
| 880 | EXPECT_TRUE(FPDFPath_MoveTo(check, 350, 550)); |
| 881 | EXPECT_TRUE(FPDFPath_LineTo(check, 450, 450)); |
Lei Zhang | 3475b48 | 2019-05-13 18:30:57 +0000 | [diff] [blame] | 882 | EXPECT_TRUE(FPDFPageObj_SetStrokeColor(check, 0, 255, 255, 180)); |
| 883 | EXPECT_TRUE(FPDFPageObj_SetStrokeWidth(check, 8.35f)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 884 | EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1)); |
| 885 | EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), check)); |
| 886 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); |
| 887 | |
| 888 | // Check that the annotation's bounding box came from its rectangle. |
| 889 | FS_RECTF new_rect; |
| 890 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect)); |
| 891 | EXPECT_EQ(rect.left, new_rect.left); |
| 892 | EXPECT_EQ(rect.bottom, new_rect.bottom); |
| 893 | EXPECT_EQ(rect.right, new_rect.right); |
| 894 | EXPECT_EQ(rect.top, new_rect.top); |
| 895 | } |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 896 | |
| 897 | // Save the document, closing the page and document. |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 898 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 899 | UnloadPage(page); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 900 | |
| 901 | // Open the saved document. |
Lei Zhang | 0b49405 | 2019-01-31 21:41:15 +0000 | [diff] [blame] | 902 | ASSERT_TRUE(OpenSavedDocument()); |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 903 | page = LoadSavedPage(0); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 904 | VerifySavedRendering(page, 595, 842, kMd5NewAnnot); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 905 | |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 906 | // Check that the document has a correct count of annotations and objects. |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 907 | EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 908 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 909 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 910 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 911 | ASSERT_TRUE(annot); |
| 912 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); |
Jane Liu | baa7ff4 | 2017-06-29 19:18:23 -0400 | [diff] [blame] | 913 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 914 | // Check that the new annotation's rectangle is as defined. |
| 915 | FS_RECTF new_rect; |
| 916 | ASSERT_TRUE(FPDFAnnot_GetRect(annot.get(), &new_rect)); |
| 917 | EXPECT_EQ(rect.left, new_rect.left); |
| 918 | EXPECT_EQ(rect.bottom, new_rect.bottom); |
| 919 | EXPECT_EQ(rect.right, new_rect.right); |
| 920 | EXPECT_EQ(rect.top, new_rect.top); |
| 921 | } |
| 922 | |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 923 | CloseSavedPage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 924 | CloseSavedDocument(); |
Jane Liu | 8ce58f5 | 2017-06-29 13:40:22 -0400 | [diff] [blame] | 925 | } |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 926 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 927 | TEST_F(FPDFAnnotEmbedderTest, ModifyAnnotationFlags) { |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 928 | // Open a file with an annotation and load its first page. |
| 929 | ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 930 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 931 | ASSERT_TRUE(page); |
| 932 | |
| 933 | // Check that the page renders correctly. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 934 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 935 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 936 | CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); |
| 937 | } |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 938 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 939 | { |
| 940 | // Retrieve the annotation. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 941 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 942 | ASSERT_TRUE(annot); |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 943 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 944 | // Check that the original flag values are as expected. |
| 945 | int flags = FPDFAnnot_GetFlags(annot.get()); |
| 946 | EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN); |
| 947 | EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 948 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 949 | // Set the HIDDEN flag. |
| 950 | flags |= FPDF_ANNOT_FLAG_HIDDEN; |
| 951 | EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags)); |
| 952 | flags = FPDFAnnot_GetFlags(annot.get()); |
| 953 | EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_HIDDEN); |
| 954 | EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 955 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 956 | // Check that the page renders correctly without rendering the annotation. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 957 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 958 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Hui Yingst | b4baceb | 2020-04-28 23:46:10 +0000 | [diff] [blame] | 959 | CompareBitmap(bitmap.get(), 612, 792, pdfium::kBlankPage612By792Checksum); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 960 | } |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 961 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 962 | // Unset the HIDDEN flag. |
| 963 | EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), FPDF_ANNOT_FLAG_NONE)); |
| 964 | EXPECT_FALSE(FPDFAnnot_GetFlags(annot.get())); |
| 965 | flags &= ~FPDF_ANNOT_FLAG_HIDDEN; |
| 966 | EXPECT_TRUE(FPDFAnnot_SetFlags(annot.get(), flags)); |
| 967 | flags = FPDFAnnot_GetFlags(annot.get()); |
| 968 | EXPECT_FALSE(flags & FPDF_ANNOT_FLAG_HIDDEN); |
| 969 | EXPECT_TRUE(flags & FPDF_ANNOT_FLAG_PRINT); |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 970 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 971 | // Check that the page renders correctly as before. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 972 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 973 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 974 | CompareBitmap(bitmap.get(), 612, 792, "dc98f06da047bd8aabfa99562d2cbd1e"); |
| 975 | } |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 976 | } |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 977 | |
Jane Liu | b137e75 | 2017-07-05 15:04:33 -0400 | [diff] [blame] | 978 | UnloadPage(page); |
| 979 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 980 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 981 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 982 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 983 | #define MAYBE_AddAndModifyImage DISABLED_AddAndModifyImage |
| 984 | #else |
| 985 | #define MAYBE_AddAndModifyImage AddAndModifyImage |
| 986 | #endif |
| 987 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndModifyImage) { |
Lei Zhang | e4cdac5 | 2019-04-30 16:45:57 +0000 | [diff] [blame] | 988 | #if defined(OS_MACOSX) |
Lei Zhang | 0f6b434 | 2020-02-25 20:00:39 +0000 | [diff] [blame] | 989 | static const char kMd5NewImage[] = "dd18709d90c245a12ce0b8c4d092bea9"; |
| 990 | static const char kMd5ModifiedImage[] = "8d6f478ff8c7e67d49b253f1af587a99"; |
Lei Zhang | e67bcc7 | 2019-04-30 18:55:58 +0000 | [diff] [blame] | 991 | #elif defined(OS_WIN) |
Lei Zhang | a2b7073 | 2019-06-25 08:34:22 +0000 | [diff] [blame] | 992 | static const char kMd5NewImage[] = "3d77d06a971bcb9fb54db082f1082c8b"; |
| 993 | static const char kMd5ModifiedImage[] = "dc4f4afc26c345418330d31c065020e1"; |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 994 | #else |
Lei Zhang | a2b7073 | 2019-06-25 08:34:22 +0000 | [diff] [blame] | 995 | static const char kMd5NewImage[] = "528e6243dc29d54f36b61e0d3287d935"; |
| 996 | static const char kMd5ModifiedImage[] = "6d9e59f3e57a1ff82fb258356b7eb731"; |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 997 | #endif |
| 998 | |
| 999 | // Open a file with two annotations and load its first page. |
| 1000 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1001 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1002 | ASSERT_TRUE(page); |
| 1003 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 1004 | |
| 1005 | // Check that the page renders correctly. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1006 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1007 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Hui Yingst | b4baceb | 2020-04-28 23:46:10 +0000 | [diff] [blame] | 1008 | CompareBitmap(bitmap.get(), 595, 842, kAnnotationStampWithApChecksum); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1009 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1010 | |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1011 | constexpr int kBitmapSize = 200; |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1012 | FPDF_BITMAP image_bitmap; |
| 1013 | |
| 1014 | { |
| 1015 | // Create a stamp annotation and set its annotation rectangle. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1016 | ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1017 | ASSERT_TRUE(annot); |
| 1018 | FS_RECTF rect; |
| 1019 | rect.left = 200.f; |
| 1020 | rect.bottom = 600.f; |
| 1021 | rect.right = 400.f; |
| 1022 | rect.top = 800.f; |
| 1023 | EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect)); |
| 1024 | |
| 1025 | // Add a solid-color translucent image object to the new annotation. |
| 1026 | image_bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 1); |
| 1027 | FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, |
| 1028 | 0xeeeecccc); |
| 1029 | EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(image_bitmap)); |
| 1030 | EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(image_bitmap)); |
| 1031 | FPDF_PAGEOBJECT image_object = FPDFPageObj_NewImageObj(document()); |
| 1032 | ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap)); |
| 1033 | ASSERT_TRUE(FPDFImageObj_SetMatrix(image_object, kBitmapSize, 0, 0, |
| 1034 | kBitmapSize, 0, 0)); |
| 1035 | FPDFPageObj_Transform(image_object, 1, 0, 0, 1, 200, 600); |
| 1036 | EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), image_object)); |
| 1037 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1038 | |
| 1039 | // Check that the page renders correctly with the new image object. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1040 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1041 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1042 | CompareBitmap(bitmap.get(), 595, 842, kMd5NewImage); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1043 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1044 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1045 | { |
| 1046 | // Retrieve the newly added stamp annotation and its image object. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1047 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1048 | ASSERT_TRUE(annot); |
| 1049 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); |
| 1050 | FPDF_PAGEOBJECT image_object = FPDFAnnot_GetObject(annot.get(), 0); |
| 1051 | EXPECT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(image_object)); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1052 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1053 | // Modify the image in the new annotation. |
| 1054 | FPDFBitmap_FillRect(image_bitmap, 0, 0, kBitmapSize, kBitmapSize, |
| 1055 | 0xff000000); |
| 1056 | ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, image_object, image_bitmap)); |
| 1057 | EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), image_object)); |
| 1058 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1059 | |
| 1060 | // Save the document, closing the page and document. |
| 1061 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1062 | UnloadPage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 1063 | FPDFBitmap_Destroy(image_bitmap); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1064 | |
| 1065 | // Test that the saved document renders the modified image object correctly. |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1066 | VerifySavedDocument(595, 842, kMd5ModifiedImage); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1067 | } |
| 1068 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 1069 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 1070 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 1071 | #define MAYBE_AddAndModifyText DISABLED_AddAndModifyText |
| 1072 | #else |
| 1073 | #define MAYBE_AddAndModifyText AddAndModifyText |
| 1074 | #endif |
| 1075 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_AddAndModifyText) { |
Lei Zhang | e4cdac5 | 2019-04-30 16:45:57 +0000 | [diff] [blame] | 1076 | #if defined(OS_MACOSX) |
Lei Zhang | 0f6b434 | 2020-02-25 20:00:39 +0000 | [diff] [blame] | 1077 | static const char kMd5NewText[] = "e657266260b88c964938efe6c9b292da"; |
| 1078 | static const char kMd5ModifiedText[] = "7accdf2bac64463101783221f53d3188"; |
Lei Zhang | e67bcc7 | 2019-04-30 18:55:58 +0000 | [diff] [blame] | 1079 | #elif defined(OS_WIN) |
Lei Zhang | a2b7073 | 2019-06-25 08:34:22 +0000 | [diff] [blame] | 1080 | static const char kMd5NewText[] = "204cc01749a70b8afc246a4ca33c7eb6"; |
| 1081 | static const char kMd5ModifiedText[] = "641261a45e8dfd68c89b80bfd237660d"; |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1082 | #else |
Lei Zhang | a2b7073 | 2019-06-25 08:34:22 +0000 | [diff] [blame] | 1083 | static const char kMd5NewText[] = "00197ad6206f763febad5719e5935306"; |
| 1084 | static const char kMd5ModifiedText[] = "85853bc0aaa5a4e3af04e58b9cbfff23"; |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1085 | #endif |
| 1086 | |
| 1087 | // Open a file with two annotations and load its first page. |
| 1088 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1089 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1090 | ASSERT_TRUE(page); |
| 1091 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 1092 | |
| 1093 | // Check that the page renders correctly. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1094 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1095 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Hui Yingst | b4baceb | 2020-04-28 23:46:10 +0000 | [diff] [blame] | 1096 | CompareBitmap(bitmap.get(), 595, 842, kAnnotationStampWithApChecksum); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1097 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1098 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1099 | { |
| 1100 | // Create a stamp annotation and set its annotation rectangle. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1101 | ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1102 | ASSERT_TRUE(annot); |
| 1103 | FS_RECTF rect; |
| 1104 | rect.left = 200.f; |
| 1105 | rect.bottom = 550.f; |
| 1106 | rect.right = 450.f; |
| 1107 | rect.top = 650.f; |
| 1108 | EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &rect)); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1109 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1110 | // Add a translucent text object to the new annotation. |
| 1111 | FPDF_PAGEOBJECT text_object = |
| 1112 | FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); |
| 1113 | EXPECT_TRUE(text_object); |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 1114 | ScopedFPDFWideString text = |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1115 | GetFPDFWideString(L"I'm a translucent text laying on other text."); |
| 1116 | EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); |
Lei Zhang | 3475b48 | 2019-05-13 18:30:57 +0000 | [diff] [blame] | 1117 | EXPECT_TRUE(FPDFPageObj_SetFillColor(text_object, 0, 0, 255, 150)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1118 | FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 600); |
| 1119 | EXPECT_TRUE(FPDFAnnot_AppendObject(annot.get(), text_object)); |
| 1120 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1121 | |
| 1122 | // Check that the page renders correctly with the new text object. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1123 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1124 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1125 | CompareBitmap(bitmap.get(), 595, 842, kMd5NewText); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1126 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1127 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1128 | { |
| 1129 | // Retrieve the newly added stamp annotation and its text object. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1130 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1131 | ASSERT_TRUE(annot); |
| 1132 | EXPECT_EQ(1, FPDFAnnot_GetObjectCount(annot.get())); |
| 1133 | FPDF_PAGEOBJECT text_object = FPDFAnnot_GetObject(annot.get(), 0); |
| 1134 | EXPECT_EQ(FPDF_PAGEOBJ_TEXT, FPDFPageObj_GetType(text_object)); |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1135 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1136 | // Modify the text in the new annotation. |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 1137 | ScopedFPDFWideString new_text = GetFPDFWideString(L"New text!"); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1138 | EXPECT_TRUE(FPDFText_SetText(text_object, new_text.get())); |
| 1139 | EXPECT_TRUE(FPDFAnnot_UpdateObject(annot.get(), text_object)); |
| 1140 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1141 | |
| 1142 | // Check that the page renders correctly with the modified text object. |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1143 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1144 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1145 | CompareBitmap(bitmap.get(), 595, 842, kMd5ModifiedText); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1146 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1147 | |
| 1148 | // Remove the new annotation, and check that the page renders as before. |
| 1149 | EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 2)); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1150 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1151 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
Hui Yingst | b4baceb | 2020-04-28 23:46:10 +0000 | [diff] [blame] | 1152 | CompareBitmap(bitmap.get(), 595, 842, kAnnotationStampWithApChecksum); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 1153 | } |
Jane Liu | 3656774 | 2017-07-06 11:13:35 -0400 | [diff] [blame] | 1154 | |
| 1155 | UnloadPage(page); |
| 1156 | } |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1157 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 1158 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 1159 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 1160 | #define MAYBE_GetSetStringValue DISABLED_GetSetStringValue |
| 1161 | #else |
| 1162 | #define MAYBE_GetSetStringValue GetSetStringValue |
| 1163 | #endif |
| 1164 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_GetSetStringValue) { |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1165 | // Open a file with four annotations and load its first page. |
| 1166 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1167 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1168 | ASSERT_TRUE(page); |
| 1169 | |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1170 | static const wchar_t kNewDate[] = L"D:201706282359Z00'00'"; |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1171 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1172 | { |
| 1173 | // Retrieve the first annotation. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1174 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1175 | ASSERT_TRUE(annot); |
| 1176 | |
| 1177 | // Check that a non-existent key does not exist. |
| 1178 | EXPECT_FALSE(FPDFAnnot_HasKey(annot.get(), "none")); |
| 1179 | |
| 1180 | // Check that the string value of a non-string dictionary entry is empty. |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1181 | EXPECT_TRUE(FPDFAnnot_HasKey(annot.get(), pdfium::annotation::kAP)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1182 | EXPECT_EQ(FPDF_OBJECT_REFERENCE, |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1183 | FPDFAnnot_GetValueType(annot.get(), pdfium::annotation::kAP)); |
| 1184 | EXPECT_EQ(2u, FPDFAnnot_GetStringValue(annot.get(), pdfium::annotation::kAP, |
| 1185 | nullptr, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1186 | |
| 1187 | // Check that the string value of the hash is correct. |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1188 | static const char kHashKey[] = "AAPL:Hash"; |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1189 | EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey)); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1190 | unsigned long length_bytes = |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1191 | FPDFAnnot_GetStringValue(annot.get(), kHashKey, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1192 | ASSERT_EQ(66u, length_bytes); |
| 1193 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
| 1194 | EXPECT_EQ(66u, FPDFAnnot_GetStringValue(annot.get(), kHashKey, buf.data(), |
| 1195 | length_bytes)); |
| 1196 | EXPECT_EQ(L"395fbcb98d558681742f30683a62a2ad", |
| 1197 | GetPlatformWString(buf.data())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1198 | |
| 1199 | // Check that the string value of the modified date is correct. |
| 1200 | EXPECT_EQ(FPDF_OBJECT_NAME, FPDFAnnot_GetValueType(annot.get(), kHashKey)); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1201 | length_bytes = FPDFAnnot_GetStringValue(annot.get(), pdfium::annotation::kM, |
| 1202 | nullptr, 0); |
| 1203 | ASSERT_EQ(44u, length_bytes); |
| 1204 | buf = GetFPDFWideStringBuffer(length_bytes); |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1205 | EXPECT_EQ(44u, FPDFAnnot_GetStringValue(annot.get(), pdfium::annotation::kM, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1206 | buf.data(), length_bytes)); |
| 1207 | EXPECT_EQ(L"D:201706071721Z00'00'", GetPlatformWString(buf.data())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1208 | |
| 1209 | // Update the date entry for the annotation. |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 1210 | ScopedFPDFWideString text = GetFPDFWideString(kNewDate); |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1211 | EXPECT_TRUE(FPDFAnnot_SetStringValue(annot.get(), pdfium::annotation::kM, |
| 1212 | text.get())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1213 | } |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1214 | |
| 1215 | // Save the document, closing the page and document. |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1216 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1217 | UnloadPage(page); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1218 | |
Lei Zhang | e4cdac5 | 2019-04-30 16:45:57 +0000 | [diff] [blame] | 1219 | #if defined(OS_MACOSX) |
Lei Zhang | 0f6b434 | 2020-02-25 20:00:39 +0000 | [diff] [blame] | 1220 | static const char kMd5[] = "5e7e185b386ad21ca83b0287268c50fb"; |
Lei Zhang | e67bcc7 | 2019-04-30 18:55:58 +0000 | [diff] [blame] | 1221 | #elif defined(OS_WIN) |
Lei Zhang | a2b7073 | 2019-06-25 08:34:22 +0000 | [diff] [blame] | 1222 | static const char kMd5[] = "20b612ebd46babcb44c48c903e2c5a48"; |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1223 | #else |
Lei Zhang | a2b7073 | 2019-06-25 08:34:22 +0000 | [diff] [blame] | 1224 | static const char kMd5[] = "1d7bea2042c6fea0558ff2aef05811b5"; |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1225 | #endif |
Dan Sinclair | 971a674 | 2018-03-28 19:23:25 +0000 | [diff] [blame] | 1226 | |
| 1227 | // Open the saved annotation. |
Lei Zhang | 0b49405 | 2019-01-31 21:41:15 +0000 | [diff] [blame] | 1228 | ASSERT_TRUE(OpenSavedDocument()); |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 1229 | page = LoadSavedPage(0); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1230 | VerifySavedRendering(page, 595, 842, kMd5); |
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)); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1233 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1234 | // Check that the string value of the modified date is the newly-set value. |
| 1235 | EXPECT_EQ(FPDF_OBJECT_STRING, |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1236 | FPDFAnnot_GetValueType(new_annot.get(), pdfium::annotation::kM)); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1237 | unsigned long length_bytes = FPDFAnnot_GetStringValue( |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1238 | new_annot.get(), pdfium::annotation::kM, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1239 | ASSERT_EQ(44u, length_bytes); |
| 1240 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1241 | EXPECT_EQ(44u, |
| 1242 | FPDFAnnot_GetStringValue(new_annot.get(), pdfium::annotation::kM, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1243 | buf.data(), length_bytes)); |
| 1244 | EXPECT_EQ(kNewDate, GetPlatformWString(buf.data())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1245 | } |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1246 | |
Henrique Nakashima | 8baea3c | 2017-11-10 20:27:23 +0000 | [diff] [blame] | 1247 | CloseSavedPage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 1248 | CloseSavedDocument(); |
Jane Liu | 2e1a32b | 2017-07-06 12:01:25 -0400 | [diff] [blame] | 1249 | } |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1250 | |
rycsmith | 3e78560 | 2019-03-05 21:48:36 +0000 | [diff] [blame] | 1251 | TEST_F(FPDFAnnotEmbedderTest, GetNumberValue) { |
Mansi Awasthi | 0b5da67 | 2020-01-23 18:17:18 +0000 | [diff] [blame] | 1252 | // Open a file with four text annotations and load its first page. |
rycsmith | 3e78560 | 2019-03-05 21:48:36 +0000 | [diff] [blame] | 1253 | ASSERT_TRUE(OpenDocument("text_form_multiple.pdf")); |
| 1254 | FPDF_PAGE page = LoadPage(0); |
| 1255 | ASSERT_TRUE(page); |
| 1256 | { |
| 1257 | // First two annotations do not have "MaxLen" attribute. |
| 1258 | for (int i = 0; i < 2; i++) { |
| 1259 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i)); |
| 1260 | ASSERT_TRUE(annot); |
| 1261 | |
| 1262 | // Verify that no "MaxLen" key present. |
| 1263 | EXPECT_FALSE(FPDFAnnot_HasKey(annot.get(), "MaxLen")); |
| 1264 | |
| 1265 | float value; |
| 1266 | EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(), "MaxLen", &value)); |
| 1267 | } |
| 1268 | |
| 1269 | // Annotation in index 2 has "MaxLen" of 10. |
| 1270 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
| 1271 | ASSERT_TRUE(annot); |
| 1272 | |
| 1273 | // Verify that "MaxLen" key present. |
| 1274 | EXPECT_TRUE(FPDFAnnot_HasKey(annot.get(), "MaxLen")); |
| 1275 | |
| 1276 | float value; |
| 1277 | EXPECT_TRUE(FPDFAnnot_GetNumberValue(annot.get(), "MaxLen", &value)); |
| 1278 | EXPECT_FLOAT_EQ(10.0f, value); |
| 1279 | |
| 1280 | // Check bad inputs. |
| 1281 | EXPECT_FALSE(FPDFAnnot_GetNumberValue(nullptr, "MaxLen", &value)); |
| 1282 | EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(), nullptr, &value)); |
| 1283 | EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(), "MaxLen", nullptr)); |
| 1284 | // Ask for key that exists but is not a number. |
| 1285 | EXPECT_FALSE(FPDFAnnot_GetNumberValue(annot.get(), "V", &value)); |
| 1286 | } |
| 1287 | |
| 1288 | UnloadPage(page); |
| 1289 | } |
| 1290 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1291 | TEST_F(FPDFAnnotEmbedderTest, GetSetAP) { |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1292 | // Open a file with four annotations and load its first page. |
| 1293 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1294 | FPDF_PAGE page = LoadPage(0); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1295 | ASSERT_TRUE(page); |
| 1296 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1297 | { |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1298 | static const char kMd5NormalAP[] = "be903df0343fd774fadab9c8900cdf4a"; |
| 1299 | static constexpr size_t kExpectNormalAPLength = 73970; |
| 1300 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1301 | // Retrieve the first annotation. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1302 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1303 | ASSERT_TRUE(annot); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1304 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1305 | // Check that the string value of an AP returns the expected length. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1306 | unsigned long normal_length_bytes = FPDFAnnot_GetAP( |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1307 | annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1308 | ASSERT_EQ(kExpectNormalAPLength, normal_length_bytes); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1309 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1310 | // Check that the string value of an AP is not returned if the buffer is too |
| 1311 | // small. The result buffer should be overwritten with an empty string. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1312 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(normal_length_bytes); |
| 1313 | // Write in the buffer to verify it's not overwritten. |
| 1314 | memcpy(buf.data(), "abcdefgh", 8); |
| 1315 | EXPECT_EQ(kExpectNormalAPLength, |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1316 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1317 | buf.data(), normal_length_bytes - 1)); |
| 1318 | EXPECT_EQ(0, memcmp(buf.data(), "abcdefgh", 8)); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1319 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1320 | // Check that the string value of an AP is returned through a buffer that is |
| 1321 | // the right size. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1322 | EXPECT_EQ(kExpectNormalAPLength, |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1323 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1324 | buf.data(), normal_length_bytes)); |
| 1325 | EXPECT_EQ(kMd5NormalAP, |
| 1326 | GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), |
| 1327 | normal_length_bytes)); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1328 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1329 | // Check that the string value of an AP is returned through a buffer that is |
| 1330 | // larger than necessary. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1331 | buf = GetFPDFWideStringBuffer(normal_length_bytes + 2); |
| 1332 | EXPECT_EQ(kExpectNormalAPLength, |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1333 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1334 | buf.data(), normal_length_bytes + 2)); |
| 1335 | EXPECT_EQ(kMd5NormalAP, |
| 1336 | GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), |
| 1337 | normal_length_bytes)); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1338 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1339 | // Check that getting an AP for a mode that does not have an AP returns an |
| 1340 | // empty string. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1341 | unsigned long rollover_length_bytes = FPDFAnnot_GetAP( |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1342 | annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1343 | ASSERT_EQ(2u, rollover_length_bytes); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1344 | |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1345 | buf = GetFPDFWideStringBuffer(1000); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1346 | EXPECT_EQ(2u, |
| 1347 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1348 | buf.data(), 1000)); |
| 1349 | EXPECT_EQ(L"", GetPlatformWString(buf.data())); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1350 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1351 | // Check that setting the AP for an invalid appearance mode fails. |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 1352 | ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap"); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1353 | EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), -1, ap_text.get())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1354 | EXPECT_FALSE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_COUNT, |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1355 | ap_text.get())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1356 | EXPECT_FALSE(FPDFAnnot_SetAP( |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1357 | annot.get(), FPDF_ANNOT_APPEARANCEMODE_COUNT + 1, ap_text.get())); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1358 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1359 | // Set the AP correctly now. |
| 1360 | EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1361 | ap_text.get())); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1362 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1363 | // Check that the new annotation value is equal to the value we just set. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1364 | rollover_length_bytes = FPDFAnnot_GetAP( |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1365 | annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1366 | ASSERT_EQ(24u, rollover_length_bytes); |
| 1367 | buf = GetFPDFWideStringBuffer(rollover_length_bytes); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1368 | EXPECT_EQ(24u, |
| 1369 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1370 | buf.data(), rollover_length_bytes)); |
| 1371 | EXPECT_EQ(L"new test ap", GetPlatformWString(buf.data())); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1372 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1373 | // Check that the Normal AP was not touched when the Rollover AP was set. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1374 | buf = GetFPDFWideStringBuffer(normal_length_bytes); |
| 1375 | EXPECT_EQ(kExpectNormalAPLength, |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1376 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1377 | buf.data(), normal_length_bytes)); |
| 1378 | EXPECT_EQ(kMd5NormalAP, |
| 1379 | GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), |
| 1380 | normal_length_bytes)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1381 | } |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1382 | |
| 1383 | // Save the modified document, then reopen it. |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1384 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1385 | UnloadPage(page); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1386 | |
Lei Zhang | 0b49405 | 2019-01-31 21:41:15 +0000 | [diff] [blame] | 1387 | ASSERT_TRUE(OpenSavedDocument()); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1388 | page = LoadSavedPage(0); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1389 | { |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1390 | ScopedFPDFAnnotation new_annot(FPDFPage_GetAnnot(page, 0)); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1391 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1392 | // Check that the new annotation value is equal to the value we set before |
| 1393 | // saving. |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1394 | unsigned long rollover_length_bytes = FPDFAnnot_GetAP( |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1395 | new_annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1396 | ASSERT_EQ(24u, rollover_length_bytes); |
| 1397 | std::vector<FPDF_WCHAR> buf = |
| 1398 | GetFPDFWideStringBuffer(rollover_length_bytes); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1399 | EXPECT_EQ(24u, FPDFAnnot_GetAP(new_annot.get(), |
| 1400 | FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1401 | buf.data(), rollover_length_bytes)); |
| 1402 | EXPECT_EQ(L"new test ap", GetPlatformWString(buf.data())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1403 | } |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1404 | |
| 1405 | // Close saved document. |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1406 | CloseSavedPage(page); |
| 1407 | CloseSavedDocument(); |
| 1408 | } |
| 1409 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1410 | TEST_F(FPDFAnnotEmbedderTest, RemoveOptionalAP) { |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1411 | // Open a file with four annotations and load its first page. |
| 1412 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1413 | FPDF_PAGE page = LoadPage(0); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1414 | ASSERT_TRUE(page); |
| 1415 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1416 | { |
| 1417 | // Retrieve the first annotation. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1418 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1419 | ASSERT_TRUE(annot); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1420 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1421 | // Set Down AP. Normal AP is already set. |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 1422 | ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap"); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1423 | EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1424 | ap_text.get())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1425 | EXPECT_EQ(73970u, |
| 1426 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
| 1427 | nullptr, 0)); |
| 1428 | EXPECT_EQ(24u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, |
| 1429 | nullptr, 0)); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1430 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1431 | // Check that setting the Down AP to null removes the Down entry but keeps |
| 1432 | // Normal intact. |
| 1433 | EXPECT_TRUE( |
| 1434 | FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, nullptr)); |
| 1435 | EXPECT_EQ(73970u, |
| 1436 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
| 1437 | nullptr, 0)); |
| 1438 | EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, |
| 1439 | nullptr, 0)); |
| 1440 | } |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1441 | |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1442 | UnloadPage(page); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1445 | TEST_F(FPDFAnnotEmbedderTest, RemoveRequiredAP) { |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1446 | // Open a file with four annotations and load its first page. |
| 1447 | ASSERT_TRUE(OpenDocument("annotation_stamp_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1448 | FPDF_PAGE page = LoadPage(0); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1449 | ASSERT_TRUE(page); |
| 1450 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1451 | { |
| 1452 | // Retrieve the first annotation. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1453 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1454 | ASSERT_TRUE(annot); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1455 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1456 | // Set Down AP. Normal AP is already set. |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 1457 | ScopedFPDFWideString ap_text = GetFPDFWideString(L"new test ap"); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1458 | EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1459 | ap_text.get())); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1460 | EXPECT_EQ(73970u, |
| 1461 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
| 1462 | nullptr, 0)); |
| 1463 | EXPECT_EQ(24u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, |
| 1464 | nullptr, 0)); |
Henrique Nakashima | 5970a47 | 2018-01-11 22:40:59 +0000 | [diff] [blame] | 1465 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1466 | // Check that setting the Normal AP to null removes the whole AP dictionary. |
| 1467 | EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
| 1468 | nullptr)); |
| 1469 | EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, |
| 1470 | nullptr, 0)); |
| 1471 | EXPECT_EQ(2u, FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_DOWN, |
| 1472 | nullptr, 0)); |
| 1473 | } |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1474 | |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1475 | UnloadPage(page); |
Henrique Nakashima | a74e75d | 2018-01-10 18:06:55 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1478 | TEST_F(FPDFAnnotEmbedderTest, ExtractLinkedAnnotations) { |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 1479 | // Open a file with annotations and load its first page. |
| 1480 | ASSERT_TRUE(OpenDocument("annotation_highlight_square_with_ap.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1481 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 1482 | ASSERT_TRUE(page); |
Jane Liu | d1ed1ce | 2017-08-24 12:31:10 -0400 | [diff] [blame] | 1483 | EXPECT_EQ(-1, FPDFPage_GetAnnotIndex(page, nullptr)); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 1484 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1485 | { |
| 1486 | // Retrieve the highlight annotation which has its popup defined. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1487 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1488 | ASSERT_TRUE(annot); |
| 1489 | EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get())); |
| 1490 | EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot.get())); |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1491 | static const char kPopupKey[] = "Popup"; |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1492 | ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), kPopupKey)); |
| 1493 | ASSERT_EQ(FPDF_OBJECT_REFERENCE, |
| 1494 | FPDFAnnot_GetValueType(annot.get(), kPopupKey)); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 1495 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1496 | // Retrieve and verify the popup of the highlight annotation. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1497 | ScopedFPDFAnnotation popup( |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1498 | FPDFAnnot_GetLinkedAnnot(annot.get(), kPopupKey)); |
| 1499 | ASSERT_TRUE(popup); |
| 1500 | EXPECT_EQ(FPDF_ANNOT_POPUP, FPDFAnnot_GetSubtype(popup.get())); |
| 1501 | EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, popup.get())); |
| 1502 | FS_RECTF rect; |
| 1503 | ASSERT_TRUE(FPDFAnnot_GetRect(popup.get(), &rect)); |
| 1504 | EXPECT_NEAR(612.0f, rect.left, 0.001f); |
| 1505 | EXPECT_NEAR(578.792, rect.bottom, 0.001f); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 1506 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1507 | // Attempting to retrieve |annot|'s "IRT"-linked annotation would fail, |
| 1508 | // since "IRT" is not a key in |annot|'s dictionary. |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1509 | static const char kIRTKey[] = "IRT"; |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1510 | ASSERT_FALSE(FPDFAnnot_HasKey(annot.get(), kIRTKey)); |
| 1511 | EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), kIRTKey)); |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 1512 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1513 | // Attempting to retrieve |annot|'s parent dictionary as an annotation |
| 1514 | // would fail, since its parent is not an annotation. |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1515 | ASSERT_TRUE(FPDFAnnot_HasKey(annot.get(), pdfium::annotation::kP)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1516 | EXPECT_EQ(FPDF_OBJECT_REFERENCE, |
Lei Zhang | a5c1daf | 2019-01-31 21:56:47 +0000 | [diff] [blame] | 1517 | FPDFAnnot_GetValueType(annot.get(), pdfium::annotation::kP)); |
| 1518 | EXPECT_FALSE(FPDFAnnot_GetLinkedAnnot(annot.get(), pdfium::annotation::kP)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1519 | } |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 1520 | |
Jane Liu | 300bb27 | 2017-08-21 14:37:53 -0400 | [diff] [blame] | 1521 | UnloadPage(page); |
| 1522 | } |
| 1523 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1524 | TEST_F(FPDFAnnotEmbedderTest, GetFormFieldFlagsTextField) { |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1525 | // Open file with form text fields. |
| 1526 | ASSERT_TRUE(OpenDocument("text_form_multiple.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1527 | FPDF_PAGE page = LoadPage(0); |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1528 | ASSERT_TRUE(page); |
| 1529 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1530 | { |
| 1531 | // Retrieve the first annotation: user-editable text field. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1532 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1533 | ASSERT_TRUE(annot); |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1534 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1535 | // Check that the flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1536 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1537 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
Mansi Awasthi | 0b5da67 | 2020-01-23 18:17:18 +0000 | [diff] [blame] | 1538 | EXPECT_FALSE(flags & FPDF_FORMFLAG_TEXT_PASSWORD); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1539 | } |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1540 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1541 | { |
| 1542 | // Retrieve the second annotation: read-only text field. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1543 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1544 | ASSERT_TRUE(annot); |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1545 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1546 | // Check that the flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1547 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1548 | EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); |
Mansi Awasthi | 0b5da67 | 2020-01-23 18:17:18 +0000 | [diff] [blame] | 1549 | EXPECT_FALSE(flags & FPDF_FORMFLAG_TEXT_PASSWORD); |
| 1550 | } |
| 1551 | |
| 1552 | { |
| 1553 | // Retrieve the fourth annotation: user-editable password text field. |
| 1554 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3)); |
| 1555 | ASSERT_TRUE(annot); |
| 1556 | |
| 1557 | // Check that the flag values are as expected. |
| 1558 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
| 1559 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1560 | EXPECT_TRUE(flags & FPDF_FORMFLAG_TEXT_PASSWORD); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1561 | } |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1562 | |
| 1563 | UnloadPage(page); |
| 1564 | } |
| 1565 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1566 | TEST_F(FPDFAnnotEmbedderTest, GetFormFieldFlagsComboBox) { |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1567 | // Open file with form text fields. |
| 1568 | ASSERT_TRUE(OpenDocument("combobox_form.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 1569 | FPDF_PAGE page = LoadPage(0); |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1570 | ASSERT_TRUE(page); |
| 1571 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1572 | { |
| 1573 | // Retrieve the first annotation: user-editable combobox. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1574 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1575 | ASSERT_TRUE(annot); |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1576 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1577 | // Check that the flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1578 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1579 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1580 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1581 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1582 | } |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1583 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1584 | { |
| 1585 | // Retrieve the second annotation: regular combobox. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1586 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1587 | ASSERT_TRUE(annot); |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1588 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1589 | // Check that the flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1590 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1591 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1592 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1593 | EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1594 | } |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1595 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1596 | { |
| 1597 | // Retrieve the third annotation: read-only combobox. |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1598 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1599 | ASSERT_TRUE(annot); |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1600 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1601 | // Check that the flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1602 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1603 | EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); |
| 1604 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1605 | EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1606 | } |
Diana Gage | 7e0c05d | 2017-07-19 17:33:33 -0700 | [diff] [blame] | 1607 | |
| 1608 | UnloadPage(page); |
| 1609 | } |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1610 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1611 | TEST_F(FPDFAnnotEmbedderTest, GetFormAnnotNull) { |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1612 | // Open file with form text fields. |
| 1613 | EXPECT_TRUE(OpenDocument("text_form.pdf")); |
| 1614 | FPDF_PAGE page = LoadPage(0); |
| 1615 | ASSERT_TRUE(page); |
| 1616 | |
| 1617 | // Attempt to get an annotation where no annotation exists on page. |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1618 | static const FS_POINTF kOriginPoint = {0.0f, 0.0f}; |
| 1619 | EXPECT_FALSE( |
| 1620 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kOriginPoint)); |
Lei Zhang | 7557e7b | 2018-09-14 17:02:40 +0000 | [diff] [blame] | 1621 | |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1622 | static const FS_POINTF kValidPoint = {120.0f, 120.0f}; |
Lei Zhang | 7557e7b | 2018-09-14 17:02:40 +0000 | [diff] [blame] | 1623 | { |
| 1624 | // Verify there is an annotation. |
| 1625 | ScopedFPDFAnnotation annot( |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1626 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kValidPoint)); |
Lei Zhang | 7557e7b | 2018-09-14 17:02:40 +0000 | [diff] [blame] | 1627 | EXPECT_TRUE(annot); |
| 1628 | } |
| 1629 | |
| 1630 | // Try other bad inputs at a valid location. |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1631 | EXPECT_FALSE(FPDFAnnot_GetFormFieldAtPoint(nullptr, nullptr, &kValidPoint)); |
| 1632 | EXPECT_FALSE(FPDFAnnot_GetFormFieldAtPoint(nullptr, page, &kValidPoint)); |
| 1633 | EXPECT_FALSE( |
| 1634 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), nullptr, &kValidPoint)); |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1635 | |
| 1636 | UnloadPage(page); |
| 1637 | } |
| 1638 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1639 | TEST_F(FPDFAnnotEmbedderTest, GetFormAnnotAndCheckFlagsTextField) { |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1640 | // Open file with form text fields. |
| 1641 | EXPECT_TRUE(OpenDocument("text_form_multiple.pdf")); |
| 1642 | FPDF_PAGE page = LoadPage(0); |
| 1643 | ASSERT_TRUE(page); |
| 1644 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1645 | { |
| 1646 | // Retrieve user-editable text field annotation. |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1647 | static const FS_POINTF kPoint = {105.0f, 118.0f}; |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1648 | ScopedFPDFAnnotation annot( |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1649 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1650 | ASSERT_TRUE(annot); |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1651 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1652 | // Check that interactive form annotation flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1653 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1654 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1655 | } |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1656 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1657 | { |
| 1658 | // Retrieve read-only text field annotation. |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1659 | static const FS_POINTF kPoint = {105.0f, 202.0f}; |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1660 | ScopedFPDFAnnotation annot( |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1661 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1662 | ASSERT_TRUE(annot); |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1663 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1664 | // Check that interactive form annotation flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1665 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1666 | EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); |
| 1667 | } |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1668 | |
| 1669 | UnloadPage(page); |
| 1670 | } |
| 1671 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 1672 | TEST_F(FPDFAnnotEmbedderTest, GetFormAnnotAndCheckFlagsComboBox) { |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1673 | // Open file with form comboboxes. |
| 1674 | EXPECT_TRUE(OpenDocument("combobox_form.pdf")); |
| 1675 | FPDF_PAGE page = LoadPage(0); |
| 1676 | ASSERT_TRUE(page); |
| 1677 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1678 | { |
| 1679 | // Retrieve user-editable combobox annotation. |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1680 | static const FS_POINTF kPoint = {102.0f, 363.0f}; |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1681 | ScopedFPDFAnnotation annot( |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1682 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1683 | ASSERT_TRUE(annot); |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1684 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1685 | // Check that interactive form annotation flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1686 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1687 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1688 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1689 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1690 | } |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1691 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1692 | { |
| 1693 | // Retrieve regular combobox annotation. |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1694 | static const FS_POINTF kPoint = {102.0f, 413.0f}; |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1695 | ScopedFPDFAnnotation annot( |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1696 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1697 | ASSERT_TRUE(annot); |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1698 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1699 | // Check that interactive form annotation flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1700 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1701 | EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY); |
| 1702 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1703 | EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1704 | } |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1705 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1706 | { |
| 1707 | // Retrieve read-only combobox annotation. |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1708 | static const FS_POINTF kPoint = {102.0f, 513.0f}; |
Tom Sepez | e08d2b1 | 2018-04-25 18:49:32 +0000 | [diff] [blame] | 1709 | ScopedFPDFAnnotation annot( |
Lei Zhang | 8da9823 | 2019-12-11 23:29:33 +0000 | [diff] [blame] | 1710 | FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, &kPoint)); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1711 | ASSERT_TRUE(annot); |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1712 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1713 | // Check that interactive form annotation flag values are as expected. |
Lei Zhang | a9d33bd | 2019-07-31 05:37:31 +0000 | [diff] [blame] | 1714 | int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get()); |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 1715 | EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY); |
| 1716 | EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO); |
| 1717 | EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT); |
| 1718 | } |
Diana Gage | 40870db | 2017-07-19 18:16:03 -0700 | [diff] [blame] | 1719 | |
| 1720 | UnloadPage(page); |
| 1721 | } |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1722 | |
Lei Zhang | 03e5e68 | 2019-09-16 19:45:55 +0000 | [diff] [blame] | 1723 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 1724 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 1725 | #define MAYBE_BUG_1206 DISABLED_BUG_1206 |
| 1726 | #else |
| 1727 | #define MAYBE_BUG_1206 BUG_1206 |
| 1728 | #endif |
| 1729 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_BUG_1206) { |
Lei Zhang | 992e7e2 | 2019-02-04 19:20:58 +0000 | [diff] [blame] | 1730 | static constexpr size_t kExpectedSize = 1609; |
| 1731 | static const char kExpectedBitmap[] = "0d9fc05c6762fd788bd23fd87a4967bc"; |
| 1732 | |
| 1733 | ASSERT_TRUE(OpenDocument("bug_1206.pdf")); |
| 1734 | |
| 1735 | FPDF_PAGE page = LoadPage(0); |
| 1736 | ASSERT_TRUE(page); |
| 1737 | |
| 1738 | ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 1739 | EXPECT_EQ(kExpectedSize, GetString().size()); |
| 1740 | ClearString(); |
| 1741 | |
| 1742 | for (size_t i = 0; i < 10; ++i) { |
| 1743 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
| 1744 | CompareBitmap(bitmap.get(), 612, 792, kExpectedBitmap); |
| 1745 | |
| 1746 | ASSERT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 1747 | // TODO(https://crbug.com/pdfium/1206): This is wrong. The size should be |
| 1748 | // equal, not bigger. |
| 1749 | EXPECT_LT(kExpectedSize, GetString().size()); |
| 1750 | ClearString(); |
| 1751 | } |
| 1752 | |
| 1753 | UnloadPage(page); |
| 1754 | } |
| 1755 | |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1756 | TEST_F(FPDFAnnotEmbedderTest, BUG_1212) { |
| 1757 | ASSERT_TRUE(OpenDocument("hello_world.pdf")); |
| 1758 | FPDF_PAGE page = LoadPage(0); |
| 1759 | ASSERT_TRUE(page); |
| 1760 | EXPECT_EQ(0, FPDFPage_GetAnnotCount(page)); |
| 1761 | |
| 1762 | static const char kTestKey[] = "test"; |
Lei Zhang | 4f556b8 | 2019-04-08 16:32:41 +0000 | [diff] [blame] | 1763 | static const wchar_t kData[] = L"\xf6\xe4"; |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1764 | static const size_t kBufSize = 12; |
| 1765 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(kBufSize); |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1766 | |
| 1767 | { |
| 1768 | // Add a text annotation to the page. |
| 1769 | ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT)); |
| 1770 | ASSERT_TRUE(annot); |
| 1771 | EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); |
| 1772 | EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get())); |
| 1773 | |
| 1774 | // Make sure there is no test key, add set a value there, and read it back. |
| 1775 | std::fill(buf.begin(), buf.end(), 'x'); |
| 1776 | ASSERT_EQ(2u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(), |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1777 | kBufSize)); |
| 1778 | EXPECT_EQ(L"", GetPlatformWString(buf.data())); |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1779 | |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 1780 | ScopedFPDFWideString text = GetFPDFWideString(kData); |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1781 | EXPECT_TRUE(FPDFAnnot_SetStringValue(annot.get(), kTestKey, text.get())); |
| 1782 | |
| 1783 | std::fill(buf.begin(), buf.end(), 'x'); |
| 1784 | ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(), |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1785 | kBufSize)); |
| 1786 | EXPECT_EQ(kData, GetPlatformWString(buf.data())); |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Lei Zhang | 05ec64c | 2019-01-09 03:00:06 +0000 | [diff] [blame] | 1789 | { |
| 1790 | ScopedFPDFAnnotation annot(FPDFPage_CreateAnnot(page, FPDF_ANNOT_STAMP)); |
| 1791 | ASSERT_TRUE(annot); |
Shikha Walia | 87ad417 | 2019-11-08 20:55:19 +0000 | [diff] [blame] | 1792 | const FS_RECTF bounding_rect{206.0f, 753.0f, 339.0f, 709.0f}; |
Shikha Walia | b54d7ad | 2019-11-06 02:06:33 +0000 | [diff] [blame] | 1793 | EXPECT_TRUE(FPDFAnnot_SetRect(annot.get(), &bounding_rect)); |
Lei Zhang | 05ec64c | 2019-01-09 03:00:06 +0000 | [diff] [blame] | 1794 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(page)); |
| 1795 | EXPECT_EQ(FPDF_ANNOT_STAMP, FPDFAnnot_GetSubtype(annot.get())); |
| 1796 | // Also do the same test for its appearance string. |
| 1797 | std::fill(buf.begin(), buf.end(), 'x'); |
| 1798 | ASSERT_EQ(2u, |
| 1799 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1800 | buf.data(), kBufSize)); |
| 1801 | EXPECT_EQ(L"", GetPlatformWString(buf.data())); |
Lei Zhang | 05ec64c | 2019-01-09 03:00:06 +0000 | [diff] [blame] | 1802 | |
Lei Zhang | f0f6768 | 2019-04-08 17:03:21 +0000 | [diff] [blame] | 1803 | ScopedFPDFWideString text = GetFPDFWideString(kData); |
Lei Zhang | 05ec64c | 2019-01-09 03:00:06 +0000 | [diff] [blame] | 1804 | EXPECT_TRUE(FPDFAnnot_SetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, |
| 1805 | text.get())); |
| 1806 | |
| 1807 | std::fill(buf.begin(), buf.end(), 'x'); |
| 1808 | ASSERT_EQ(6u, |
| 1809 | FPDFAnnot_GetAP(annot.get(), FPDF_ANNOT_APPEARANCEMODE_ROLLOVER, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1810 | buf.data(), kBufSize)); |
| 1811 | EXPECT_EQ(kData, GetPlatformWString(buf.data())); |
Lei Zhang | 05ec64c | 2019-01-09 03:00:06 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1814 | UnloadPage(page); |
| 1815 | |
| 1816 | { |
| 1817 | // Save a copy, open the copy, and check the annotation again. |
| 1818 | // Note that it renders the rotation. |
| 1819 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Lei Zhang | 0b49405 | 2019-01-31 21:41:15 +0000 | [diff] [blame] | 1820 | ASSERT_TRUE(OpenSavedDocument()); |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1821 | FPDF_PAGE saved_page = LoadSavedPage(0); |
| 1822 | ASSERT_TRUE(saved_page); |
| 1823 | |
Lei Zhang | 05ec64c | 2019-01-09 03:00:06 +0000 | [diff] [blame] | 1824 | EXPECT_EQ(2, FPDFPage_GetAnnotCount(saved_page)); |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1825 | { |
| 1826 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(saved_page, 0)); |
| 1827 | ASSERT_TRUE(annot); |
| 1828 | EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get())); |
| 1829 | |
| 1830 | std::fill(buf.begin(), buf.end(), 'x'); |
| 1831 | ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(), |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1832 | kBufSize)); |
| 1833 | EXPECT_EQ(kData, GetPlatformWString(buf.data())); |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
Lei Zhang | 05ec64c | 2019-01-09 03:00:06 +0000 | [diff] [blame] | 1836 | { |
| 1837 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(saved_page, 0)); |
| 1838 | ASSERT_TRUE(annot); |
| 1839 | // TODO(thestig): This return FPDF_ANNOT_UNKNOWN for some reason. |
| 1840 | // EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot.get())); |
| 1841 | |
| 1842 | std::fill(buf.begin(), buf.end(), 'x'); |
| 1843 | ASSERT_EQ(6u, FPDFAnnot_GetStringValue(annot.get(), kTestKey, buf.data(), |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1844 | kBufSize)); |
| 1845 | EXPECT_EQ(kData, GetPlatformWString(buf.data())); |
Lei Zhang | 05ec64c | 2019-01-09 03:00:06 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
Lei Zhang | f5fcd9e | 2018-12-23 03:11:50 +0000 | [diff] [blame] | 1848 | CloseSavedPage(saved_page); |
| 1849 | CloseSavedDocument(); |
| 1850 | } |
| 1851 | } |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1852 | |
| 1853 | TEST_F(FPDFAnnotEmbedderTest, GetOptionCountCombobox) { |
| 1854 | // Open a file with combobox widget annotations and load its first page. |
| 1855 | ASSERT_TRUE(OpenDocument("combobox_form.pdf")); |
| 1856 | FPDF_PAGE page = LoadPage(0); |
| 1857 | ASSERT_TRUE(page); |
| 1858 | |
| 1859 | { |
| 1860 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 1861 | ASSERT_TRUE(annot); |
| 1862 | |
| 1863 | EXPECT_EQ(3, FPDFAnnot_GetOptionCount(form_handle(), annot.get())); |
| 1864 | |
| 1865 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 1866 | ASSERT_TRUE(annot); |
| 1867 | |
| 1868 | EXPECT_EQ(26, FPDFAnnot_GetOptionCount(form_handle(), annot.get())); |
Lei Zhang | e7033c8 | 2019-02-26 19:30:49 +0000 | [diff] [blame] | 1869 | |
| 1870 | // Check bad form handle / annot. |
| 1871 | EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(nullptr, nullptr)); |
| 1872 | EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), nullptr)); |
| 1873 | EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(nullptr, annot.get())); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | UnloadPage(page); |
| 1877 | } |
| 1878 | |
| 1879 | TEST_F(FPDFAnnotEmbedderTest, GetOptionCountListbox) { |
| 1880 | // Open a file with listbox widget annotations and load its first page. |
| 1881 | ASSERT_TRUE(OpenDocument("listbox_form.pdf")); |
| 1882 | FPDF_PAGE page = LoadPage(0); |
| 1883 | ASSERT_TRUE(page); |
| 1884 | |
| 1885 | { |
| 1886 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 1887 | ASSERT_TRUE(annot); |
| 1888 | |
| 1889 | EXPECT_EQ(3, FPDFAnnot_GetOptionCount(form_handle(), annot.get())); |
| 1890 | |
| 1891 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 1892 | ASSERT_TRUE(annot); |
| 1893 | |
| 1894 | EXPECT_EQ(26, FPDFAnnot_GetOptionCount(form_handle(), annot.get())); |
| 1895 | } |
| 1896 | |
| 1897 | UnloadPage(page); |
| 1898 | } |
| 1899 | |
| 1900 | TEST_F(FPDFAnnotEmbedderTest, GetOptionCountInvalidAnnotations) { |
| 1901 | // Open a file with ink annotations and load its first page. |
| 1902 | ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); |
| 1903 | FPDF_PAGE page = LoadPage(0); |
| 1904 | ASSERT_TRUE(page); |
| 1905 | |
| 1906 | { |
| 1907 | // annotations do not have "Opt" array and will return -1 |
| 1908 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 1909 | ASSERT_TRUE(annot); |
| 1910 | |
| 1911 | EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), annot.get())); |
| 1912 | |
| 1913 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 1914 | ASSERT_TRUE(annot); |
| 1915 | |
| 1916 | EXPECT_EQ(-1, FPDFAnnot_GetOptionCount(form_handle(), annot.get())); |
| 1917 | } |
| 1918 | |
| 1919 | UnloadPage(page); |
| 1920 | } |
| 1921 | |
| 1922 | TEST_F(FPDFAnnotEmbedderTest, GetOptionLabelCombobox) { |
| 1923 | // Open a file with combobox widget annotations and load its first page. |
| 1924 | ASSERT_TRUE(OpenDocument("combobox_form.pdf")); |
| 1925 | FPDF_PAGE page = LoadPage(0); |
| 1926 | ASSERT_TRUE(page); |
| 1927 | |
| 1928 | { |
| 1929 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 1930 | ASSERT_TRUE(annot); |
| 1931 | |
| 1932 | int index = 0; |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1933 | unsigned long length_bytes = |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1934 | FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1935 | ASSERT_EQ(8u, length_bytes); |
| 1936 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1937 | EXPECT_EQ(8u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1938 | buf.data(), length_bytes)); |
| 1939 | EXPECT_EQ(L"Foo", GetPlatformWString(buf.data())); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1940 | |
| 1941 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 1942 | ASSERT_TRUE(annot); |
| 1943 | |
| 1944 | index = 0; |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1945 | length_bytes = |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1946 | FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1947 | ASSERT_EQ(12u, length_bytes); |
| 1948 | buf = GetFPDFWideStringBuffer(length_bytes); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1949 | EXPECT_EQ(12u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1950 | buf.data(), length_bytes)); |
| 1951 | EXPECT_EQ(L"Apple", GetPlatformWString(buf.data())); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1952 | |
| 1953 | index = 25; |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1954 | length_bytes = |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1955 | FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1956 | buf = GetFPDFWideStringBuffer(length_bytes); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1957 | EXPECT_EQ(18u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1958 | buf.data(), length_bytes)); |
| 1959 | EXPECT_EQ(L"Zucchini", GetPlatformWString(buf.data())); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1960 | |
Lei Zhang | e7033c8 | 2019-02-26 19:30:49 +0000 | [diff] [blame] | 1961 | // Indices out of range |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1962 | EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), -1, |
| 1963 | nullptr, 0)); |
| 1964 | EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 26, |
| 1965 | nullptr, 0)); |
Lei Zhang | e7033c8 | 2019-02-26 19:30:49 +0000 | [diff] [blame] | 1966 | |
| 1967 | // Check bad form handle / annot. |
| 1968 | EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(nullptr, nullptr, 0, nullptr, 0)); |
| 1969 | EXPECT_EQ(0u, |
| 1970 | FPDFAnnot_GetOptionLabel(nullptr, annot.get(), 0, nullptr, 0)); |
| 1971 | EXPECT_EQ(0u, |
| 1972 | FPDFAnnot_GetOptionLabel(form_handle(), nullptr, 0, nullptr, 0)); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | UnloadPage(page); |
| 1976 | } |
| 1977 | |
| 1978 | TEST_F(FPDFAnnotEmbedderTest, GetOptionLabelListbox) { |
| 1979 | // Open a file with listbox widget annotations and load its first page. |
| 1980 | ASSERT_TRUE(OpenDocument("listbox_form.pdf")); |
| 1981 | FPDF_PAGE page = LoadPage(0); |
| 1982 | ASSERT_TRUE(page); |
| 1983 | |
| 1984 | { |
| 1985 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 1986 | ASSERT_TRUE(annot); |
| 1987 | |
| 1988 | int index = 0; |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1989 | unsigned long length_bytes = |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1990 | FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1991 | ASSERT_EQ(8u, length_bytes); |
| 1992 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1993 | EXPECT_EQ(8u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 1994 | buf.data(), length_bytes)); |
| 1995 | EXPECT_EQ(L"Foo", GetPlatformWString(buf.data())); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 1996 | |
| 1997 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 1998 | ASSERT_TRUE(annot); |
| 1999 | |
| 2000 | index = 0; |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 2001 | length_bytes = |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 2002 | FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 2003 | ASSERT_EQ(12u, length_bytes); |
| 2004 | buf = GetFPDFWideStringBuffer(length_bytes); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 2005 | EXPECT_EQ(12u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 2006 | buf.data(), length_bytes)); |
| 2007 | EXPECT_EQ(L"Apple", GetPlatformWString(buf.data())); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 2008 | |
| 2009 | index = 25; |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 2010 | length_bytes = |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 2011 | FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, nullptr, 0); |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 2012 | ASSERT_EQ(18u, length_bytes); |
| 2013 | buf = GetFPDFWideStringBuffer(length_bytes); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 2014 | EXPECT_EQ(18u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), index, |
Lei Zhang | 5bf8c7f | 2019-04-08 17:50:11 +0000 | [diff] [blame] | 2015 | buf.data(), length_bytes)); |
| 2016 | EXPECT_EQ(L"Zucchini", GetPlatformWString(buf.data())); |
rycsmith | cb752f3 | 2019-02-21 18:40:53 +0000 | [diff] [blame] | 2017 | |
| 2018 | // indices out of range |
| 2019 | EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), -1, |
| 2020 | nullptr, 0)); |
| 2021 | EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 26, |
| 2022 | nullptr, 0)); |
| 2023 | } |
| 2024 | |
| 2025 | UnloadPage(page); |
| 2026 | } |
| 2027 | |
| 2028 | TEST_F(FPDFAnnotEmbedderTest, GetOptionLabelInvalidAnnotations) { |
| 2029 | // Open a file with ink annotations and load its first page. |
| 2030 | ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); |
| 2031 | FPDF_PAGE page = LoadPage(0); |
| 2032 | ASSERT_TRUE(page); |
| 2033 | |
| 2034 | { |
| 2035 | // annotations do not have "Opt" array and will return 0 |
| 2036 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2037 | ASSERT_TRUE(annot); |
| 2038 | |
| 2039 | EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 0, |
| 2040 | nullptr, 0)); |
| 2041 | |
| 2042 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 2043 | ASSERT_TRUE(annot); |
| 2044 | |
| 2045 | EXPECT_EQ(0u, FPDFAnnot_GetOptionLabel(form_handle(), annot.get(), 0, |
| 2046 | nullptr, 0)); |
| 2047 | } |
| 2048 | |
| 2049 | UnloadPage(page); |
| 2050 | } |
Ryan Smith | 09c23b1 | 2019-04-25 18:09:06 +0000 | [diff] [blame] | 2051 | |
| 2052 | TEST_F(FPDFAnnotEmbedderTest, GetFontSizeCombobox) { |
| 2053 | // Open a file with combobox annotations and load its first page. |
| 2054 | ASSERT_TRUE(OpenDocument("combobox_form.pdf")); |
| 2055 | FPDF_PAGE page = LoadPage(0); |
| 2056 | ASSERT_TRUE(page); |
| 2057 | |
| 2058 | { |
| 2059 | // All 3 widgets have Tf font size 12. |
| 2060 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2061 | ASSERT_TRUE(annot); |
| 2062 | |
| 2063 | float value; |
| 2064 | ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value)); |
| 2065 | EXPECT_EQ(12.0, value); |
| 2066 | |
| 2067 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 2068 | ASSERT_TRUE(annot); |
| 2069 | |
| 2070 | float value_two; |
| 2071 | ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_two)); |
| 2072 | EXPECT_EQ(12.0, value_two); |
| 2073 | |
| 2074 | annot.reset(FPDFPage_GetAnnot(page, 2)); |
| 2075 | ASSERT_TRUE(annot); |
| 2076 | |
| 2077 | float value_three; |
| 2078 | ASSERT_TRUE( |
| 2079 | FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_three)); |
| 2080 | EXPECT_EQ(12.0, value_three); |
| 2081 | } |
| 2082 | |
| 2083 | UnloadPage(page); |
| 2084 | } |
| 2085 | |
| 2086 | TEST_F(FPDFAnnotEmbedderTest, GetFontSizeTextField) { |
| 2087 | // Open a file with textfield annotations and load its first page. |
| 2088 | ASSERT_TRUE(OpenDocument("text_form_multiple.pdf")); |
| 2089 | FPDF_PAGE page = LoadPage(0); |
| 2090 | ASSERT_TRUE(page); |
| 2091 | |
| 2092 | { |
Mansi Awasthi | 0b5da67 | 2020-01-23 18:17:18 +0000 | [diff] [blame] | 2093 | // All 4 widgets have Tf font size 12. |
Ryan Smith | 09c23b1 | 2019-04-25 18:09:06 +0000 | [diff] [blame] | 2094 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2095 | ASSERT_TRUE(annot); |
| 2096 | |
| 2097 | float value; |
| 2098 | ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value)); |
| 2099 | EXPECT_EQ(12.0, value); |
| 2100 | |
| 2101 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 2102 | ASSERT_TRUE(annot); |
| 2103 | |
| 2104 | float value_two; |
| 2105 | ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_two)); |
| 2106 | EXPECT_EQ(12.0, value_two); |
| 2107 | |
| 2108 | annot.reset(FPDFPage_GetAnnot(page, 2)); |
| 2109 | ASSERT_TRUE(annot); |
| 2110 | |
| 2111 | float value_three; |
| 2112 | ASSERT_TRUE( |
| 2113 | FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_three)); |
| 2114 | EXPECT_EQ(12.0, value_three); |
Mansi Awasthi | 0b5da67 | 2020-01-23 18:17:18 +0000 | [diff] [blame] | 2115 | |
| 2116 | float value_four; |
| 2117 | ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_four)); |
| 2118 | EXPECT_EQ(12.0, value_four); |
Ryan Smith | 09c23b1 | 2019-04-25 18:09:06 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | UnloadPage(page); |
| 2122 | } |
| 2123 | |
| 2124 | TEST_F(FPDFAnnotEmbedderTest, GetFontSizeInvalidAnnotationTypes) { |
| 2125 | // Open a file with ink annotations and load its first page. |
| 2126 | ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf")); |
| 2127 | FPDF_PAGE page = LoadPage(0); |
| 2128 | ASSERT_TRUE(page); |
| 2129 | |
| 2130 | { |
| 2131 | // Annotations that do not have variable text and will return -1. |
| 2132 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2133 | ASSERT_TRUE(annot); |
| 2134 | |
| 2135 | float value; |
| 2136 | ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value)); |
| 2137 | |
| 2138 | annot.reset(FPDFPage_GetAnnot(page, 1)); |
| 2139 | ASSERT_TRUE(annot); |
| 2140 | |
| 2141 | ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value)); |
| 2142 | } |
| 2143 | |
| 2144 | UnloadPage(page); |
| 2145 | } |
| 2146 | |
| 2147 | TEST_F(FPDFAnnotEmbedderTest, GetFontSizeInvalidArguments) { |
| 2148 | // Open a file with combobox annotations and load its first page. |
| 2149 | ASSERT_TRUE(OpenDocument("combobox_form.pdf")); |
| 2150 | FPDF_PAGE page = LoadPage(0); |
| 2151 | ASSERT_TRUE(page); |
| 2152 | |
| 2153 | { |
| 2154 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2155 | ASSERT_TRUE(annot); |
| 2156 | |
| 2157 | // Check bad form handle / annot. |
| 2158 | float value; |
| 2159 | ASSERT_FALSE(FPDFAnnot_GetFontSize(nullptr, annot.get(), &value)); |
| 2160 | ASSERT_FALSE(FPDFAnnot_GetFontSize(form_handle(), nullptr, &value)); |
| 2161 | ASSERT_FALSE(FPDFAnnot_GetFontSize(nullptr, nullptr, &value)); |
| 2162 | } |
| 2163 | |
| 2164 | UnloadPage(page); |
| 2165 | } |
| 2166 | |
| 2167 | TEST_F(FPDFAnnotEmbedderTest, GetFontSizeNegative) { |
| 2168 | // Open a file with textfield annotations and load its first page. |
| 2169 | ASSERT_TRUE(OpenDocument("text_form_negative_fontsize.pdf")); |
| 2170 | FPDF_PAGE page = LoadPage(0); |
| 2171 | ASSERT_TRUE(page); |
| 2172 | |
| 2173 | { |
| 2174 | // Obtain the first annotation, a text field with negative font size, -12. |
| 2175 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2176 | ASSERT_TRUE(annot); |
| 2177 | |
| 2178 | float value; |
| 2179 | ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value)); |
| 2180 | EXPECT_EQ(-12.0, value); |
| 2181 | } |
| 2182 | |
| 2183 | UnloadPage(page); |
| 2184 | } |
Ryan Smith | 23fdf89 | 2019-07-17 21:51:26 +0000 | [diff] [blame] | 2185 | |
| 2186 | TEST_F(FPDFAnnotEmbedderTest, IsCheckedCheckbox) { |
| 2187 | // Open a file with checkbox and radiobuttons widget annotations and load its |
| 2188 | // first page. |
| 2189 | ASSERT_TRUE(OpenDocument("click_form.pdf")); |
| 2190 | FPDF_PAGE page = LoadPage(0); |
| 2191 | ASSERT_TRUE(page); |
| 2192 | |
| 2193 | { |
| 2194 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); |
| 2195 | ASSERT_TRUE(annot); |
| 2196 | ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2197 | } |
| 2198 | |
| 2199 | UnloadPage(page); |
| 2200 | } |
| 2201 | |
| 2202 | TEST_F(FPDFAnnotEmbedderTest, IsCheckedCheckboxReadOnly) { |
| 2203 | // Open a file with checkbox and radiobutton widget annotations and load its |
| 2204 | // first page. |
| 2205 | ASSERT_TRUE(OpenDocument("click_form.pdf")); |
| 2206 | FPDF_PAGE page = LoadPage(0); |
| 2207 | ASSERT_TRUE(page); |
| 2208 | |
| 2209 | { |
| 2210 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2211 | ASSERT_TRUE(annot); |
| 2212 | ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2213 | } |
| 2214 | |
| 2215 | UnloadPage(page); |
| 2216 | } |
| 2217 | |
| 2218 | TEST_F(FPDFAnnotEmbedderTest, IsCheckedRadioButton) { |
| 2219 | // Open a file with checkbox and radiobutton widget annotations and load its |
| 2220 | // first page. |
| 2221 | ASSERT_TRUE(OpenDocument("click_form.pdf")); |
| 2222 | FPDF_PAGE page = LoadPage(0); |
| 2223 | ASSERT_TRUE(page); |
| 2224 | |
| 2225 | { |
| 2226 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 5)); |
| 2227 | ASSERT_TRUE(annot); |
| 2228 | ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2229 | |
| 2230 | annot.reset(FPDFPage_GetAnnot(page, 6)); |
| 2231 | ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2232 | |
| 2233 | annot.reset(FPDFPage_GetAnnot(page, 7)); |
| 2234 | ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2235 | } |
| 2236 | |
| 2237 | UnloadPage(page); |
| 2238 | } |
| 2239 | |
| 2240 | TEST_F(FPDFAnnotEmbedderTest, IsCheckedRadioButtonReadOnly) { |
| 2241 | // Open a file with checkbox and radiobutton widget annotations and load its |
| 2242 | // first page. |
| 2243 | ASSERT_TRUE(OpenDocument("click_form.pdf")); |
| 2244 | FPDF_PAGE page = LoadPage(0); |
| 2245 | ASSERT_TRUE(page); |
| 2246 | |
| 2247 | { |
| 2248 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
| 2249 | ASSERT_TRUE(annot); |
| 2250 | ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2251 | |
| 2252 | annot.reset(FPDFPage_GetAnnot(page, 3)); |
| 2253 | ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2254 | |
| 2255 | annot.reset(FPDFPage_GetAnnot(page, 4)); |
| 2256 | ASSERT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2257 | } |
| 2258 | |
| 2259 | UnloadPage(page); |
| 2260 | } |
| 2261 | |
| 2262 | TEST_F(FPDFAnnotEmbedderTest, IsCheckedInvalidArguments) { |
| 2263 | // Open a file with checkbox and radiobuttons widget annotations and load its |
| 2264 | // first page. |
| 2265 | ASSERT_TRUE(OpenDocument("click_form.pdf")); |
| 2266 | FPDF_PAGE page = LoadPage(0); |
| 2267 | ASSERT_TRUE(page); |
| 2268 | |
| 2269 | { |
| 2270 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2271 | ASSERT_TRUE(annot); |
| 2272 | ASSERT_FALSE(FPDFAnnot_IsChecked(nullptr, annot.get())); |
| 2273 | ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), nullptr)); |
| 2274 | ASSERT_FALSE(FPDFAnnot_IsChecked(nullptr, nullptr)); |
| 2275 | } |
| 2276 | |
| 2277 | UnloadPage(page); |
| 2278 | } |
| 2279 | |
| 2280 | TEST_F(FPDFAnnotEmbedderTest, IsCheckedInvalidWidgetType) { |
| 2281 | // Open a file with text widget annotations and load its first page. |
| 2282 | ASSERT_TRUE(OpenDocument("text_form.pdf")); |
| 2283 | FPDF_PAGE page = LoadPage(0); |
| 2284 | ASSERT_TRUE(page); |
| 2285 | |
| 2286 | { |
| 2287 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2288 | ASSERT_TRUE(annot); |
| 2289 | ASSERT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot.get())); |
| 2290 | } |
| 2291 | |
| 2292 | UnloadPage(page); |
| 2293 | } |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2294 | |
Ankit Kumar | 8c7e4ad | 2020-02-07 08:56:49 +0000 | [diff] [blame] | 2295 | TEST_F(FPDFAnnotEmbedderTest, GetFormFieldType) { |
| 2296 | ASSERT_TRUE(OpenDocument("multiple_form_types.pdf")); |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2297 | FPDF_PAGE page = LoadPage(0); |
| 2298 | ASSERT_TRUE(page); |
| 2299 | |
Ankit Kumar | 8c7e4ad | 2020-02-07 08:56:49 +0000 | [diff] [blame] | 2300 | EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(form_handle(), nullptr)); |
| 2301 | |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2302 | { |
Ankit Kumar | 8c7e4ad | 2020-02-07 08:56:49 +0000 | [diff] [blame] | 2303 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2304 | ASSERT_TRUE(annot); |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2305 | EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(nullptr, annot.get())); |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2306 | } |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2307 | |
Ankit Kumar | 8c7e4ad | 2020-02-07 08:56:49 +0000 | [diff] [blame] | 2308 | constexpr int kExpectedAnnotTypes[] = {-1, |
| 2309 | FPDF_FORMFIELD_COMBOBOX, |
| 2310 | FPDF_FORMFIELD_LISTBOX, |
| 2311 | FPDF_FORMFIELD_TEXTFIELD, |
| 2312 | FPDF_FORMFIELD_CHECKBOX, |
| 2313 | FPDF_FORMFIELD_RADIOBUTTON}; |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2314 | |
Ankit Kumar | 8c7e4ad | 2020-02-07 08:56:49 +0000 | [diff] [blame] | 2315 | for (size_t i = 0; i < FX_ArraySize(kExpectedAnnotTypes); ++i) { |
| 2316 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i)); |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2317 | ASSERT_TRUE(annot); |
Ankit Kumar | 8c7e4ad | 2020-02-07 08:56:49 +0000 | [diff] [blame] | 2318 | EXPECT_EQ(kExpectedAnnotTypes[i], |
Mansi Awasthi | 07bf7e6 | 2020-01-24 10:34:17 +0000 | [diff] [blame] | 2319 | FPDFAnnot_GetFormFieldType(form_handle(), annot.get())); |
| 2320 | } |
| 2321 | UnloadPage(page); |
| 2322 | } |
| 2323 | |
| 2324 | TEST_F(FPDFAnnotEmbedderTest, GetFormFieldValueTextField) { |
| 2325 | ASSERT_TRUE(OpenDocument("text_form_multiple.pdf")); |
| 2326 | FPDF_PAGE page = LoadPage(0); |
| 2327 | ASSERT_TRUE(page); |
| 2328 | |
| 2329 | { |
| 2330 | EXPECT_EQ(0u, |
| 2331 | FPDFAnnot_GetFormFieldValue(form_handle(), nullptr, nullptr, 0)); |
| 2332 | |
| 2333 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2334 | ASSERT_TRUE(annot); |
| 2335 | |
| 2336 | EXPECT_EQ(0u, |
| 2337 | FPDFAnnot_GetFormFieldValue(nullptr, annot.get(), nullptr, 0)); |
| 2338 | |
| 2339 | unsigned long length_bytes = |
| 2340 | FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(), nullptr, 0); |
| 2341 | ASSERT_EQ(2u, length_bytes); |
| 2342 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
| 2343 | EXPECT_EQ(2u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(), |
| 2344 | buf.data(), length_bytes)); |
| 2345 | EXPECT_EQ(L"", GetPlatformWString(buf.data())); |
| 2346 | } |
| 2347 | { |
| 2348 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 2)); |
| 2349 | ASSERT_TRUE(annot); |
| 2350 | |
| 2351 | unsigned long length_bytes = |
| 2352 | FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(), nullptr, 0); |
| 2353 | ASSERT_EQ(18u, length_bytes); |
| 2354 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
| 2355 | EXPECT_EQ(18u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(), |
| 2356 | buf.data(), length_bytes)); |
| 2357 | EXPECT_EQ(L"Elephant", GetPlatformWString(buf.data())); |
| 2358 | } |
| 2359 | UnloadPage(page); |
| 2360 | } |
| 2361 | |
| 2362 | TEST_F(FPDFAnnotEmbedderTest, GetFormFieldValueComboBox) { |
| 2363 | ASSERT_TRUE(OpenDocument("combobox_form.pdf")); |
| 2364 | FPDF_PAGE page = LoadPage(0); |
| 2365 | ASSERT_TRUE(page); |
| 2366 | |
| 2367 | { |
| 2368 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2369 | ASSERT_TRUE(annot); |
| 2370 | |
| 2371 | unsigned long length_bytes = |
| 2372 | FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(), nullptr, 0); |
| 2373 | ASSERT_EQ(2u, length_bytes); |
| 2374 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
| 2375 | EXPECT_EQ(2u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(), |
| 2376 | buf.data(), length_bytes)); |
| 2377 | EXPECT_EQ(L"", GetPlatformWString(buf.data())); |
| 2378 | } |
| 2379 | { |
| 2380 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1)); |
| 2381 | ASSERT_TRUE(annot); |
| 2382 | |
| 2383 | unsigned long length_bytes = |
| 2384 | FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(), nullptr, 0); |
| 2385 | ASSERT_EQ(14u, length_bytes); |
| 2386 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
| 2387 | EXPECT_EQ(14u, FPDFAnnot_GetFormFieldValue(form_handle(), annot.get(), |
| 2388 | buf.data(), length_bytes)); |
| 2389 | EXPECT_EQ(L"Banana", GetPlatformWString(buf.data())); |
| 2390 | } |
| 2391 | UnloadPage(page); |
| 2392 | } |
| 2393 | |
| 2394 | TEST_F(FPDFAnnotEmbedderTest, GetFormFieldNameTextField) { |
| 2395 | ASSERT_TRUE(OpenDocument("text_form.pdf")); |
| 2396 | FPDF_PAGE page = LoadPage(0); |
| 2397 | ASSERT_TRUE(page); |
| 2398 | |
| 2399 | { |
| 2400 | EXPECT_EQ(0u, |
| 2401 | FPDFAnnot_GetFormFieldName(form_handle(), nullptr, nullptr, 0)); |
| 2402 | |
| 2403 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2404 | ASSERT_TRUE(annot); |
| 2405 | |
| 2406 | EXPECT_EQ(0u, FPDFAnnot_GetFormFieldName(nullptr, annot.get(), nullptr, 0)); |
| 2407 | |
| 2408 | unsigned long length_bytes = |
| 2409 | FPDFAnnot_GetFormFieldName(form_handle(), annot.get(), nullptr, 0); |
| 2410 | ASSERT_EQ(18u, length_bytes); |
| 2411 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
| 2412 | EXPECT_EQ(18u, FPDFAnnot_GetFormFieldName(form_handle(), annot.get(), |
| 2413 | buf.data(), length_bytes)); |
| 2414 | EXPECT_EQ(L"Text Box", GetPlatformWString(buf.data())); |
| 2415 | } |
| 2416 | UnloadPage(page); |
| 2417 | } |
| 2418 | |
| 2419 | TEST_F(FPDFAnnotEmbedderTest, GetFormFieldNameComboBox) { |
| 2420 | ASSERT_TRUE(OpenDocument("combobox_form.pdf")); |
| 2421 | FPDF_PAGE page = LoadPage(0); |
| 2422 | ASSERT_TRUE(page); |
| 2423 | |
| 2424 | { |
| 2425 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2426 | ASSERT_TRUE(annot); |
| 2427 | |
| 2428 | unsigned long length_bytes = |
| 2429 | FPDFAnnot_GetFormFieldName(form_handle(), annot.get(), nullptr, 0); |
| 2430 | ASSERT_EQ(30u, length_bytes); |
| 2431 | std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes); |
| 2432 | EXPECT_EQ(30u, FPDFAnnot_GetFormFieldName(form_handle(), annot.get(), |
| 2433 | buf.data(), length_bytes)); |
| 2434 | EXPECT_EQ(L"Combo_Editable", GetPlatformWString(buf.data())); |
| 2435 | } |
| 2436 | UnloadPage(page); |
| 2437 | } |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2438 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2439 | TEST_F(FPDFAnnotEmbedderTest, FocusableAnnotSubtypes) { |
| 2440 | ASSERT_TRUE(OpenDocument("annots.pdf")); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2441 | FPDF_PAGE page = LoadPage(0); |
| 2442 | ASSERT_TRUE(page); |
| 2443 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2444 | // Verify widgets are by default focusable. |
| 2445 | const FPDF_ANNOTATION_SUBTYPE kDefaultSubtypes[] = {FPDF_ANNOT_WIDGET}; |
| 2446 | VerifyFocusableAnnotSubtypes(form_handle(), kDefaultSubtypes); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2447 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2448 | // Expected annot subtypes for page 0 of annots.pdf. |
| 2449 | const FPDF_ANNOTATION_SUBTYPE kExpectedAnnotSubtypes[] = { |
| 2450 | FPDF_ANNOT_LINK, FPDF_ANNOT_LINK, FPDF_ANNOT_LINK, |
| 2451 | FPDF_ANNOT_LINK, FPDF_ANNOT_HIGHLIGHT, FPDF_ANNOT_HIGHLIGHT, |
| 2452 | FPDF_ANNOT_POPUP, FPDF_ANNOT_HIGHLIGHT, FPDF_ANNOT_WIDGET, |
| 2453 | }; |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2454 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2455 | const FPDF_ANNOTATION_SUBTYPE kExpectedDefaultFocusableSubtypes[] = { |
Ankit Kumar | 69cab67 | 2020-04-20 19:50:41 +0000 | [diff] [blame] | 2456 | FPDF_ANNOT_WIDGET}; |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2457 | VerifyAnnotationSubtypesAndFocusability(form_handle(), page, |
| 2458 | kExpectedAnnotSubtypes, |
| 2459 | kExpectedDefaultFocusableSubtypes); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2460 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2461 | // Make no annotation type focusable using the preferred method. |
| 2462 | ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes(form_handle(), nullptr, 0)); |
| 2463 | ASSERT_EQ(0, FPDFAnnot_GetFocusableSubtypesCount(form_handle())); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2464 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2465 | // Restore the focusable type count back to 1, then set it back to 0 using a |
| 2466 | // different method. |
| 2467 | SetAndVerifyFocusableAnnotSubtypes(form_handle(), kDefaultSubtypes); |
| 2468 | ASSERT_TRUE( |
| 2469 | FPDFAnnot_SetFocusableSubtypes(form_handle(), kDefaultSubtypes, 0)); |
| 2470 | ASSERT_EQ(0, FPDFAnnot_GetFocusableSubtypesCount(form_handle())); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2471 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2472 | VerifyAnnotationSubtypesAndFocusability(form_handle(), page, |
Ankit Kumar | 906ac57 | 2020-04-21 05:58:04 +0000 | [diff] [blame] | 2473 | kExpectedAnnotSubtypes, {}); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2474 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2475 | // Now make links focusable. |
| 2476 | const FPDF_ANNOTATION_SUBTYPE kLinkSubtypes[] = {FPDF_ANNOT_LINK}; |
| 2477 | SetAndVerifyFocusableAnnotSubtypes(form_handle(), kLinkSubtypes); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2478 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2479 | const FPDF_ANNOTATION_SUBTYPE kExpectedLinkocusableSubtypes[] = { |
Ankit Kumar | 906ac57 | 2020-04-21 05:58:04 +0000 | [diff] [blame] | 2480 | FPDF_ANNOT_LINK}; |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2481 | VerifyAnnotationSubtypesAndFocusability(form_handle(), page, |
| 2482 | kExpectedAnnotSubtypes, |
| 2483 | kExpectedLinkocusableSubtypes); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2484 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2485 | // Test invalid parameters. |
| 2486 | EXPECT_FALSE(FPDFAnnot_SetFocusableSubtypes(nullptr, kDefaultSubtypes, |
| 2487 | FX_ArraySize(kDefaultSubtypes))); |
| 2488 | EXPECT_FALSE(FPDFAnnot_SetFocusableSubtypes(form_handle(), nullptr, |
| 2489 | FX_ArraySize(kDefaultSubtypes))); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2490 | EXPECT_EQ(-1, FPDFAnnot_GetFocusableSubtypesCount(nullptr)); |
| 2491 | |
Lei Zhang | 9b44400 | 2020-04-17 17:35:23 +0000 | [diff] [blame] | 2492 | std::vector<FPDF_ANNOTATION_SUBTYPE> subtypes(1); |
| 2493 | EXPECT_FALSE(FPDFAnnot_GetFocusableSubtypes(nullptr, subtypes.data(), |
| 2494 | subtypes.size())); |
| 2495 | EXPECT_FALSE( |
| 2496 | FPDFAnnot_GetFocusableSubtypes(form_handle(), nullptr, subtypes.size())); |
| 2497 | EXPECT_FALSE( |
| 2498 | FPDFAnnot_GetFocusableSubtypes(form_handle(), subtypes.data(), 0)); |
Neha Gupta | 1eb6ddd | 2020-03-19 08:37:15 +0000 | [diff] [blame] | 2499 | |
| 2500 | UnloadPage(page); |
| 2501 | } |
Lei Zhang | 671aece | 2020-04-14 19:02:26 +0000 | [diff] [blame] | 2502 | |
Hui Yingst | 609f7d6 | 2020-04-23 23:14:13 +0000 | [diff] [blame] | 2503 | // TODO(crbug.com/pdfium/11): Fix this test and enable. |
| 2504 | #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_) |
| 2505 | #define MAYBE_FocusableAnnotRendering DISABLED_FocusableAnnotRendering |
| 2506 | #else |
| 2507 | #define MAYBE_FocusableAnnotRendering FocusableAnnotRendering |
| 2508 | #endif |
| 2509 | TEST_F(FPDFAnnotEmbedderTest, MAYBE_FocusableAnnotRendering) { |
Lei Zhang | 671aece | 2020-04-14 19:02:26 +0000 | [diff] [blame] | 2510 | ASSERT_TRUE(OpenDocument("annots.pdf")); |
| 2511 | FPDF_PAGE page = LoadPage(0); |
| 2512 | ASSERT_TRUE(page); |
| 2513 | |
| 2514 | { |
| 2515 | #if defined(OS_WIN) |
| 2516 | static const char kMd5sum[] = "3877bec7cb3e3144eaa6d10f38bf7a30"; |
| 2517 | #elif defined(OS_MACOSX) |
| 2518 | static const char kMd5sum[] = "04b16db5026b5490a50fb6ff0954c867"; |
| 2519 | #else |
| 2520 | static const char kMd5sum[] = "40a7354d1f653127bcdac10e15f81654"; |
| 2521 | #endif |
| 2522 | // Check the initial rendering. |
| 2523 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
| 2524 | CompareBitmap(bitmap.get(), 612, 792, kMd5sum); |
| 2525 | } |
| 2526 | |
| 2527 | // Make links and highlights focusable. |
| 2528 | static constexpr FPDF_ANNOTATION_SUBTYPE kSubTypes[] = {FPDF_ANNOT_LINK, |
| 2529 | FPDF_ANNOT_HIGHLIGHT}; |
| 2530 | constexpr int kSubTypesCount = FX_ArraySize(kSubTypes); |
| 2531 | ASSERT_TRUE( |
| 2532 | FPDFAnnot_SetFocusableSubtypes(form_handle(), kSubTypes, kSubTypesCount)); |
| 2533 | ASSERT_EQ(kSubTypesCount, FPDFAnnot_GetFocusableSubtypesCount(form_handle())); |
| 2534 | std::vector<FPDF_ANNOTATION_SUBTYPE> subtypes(kSubTypesCount); |
| 2535 | ASSERT_TRUE(FPDFAnnot_GetFocusableSubtypes(form_handle(), subtypes.data(), |
| 2536 | subtypes.size())); |
| 2537 | ASSERT_EQ(FPDF_ANNOT_LINK, subtypes[0]); |
| 2538 | ASSERT_EQ(FPDF_ANNOT_HIGHLIGHT, subtypes[1]); |
| 2539 | |
| 2540 | { |
| 2541 | #if defined(OS_WIN) |
| 2542 | static const char kMd5sum[] = "a30f1bd1cac022d08ceb100df4940b5f"; |
| 2543 | #elif defined(OS_MACOSX) |
| 2544 | static const char kMd5sum[] = "3f984a164f2f6d6e3d69f27fd430e346"; |
| 2545 | #else |
| 2546 | static const char kMd5sum[] = "e4c4de73addabf10672c308870e8a4ee"; |
| 2547 | #endif |
| 2548 | // Focus the first link and check the rendering. |
| 2549 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0)); |
| 2550 | ASSERT_TRUE(annot); |
| 2551 | EXPECT_EQ(FPDF_ANNOT_LINK, FPDFAnnot_GetSubtype(annot.get())); |
| 2552 | EXPECT_TRUE(FORM_SetFocusedAnnot(form_handle(), annot.get())); |
| 2553 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
| 2554 | CompareBitmap(bitmap.get(), 612, 792, kMd5sum); |
| 2555 | } |
| 2556 | |
| 2557 | { |
| 2558 | #if defined(OS_WIN) |
| 2559 | static const char kMd5sum[] = "467f5a4db98fcadd5121807ff4e2eb10"; |
| 2560 | #elif defined(OS_MACOSX) |
| 2561 | static const char kMd5sum[] = "c6d6f9dc7090e8eaf3867ba714023b1e"; |
| 2562 | #else |
| 2563 | static const char kMd5sum[] = "65e831885e16b7ecc977cce2e4a27110"; |
| 2564 | #endif |
| 2565 | // Focus the first highlight and check the rendering. |
| 2566 | ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 4)); |
| 2567 | ASSERT_TRUE(annot); |
| 2568 | EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot.get())); |
| 2569 | EXPECT_TRUE(FORM_SetFocusedAnnot(form_handle(), annot.get())); |
| 2570 | ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT); |
| 2571 | CompareBitmap(bitmap.get(), 612, 792, kMd5sum); |
| 2572 | } |
| 2573 | |
| 2574 | UnloadPage(page); |
| 2575 | } |