Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 1 | // Copyright 2016 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 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 5 | #include <memory> |
| 6 | #include <string> |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 7 | #include <utility> |
Jane Liu | 548334e | 2017-08-03 16:33:40 -0400 | [diff] [blame] | 8 | #include <vector> |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 10 | #include "core/fpdfapi/font/cpdf_font.h" |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 11 | #include "core/fpdfapi/page/cpdf_page.h" |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_array.h" |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_number.h" |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_stream.h" |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 16 | #include "core/fxcrt/fx_system.h" |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 17 | #include "fpdfsdk/fsdk_define.h" |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 18 | #include "public/cpp/fpdf_deleters.h" |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 19 | #include "public/fpdf_annot.h" |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 20 | #include "public/fpdf_edit.h" |
| 21 | #include "public/fpdfview.h" |
| 22 | #include "testing/embedder_test.h" |
Tom Sepez | 0aec19b | 2016-01-07 12:22:44 -0800 | [diff] [blame] | 23 | #include "testing/gmock/include/gmock/gmock-matchers.h" |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 24 | #include "testing/gtest/include/gtest/gtest.h" |
Tom Sepez | 0aec19b | 2016-01-07 12:22:44 -0800 | [diff] [blame] | 25 | #include "testing/test_support.h" |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 26 | |
Nicolas Pena | 3ff5400 | 2017-07-05 11:55:35 -0400 | [diff] [blame] | 27 | class FPDFEditEmbeddertest : public EmbedderTest { |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 28 | protected: |
| 29 | FPDF_DOCUMENT CreateNewDocument() { |
| 30 | document_ = FPDF_CreateNewDocument(); |
Tom Sepez | 41066c1 | 2017-05-18 09:28:49 -0700 | [diff] [blame] | 31 | cpdf_doc_ = CPDFDocumentFromFPDFDocument(document_); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 32 | return document_; |
| 33 | } |
| 34 | |
| 35 | void CheckFontDescriptor(CPDF_Dictionary* font_dict, |
| 36 | int font_type, |
| 37 | bool bold, |
| 38 | bool italic, |
| 39 | uint32_t size, |
| 40 | const uint8_t* data) { |
| 41 | CPDF_Dictionary* font_desc = font_dict->GetDictFor("FontDescriptor"); |
| 42 | ASSERT_TRUE(font_desc); |
| 43 | EXPECT_EQ("FontDescriptor", font_desc->GetStringFor("Type")); |
| 44 | EXPECT_EQ(font_dict->GetStringFor("BaseFont"), |
| 45 | font_desc->GetStringFor("FontName")); |
| 46 | |
| 47 | // Check that the font descriptor has the required keys according to spec |
| 48 | // 1.7 Table 5.19 |
| 49 | ASSERT_TRUE(font_desc->KeyExist("Flags")); |
Dan Sinclair | 10e1f05 | 2017-09-28 15:59:42 -0400 | [diff] [blame] | 50 | |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 51 | int font_flags = font_desc->GetIntegerFor("Flags"); |
Dan Sinclair | 10e1f05 | 2017-09-28 15:59:42 -0400 | [diff] [blame] | 52 | EXPECT_EQ(bold, FontStyleIsBold(font_flags)); |
| 53 | EXPECT_EQ(italic, FontStyleIsItalic(font_flags)); |
| 54 | EXPECT_TRUE(FontStyleIsNonSymbolic(font_flags)); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 55 | ASSERT_TRUE(font_desc->KeyExist("FontBBox")); |
Nicolás Peña | 5f95f36 | 2017-09-28 13:00:45 +0900 | [diff] [blame] | 56 | |
| 57 | CPDF_Array* fontBBox = font_desc->GetArrayFor("FontBBox"); |
| 58 | ASSERT_TRUE(fontBBox); |
| 59 | EXPECT_EQ(4U, fontBBox->GetCount()); |
| 60 | // Check that the coordinates are in the preferred order according to spec |
| 61 | // 1.7 Section 3.8.4 |
| 62 | EXPECT_TRUE(fontBBox->GetIntegerAt(0) < fontBBox->GetIntegerAt(2)); |
| 63 | EXPECT_TRUE(fontBBox->GetIntegerAt(1) < fontBBox->GetIntegerAt(3)); |
| 64 | |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 65 | EXPECT_TRUE(font_desc->KeyExist("ItalicAngle")); |
| 66 | EXPECT_TRUE(font_desc->KeyExist("Ascent")); |
| 67 | EXPECT_TRUE(font_desc->KeyExist("Descent")); |
| 68 | EXPECT_TRUE(font_desc->KeyExist("CapHeight")); |
| 69 | EXPECT_TRUE(font_desc->KeyExist("StemV")); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 70 | ByteString present("FontFile"); |
| 71 | ByteString absent("FontFile2"); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 72 | if (font_type == FPDF_FONT_TRUETYPE) |
| 73 | std::swap(present, absent); |
| 74 | EXPECT_TRUE(font_desc->KeyExist(present)); |
| 75 | EXPECT_FALSE(font_desc->KeyExist(absent)); |
| 76 | |
| 77 | // Check that the font stream is the one that was provided |
| 78 | CPDF_Stream* font_stream = font_desc->GetStreamFor(present); |
| 79 | ASSERT_EQ(size, font_stream->GetRawSize()); |
Nicolás Peña | 79eab23 | 2017-09-28 13:29:05 +0900 | [diff] [blame] | 80 | if (font_type == FPDF_FONT_TRUETYPE) { |
| 81 | ASSERT_EQ(static_cast<int>(size), |
| 82 | font_stream->GetDict()->GetIntegerFor("Length1")); |
| 83 | } |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 84 | uint8_t* stream_data = font_stream->GetRawData(); |
| 85 | for (size_t j = 0; j < size; j++) |
| 86 | EXPECT_EQ(data[j], stream_data[j]) << " at byte " << j; |
| 87 | } |
| 88 | |
| 89 | void CheckCompositeFontWidths(CPDF_Array* widths_array, |
| 90 | CPDF_Font* typed_font) { |
| 91 | // Check that W array is in a format that conforms to PDF spec 1.7 section |
| 92 | // "Glyph Metrics in CIDFonts" (these checks are not |
| 93 | // implementation-specific). |
| 94 | EXPECT_GT(widths_array->GetCount(), 1U); |
| 95 | int num_cids_checked = 0; |
| 96 | int cur_cid = 0; |
| 97 | for (size_t idx = 0; idx < widths_array->GetCount(); idx++) { |
| 98 | int cid = widths_array->GetNumberAt(idx); |
| 99 | EXPECT_GE(cid, cur_cid); |
| 100 | ASSERT_FALSE(++idx == widths_array->GetCount()); |
| 101 | CPDF_Object* next = widths_array->GetObjectAt(idx); |
| 102 | if (next->IsArray()) { |
| 103 | // We are in the c [w1 w2 ...] case |
| 104 | CPDF_Array* arr = next->AsArray(); |
| 105 | int cnt = static_cast<int>(arr->GetCount()); |
| 106 | size_t inner_idx = 0; |
| 107 | for (cur_cid = cid; cur_cid < cid + cnt; cur_cid++) { |
Nicolas Pena | 2334660 | 2018-01-30 21:42:41 +0000 | [diff] [blame] | 108 | uint32_t width = arr->GetNumberAt(inner_idx++); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 109 | EXPECT_EQ(width, typed_font->GetCharWidthF(cur_cid)) << " at cid " |
| 110 | << cur_cid; |
| 111 | } |
| 112 | num_cids_checked += cnt; |
| 113 | continue; |
| 114 | } |
| 115 | // Otherwise, are in the c_first c_last w case. |
| 116 | ASSERT_TRUE(next->IsNumber()); |
| 117 | int last_cid = next->AsNumber()->GetInteger(); |
| 118 | ASSERT_FALSE(++idx == widths_array->GetCount()); |
Nicolas Pena | 2334660 | 2018-01-30 21:42:41 +0000 | [diff] [blame] | 119 | uint32_t width = widths_array->GetNumberAt(idx); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 120 | for (cur_cid = cid; cur_cid <= last_cid; cur_cid++) { |
| 121 | EXPECT_EQ(width, typed_font->GetCharWidthF(cur_cid)) << " at cid " |
| 122 | << cur_cid; |
| 123 | } |
| 124 | num_cids_checked += last_cid - cid + 1; |
| 125 | } |
| 126 | // Make sure we have a good amount of cids described |
| 127 | EXPECT_GT(num_cids_checked, 900); |
| 128 | } |
| 129 | CPDF_Document* cpdf_doc() { return cpdf_doc_; } |
| 130 | |
| 131 | private: |
| 132 | CPDF_Document* cpdf_doc_; |
| 133 | }; |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 134 | |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 135 | namespace { |
thestig | dc7ec03 | 2016-11-21 15:32:52 -0800 | [diff] [blame] | 136 | |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 137 | const char kExpectedPDF[] = |
| 138 | "%PDF-1.7\r\n" |
| 139 | "%\xA1\xB3\xC5\xD7\r\n" |
| 140 | "1 0 obj\r\n" |
| 141 | "<</Pages 2 0 R /Type/Catalog>>\r\n" |
| 142 | "endobj\r\n" |
| 143 | "2 0 obj\r\n" |
| 144 | "<</Count 1/Kids\\[ 4 0 R \\]/Type/Pages>>\r\n" |
| 145 | "endobj\r\n" |
| 146 | "3 0 obj\r\n" |
| 147 | "<</CreationDate\\(D:.*\\)/Creator\\(PDFium\\)>>\r\n" |
| 148 | "endobj\r\n" |
| 149 | "4 0 obj\r\n" |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 150 | "<</MediaBox\\[ 0 0 640 480\\]/Parent 2 0 R " |
| 151 | "/Resources<</ExtGState<</FXE1 5 0 R >>>>" |
Nicolas Pena | d9d6c29 | 2017-06-06 16:12:10 -0400 | [diff] [blame] | 152 | "/Rotate 0/Type/Page" |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 153 | ">>\r\n" |
| 154 | "endobj\r\n" |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 155 | "5 0 obj\r\n" |
| 156 | "<</BM/Normal/CA 1/ca 1>>\r\n" |
| 157 | "endobj\r\n" |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 158 | "xref\r\n" |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 159 | "0 6\r\n" |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 160 | "0000000000 65535 f\r\n" |
| 161 | "0000000017 00000 n\r\n" |
| 162 | "0000000066 00000 n\r\n" |
| 163 | "0000000122 00000 n\r\n" |
| 164 | "0000000192 00000 n\r\n" |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 165 | "0000000311 00000 n\r\n" |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 166 | "trailer\r\n" |
| 167 | "<<\r\n" |
| 168 | "/Root 1 0 R\r\n" |
| 169 | "/Info 3 0 R\r\n" |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 170 | "/Size 6/ID\\[<.*><.*>\\]>>\r\n" |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 171 | "startxref\r\n" |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 172 | "354\r\n" |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 173 | "%%EOF\r\n"; |
thestig | dc7ec03 | 2016-11-21 15:32:52 -0800 | [diff] [blame] | 174 | |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 175 | } // namespace |
| 176 | |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 177 | TEST_F(FPDFEditEmbeddertest, EmptyCreation) { |
| 178 | EXPECT_TRUE(CreateEmptyDocument()); |
weili | 9b777de | 2016-08-19 16:19:46 -0700 | [diff] [blame] | 179 | FPDF_PAGE page = FPDFPage_New(document(), 0, 640.0, 480.0); |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 180 | EXPECT_NE(nullptr, page); |
Nicolas Pena | d9d6c29 | 2017-06-06 16:12:10 -0400 | [diff] [blame] | 181 | // The FPDFPage_GenerateContent call should do nothing. |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 182 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Tom Sepez | 0aec19b | 2016-01-07 12:22:44 -0800 | [diff] [blame] | 183 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 184 | |
Nicolas Pena | d9d6c29 | 2017-06-06 16:12:10 -0400 | [diff] [blame] | 185 | EXPECT_THAT(GetString(), testing::MatchesRegex(std::string( |
| 186 | kExpectedPDF, sizeof(kExpectedPDF)))); |
weili | 9b777de | 2016-08-19 16:19:46 -0700 | [diff] [blame] | 187 | FPDF_ClosePage(page); |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 188 | } |
thestig | dc7ec03 | 2016-11-21 15:32:52 -0800 | [diff] [blame] | 189 | |
| 190 | // Regression test for https://crbug.com/667012 |
| 191 | TEST_F(FPDFEditEmbeddertest, RasterizePDF) { |
| 192 | const char kAllBlackMd5sum[] = "5708fc5c4a8bd0abde99c8e8f0390615"; |
| 193 | |
| 194 | // Get the bitmap for the original document/ |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 195 | std::unique_ptr<void, FPDFBitmapDeleter> orig_bitmap; |
thestig | dc7ec03 | 2016-11-21 15:32:52 -0800 | [diff] [blame] | 196 | { |
| 197 | EXPECT_TRUE(OpenDocument("black.pdf")); |
| 198 | FPDF_PAGE orig_page = LoadPage(0); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 199 | ASSERT_TRUE(orig_page); |
| 200 | orig_bitmap = RenderLoadedPage(orig_page); |
| 201 | CompareBitmap(orig_bitmap.get(), 612, 792, kAllBlackMd5sum); |
thestig | dc7ec03 | 2016-11-21 15:32:52 -0800 | [diff] [blame] | 202 | UnloadPage(orig_page); |
| 203 | } |
| 204 | |
| 205 | // Create a new document from |orig_bitmap| and save it. |
| 206 | { |
| 207 | FPDF_DOCUMENT temp_doc = FPDF_CreateNewDocument(); |
| 208 | FPDF_PAGE temp_page = FPDFPage_New(temp_doc, 0, 612, 792); |
| 209 | |
| 210 | // Add the bitmap to an image object and add the image object to the output |
| 211 | // page. |
Lei Zhang | cbd8957 | 2017-03-15 17:35:47 -0700 | [diff] [blame] | 212 | FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImageObj(temp_doc); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 213 | EXPECT_TRUE( |
| 214 | FPDFImageObj_SetBitmap(&temp_page, 1, temp_img, orig_bitmap.get())); |
thestig | dc7ec03 | 2016-11-21 15:32:52 -0800 | [diff] [blame] | 215 | EXPECT_TRUE(FPDFImageObj_SetMatrix(temp_img, 612, 0, 0, 792, 0, 0)); |
| 216 | FPDFPage_InsertObject(temp_page, temp_img); |
| 217 | EXPECT_TRUE(FPDFPage_GenerateContent(temp_page)); |
| 218 | EXPECT_TRUE(FPDF_SaveAsCopy(temp_doc, this, 0)); |
| 219 | FPDF_ClosePage(temp_page); |
| 220 | FPDF_CloseDocument(temp_doc); |
| 221 | } |
thestig | dc7ec03 | 2016-11-21 15:32:52 -0800 | [diff] [blame] | 222 | |
| 223 | // Get the generated content. Make sure it is at least as big as the original |
| 224 | // PDF. |
Nicolas Pena | a0b48aa | 2017-06-29 11:01:46 -0400 | [diff] [blame] | 225 | EXPECT_GT(GetString().size(), 923U); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 226 | VerifySavedDocument(612, 792, kAllBlackMd5sum); |
thestig | dc7ec03 | 2016-11-21 15:32:52 -0800 | [diff] [blame] | 227 | } |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 228 | |
| 229 | TEST_F(FPDFEditEmbeddertest, AddPaths) { |
| 230 | // Start with a blank page |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 231 | FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 232 | ASSERT_TRUE(page); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 233 | |
| 234 | // We will first add a red rectangle |
| 235 | FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 236 | ASSERT_TRUE(red_rect); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 237 | // Expect false when trying to set colors out of range |
| 238 | EXPECT_FALSE(FPDFPath_SetStrokeColor(red_rect, 100, 100, 100, 300)); |
| 239 | EXPECT_FALSE(FPDFPath_SetFillColor(red_rect, 200, 256, 200, 0)); |
| 240 | |
| 241 | // Fill rectangle with red and insert to the page |
| 242 | EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); |
| 243 | EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); |
| 244 | FPDFPage_InsertObject(page, red_rect); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 245 | { |
| 246 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 247 | RenderPageWithFlags(page, nullptr, 0); |
| 248 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 249 | "66d02eaa6181e2c069ce2ea99beda497"); |
| 250 | } |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 251 | |
| 252 | // Now add to that a green rectangle with some medium alpha |
| 253 | FPDF_PAGEOBJECT green_rect = FPDFPageObj_CreateNewRect(100, 100, 40, 40); |
| 254 | EXPECT_TRUE(FPDFPath_SetFillColor(green_rect, 0, 255, 0, 128)); |
Miklos Vajna | ed4705b | 2017-04-05 09:24:50 +0200 | [diff] [blame] | 255 | |
Miklos Vajna | 1ef04c9 | 2017-05-08 18:14:19 +0200 | [diff] [blame] | 256 | // Make sure the type of the rectangle is a path. |
| 257 | EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(green_rect)); |
| 258 | |
Miklos Vajna | ed4705b | 2017-04-05 09:24:50 +0200 | [diff] [blame] | 259 | // Make sure we get back the same color we set previously. |
| 260 | unsigned int R; |
| 261 | unsigned int G; |
| 262 | unsigned int B; |
| 263 | unsigned int A; |
| 264 | EXPECT_TRUE(FPDFPath_GetFillColor(green_rect, &R, &G, &B, &A)); |
| 265 | EXPECT_EQ(0U, R); |
| 266 | EXPECT_EQ(255U, G); |
| 267 | EXPECT_EQ(0U, B); |
| 268 | EXPECT_EQ(128U, A); |
| 269 | |
Miklos Vajna | 12abfd0 | 2017-09-15 07:49:03 +0200 | [diff] [blame] | 270 | // Make sure the path has 5 points (1 FXPT_TYPE::MoveTo and 4 |
| 271 | // FXPT_TYPE::LineTo). |
Miklos Vajna | 0150a54 | 2017-09-21 21:46:56 +0200 | [diff] [blame] | 272 | ASSERT_EQ(5, FPDFPath_CountSegments(green_rect)); |
Miklos Vajna | 36eed87 | 2017-09-20 22:52:43 +0200 | [diff] [blame] | 273 | // Verify actual coordinates. |
| 274 | FPDF_PATHSEGMENT segment = FPDFPath_GetPathSegment(green_rect, 0); |
| 275 | float x; |
| 276 | float y; |
| 277 | EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y)); |
| 278 | EXPECT_EQ(100, x); |
| 279 | EXPECT_EQ(100, y); |
| 280 | EXPECT_EQ(FPDF_SEGMENT_MOVETO, FPDFPathSegment_GetType(segment)); |
| 281 | EXPECT_FALSE(FPDFPathSegment_GetClose(segment)); |
| 282 | segment = FPDFPath_GetPathSegment(green_rect, 1); |
| 283 | EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y)); |
| 284 | EXPECT_EQ(100, x); |
| 285 | EXPECT_EQ(140, y); |
| 286 | EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment)); |
| 287 | EXPECT_FALSE(FPDFPathSegment_GetClose(segment)); |
| 288 | segment = FPDFPath_GetPathSegment(green_rect, 2); |
| 289 | EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y)); |
| 290 | EXPECT_EQ(140, x); |
| 291 | EXPECT_EQ(140, y); |
| 292 | EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment)); |
| 293 | EXPECT_FALSE(FPDFPathSegment_GetClose(segment)); |
| 294 | segment = FPDFPath_GetPathSegment(green_rect, 3); |
| 295 | EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y)); |
| 296 | EXPECT_EQ(140, x); |
| 297 | EXPECT_EQ(100, y); |
| 298 | EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment)); |
| 299 | EXPECT_FALSE(FPDFPathSegment_GetClose(segment)); |
| 300 | segment = FPDFPath_GetPathSegment(green_rect, 4); |
| 301 | EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y)); |
| 302 | EXPECT_EQ(100, x); |
| 303 | EXPECT_EQ(100, y); |
| 304 | EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment)); |
| 305 | EXPECT_TRUE(FPDFPathSegment_GetClose(segment)); |
Miklos Vajna | 12abfd0 | 2017-09-15 07:49:03 +0200 | [diff] [blame] | 306 | |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 307 | EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_WINDING, 0)); |
| 308 | FPDFPage_InsertObject(page, green_rect); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 309 | { |
| 310 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 311 | RenderPageWithFlags(page, nullptr, 0); |
| 312 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 313 | "7b0b87604594e773add528fae567a558"); |
| 314 | } |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 315 | |
| 316 | // Add a black triangle. |
| 317 | FPDF_PAGEOBJECT black_path = FPDFPageObj_CreateNewPath(400, 100); |
| 318 | EXPECT_TRUE(FPDFPath_SetFillColor(black_path, 0, 0, 0, 200)); |
| 319 | EXPECT_TRUE(FPDFPath_SetDrawMode(black_path, FPDF_FILLMODE_ALTERNATE, 0)); |
| 320 | EXPECT_TRUE(FPDFPath_LineTo(black_path, 400, 200)); |
| 321 | EXPECT_TRUE(FPDFPath_LineTo(black_path, 300, 100)); |
| 322 | EXPECT_TRUE(FPDFPath_Close(black_path)); |
Miklos Vajna | 12abfd0 | 2017-09-15 07:49:03 +0200 | [diff] [blame] | 323 | |
| 324 | // Make sure the path has 3 points (1 FXPT_TYPE::MoveTo and 2 |
| 325 | // FXPT_TYPE::LineTo). |
Miklos Vajna | 0150a54 | 2017-09-21 21:46:56 +0200 | [diff] [blame] | 326 | ASSERT_EQ(3, FPDFPath_CountSegments(black_path)); |
Miklos Vajna | 36eed87 | 2017-09-20 22:52:43 +0200 | [diff] [blame] | 327 | // Verify actual coordinates. |
| 328 | segment = FPDFPath_GetPathSegment(black_path, 0); |
| 329 | EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y)); |
| 330 | EXPECT_EQ(400, x); |
| 331 | EXPECT_EQ(100, y); |
| 332 | EXPECT_EQ(FPDF_SEGMENT_MOVETO, FPDFPathSegment_GetType(segment)); |
| 333 | EXPECT_FALSE(FPDFPathSegment_GetClose(segment)); |
| 334 | segment = FPDFPath_GetPathSegment(black_path, 1); |
| 335 | EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y)); |
| 336 | EXPECT_EQ(400, x); |
| 337 | EXPECT_EQ(200, y); |
| 338 | EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment)); |
| 339 | EXPECT_FALSE(FPDFPathSegment_GetClose(segment)); |
| 340 | segment = FPDFPath_GetPathSegment(black_path, 2); |
| 341 | EXPECT_TRUE(FPDFPathSegment_GetPoint(segment, &x, &y)); |
| 342 | EXPECT_EQ(300, x); |
| 343 | EXPECT_EQ(100, y); |
| 344 | EXPECT_EQ(FPDF_SEGMENT_LINETO, FPDFPathSegment_GetType(segment)); |
| 345 | EXPECT_TRUE(FPDFPathSegment_GetClose(segment)); |
| 346 | // Make sure out of bounds index access fails properly. |
| 347 | EXPECT_EQ(nullptr, FPDFPath_GetPathSegment(black_path, 3)); |
Miklos Vajna | 12abfd0 | 2017-09-15 07:49:03 +0200 | [diff] [blame] | 348 | |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 349 | FPDFPage_InsertObject(page, black_path); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 350 | { |
| 351 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 352 | RenderPageWithFlags(page, nullptr, 0); |
| 353 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 354 | "eadc8020a14dfcf091da2688733d8806"); |
| 355 | } |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 356 | |
| 357 | // Now add a more complex blue path. |
| 358 | FPDF_PAGEOBJECT blue_path = FPDFPageObj_CreateNewPath(200, 200); |
| 359 | EXPECT_TRUE(FPDFPath_SetFillColor(blue_path, 0, 0, 255, 255)); |
| 360 | EXPECT_TRUE(FPDFPath_SetDrawMode(blue_path, FPDF_FILLMODE_WINDING, 0)); |
| 361 | EXPECT_TRUE(FPDFPath_LineTo(blue_path, 230, 230)); |
| 362 | EXPECT_TRUE(FPDFPath_BezierTo(blue_path, 250, 250, 280, 280, 300, 300)); |
| 363 | EXPECT_TRUE(FPDFPath_LineTo(blue_path, 325, 325)); |
| 364 | EXPECT_TRUE(FPDFPath_LineTo(blue_path, 350, 325)); |
| 365 | EXPECT_TRUE(FPDFPath_BezierTo(blue_path, 375, 330, 390, 360, 400, 400)); |
| 366 | EXPECT_TRUE(FPDFPath_Close(blue_path)); |
| 367 | FPDFPage_InsertObject(page, blue_path); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 368 | const char kLastMD5[] = "9823e1a21bd9b72b6a442ba4f12af946"; |
| 369 | { |
| 370 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 371 | RenderPageWithFlags(page, nullptr, 0); |
| 372 | CompareBitmap(page_bitmap.get(), 612, 792, kLastMD5); |
| 373 | } |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 374 | |
| 375 | // Now save the result, closing the page and document |
Nicolas Pena | 207b727 | 2017-05-26 17:37:06 -0400 | [diff] [blame] | 376 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 377 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 378 | FPDF_ClosePage(page); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 379 | |
| 380 | // Render the saved result |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 381 | VerifySavedDocument(612, 792, kLastMD5); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Miklos Vajna | 12abfd0 | 2017-09-15 07:49:03 +0200 | [diff] [blame] | 384 | TEST_F(FPDFEditEmbeddertest, PathsPoints) { |
| 385 | CreateNewDocument(); |
| 386 | FPDF_PAGEOBJECT img = FPDFPageObj_NewImageObj(document_); |
| 387 | // This should fail gracefully, even if img is not a path. |
Miklos Vajna | 0150a54 | 2017-09-21 21:46:56 +0200 | [diff] [blame] | 388 | ASSERT_EQ(-1, FPDFPath_CountSegments(img)); |
Miklos Vajna | 12abfd0 | 2017-09-15 07:49:03 +0200 | [diff] [blame] | 389 | |
| 390 | // This should fail gracefully, even if path is NULL. |
Miklos Vajna | 0150a54 | 2017-09-21 21:46:56 +0200 | [diff] [blame] | 391 | ASSERT_EQ(-1, FPDFPath_CountSegments(nullptr)); |
Miklos Vajna | 12abfd0 | 2017-09-15 07:49:03 +0200 | [diff] [blame] | 392 | |
Miklos Vajna | 36eed87 | 2017-09-20 22:52:43 +0200 | [diff] [blame] | 393 | // FPDFPath_GetPathSegment() with a non-path. |
| 394 | ASSERT_EQ(nullptr, FPDFPath_GetPathSegment(img, 0)); |
| 395 | // FPDFPath_GetPathSegment() with a NULL path. |
| 396 | ASSERT_EQ(nullptr, FPDFPath_GetPathSegment(nullptr, 0)); |
| 397 | float x; |
| 398 | float y; |
| 399 | // FPDFPathSegment_GetPoint() with a NULL segment. |
| 400 | EXPECT_FALSE(FPDFPathSegment_GetPoint(nullptr, &x, &y)); |
| 401 | |
| 402 | // FPDFPathSegment_GetType() with a NULL segment. |
| 403 | ASSERT_EQ(FPDF_SEGMENT_UNKNOWN, FPDFPathSegment_GetType(nullptr)); |
| 404 | |
| 405 | // FPDFPathSegment_GetClose() with a NULL segment. |
| 406 | EXPECT_FALSE(FPDFPathSegment_GetClose(nullptr)); |
| 407 | |
Miklos Vajna | 12abfd0 | 2017-09-15 07:49:03 +0200 | [diff] [blame] | 408 | FPDFPageObj_Destroy(img); |
| 409 | } |
| 410 | |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 411 | TEST_F(FPDFEditEmbeddertest, PathOnTopOfText) { |
| 412 | // Load document with some text |
| 413 | EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
| 414 | FPDF_PAGE page = LoadPage(0); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 415 | ASSERT_TRUE(page); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 416 | |
| 417 | // Add an opaque rectangle on top of some of the text. |
| 418 | FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(20, 100, 50, 50); |
| 419 | EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); |
| 420 | EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); |
| 421 | FPDFPage_InsertObject(page, red_rect); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 422 | |
| 423 | // Add a transparent triangle on top of other part of the text. |
| 424 | FPDF_PAGEOBJECT black_path = FPDFPageObj_CreateNewPath(20, 50); |
| 425 | EXPECT_TRUE(FPDFPath_SetFillColor(black_path, 0, 0, 0, 100)); |
| 426 | EXPECT_TRUE(FPDFPath_SetDrawMode(black_path, FPDF_FILLMODE_ALTERNATE, 0)); |
| 427 | EXPECT_TRUE(FPDFPath_LineTo(black_path, 30, 80)); |
| 428 | EXPECT_TRUE(FPDFPath_LineTo(black_path, 40, 10)); |
| 429 | EXPECT_TRUE(FPDFPath_Close(black_path)); |
| 430 | FPDFPage_InsertObject(page, black_path); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 431 | |
| 432 | // Render and check the result. Text is slightly different on Mac. |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 433 | std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 434 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Lei Zhang | 0d6d178 | 2017-03-24 15:52:00 -0700 | [diff] [blame] | 435 | const char md5[] = "f9e6fa74230f234286bfcada9f7606d8"; |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 436 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 437 | const char md5[] = "aa71b09b93b55f467f1290e5111babee"; |
Nicolas Pena | 5bcd9a3 | 2017-03-22 11:04:35 -0400 | [diff] [blame] | 438 | #endif |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 439 | CompareBitmap(bitmap.get(), 200, 200, md5); |
Nicolas Pena | 0fc185e | 2017-02-08 12:13:20 -0500 | [diff] [blame] | 440 | UnloadPage(page); |
| 441 | } |
Nicolas Pena | 2eb1a70 | 2017-02-09 18:17:33 -0500 | [diff] [blame] | 442 | |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 443 | TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) { |
| 444 | // Load document with existing content |
| 445 | EXPECT_TRUE(OpenDocument("bug_717.pdf")); |
| 446 | FPDF_PAGE page = LoadPage(0); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 447 | ASSERT_TRUE(page); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 448 | |
| 449 | // Add a transparent rectangle on top of the existing content |
| 450 | FPDF_PAGEOBJECT red_rect2 = FPDFPageObj_CreateNewRect(90, 700, 25, 50); |
| 451 | EXPECT_TRUE(FPDFPath_SetFillColor(red_rect2, 255, 0, 0, 100)); |
| 452 | EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect2, FPDF_FILLMODE_ALTERNATE, 0)); |
| 453 | FPDFPage_InsertObject(page, red_rect2); |
| 454 | |
| 455 | // Add an opaque rectangle on top of the existing content |
| 456 | FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(115, 700, 25, 50); |
| 457 | EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); |
| 458 | EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); |
| 459 | FPDFPage_InsertObject(page, red_rect); |
| 460 | |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 461 | std::unique_ptr<void, FPDFBitmapDeleter> bitmap = RenderLoadedPage(page); |
| 462 | CompareBitmap(bitmap.get(), 612, 792, "ad04e5bd0f471a9a564fb034bd0fb073"); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 463 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
| 464 | |
| 465 | // Now save the result, closing the page and document |
| 466 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
Nicolas Pena | 3ff5400 | 2017-07-05 11:55:35 -0400 | [diff] [blame] | 467 | UnloadPage(page); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 468 | |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 469 | OpenSavedDocument(); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 470 | FPDF_PAGE saved_page = LoadSavedPage(0); |
| 471 | VerifySavedRendering(saved_page, 612, 792, |
| 472 | "ad04e5bd0f471a9a564fb034bd0fb073"); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 473 | |
| 474 | ClearString(); |
| 475 | // Add another opaque rectangle on top of the existing content |
| 476 | FPDF_PAGEOBJECT green_rect = FPDFPageObj_CreateNewRect(150, 700, 25, 50); |
| 477 | EXPECT_TRUE(FPDFPath_SetFillColor(green_rect, 0, 255, 0, 255)); |
| 478 | EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_ALTERNATE, 0)); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 479 | FPDFPage_InsertObject(saved_page, green_rect); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 480 | |
| 481 | // Add another transparent rectangle on top of existing content |
| 482 | FPDF_PAGEOBJECT green_rect2 = FPDFPageObj_CreateNewRect(175, 700, 25, 50); |
| 483 | EXPECT_TRUE(FPDFPath_SetFillColor(green_rect2, 0, 255, 0, 100)); |
| 484 | EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect2, FPDF_FILLMODE_ALTERNATE, 0)); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 485 | FPDFPage_InsertObject(saved_page, green_rect2); |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 486 | const char kLastMD5[] = "4b5b00f824620f8c9b8801ebb98e1cdd"; |
| 487 | { |
| 488 | std::unique_ptr<void, FPDFBitmapDeleter> new_bitmap = |
| 489 | RenderSavedPage(saved_page); |
| 490 | CompareBitmap(new_bitmap.get(), 612, 792, kLastMD5); |
| 491 | } |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 492 | EXPECT_TRUE(FPDFPage_GenerateContent(saved_page)); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 493 | |
| 494 | // Now save the result, closing the page and document |
Lei Zhang | 0729be2 | 2018-02-05 21:13:51 +0000 | [diff] [blame] | 495 | EXPECT_TRUE(FPDF_SaveAsCopy(saved_document_, this, 0)); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 496 | |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 497 | CloseSavedPage(saved_page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 498 | CloseSavedDocument(); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 499 | |
| 500 | // Render the saved result |
Lei Zhang | c113c7a | 2018-02-12 14:58:44 +0000 | [diff] [blame] | 501 | VerifySavedDocument(612, 792, kLastMD5); |
wileyrya | e858aa4 | 2017-05-31 14:49:05 -0500 | [diff] [blame] | 502 | } |
| 503 | |
Nicolas Pena | 2eb1a70 | 2017-02-09 18:17:33 -0500 | [diff] [blame] | 504 | TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) { |
| 505 | // Start with a blank page |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 506 | FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); |
Nicolas Pena | 2eb1a70 | 2017-02-09 18:17:33 -0500 | [diff] [blame] | 507 | |
| 508 | // Add a large stroked rectangle (fill color should not affect it). |
| 509 | FPDF_PAGEOBJECT rect = FPDFPageObj_CreateNewRect(20, 20, 200, 400); |
| 510 | EXPECT_TRUE(FPDFPath_SetFillColor(rect, 255, 0, 0, 255)); |
| 511 | EXPECT_TRUE(FPDFPath_SetStrokeColor(rect, 0, 255, 0, 255)); |
| 512 | EXPECT_TRUE(FPDFPath_SetStrokeWidth(rect, 15.0f)); |
| 513 | EXPECT_TRUE(FPDFPath_SetDrawMode(rect, 0, 1)); |
| 514 | FPDFPage_InsertObject(page, rect); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 515 | { |
| 516 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 517 | RenderPageWithFlags(page, nullptr, 0); |
| 518 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 519 | "64bd31f862a89e0a9e505a5af6efd506"); |
| 520 | } |
Nicolas Pena | 2eb1a70 | 2017-02-09 18:17:33 -0500 | [diff] [blame] | 521 | |
| 522 | // Add crossed-checkmark |
| 523 | FPDF_PAGEOBJECT check = FPDFPageObj_CreateNewPath(300, 500); |
| 524 | EXPECT_TRUE(FPDFPath_LineTo(check, 400, 400)); |
| 525 | EXPECT_TRUE(FPDFPath_LineTo(check, 600, 600)); |
| 526 | EXPECT_TRUE(FPDFPath_MoveTo(check, 400, 600)); |
| 527 | EXPECT_TRUE(FPDFPath_LineTo(check, 600, 400)); |
| 528 | EXPECT_TRUE(FPDFPath_SetStrokeColor(check, 128, 128, 128, 180)); |
| 529 | EXPECT_TRUE(FPDFPath_SetStrokeWidth(check, 8.35f)); |
| 530 | EXPECT_TRUE(FPDFPath_SetDrawMode(check, 0, 1)); |
| 531 | FPDFPage_InsertObject(page, check); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 532 | { |
| 533 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 534 | RenderPageWithFlags(page, nullptr, 0); |
| 535 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 536 | "4b6f3b9d25c4e194821217d5016c3724"); |
| 537 | } |
Nicolas Pena | 2eb1a70 | 2017-02-09 18:17:33 -0500 | [diff] [blame] | 538 | |
| 539 | // Add stroked and filled oval-ish path. |
| 540 | FPDF_PAGEOBJECT path = FPDFPageObj_CreateNewPath(250, 100); |
| 541 | EXPECT_TRUE(FPDFPath_BezierTo(path, 180, 166, 180, 233, 250, 300)); |
| 542 | EXPECT_TRUE(FPDFPath_LineTo(path, 255, 305)); |
| 543 | EXPECT_TRUE(FPDFPath_BezierTo(path, 325, 233, 325, 166, 255, 105)); |
| 544 | EXPECT_TRUE(FPDFPath_Close(path)); |
| 545 | EXPECT_TRUE(FPDFPath_SetFillColor(path, 200, 128, 128, 100)); |
| 546 | EXPECT_TRUE(FPDFPath_SetStrokeColor(path, 128, 200, 128, 150)); |
| 547 | EXPECT_TRUE(FPDFPath_SetStrokeWidth(path, 10.5f)); |
| 548 | EXPECT_TRUE(FPDFPath_SetDrawMode(path, FPDF_FILLMODE_ALTERNATE, 1)); |
| 549 | FPDFPage_InsertObject(page, path); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 550 | { |
| 551 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 552 | RenderPageWithFlags(page, nullptr, 0); |
| 553 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 554 | "ff3e6a22326754944cc6e56609acd73b"); |
| 555 | } |
Nicolas Pena | 2eb1a70 | 2017-02-09 18:17:33 -0500 | [diff] [blame] | 556 | FPDF_ClosePage(page); |
Nicolas Pena | 2eb1a70 | 2017-02-09 18:17:33 -0500 | [diff] [blame] | 557 | } |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 558 | |
| 559 | TEST_F(FPDFEditEmbeddertest, AddStandardFontText) { |
| 560 | // Start with a blank page |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 561 | FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 562 | |
| 563 | // Add some text to the page |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 564 | FPDF_PAGEOBJECT text_object1 = |
| 565 | FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); |
| 566 | EXPECT_TRUE(text_object1); |
| 567 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text1 = |
| 568 | GetFPDFWideString(L"I'm at the bottom of the page"); |
| 569 | EXPECT_TRUE(FPDFText_SetText(text_object1, text1.get())); |
| 570 | FPDFPageObj_Transform(text_object1, 1, 0, 0, 1, 20, 20); |
| 571 | FPDFPage_InsertObject(page, text_object1); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 572 | { |
| 573 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 574 | RenderPageWithFlags(page, nullptr, 0); |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 575 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 576 | const char md5[] = "a4dddc1a3930fa694bbff9789dab4161"; |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 577 | #else |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 578 | const char md5[] = "eacaa24573b8ce997b3882595f096f00"; |
Nicolas Pena | 5bcd9a3 | 2017-03-22 11:04:35 -0400 | [diff] [blame] | 579 | #endif |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 580 | CompareBitmap(page_bitmap.get(), 612, 792, md5); |
| 581 | } |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 582 | |
| 583 | // Try another font |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 584 | FPDF_PAGEOBJECT text_object2 = |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 585 | FPDFPageObj_NewTextObj(document(), "TimesNewRomanBold", 15.0f); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 586 | EXPECT_TRUE(text_object2); |
| 587 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text2 = |
| 588 | GetFPDFWideString(L"Hi, I'm Bold. Times New Roman Bold."); |
| 589 | EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get())); |
| 590 | FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 100, 600); |
| 591 | FPDFPage_InsertObject(page, text_object2); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 592 | { |
| 593 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 594 | RenderPageWithFlags(page, nullptr, 0); |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 595 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Lei Zhang | 0d6d178 | 2017-03-24 15:52:00 -0700 | [diff] [blame] | 596 | const char md5_2[] = "a5c4ace4c6f27644094813fe1441a21c"; |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 597 | #elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 598 | const char md5_2[] = "2587eac9a787e97a37636d54d11bd28d"; |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 599 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 600 | const char md5_2[] = "76fcc7d08aa15445efd2e2ceb7c6cc3b"; |
Nicolas Pena | 5bcd9a3 | 2017-03-22 11:04:35 -0400 | [diff] [blame] | 601 | #endif |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 602 | CompareBitmap(page_bitmap.get(), 612, 792, md5_2); |
| 603 | } |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 604 | |
| 605 | // And some randomly transformed text |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 606 | FPDF_PAGEOBJECT text_object3 = |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 607 | FPDFPageObj_NewTextObj(document(), "Courier-Bold", 20.0f); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 608 | EXPECT_TRUE(text_object3); |
| 609 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text3 = |
| 610 | GetFPDFWideString(L"Can you read me? <:)>"); |
| 611 | EXPECT_TRUE(FPDFText_SetText(text_object3, text3.get())); |
| 612 | FPDFPageObj_Transform(text_object3, 1, 1.5, 2, 0.5, 200, 200); |
| 613 | FPDFPage_InsertObject(page, text_object3); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 614 | { |
| 615 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 616 | RenderPageWithFlags(page, nullptr, 0); |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 617 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 618 | const char md5_3[] = "40b3ef04f915ff4c4208948001763544"; |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 619 | #elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 620 | const char md5_3[] = "7cb61ec112cf400b489360d443ffc9d2"; |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 621 | #else |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 622 | const char md5_3[] = "b8a21668f1dab625af7c072e07fcefc4"; |
Nicolas Pena | 5bcd9a3 | 2017-03-22 11:04:35 -0400 | [diff] [blame] | 623 | #endif |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 624 | CompareBitmap(page_bitmap.get(), 612, 792, md5_3); |
| 625 | } |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 626 | |
| 627 | // TODO(npm): Why are there issues with text rotated by 90 degrees? |
| 628 | // TODO(npm): FPDF_SaveAsCopy not giving the desired result after this. |
| 629 | FPDF_ClosePage(page); |
Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 630 | } |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 631 | |
Nicolas Pena | 603a31d | 2017-06-14 11:41:18 -0400 | [diff] [blame] | 632 | TEST_F(FPDFEditEmbeddertest, GraphicsData) { |
| 633 | // New page |
| 634 | std::unique_ptr<void, FPDFPageDeleter> page( |
| 635 | FPDFPage_New(CreateNewDocument(), 0, 612, 792)); |
| 636 | |
| 637 | // Create a rect with nontrivial graphics |
| 638 | FPDF_PAGEOBJECT rect1 = FPDFPageObj_CreateNewRect(10, 10, 100, 100); |
| 639 | FPDFPageObj_SetBlendMode(rect1, "Color"); |
| 640 | FPDFPage_InsertObject(page.get(), rect1); |
| 641 | EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); |
| 642 | |
| 643 | // Check that the ExtGState was created |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 644 | CPDF_Page* cpage = CPDFPageFromFPDFPage(page.get()); |
| 645 | CPDF_Dictionary* graphics_dict = cpage->m_pResources->GetDictFor("ExtGState"); |
Nicolas Pena | 603a31d | 2017-06-14 11:41:18 -0400 | [diff] [blame] | 646 | ASSERT_TRUE(graphics_dict); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 647 | EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); |
Nicolas Pena | 603a31d | 2017-06-14 11:41:18 -0400 | [diff] [blame] | 648 | |
| 649 | // Add a text object causing no change to the graphics dictionary |
| 650 | FPDF_PAGEOBJECT text1 = FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); |
| 651 | // Only alpha, the last component, matters for the graphics dictionary. And |
| 652 | // the default value is 255. |
| 653 | EXPECT_TRUE(FPDFText_SetFillColor(text1, 100, 100, 100, 255)); |
| 654 | FPDFPage_InsertObject(page.get(), text1); |
| 655 | EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 656 | EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); |
Nicolas Pena | 603a31d | 2017-06-14 11:41:18 -0400 | [diff] [blame] | 657 | |
| 658 | // Add a text object increasing the size of the graphics dictionary |
| 659 | FPDF_PAGEOBJECT text2 = |
| 660 | FPDFPageObj_NewTextObj(document(), "Times-Roman", 12.0f); |
| 661 | FPDFPage_InsertObject(page.get(), text2); |
| 662 | FPDFPageObj_SetBlendMode(text2, "Darken"); |
| 663 | EXPECT_TRUE(FPDFText_SetFillColor(text2, 0, 0, 255, 150)); |
| 664 | EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 665 | EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); |
Nicolas Pena | 603a31d | 2017-06-14 11:41:18 -0400 | [diff] [blame] | 666 | |
| 667 | // Add a path that should reuse graphics |
Nicolas Pena | ce67be4 | 2017-06-14 14:52:49 -0400 | [diff] [blame] | 668 | FPDF_PAGEOBJECT path = FPDFPageObj_CreateNewPath(400, 100); |
Nicolas Pena | 603a31d | 2017-06-14 11:41:18 -0400 | [diff] [blame] | 669 | FPDFPageObj_SetBlendMode(path, "Darken"); |
| 670 | EXPECT_TRUE(FPDFPath_SetFillColor(path, 200, 200, 100, 150)); |
| 671 | FPDFPage_InsertObject(page.get(), path); |
| 672 | EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 673 | EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); |
Nicolas Pena | 603a31d | 2017-06-14 11:41:18 -0400 | [diff] [blame] | 674 | |
| 675 | // Add a rect increasing the size of the graphics dictionary |
| 676 | FPDF_PAGEOBJECT rect2 = FPDFPageObj_CreateNewRect(10, 10, 100, 100); |
| 677 | FPDFPageObj_SetBlendMode(rect2, "Darken"); |
| 678 | EXPECT_TRUE(FPDFPath_SetFillColor(rect2, 0, 0, 255, 150)); |
| 679 | EXPECT_TRUE(FPDFPath_SetStrokeColor(rect2, 0, 0, 0, 200)); |
| 680 | FPDFPage_InsertObject(page.get(), rect2); |
| 681 | EXPECT_TRUE(FPDFPage_GenerateContent(page.get())); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 682 | EXPECT_EQ(4, static_cast<int>(graphics_dict->GetCount())); |
Nicolas Pena | 603a31d | 2017-06-14 11:41:18 -0400 | [diff] [blame] | 683 | } |
| 684 | |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 685 | TEST_F(FPDFEditEmbeddertest, DoubleGenerating) { |
| 686 | // Start with a blank page |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 687 | FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 688 | |
| 689 | // Add a red rectangle with some non-default alpha |
| 690 | FPDF_PAGEOBJECT rect = FPDFPageObj_CreateNewRect(10, 10, 100, 100); |
| 691 | EXPECT_TRUE(FPDFPath_SetFillColor(rect, 255, 0, 0, 128)); |
| 692 | EXPECT_TRUE(FPDFPath_SetDrawMode(rect, FPDF_FILLMODE_WINDING, 0)); |
| 693 | FPDFPage_InsertObject(page, rect); |
| 694 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
| 695 | |
| 696 | // Check the ExtGState |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 697 | CPDF_Page* cpage = CPDFPageFromFPDFPage(page); |
| 698 | CPDF_Dictionary* graphics_dict = cpage->m_pResources->GetDictFor("ExtGState"); |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 699 | ASSERT_TRUE(graphics_dict); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 700 | EXPECT_EQ(2, static_cast<int>(graphics_dict->GetCount())); |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 701 | |
| 702 | // Check the bitmap |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 703 | { |
| 704 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 705 | RenderPageWithFlags(page, nullptr, 0); |
| 706 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 707 | "5384da3406d62360ffb5cac4476fff1c"); |
| 708 | } |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 709 | |
| 710 | // Never mind, my new favorite color is blue, increase alpha |
| 711 | EXPECT_TRUE(FPDFPath_SetFillColor(rect, 0, 0, 255, 180)); |
| 712 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 713 | EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 714 | |
| 715 | // Check that bitmap displays changed content |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 716 | { |
| 717 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 718 | RenderPageWithFlags(page, nullptr, 0); |
| 719 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 720 | "2e51656f5073b0bee611d9cd086aa09c"); |
| 721 | } |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 722 | |
| 723 | // And now generate, without changes |
| 724 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 725 | EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 726 | { |
| 727 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 728 | RenderPageWithFlags(page, nullptr, 0); |
| 729 | CompareBitmap(page_bitmap.get(), 612, 792, |
| 730 | "2e51656f5073b0bee611d9cd086aa09c"); |
| 731 | } |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 732 | |
| 733 | // Add some text to the page |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 734 | FPDF_PAGEOBJECT text_object = |
| 735 | FPDFPageObj_NewTextObj(document(), "Arial", 12.0f); |
| 736 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = |
| 737 | GetFPDFWideString(L"Something something #text# something"); |
| 738 | EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); |
| 739 | FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 300, 300); |
| 740 | FPDFPage_InsertObject(page, text_object); |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 741 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 742 | CPDF_Dictionary* font_dict = cpage->m_pResources->GetDictFor("Font"); |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 743 | ASSERT_TRUE(font_dict); |
| 744 | EXPECT_EQ(1, static_cast<int>(font_dict->GetCount())); |
| 745 | |
| 746 | // Generate yet again, check dicts are reasonably sized |
| 747 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 748 | EXPECT_EQ(3, static_cast<int>(graphics_dict->GetCount())); |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 749 | EXPECT_EQ(1, static_cast<int>(font_dict->GetCount())); |
| 750 | FPDF_ClosePage(page); |
Nicolas Pena | a4ad01f | 2017-02-15 16:26:48 -0500 | [diff] [blame] | 751 | } |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 752 | |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 753 | TEST_F(FPDFEditEmbeddertest, LoadSimpleType1Font) { |
| 754 | CreateNewDocument(); |
| 755 | // TODO(npm): use other fonts after disallowing loading any font as any type |
| 756 | const CPDF_Font* stock_font = |
| 757 | CPDF_Font::GetStockFont(cpdf_doc(), "Times-Bold"); |
Lei Zhang | d74da7b | 2017-05-04 13:30:29 -0700 | [diff] [blame] | 758 | const uint8_t* data = stock_font->GetFont()->GetFontData(); |
| 759 | const uint32_t size = stock_font->GetFont()->GetSize(); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 760 | std::unique_ptr<void, FPDFFontDeleter> font( |
| 761 | FPDFText_LoadFont(document(), data, size, FPDF_FONT_TYPE1, false)); |
| 762 | ASSERT_TRUE(font.get()); |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 763 | CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get()); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 764 | EXPECT_TRUE(typed_font->IsType1Font()); |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 765 | |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 766 | CPDF_Dictionary* font_dict = typed_font->GetFontDict(); |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 767 | EXPECT_EQ("Font", font_dict->GetStringFor("Type")); |
| 768 | EXPECT_EQ("Type1", font_dict->GetStringFor("Subtype")); |
| 769 | EXPECT_EQ("Times New Roman Bold", font_dict->GetStringFor("BaseFont")); |
| 770 | ASSERT_TRUE(font_dict->KeyExist("FirstChar")); |
| 771 | ASSERT_TRUE(font_dict->KeyExist("LastChar")); |
| 772 | EXPECT_EQ(32, font_dict->GetIntegerFor("FirstChar")); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 773 | EXPECT_EQ(255, font_dict->GetIntegerFor("LastChar")); |
| 774 | |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 775 | CPDF_Array* widths_array = font_dict->GetArrayFor("Widths"); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 776 | ASSERT_TRUE(widths_array); |
| 777 | ASSERT_EQ(224U, widths_array->GetCount()); |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 778 | EXPECT_EQ(250, widths_array->GetNumberAt(0)); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 779 | EXPECT_EQ(569, widths_array->GetNumberAt(11)); |
| 780 | EXPECT_EQ(500, widths_array->GetNumberAt(223)); |
| 781 | CheckFontDescriptor(font_dict, FPDF_FONT_TYPE1, true, false, size, data); |
| 782 | } |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 783 | |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 784 | TEST_F(FPDFEditEmbeddertest, LoadSimpleTrueTypeFont) { |
| 785 | CreateNewDocument(); |
| 786 | const CPDF_Font* stock_font = CPDF_Font::GetStockFont(cpdf_doc(), "Courier"); |
Lei Zhang | d74da7b | 2017-05-04 13:30:29 -0700 | [diff] [blame] | 787 | const uint8_t* data = stock_font->GetFont()->GetFontData(); |
| 788 | const uint32_t size = stock_font->GetFont()->GetSize(); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 789 | std::unique_ptr<void, FPDFFontDeleter> font( |
| 790 | FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, false)); |
| 791 | ASSERT_TRUE(font.get()); |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 792 | CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get()); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 793 | EXPECT_TRUE(typed_font->IsTrueTypeFont()); |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 794 | |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 795 | CPDF_Dictionary* font_dict = typed_font->GetFontDict(); |
| 796 | EXPECT_EQ("Font", font_dict->GetStringFor("Type")); |
| 797 | EXPECT_EQ("TrueType", font_dict->GetStringFor("Subtype")); |
| 798 | EXPECT_EQ("Courier New", font_dict->GetStringFor("BaseFont")); |
| 799 | ASSERT_TRUE(font_dict->KeyExist("FirstChar")); |
| 800 | ASSERT_TRUE(font_dict->KeyExist("LastChar")); |
| 801 | EXPECT_EQ(32, font_dict->GetIntegerFor("FirstChar")); |
| 802 | EXPECT_EQ(255, font_dict->GetIntegerFor("LastChar")); |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 803 | |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 804 | CPDF_Array* widths_array = font_dict->GetArrayFor("Widths"); |
| 805 | ASSERT_TRUE(widths_array); |
| 806 | ASSERT_EQ(224U, widths_array->GetCount()); |
| 807 | EXPECT_EQ(600, widths_array->GetNumberAt(33)); |
| 808 | EXPECT_EQ(600, widths_array->GetNumberAt(74)); |
| 809 | EXPECT_EQ(600, widths_array->GetNumberAt(223)); |
| 810 | CheckFontDescriptor(font_dict, FPDF_FONT_TRUETYPE, false, false, size, data); |
| 811 | } |
| 812 | |
| 813 | TEST_F(FPDFEditEmbeddertest, LoadCIDType0Font) { |
| 814 | CreateNewDocument(); |
| 815 | const CPDF_Font* stock_font = |
| 816 | CPDF_Font::GetStockFont(cpdf_doc(), "Times-Roman"); |
Lei Zhang | d74da7b | 2017-05-04 13:30:29 -0700 | [diff] [blame] | 817 | const uint8_t* data = stock_font->GetFont()->GetFontData(); |
| 818 | const uint32_t size = stock_font->GetFont()->GetSize(); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 819 | std::unique_ptr<void, FPDFFontDeleter> font( |
| 820 | FPDFText_LoadFont(document(), data, size, FPDF_FONT_TYPE1, 1)); |
| 821 | ASSERT_TRUE(font.get()); |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 822 | CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get()); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 823 | EXPECT_TRUE(typed_font->IsCIDFont()); |
| 824 | |
| 825 | // Check font dictionary entries |
| 826 | CPDF_Dictionary* font_dict = typed_font->GetFontDict(); |
| 827 | EXPECT_EQ("Font", font_dict->GetStringFor("Type")); |
| 828 | EXPECT_EQ("Type0", font_dict->GetStringFor("Subtype")); |
| 829 | EXPECT_EQ("Times New Roman-Identity-H", font_dict->GetStringFor("BaseFont")); |
| 830 | EXPECT_EQ("Identity-H", font_dict->GetStringFor("Encoding")); |
| 831 | CPDF_Array* descendant_array = font_dict->GetArrayFor("DescendantFonts"); |
| 832 | ASSERT_TRUE(descendant_array); |
| 833 | EXPECT_EQ(1U, descendant_array->GetCount()); |
| 834 | |
| 835 | // Check the CIDFontDict |
| 836 | CPDF_Dictionary* cidfont_dict = descendant_array->GetDictAt(0); |
| 837 | EXPECT_EQ("Font", cidfont_dict->GetStringFor("Type")); |
| 838 | EXPECT_EQ("CIDFontType0", cidfont_dict->GetStringFor("Subtype")); |
| 839 | EXPECT_EQ("Times New Roman", cidfont_dict->GetStringFor("BaseFont")); |
| 840 | CPDF_Dictionary* cidinfo_dict = cidfont_dict->GetDictFor("CIDSystemInfo"); |
| 841 | ASSERT_TRUE(cidinfo_dict); |
| 842 | EXPECT_EQ("Adobe", cidinfo_dict->GetStringFor("Registry")); |
| 843 | EXPECT_EQ("Identity", cidinfo_dict->GetStringFor("Ordering")); |
| 844 | EXPECT_EQ(0, cidinfo_dict->GetNumberFor("Supplement")); |
| 845 | CheckFontDescriptor(cidfont_dict, FPDF_FONT_TYPE1, false, false, size, data); |
| 846 | |
| 847 | // Check widths |
| 848 | CPDF_Array* widths_array = cidfont_dict->GetArrayFor("W"); |
| 849 | ASSERT_TRUE(widths_array); |
Nicolas Pena | f45ade3 | 2017-05-03 10:23:49 -0400 | [diff] [blame] | 850 | EXPECT_GT(widths_array->GetCount(), 1U); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 851 | CheckCompositeFontWidths(widths_array, typed_font); |
| 852 | } |
| 853 | |
| 854 | TEST_F(FPDFEditEmbeddertest, LoadCIDType2Font) { |
| 855 | CreateNewDocument(); |
| 856 | const CPDF_Font* stock_font = |
| 857 | CPDF_Font::GetStockFont(cpdf_doc(), "Helvetica-Oblique"); |
Lei Zhang | d74da7b | 2017-05-04 13:30:29 -0700 | [diff] [blame] | 858 | const uint8_t* data = stock_font->GetFont()->GetFontData(); |
| 859 | const uint32_t size = stock_font->GetFont()->GetSize(); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 860 | |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 861 | std::unique_ptr<void, FPDFFontDeleter> font( |
| 862 | FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 1)); |
| 863 | ASSERT_TRUE(font.get()); |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 864 | CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get()); |
Nicolas Pena | d03ca42 | 2017-03-06 13:54:33 -0500 | [diff] [blame] | 865 | EXPECT_TRUE(typed_font->IsCIDFont()); |
| 866 | |
| 867 | // Check font dictionary entries |
| 868 | CPDF_Dictionary* font_dict = typed_font->GetFontDict(); |
| 869 | EXPECT_EQ("Font", font_dict->GetStringFor("Type")); |
| 870 | EXPECT_EQ("Type0", font_dict->GetStringFor("Subtype")); |
| 871 | EXPECT_EQ("Arial Italic", font_dict->GetStringFor("BaseFont")); |
| 872 | EXPECT_EQ("Identity-H", font_dict->GetStringFor("Encoding")); |
| 873 | CPDF_Array* descendant_array = font_dict->GetArrayFor("DescendantFonts"); |
| 874 | ASSERT_TRUE(descendant_array); |
| 875 | EXPECT_EQ(1U, descendant_array->GetCount()); |
| 876 | |
| 877 | // Check the CIDFontDict |
| 878 | CPDF_Dictionary* cidfont_dict = descendant_array->GetDictAt(0); |
| 879 | EXPECT_EQ("Font", cidfont_dict->GetStringFor("Type")); |
| 880 | EXPECT_EQ("CIDFontType2", cidfont_dict->GetStringFor("Subtype")); |
| 881 | EXPECT_EQ("Arial Italic", cidfont_dict->GetStringFor("BaseFont")); |
| 882 | CPDF_Dictionary* cidinfo_dict = cidfont_dict->GetDictFor("CIDSystemInfo"); |
| 883 | ASSERT_TRUE(cidinfo_dict); |
| 884 | EXPECT_EQ("Adobe", cidinfo_dict->GetStringFor("Registry")); |
| 885 | EXPECT_EQ("Identity", cidinfo_dict->GetStringFor("Ordering")); |
| 886 | EXPECT_EQ(0, cidinfo_dict->GetNumberFor("Supplement")); |
| 887 | CheckFontDescriptor(cidfont_dict, FPDF_FONT_TRUETYPE, false, true, size, |
| 888 | data); |
| 889 | |
| 890 | // Check widths |
| 891 | CPDF_Array* widths_array = cidfont_dict->GetArrayFor("W"); |
| 892 | ASSERT_TRUE(widths_array); |
| 893 | CheckCompositeFontWidths(widths_array, typed_font); |
Nicolas Pena | be90aae | 2017-02-27 10:41:41 -0500 | [diff] [blame] | 894 | } |
rbpotter | ce8e51e | 2017-04-28 12:42:47 -0700 | [diff] [blame] | 895 | |
| 896 | TEST_F(FPDFEditEmbeddertest, NormalizeNegativeRotation) { |
| 897 | // Load document with a -90 degree rotation |
| 898 | EXPECT_TRUE(OpenDocument("bug_713197.pdf")); |
| 899 | FPDF_PAGE page = LoadPage(0); |
| 900 | EXPECT_NE(nullptr, page); |
| 901 | |
| 902 | EXPECT_EQ(3, FPDFPage_GetRotation(page)); |
| 903 | UnloadPage(page); |
| 904 | } |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 905 | |
| 906 | TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) { |
| 907 | // Start with a blank page |
| 908 | FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); |
| 909 | { |
| 910 | const CPDF_Font* stock_font = CPDF_Font::GetStockFont(cpdf_doc(), "Arial"); |
Lei Zhang | d74da7b | 2017-05-04 13:30:29 -0700 | [diff] [blame] | 911 | const uint8_t* data = stock_font->GetFont()->GetFontData(); |
| 912 | const uint32_t size = stock_font->GetFont()->GetSize(); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 913 | std::unique_ptr<void, FPDFFontDeleter> font( |
| 914 | FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 0)); |
| 915 | ASSERT_TRUE(font.get()); |
| 916 | |
| 917 | // Add some text to the page |
| 918 | FPDF_PAGEOBJECT text_object = |
| 919 | FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f); |
| 920 | EXPECT_TRUE(text_object); |
| 921 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = |
| 922 | GetFPDFWideString(L"I am testing my loaded font, WEE."); |
| 923 | EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); |
| 924 | FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 400, 400); |
| 925 | FPDFPage_InsertObject(page, text_object); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 926 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 927 | RenderPageWithFlags(page, nullptr, 0); |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 928 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 929 | const char md5[] = "17d2b6cd574cf66170b09c8927529a94"; |
| 930 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 931 | const char md5[] = "70592859010ffbf532a2237b8118bcc4"; |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 932 | #endif // _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 933 | CompareBitmap(page_bitmap.get(), 612, 792, md5); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 934 | |
| 935 | // Add some more text, same font |
| 936 | FPDF_PAGEOBJECT text_object2 = |
| 937 | FPDFPageObj_CreateTextObj(document(), font.get(), 15.0f); |
| 938 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text2 = |
| 939 | GetFPDFWideString(L"Bigger font size"); |
| 940 | EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get())); |
| 941 | FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 200, 200); |
| 942 | FPDFPage_InsertObject(page, text_object2); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 943 | } |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 944 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap2 = |
| 945 | RenderPageWithFlags(page, nullptr, 0); |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 946 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 947 | const char md5_2[] = "8eded4193ff1f0f77b8b600a825e97ea"; |
| 948 | #else |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 949 | const char md5_2[] = "c1d10cce1761c4a998a16b2562030568"; |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 950 | #endif // _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 951 | CompareBitmap(page_bitmap2.get(), 612, 792, md5_2); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 952 | |
Nicolas Pena | 207b727 | 2017-05-26 17:37:06 -0400 | [diff] [blame] | 953 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 954 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 955 | FPDF_ClosePage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 956 | |
| 957 | VerifySavedDocument(612, 792, md5_2); |
Nicolas Pena | b316185 | 2017-05-02 14:12:50 -0400 | [diff] [blame] | 958 | } |
Nicolas Pena | f45ade3 | 2017-05-03 10:23:49 -0400 | [diff] [blame] | 959 | |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 960 | TEST_F(FPDFEditEmbeddertest, TransformAnnot) { |
| 961 | // Open a file with one annotation and load its first page. |
| 962 | ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); |
Lei Zhang | 75c8171 | 2018-02-08 17:22:39 +0000 | [diff] [blame] | 963 | FPDF_PAGE page = LoadPage(0); |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 964 | ASSERT_TRUE(page); |
| 965 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 966 | { |
| 967 | // Add an underline annotation to the page without specifying its rectangle. |
| 968 | std::unique_ptr<void, FPDFAnnotationDeleter> annot( |
| 969 | FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE)); |
| 970 | ASSERT_TRUE(annot); |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 971 | |
Lei Zhang | a21d593 | 2018-02-05 18:28:38 +0000 | [diff] [blame] | 972 | // FPDFPage_TransformAnnots() should run without errors when modifying |
| 973 | // annotation rectangles. |
| 974 | FPDFPage_TransformAnnots(page, 1, 2, 3, 4, 5, 6); |
| 975 | } |
Jane Liu | eda6525 | 2017-06-07 11:31:27 -0400 | [diff] [blame] | 976 | UnloadPage(page); |
| 977 | } |
| 978 | |
Nicolas Pena | f45ade3 | 2017-05-03 10:23:49 -0400 | [diff] [blame] | 979 | // TODO(npm): Add tests using Japanese fonts in other OS. |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 980 | #if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_ |
Nicolas Pena | f45ade3 | 2017-05-03 10:23:49 -0400 | [diff] [blame] | 981 | TEST_F(FPDFEditEmbeddertest, AddCIDFontText) { |
| 982 | // Start with a blank page |
| 983 | FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792); |
| 984 | CFX_Font CIDfont; |
| 985 | { |
| 986 | // First, get the data from the font |
| 987 | CIDfont.LoadSubst("IPAGothic", 1, 0, 400, 0, 932, 0); |
| 988 | EXPECT_EQ("IPAGothic", CIDfont.GetFaceName()); |
| 989 | const uint8_t* data = CIDfont.GetFontData(); |
| 990 | const uint32_t size = CIDfont.GetSize(); |
| 991 | |
| 992 | // Load the data into a FPDF_Font. |
| 993 | std::unique_ptr<void, FPDFFontDeleter> font( |
| 994 | FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 1)); |
| 995 | ASSERT_TRUE(font.get()); |
| 996 | |
| 997 | // Add some text to the page |
| 998 | FPDF_PAGEOBJECT text_object = |
| 999 | FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f); |
| 1000 | ASSERT_TRUE(text_object); |
| 1001 | std::wstring wstr = L"ABCDEFGhijklmnop."; |
| 1002 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = |
| 1003 | GetFPDFWideString(wstr); |
| 1004 | EXPECT_TRUE(FPDFText_SetText(text_object, text.get())); |
| 1005 | FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 200, 200); |
| 1006 | FPDFPage_InsertObject(page, text_object); |
| 1007 | |
| 1008 | // And add some Japanese characters |
| 1009 | FPDF_PAGEOBJECT text_object2 = |
| 1010 | FPDFPageObj_CreateTextObj(document(), font.get(), 18.0f); |
| 1011 | ASSERT_TRUE(text_object2); |
| 1012 | std::wstring wstr2 = |
| 1013 | L"\u3053\u3093\u306B\u3061\u306f\u4e16\u754C\u3002\u3053\u3053\u306B1" |
| 1014 | L"\u756A"; |
| 1015 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text2 = |
| 1016 | GetFPDFWideString(wstr2); |
| 1017 | EXPECT_TRUE(FPDFText_SetText(text_object2, text2.get())); |
| 1018 | FPDFPageObj_Transform(text_object2, 1, 0, 0, 1, 100, 500); |
| 1019 | FPDFPage_InsertObject(page, text_object2); |
| 1020 | } |
| 1021 | |
Nicolas Pena | 207b727 | 2017-05-26 17:37:06 -0400 | [diff] [blame] | 1022 | // Check that the text renders properly. |
Henrique Nakashima | 09b4192 | 2017-10-27 20:39:29 +0000 | [diff] [blame] | 1023 | const char md5[] = "c68cd79aa72bf83a7b25271370d46b21"; |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 1024 | { |
| 1025 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 1026 | RenderPageWithFlags(page, nullptr, 0); |
| 1027 | CompareBitmap(page_bitmap.get(), 612, 792, md5); |
| 1028 | } |
Nicolas Pena | f45ade3 | 2017-05-03 10:23:49 -0400 | [diff] [blame] | 1029 | |
| 1030 | // Save the document, close the page. |
Nicolas Pena | 207b727 | 2017-05-26 17:37:06 -0400 | [diff] [blame] | 1031 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Nicolas Pena | f45ade3 | 2017-05-03 10:23:49 -0400 | [diff] [blame] | 1032 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 1033 | FPDF_ClosePage(page); |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 1034 | |
| 1035 | VerifySavedDocument(612, 792, md5); |
Nicolas Pena | f45ade3 | 2017-05-03 10:23:49 -0400 | [diff] [blame] | 1036 | } |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 1037 | #endif // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_ |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 1038 | |
| 1039 | TEST_F(FPDFEditEmbeddertest, SaveAndRender) { |
Nicolas Pena | a0b48aa | 2017-06-29 11:01:46 -0400 | [diff] [blame] | 1040 | const char md5[] = "3c20472b0552c0c22b88ab1ed8c6202b"; |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 1041 | { |
| 1042 | EXPECT_TRUE(OpenDocument("bug_779.pdf")); |
| 1043 | FPDF_PAGE page = LoadPage(0); |
| 1044 | ASSERT_NE(nullptr, page); |
| 1045 | |
| 1046 | // Now add a more complex blue path. |
| 1047 | FPDF_PAGEOBJECT green_path = FPDFPageObj_CreateNewPath(20, 20); |
| 1048 | EXPECT_TRUE(FPDFPath_SetFillColor(green_path, 0, 255, 0, 200)); |
| 1049 | // TODO(npm): stroking will cause the MD5s to differ. |
| 1050 | EXPECT_TRUE(FPDFPath_SetDrawMode(green_path, FPDF_FILLMODE_WINDING, 0)); |
| 1051 | EXPECT_TRUE(FPDFPath_LineTo(green_path, 20, 63)); |
| 1052 | EXPECT_TRUE(FPDFPath_BezierTo(green_path, 55, 55, 78, 78, 90, 90)); |
| 1053 | EXPECT_TRUE(FPDFPath_LineTo(green_path, 133, 133)); |
| 1054 | EXPECT_TRUE(FPDFPath_LineTo(green_path, 133, 33)); |
| 1055 | EXPECT_TRUE(FPDFPath_BezierTo(green_path, 38, 33, 39, 36, 40, 40)); |
| 1056 | EXPECT_TRUE(FPDFPath_Close(green_path)); |
| 1057 | FPDFPage_InsertObject(page, green_path); |
Lei Zhang | 107fa7b | 2018-02-09 21:48:15 +0000 | [diff] [blame] | 1058 | std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap = |
| 1059 | RenderLoadedPage(page); |
| 1060 | CompareBitmap(page_bitmap.get(), 612, 792, md5); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 1061 | |
| 1062 | // Now save the result, closing the page and document |
| 1063 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
| 1064 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 1065 | UnloadPage(page); |
| 1066 | } |
Dan Sinclair | 04e4dc8 | 2017-10-18 12:17:14 -0400 | [diff] [blame] | 1067 | |
| 1068 | VerifySavedDocument(612, 792, md5); |
Nicolas Pena | 9ba8fbc | 2017-06-28 15:31:56 -0400 | [diff] [blame] | 1069 | } |
Jane Liu | 28fb7ba | 2017-08-02 21:45:57 -0400 | [diff] [blame] | 1070 | |
| 1071 | TEST_F(FPDFEditEmbeddertest, ExtractImageBitmap) { |
| 1072 | ASSERT_TRUE(OpenDocument("embedded_images.pdf")); |
| 1073 | FPDF_PAGE page = LoadPage(0); |
| 1074 | ASSERT_TRUE(page); |
Miklos Vajna | 9262761 | 2017-09-25 12:59:29 +0200 | [diff] [blame] | 1075 | ASSERT_EQ(39, FPDFPage_CountObjects(page)); |
Jane Liu | 28fb7ba | 2017-08-02 21:45:57 -0400 | [diff] [blame] | 1076 | |
| 1077 | FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 32); |
| 1078 | EXPECT_NE(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1079 | EXPECT_FALSE(FPDFImageObj_GetBitmap(obj)); |
| 1080 | |
| 1081 | obj = FPDFPage_GetObject(page, 33); |
| 1082 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1083 | FPDF_BITMAP bitmap = FPDFImageObj_GetBitmap(obj); |
| 1084 | EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap)); |
| 1085 | CompareBitmap(bitmap, 109, 88, "d65e98d968d196abf13f78aec655ffae"); |
| 1086 | FPDFBitmap_Destroy(bitmap); |
| 1087 | |
| 1088 | obj = FPDFPage_GetObject(page, 34); |
| 1089 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1090 | bitmap = FPDFImageObj_GetBitmap(obj); |
| 1091 | EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap)); |
| 1092 | CompareBitmap(bitmap, 103, 75, "1287711c84dbef767c435d11697661d6"); |
| 1093 | FPDFBitmap_Destroy(bitmap); |
| 1094 | |
| 1095 | obj = FPDFPage_GetObject(page, 35); |
| 1096 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1097 | bitmap = FPDFImageObj_GetBitmap(obj); |
| 1098 | EXPECT_EQ(FPDFBitmap_Gray, FPDFBitmap_GetFormat(bitmap)); |
| 1099 | CompareBitmap(bitmap, 92, 68, "9c6d76cb1e37ef8514f9455d759391f3"); |
| 1100 | FPDFBitmap_Destroy(bitmap); |
| 1101 | |
| 1102 | obj = FPDFPage_GetObject(page, 36); |
| 1103 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1104 | bitmap = FPDFImageObj_GetBitmap(obj); |
| 1105 | EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap)); |
| 1106 | CompareBitmap(bitmap, 79, 60, "15cb6a49a2e354ed0e9f45dd34e3da1a"); |
| 1107 | FPDFBitmap_Destroy(bitmap); |
| 1108 | |
| 1109 | obj = FPDFPage_GetObject(page, 37); |
| 1110 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1111 | bitmap = FPDFImageObj_GetBitmap(obj); |
| 1112 | EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap)); |
| 1113 | CompareBitmap(bitmap, 126, 106, "be5a64ba7890d2657522af6524118534"); |
| 1114 | FPDFBitmap_Destroy(bitmap); |
| 1115 | |
| 1116 | obj = FPDFPage_GetObject(page, 38); |
| 1117 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1118 | bitmap = FPDFImageObj_GetBitmap(obj); |
| 1119 | EXPECT_EQ(FPDFBitmap_BGR, FPDFBitmap_GetFormat(bitmap)); |
| 1120 | CompareBitmap(bitmap, 194, 119, "f9e24207ee1bc0db6c543d33a5f12ec5"); |
| 1121 | FPDFBitmap_Destroy(bitmap); |
| 1122 | UnloadPage(page); |
| 1123 | } |
Jane Liu | 548334e | 2017-08-03 16:33:40 -0400 | [diff] [blame] | 1124 | |
Lei Zhang | 53341dd | 2018-03-01 15:42:47 +0000 | [diff] [blame^] | 1125 | TEST_F(FPDFEditEmbeddertest, ExtractJBigImageBitmap) { |
| 1126 | ASSERT_TRUE(OpenDocument("bug_631912.pdf")); |
| 1127 | FPDF_PAGE page = LoadPage(0); |
| 1128 | ASSERT_TRUE(page); |
| 1129 | ASSERT_EQ(1, FPDFPage_CountObjects(page)); |
| 1130 | |
| 1131 | FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0); |
| 1132 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1133 | { |
| 1134 | // TODO(bug_945): This should return a valid bitmap. This test should be |
| 1135 | // able to successfully check |bitmap| using FPDFBitmap_GetFormat() and |
| 1136 | // CompareBitmap(). |
| 1137 | std::unique_ptr<void, FPDFBitmapDeleter> bitmap( |
| 1138 | FPDFImageObj_GetBitmap(obj)); |
| 1139 | ASSERT_FALSE(bitmap); |
| 1140 | } |
| 1141 | |
| 1142 | UnloadPage(page); |
| 1143 | } |
| 1144 | |
Jane Liu | 548334e | 2017-08-03 16:33:40 -0400 | [diff] [blame] | 1145 | TEST_F(FPDFEditEmbeddertest, GetImageData) { |
| 1146 | EXPECT_TRUE(OpenDocument("embedded_images.pdf")); |
| 1147 | FPDF_PAGE page = LoadPage(0); |
| 1148 | ASSERT_TRUE(page); |
Miklos Vajna | 9262761 | 2017-09-25 12:59:29 +0200 | [diff] [blame] | 1149 | ASSERT_EQ(39, FPDFPage_CountObjects(page)); |
Jane Liu | 548334e | 2017-08-03 16:33:40 -0400 | [diff] [blame] | 1150 | |
| 1151 | // Retrieve an image object with flate-encoded data stream. |
| 1152 | FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 33); |
| 1153 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1154 | |
| 1155 | // Check that the raw image data has the correct length and hash value. |
| 1156 | unsigned long len = FPDFImageObj_GetImageDataRaw(obj, nullptr, 0); |
| 1157 | std::vector<char> buf(len); |
| 1158 | EXPECT_EQ(4091u, FPDFImageObj_GetImageDataRaw(obj, buf.data(), len)); |
| 1159 | EXPECT_EQ("f73802327d2e88e890f653961bcda81a", |
| 1160 | GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len)); |
| 1161 | |
| 1162 | // Check that the decoded image data has the correct length and hash value. |
| 1163 | len = FPDFImageObj_GetImageDataDecoded(obj, nullptr, 0); |
| 1164 | buf.clear(); |
| 1165 | buf.resize(len); |
| 1166 | EXPECT_EQ(28776u, FPDFImageObj_GetImageDataDecoded(obj, buf.data(), len)); |
| 1167 | EXPECT_EQ("cb3637934bb3b95a6e4ae1ea9eb9e56e", |
| 1168 | GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len)); |
| 1169 | |
| 1170 | // Retrieve an image obejct with DCTDecode-encoded data stream. |
| 1171 | obj = FPDFPage_GetObject(page, 37); |
| 1172 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1173 | |
| 1174 | // Check that the raw image data has the correct length and hash value. |
| 1175 | len = FPDFImageObj_GetImageDataRaw(obj, nullptr, 0); |
| 1176 | buf.clear(); |
| 1177 | buf.resize(len); |
| 1178 | EXPECT_EQ(4370u, FPDFImageObj_GetImageDataRaw(obj, buf.data(), len)); |
| 1179 | EXPECT_EQ("6aae1f3710335023a9e12191be66b64b", |
| 1180 | GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len)); |
| 1181 | |
| 1182 | // Check that the decoded image data has the correct length and hash value, |
| 1183 | // which should be the same as those of the raw data, since this image is |
| 1184 | // encoded by a single DCTDecode filter and decoding is a noop. |
| 1185 | len = FPDFImageObj_GetImageDataDecoded(obj, nullptr, 0); |
| 1186 | buf.clear(); |
| 1187 | buf.resize(len); |
| 1188 | EXPECT_EQ(4370u, FPDFImageObj_GetImageDataDecoded(obj, buf.data(), len)); |
| 1189 | EXPECT_EQ("6aae1f3710335023a9e12191be66b64b", |
| 1190 | GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len)); |
| 1191 | |
| 1192 | UnloadPage(page); |
| 1193 | } |
Jane Liu | 2e5f0ae | 2017-08-08 15:23:27 -0400 | [diff] [blame] | 1194 | |
| 1195 | TEST_F(FPDFEditEmbeddertest, DestroyPageObject) { |
| 1196 | FPDF_PAGEOBJECT rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20); |
| 1197 | ASSERT_TRUE(rect); |
| 1198 | |
| 1199 | // There should be no memory leaks with a call to FPDFPageObj_Destroy(). |
| 1200 | FPDFPageObj_Destroy(rect); |
| 1201 | } |
Jane Liu | be63ab9 | 2017-08-09 14:09:34 -0400 | [diff] [blame] | 1202 | |
| 1203 | TEST_F(FPDFEditEmbeddertest, GetImageFilters) { |
| 1204 | EXPECT_TRUE(OpenDocument("embedded_images.pdf")); |
| 1205 | FPDF_PAGE page = LoadPage(0); |
| 1206 | ASSERT_TRUE(page); |
| 1207 | |
| 1208 | // Verify that retrieving the filter of a non-image object would fail. |
| 1209 | FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 32); |
| 1210 | ASSERT_NE(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1211 | ASSERT_EQ(0, FPDFImageObj_GetImageFilterCount(obj)); |
| 1212 | EXPECT_EQ(0u, FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0)); |
| 1213 | |
| 1214 | // Verify the returned filter string for an image object with a single filter. |
| 1215 | obj = FPDFPage_GetObject(page, 33); |
| 1216 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1217 | ASSERT_EQ(1, FPDFImageObj_GetImageFilterCount(obj)); |
| 1218 | unsigned long len = FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0); |
| 1219 | std::vector<char> buf(len); |
Lei Zhang | 0733a1b | 2017-08-31 12:36:31 -0700 | [diff] [blame] | 1220 | static constexpr char kFlateDecode[] = "FlateDecode"; |
| 1221 | EXPECT_EQ(sizeof(kFlateDecode), |
| 1222 | FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len)); |
| 1223 | EXPECT_STREQ(kFlateDecode, buf.data()); |
Jane Liu | be63ab9 | 2017-08-09 14:09:34 -0400 | [diff] [blame] | 1224 | EXPECT_EQ(0u, FPDFImageObj_GetImageFilter(obj, 1, nullptr, 0)); |
| 1225 | |
| 1226 | // Verify all the filters for an image object with a list of filters. |
| 1227 | obj = FPDFPage_GetObject(page, 38); |
| 1228 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1229 | ASSERT_EQ(2, FPDFImageObj_GetImageFilterCount(obj)); |
| 1230 | len = FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0); |
| 1231 | buf.clear(); |
| 1232 | buf.resize(len); |
Lei Zhang | 0733a1b | 2017-08-31 12:36:31 -0700 | [diff] [blame] | 1233 | static constexpr char kASCIIHexDecode[] = "ASCIIHexDecode"; |
| 1234 | EXPECT_EQ(sizeof(kASCIIHexDecode), |
| 1235 | FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len)); |
| 1236 | EXPECT_STREQ(kASCIIHexDecode, buf.data()); |
Jane Liu | be63ab9 | 2017-08-09 14:09:34 -0400 | [diff] [blame] | 1237 | |
| 1238 | len = FPDFImageObj_GetImageFilter(obj, 1, nullptr, 0); |
| 1239 | buf.clear(); |
| 1240 | buf.resize(len); |
Lei Zhang | 0733a1b | 2017-08-31 12:36:31 -0700 | [diff] [blame] | 1241 | static constexpr char kDCTDecode[] = "DCTDecode"; |
| 1242 | EXPECT_EQ(sizeof(kDCTDecode), |
| 1243 | FPDFImageObj_GetImageFilter(obj, 1, buf.data(), len)); |
| 1244 | EXPECT_STREQ(kDCTDecode, buf.data()); |
Jane Liu | be63ab9 | 2017-08-09 14:09:34 -0400 | [diff] [blame] | 1245 | |
| 1246 | UnloadPage(page); |
| 1247 | } |
Jane Liu | ca89829 | 2017-08-16 11:25:35 -0400 | [diff] [blame] | 1248 | |
| 1249 | TEST_F(FPDFEditEmbeddertest, GetImageMetadata) { |
| 1250 | ASSERT_TRUE(OpenDocument("embedded_images.pdf")); |
| 1251 | FPDF_PAGE page = LoadPage(0); |
| 1252 | ASSERT_TRUE(page); |
| 1253 | |
| 1254 | // Check that getting the metadata of a null object would fail. |
| 1255 | FPDF_IMAGEOBJ_METADATA metadata; |
| 1256 | EXPECT_FALSE(FPDFImageObj_GetImageMetadata(nullptr, page, &metadata)); |
| 1257 | |
| 1258 | // Check that receiving the metadata with a null metadata object would fail. |
| 1259 | FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 35); |
| 1260 | EXPECT_FALSE(FPDFImageObj_GetImageMetadata(obj, page, nullptr)); |
| 1261 | |
| 1262 | // Check that when retrieving an image object's metadata without passing in |
| 1263 | // |page|, all values are correct, with the last two being default values. |
| 1264 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1265 | ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, nullptr, &metadata)); |
Julian Lunger | ecd063e | 2017-12-27 10:18:50 -0500 | [diff] [blame] | 1266 | EXPECT_EQ(7, metadata.marked_content_id); |
Jane Liu | ca89829 | 2017-08-16 11:25:35 -0400 | [diff] [blame] | 1267 | EXPECT_EQ(92u, metadata.width); |
| 1268 | EXPECT_EQ(68u, metadata.height); |
| 1269 | EXPECT_NEAR(96.000000, metadata.horizontal_dpi, 0.001); |
| 1270 | EXPECT_NEAR(96.000000, metadata.vertical_dpi, 0.001); |
| 1271 | EXPECT_EQ(0u, metadata.bits_per_pixel); |
| 1272 | EXPECT_EQ(FPDF_COLORSPACE_UNKNOWN, metadata.colorspace); |
| 1273 | |
| 1274 | // Verify the metadata of a bitmap image with indexed colorspace. |
| 1275 | ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page, &metadata)); |
Julian Lunger | ecd063e | 2017-12-27 10:18:50 -0500 | [diff] [blame] | 1276 | EXPECT_EQ(7, metadata.marked_content_id); |
Jane Liu | ca89829 | 2017-08-16 11:25:35 -0400 | [diff] [blame] | 1277 | EXPECT_EQ(92u, metadata.width); |
| 1278 | EXPECT_EQ(68u, metadata.height); |
| 1279 | EXPECT_NEAR(96.000000, metadata.horizontal_dpi, 0.001); |
| 1280 | EXPECT_NEAR(96.000000, metadata.vertical_dpi, 0.001); |
| 1281 | EXPECT_EQ(1u, metadata.bits_per_pixel); |
| 1282 | EXPECT_EQ(FPDF_COLORSPACE_INDEXED, metadata.colorspace); |
| 1283 | |
| 1284 | // Verify the metadata of an image with RGB colorspace. |
| 1285 | obj = FPDFPage_GetObject(page, 37); |
| 1286 | ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); |
| 1287 | ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page, &metadata)); |
Julian Lunger | ecd063e | 2017-12-27 10:18:50 -0500 | [diff] [blame] | 1288 | EXPECT_EQ(9, metadata.marked_content_id); |
Jane Liu | ca89829 | 2017-08-16 11:25:35 -0400 | [diff] [blame] | 1289 | EXPECT_EQ(126u, metadata.width); |
| 1290 | EXPECT_EQ(106u, metadata.height); |
| 1291 | EXPECT_NEAR(162.173752, metadata.horizontal_dpi, 0.001); |
| 1292 | EXPECT_NEAR(162.555878, metadata.vertical_dpi, 0.001); |
| 1293 | EXPECT_EQ(24u, metadata.bits_per_pixel); |
| 1294 | EXPECT_EQ(FPDF_COLORSPACE_DEVICERGB, metadata.colorspace); |
| 1295 | |
| 1296 | UnloadPage(page); |
| 1297 | } |