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