John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium 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 | |
| 5 | #include <limits.h> |
| 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame] | 10 | #include <map> |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 11 | #include <sstream> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <utility> |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 14 | #include <vector> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 16 | #if defined PDF_ENABLE_SKIA && !defined _SKIA_SUPPORT_ |
| 17 | #define _SKIA_SUPPORT_ |
| 18 | #endif |
| 19 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 20 | #include "core/fdrm/crypto/fx_crypt.h" |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 21 | #include "public/cpp/fpdf_deleters.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 22 | #include "public/fpdf_dataavail.h" |
Lei Zhang | 453d96b | 2015-12-31 13:13:10 -0800 | [diff] [blame] | 23 | #include "public/fpdf_edit.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 24 | #include "public/fpdf_ext.h" |
| 25 | #include "public/fpdf_formfill.h" |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 26 | #include "public/fpdf_structtree.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 27 | #include "public/fpdf_text.h" |
| 28 | #include "public/fpdfview.h" |
Dan Sinclair | efbc191 | 2016-02-17 16:54:43 -0500 | [diff] [blame] | 29 | #include "samples/image_diff_png.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 30 | #include "testing/test_support.h" |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 31 | |
thestig | f2b940c | 2016-10-13 06:48:47 -0700 | [diff] [blame] | 32 | #ifdef _WIN32 |
| 33 | #include <io.h> |
| 34 | #else |
| 35 | #include <unistd.h> |
| 36 | #endif |
| 37 | |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 38 | #ifdef PDF_ENABLE_V8 |
John Abd-El-Malek | b045ed2 | 2015-02-10 09:15:12 -0800 | [diff] [blame] | 39 | #include "v8/include/libplatform/libplatform.h" |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 40 | #include "v8/include/v8.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 41 | #endif // PDF_ENABLE_V8 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 43 | #ifdef PDF_ENABLE_SKIA |
| 44 | #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 45 | #include "third_party/skia/include/core/SkStream.h" |
| 46 | #endif |
| 47 | |
thestig | f2b940c | 2016-10-13 06:48:47 -0700 | [diff] [blame] | 48 | #ifdef _WIN32 |
| 49 | #define access _access |
| 50 | #define snprintf _snprintf |
| 51 | #define R_OK 4 |
| 52 | #endif |
| 53 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 54 | enum OutputFormat { |
| 55 | OUTPUT_NONE, |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 56 | OUTPUT_STRUCTURE, |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 57 | OUTPUT_TEXT, |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 58 | OUTPUT_PPM, |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 59 | OUTPUT_PNG, |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 60 | #ifdef _WIN32 |
| 61 | OUTPUT_BMP, |
| 62 | OUTPUT_EMF, |
Lei Zhang | d1c9b45 | 2017-05-05 17:21:36 -0700 | [diff] [blame^] | 63 | OUTPUT_PS2, |
| 64 | OUTPUT_PS3, |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 65 | #endif |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 66 | #ifdef PDF_ENABLE_SKIA |
| 67 | OUTPUT_SKP, |
| 68 | #endif |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 71 | struct Options { |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 72 | Options() |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 73 | : show_config(false), |
npm | e3c7315 | 2016-11-14 09:14:52 -0800 | [diff] [blame] | 74 | send_events(false), |
| 75 | pages(false), |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 76 | md5(false), |
npm | e3c7315 | 2016-11-14 09:14:52 -0800 | [diff] [blame] | 77 | output_format(OUTPUT_NONE) {} |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 78 | |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 79 | bool show_config; |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 80 | bool send_events; |
npm | e3c7315 | 2016-11-14 09:14:52 -0800 | [diff] [blame] | 81 | bool pages; |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 82 | bool md5; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 83 | OutputFormat output_format; |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 84 | std::string scale_factor_as_string; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 85 | std::string exe_path; |
| 86 | std::string bin_directory; |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 87 | std::string font_directory; |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 88 | // 0-based page numbers to be rendered. |
| 89 | int first_page; |
| 90 | int last_page; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 91 | }; |
| 92 | |
tonikitoo | 81d92f8 | 2016-09-21 12:44:56 -0700 | [diff] [blame] | 93 | struct FPDF_FORMFILLINFO_PDFiumTest : public FPDF_FORMFILLINFO { |
| 94 | // Hold a map of the currently loaded pages in order to avoid them |
| 95 | // to get loaded twice. |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 96 | std::map<int, FPDF_PAGE> loaded_pages; |
tonikitoo | 81d92f8 | 2016-09-21 12:44:56 -0700 | [diff] [blame] | 97 | |
| 98 | // Hold a pointer of FPDF_FORMHANDLE so that PDFium app hooks can |
| 99 | // make use of it. |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 100 | FPDF_FORMHANDLE form_handle; |
tonikitoo | 81d92f8 | 2016-09-21 12:44:56 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | static FPDF_FORMFILLINFO_PDFiumTest* ToPDFiumTestFormFillInfo( |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 104 | FPDF_FORMFILLINFO* form_fill_info) { |
| 105 | return static_cast<FPDF_FORMFILLINFO_PDFiumTest*>(form_fill_info); |
tonikitoo | 81d92f8 | 2016-09-21 12:44:56 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 108 | static bool CheckDimensions(int stride, int width, int height) { |
| 109 | if (stride < 0 || width < 0 || height < 0) |
| 110 | return false; |
| 111 | if (height > 0 && width > INT_MAX / height) |
| 112 | return false; |
| 113 | return true; |
| 114 | } |
| 115 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 116 | static void OutputMD5Hash(const char* file_name, const char* buffer, int len) { |
| 117 | // Get the MD5 hash and write it to stdout. |
| 118 | uint8_t digest[16]; |
| 119 | CRYPT_MD5Generate(reinterpret_cast<const uint8_t*>(buffer), len, digest); |
| 120 | printf("MD5:%s:", file_name); |
| 121 | for (int i = 0; i < 16; i++) |
| 122 | printf("%02x", digest[i]); |
| 123 | printf("\n"); |
| 124 | } |
| 125 | |
| 126 | static std::string WritePpm(const char* pdf_name, |
| 127 | int num, |
| 128 | const void* buffer_void, |
| 129 | int stride, |
| 130 | int width, |
| 131 | int height) { |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 132 | const char* buffer = reinterpret_cast<const char*>(buffer_void); |
| 133 | |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 134 | if (!CheckDimensions(stride, width, height)) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 135 | return ""; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 136 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | int out_len = width * height; |
| 138 | if (out_len > INT_MAX / 3) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 139 | return ""; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 140 | out_len *= 3; |
| 141 | |
| 142 | char filename[256]; |
| 143 | snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num); |
John Abd-El-Malek | a548d30 | 2014-06-26 10:18:11 -0700 | [diff] [blame] | 144 | FILE* fp = fopen(filename, "wb"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | if (!fp) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 146 | return ""; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 147 | fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height); |
| 148 | // Source data is B, G, R, unused. |
| 149 | // Dest data is R, G, B. |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 150 | std::vector<char> result(out_len); |
Lei Zhang | e00660b | 2015-08-13 15:40:18 -0700 | [diff] [blame] | 151 | for (int h = 0; h < height; ++h) { |
| 152 | const char* src_line = buffer + (stride * h); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 153 | char* dest_line = result.data() + (width * h * 3); |
Lei Zhang | e00660b | 2015-08-13 15:40:18 -0700 | [diff] [blame] | 154 | for (int w = 0; w < width; ++w) { |
| 155 | // R |
| 156 | dest_line[w * 3] = src_line[(w * 4) + 2]; |
| 157 | // G |
| 158 | dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; |
| 159 | // B |
| 160 | dest_line[(w * 3) + 2] = src_line[w * 4]; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 161 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 162 | } |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 163 | fwrite(result.data(), out_len, 1, fp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | fclose(fp); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 165 | return std::string(filename); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 166 | } |
| 167 | |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 168 | void WriteText(FPDF_PAGE page, const char* pdf_name, int num) { |
| 169 | char filename[256]; |
| 170 | int chars_formatted = |
| 171 | snprintf(filename, sizeof(filename), "%s.%d.txt", pdf_name, num); |
| 172 | if (chars_formatted < 0 || |
| 173 | static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
| 174 | fprintf(stderr, "Filename %s is too long\n", filename); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | FILE* fp = fopen(filename, "w"); |
| 179 | if (!fp) { |
| 180 | fprintf(stderr, "Failed to open %s for output\n", filename); |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | // Output in UTF32-LE. |
| 185 | uint32_t bom = 0x0000FEFF; |
| 186 | fwrite(&bom, sizeof(bom), 1, fp); |
| 187 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 188 | std::unique_ptr<void, FPDFTextPageDeleter> textpage(FPDFText_LoadPage(page)); |
| 189 | for (int i = 0; i < FPDFText_CountChars(textpage.get()); i++) { |
| 190 | uint32_t c = FPDFText_GetUnicode(textpage.get(), i); |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 191 | fwrite(&c, sizeof(c), 1, fp); |
| 192 | } |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 193 | (void)fclose(fp); |
| 194 | } |
| 195 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 196 | static std::string WritePng(const char* pdf_name, |
| 197 | int num, |
| 198 | const void* buffer_void, |
| 199 | int stride, |
| 200 | int width, |
| 201 | int height) { |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 202 | if (!CheckDimensions(stride, width, height)) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 203 | return ""; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 204 | |
| 205 | std::vector<unsigned char> png_encoding; |
| 206 | const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); |
| 207 | if (!image_diff_png::EncodeBGRAPNG( |
| 208 | buffer, width, height, stride, false, &png_encoding)) { |
| 209 | fprintf(stderr, "Failed to convert bitmap to PNG\n"); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 210 | return ""; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | char filename[256]; |
| 214 | int chars_formatted = snprintf( |
| 215 | filename, sizeof(filename), "%s.%d.png", pdf_name, num); |
| 216 | if (chars_formatted < 0 || |
| 217 | static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 218 | fprintf(stderr, "Filename %s is too long\n", filename); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 219 | return ""; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | FILE* fp = fopen(filename, "wb"); |
| 223 | if (!fp) { |
| 224 | fprintf(stderr, "Failed to open %s for output\n", filename); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 225 | return ""; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | size_t bytes_written = fwrite( |
| 229 | &png_encoding.front(), 1, png_encoding.size(), fp); |
| 230 | if (bytes_written != png_encoding.size()) |
| 231 | fprintf(stderr, "Failed to write to %s\n", filename); |
| 232 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 233 | (void)fclose(fp); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 234 | return std::string(filename); |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 237 | #ifdef _WIN32 |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 238 | static std::string WriteBmp(const char* pdf_name, |
| 239 | int num, |
| 240 | const void* buffer, |
| 241 | int stride, |
| 242 | int width, |
| 243 | int height) { |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 244 | if (!CheckDimensions(stride, width, height)) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 245 | return ""; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 246 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 247 | int out_len = stride * height; |
| 248 | if (out_len > INT_MAX / 3) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 249 | return ""; |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 250 | |
| 251 | char filename[256]; |
| 252 | snprintf(filename, sizeof(filename), "%s.%d.bmp", pdf_name, num); |
| 253 | FILE* fp = fopen(filename, "wb"); |
| 254 | if (!fp) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 255 | return ""; |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 256 | |
Nico Weber | 2827bdd | 2015-07-01 14:08:08 -0700 | [diff] [blame] | 257 | BITMAPINFO bmi = {}; |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 258 | bmi.bmiHeader.biSize = sizeof(bmi) - sizeof(RGBQUAD); |
| 259 | bmi.bmiHeader.biWidth = width; |
| 260 | bmi.bmiHeader.biHeight = -height; // top-down image |
| 261 | bmi.bmiHeader.biPlanes = 1; |
| 262 | bmi.bmiHeader.biBitCount = 32; |
| 263 | bmi.bmiHeader.biCompression = BI_RGB; |
| 264 | bmi.bmiHeader.biSizeImage = 0; |
| 265 | |
Nico Weber | 2827bdd | 2015-07-01 14:08:08 -0700 | [diff] [blame] | 266 | BITMAPFILEHEADER file_header = {}; |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 267 | file_header.bfType = 0x4d42; |
| 268 | file_header.bfSize = sizeof(file_header) + bmi.bmiHeader.biSize + out_len; |
| 269 | file_header.bfOffBits = file_header.bfSize - out_len; |
| 270 | |
| 271 | fwrite(&file_header, sizeof(file_header), 1, fp); |
| 272 | fwrite(&bmi, bmi.bmiHeader.biSize, 1, fp); |
| 273 | fwrite(buffer, out_len, 1, fp); |
| 274 | fclose(fp); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 275 | return std::string(filename); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) { |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 279 | char filename[256]; |
| 280 | snprintf(filename, sizeof(filename), "%s.%d.emf", pdf_name, num); |
| 281 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 282 | HDC dc = CreateEnhMetaFileA(nullptr, filename, nullptr, nullptr); |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 283 | |
Lei Zhang | d1c9b45 | 2017-05-05 17:21:36 -0700 | [diff] [blame^] | 284 | int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 285 | int height = static_cast<int>(FPDF_GetPageHeight(page)); |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 286 | HRGN rgn = CreateRectRgn(0, 0, width, height); |
| 287 | SelectClipRgn(dc, rgn); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 288 | DeleteObject(rgn); |
| 289 | |
| 290 | SelectObject(dc, GetStockObject(NULL_PEN)); |
| 291 | SelectObject(dc, GetStockObject(WHITE_BRUSH)); |
| 292 | // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. |
| 293 | Rectangle(dc, 0, 0, width + 1, height + 1); |
| 294 | |
| 295 | FPDF_RenderPage(dc, page, 0, 0, width, height, 0, |
| 296 | FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 297 | |
| 298 | DeleteEnhMetaFile(CloseEnhMetaFile(dc)); |
| 299 | } |
Lei Zhang | d1c9b45 | 2017-05-05 17:21:36 -0700 | [diff] [blame^] | 300 | |
| 301 | int CALLBACK EnhMetaFileProc(HDC hdc, |
| 302 | HANDLETABLE* handle_table, |
| 303 | const ENHMETARECORD* record, |
| 304 | int objects_count, |
| 305 | LPARAM param) { |
| 306 | std::vector<const ENHMETARECORD*>& items = |
| 307 | *reinterpret_cast<std::vector<const ENHMETARECORD*>*>(param); |
| 308 | items.push_back(record); |
| 309 | return 1; |
| 310 | } |
| 311 | |
| 312 | void WritePS(FPDF_PAGE page, const char* pdf_name, int num) { |
| 313 | char filename[256]; |
| 314 | snprintf(filename, sizeof(filename), "%s.%d.ps", pdf_name, num); |
| 315 | FILE* fp = fopen(filename, "wb"); |
| 316 | if (!fp) |
| 317 | return; |
| 318 | |
| 319 | HDC dc = CreateEnhMetaFileA(nullptr, nullptr, nullptr, nullptr); |
| 320 | |
| 321 | int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 322 | int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 323 | FPDF_RenderPage(dc, page, 0, 0, width, height, 0, |
| 324 | FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 325 | |
| 326 | HENHMETAFILE emf = CloseEnhMetaFile(dc); |
| 327 | std::vector<const ENHMETARECORD*> items; |
| 328 | EnumEnhMetaFile(nullptr, emf, &EnhMetaFileProc, &items, nullptr); |
| 329 | for (const ENHMETARECORD* record : items) { |
| 330 | if (record->iType != EMR_GDICOMMENT) |
| 331 | continue; |
| 332 | |
| 333 | const auto* comment = reinterpret_cast<const EMRGDICOMMENT*>(record); |
| 334 | const char* data = reinterpret_cast<const char*>(comment->Data); |
| 335 | uint16_t size = *reinterpret_cast<const uint16_t*>(data); |
| 336 | fwrite(data + sizeof(uint16_t), size, 1, fp); |
| 337 | } |
| 338 | fclose(fp); |
| 339 | DeleteEnhMetaFile(emf); |
| 340 | } |
| 341 | #endif // _WIN32 |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 342 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 343 | #ifdef PDF_ENABLE_SKIA |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 344 | static std::string WriteSkp(const char* pdf_name, |
| 345 | int num, |
| 346 | SkPictureRecorder* recorder) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 347 | char filename[256]; |
| 348 | int chars_formatted = |
| 349 | snprintf(filename, sizeof(filename), "%s.%d.skp", pdf_name, num); |
| 350 | |
| 351 | if (chars_formatted < 0 || |
| 352 | static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
| 353 | fprintf(stderr, "Filename %s is too long\n", filename); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 354 | return ""; |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 355 | } |
| 356 | |
thestig | b97e07e | 2016-09-28 22:16:40 -0700 | [diff] [blame] | 357 | sk_sp<SkPicture> picture(recorder->finishRecordingAsPicture()); |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 358 | SkFILEWStream wStream(filename); |
| 359 | picture->serialize(&wStream); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 360 | return std::string(filename); |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 361 | } |
| 362 | #endif |
| 363 | |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 364 | // These example JS platform callback handlers are entirely optional, |
| 365 | // and exist here to show the flow of information from a document back |
| 366 | // to the embedder. |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 367 | int ExampleAppAlert(IPDF_JSPLATFORM*, |
| 368 | FPDF_WIDESTRING msg, |
| 369 | FPDF_WIDESTRING title, |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 370 | int type, |
| 371 | int icon) { |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 372 | printf("%ls", GetPlatformWString(title).c_str()); |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 373 | if (icon || type) |
| 374 | printf("[icon=%d,type=%d]", icon, type); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 375 | printf(": %ls\n", GetPlatformWString(msg).c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 379 | int ExampleAppResponse(IPDF_JSPLATFORM*, |
| 380 | FPDF_WIDESTRING question, |
| 381 | FPDF_WIDESTRING title, |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 382 | FPDF_WIDESTRING default_value, |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 383 | FPDF_WIDESTRING label, |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 384 | FPDF_BOOL is_password, |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 385 | void* response, |
| 386 | int length) { |
| 387 | printf("%ls: %ls, defaultValue=%ls, label=%ls, isPassword=%d, length=%d\n", |
| 388 | GetPlatformWString(title).c_str(), |
| 389 | GetPlatformWString(question).c_str(), |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 390 | GetPlatformWString(default_value).c_str(), |
| 391 | GetPlatformWString(label).c_str(), is_password, length); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 392 | |
| 393 | // UTF-16, always LE regardless of platform. |
| 394 | uint8_t* ptr = static_cast<uint8_t*>(response); |
| 395 | ptr[0] = 'N'; |
| 396 | ptr[1] = 0; |
| 397 | ptr[2] = 'o'; |
| 398 | ptr[3] = 0; |
| 399 | return 4; |
| 400 | } |
| 401 | |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 402 | void ExampleDocGotoPage(IPDF_JSPLATFORM*, int page_number) { |
| 403 | printf("Goto Page: %d\n", page_number); |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 404 | } |
| 405 | |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 406 | void ExampleDocMail(IPDF_JSPLATFORM*, |
| 407 | void* mailData, |
| 408 | int length, |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 409 | FPDF_BOOL UI, |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 410 | FPDF_WIDESTRING To, |
| 411 | FPDF_WIDESTRING Subject, |
| 412 | FPDF_WIDESTRING CC, |
| 413 | FPDF_WIDESTRING BCC, |
| 414 | FPDF_WIDESTRING Msg) { |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 415 | printf("Mail Msg: %d, to=%ls, cc=%ls, bcc=%ls, subject=%ls, body=%ls\n", UI, |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 416 | GetPlatformWString(To).c_str(), GetPlatformWString(CC).c_str(), |
| 417 | GetPlatformWString(BCC).c_str(), GetPlatformWString(Subject).c_str(), |
| 418 | GetPlatformWString(Msg).c_str()); |
| 419 | } |
| 420 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 421 | void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 422 | std::string feature = "Unknown"; |
| 423 | switch (type) { |
| 424 | case FPDF_UNSP_DOC_XFAFORM: |
| 425 | feature = "XFA"; |
| 426 | break; |
| 427 | case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| 428 | feature = "Portfolios_Packages"; |
| 429 | break; |
| 430 | case FPDF_UNSP_DOC_ATTACHMENT: |
| 431 | case FPDF_UNSP_ANNOT_ATTACHMENT: |
| 432 | feature = "Attachment"; |
| 433 | break; |
| 434 | case FPDF_UNSP_DOC_SECURITY: |
| 435 | feature = "Rights_Management"; |
| 436 | break; |
| 437 | case FPDF_UNSP_DOC_SHAREDREVIEW: |
| 438 | feature = "Shared_Review"; |
| 439 | break; |
| 440 | case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT: |
| 441 | case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM: |
| 442 | case FPDF_UNSP_DOC_SHAREDFORM_EMAIL: |
| 443 | feature = "Shared_Form"; |
| 444 | break; |
| 445 | case FPDF_UNSP_ANNOT_3DANNOT: |
| 446 | feature = "3D"; |
| 447 | break; |
| 448 | case FPDF_UNSP_ANNOT_MOVIE: |
| 449 | feature = "Movie"; |
| 450 | break; |
| 451 | case FPDF_UNSP_ANNOT_SOUND: |
| 452 | feature = "Sound"; |
| 453 | break; |
| 454 | case FPDF_UNSP_ANNOT_SCREEN_MEDIA: |
| 455 | case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA: |
| 456 | feature = "Screen"; |
| 457 | break; |
| 458 | case FPDF_UNSP_ANNOT_SIG: |
| 459 | feature = "Digital_Signature"; |
| 460 | break; |
| 461 | } |
| 462 | printf("Unsupported feature: %s.\n", feature.c_str()); |
| 463 | } |
| 464 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 465 | bool ParseCommandLine(const std::vector<std::string>& args, |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 466 | Options* options, |
| 467 | std::vector<std::string>* files) { |
| 468 | if (args.empty()) |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 469 | return false; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 470 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 471 | options->exe_path = args[0]; |
Bo Xu | d44e392 | 2014-12-19 02:27:25 -0800 | [diff] [blame] | 472 | size_t cur_idx = 1; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 473 | for (; cur_idx < args.size(); ++cur_idx) { |
| 474 | const std::string& cur_arg = args[cur_idx]; |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 475 | if (cur_arg == "--show-config") { |
| 476 | options->show_config = true; |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 477 | } else if (cur_arg == "--send-events") { |
| 478 | options->send_events = true; |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 479 | } else if (cur_arg == "--ppm") { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 480 | if (options->output_format != OUTPUT_NONE) { |
| 481 | fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); |
| 482 | return false; |
| 483 | } |
| 484 | options->output_format = OUTPUT_PPM; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 485 | } else if (cur_arg == "--png") { |
| 486 | if (options->output_format != OUTPUT_NONE) { |
| 487 | fprintf(stderr, "Duplicate or conflicting --png argument\n"); |
| 488 | return false; |
| 489 | } |
| 490 | options->output_format = OUTPUT_PNG; |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 491 | } else if (cur_arg == "--txt") { |
| 492 | if (options->output_format != OUTPUT_NONE) { |
| 493 | fprintf(stderr, "Duplicate or conflicting --txt argument\n"); |
| 494 | return false; |
| 495 | } |
| 496 | options->output_format = OUTPUT_TEXT; |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 497 | #ifdef PDF_ENABLE_SKIA |
| 498 | } else if (cur_arg == "--skp") { |
| 499 | if (options->output_format != OUTPUT_NONE) { |
| 500 | fprintf(stderr, "Duplicate or conflicting --skp argument\n"); |
| 501 | return false; |
| 502 | } |
| 503 | options->output_format = OUTPUT_SKP; |
| 504 | #endif |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 505 | } else if (cur_arg.size() > 11 && |
| 506 | cur_arg.compare(0, 11, "--font-dir=") == 0) { |
| 507 | if (!options->font_directory.empty()) { |
| 508 | fprintf(stderr, "Duplicate --font-dir argument\n"); |
| 509 | return false; |
| 510 | } |
| 511 | options->font_directory = cur_arg.substr(11); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 512 | #ifdef _WIN32 |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 513 | } else if (cur_arg == "--emf") { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 514 | if (options->output_format != OUTPUT_NONE) { |
| 515 | fprintf(stderr, "Duplicate or conflicting --emf argument\n"); |
| 516 | return false; |
| 517 | } |
| 518 | options->output_format = OUTPUT_EMF; |
Lei Zhang | d1c9b45 | 2017-05-05 17:21:36 -0700 | [diff] [blame^] | 519 | } else if (cur_arg == "--ps2") { |
| 520 | if (options->output_format != OUTPUT_NONE) { |
| 521 | fprintf(stderr, "Duplicate or conflicting --ps2 argument\n"); |
| 522 | return false; |
| 523 | } |
| 524 | options->output_format = OUTPUT_PS2; |
| 525 | } else if (cur_arg == "--ps3") { |
| 526 | if (options->output_format != OUTPUT_NONE) { |
| 527 | fprintf(stderr, "Duplicate or conflicting --ps3 argument\n"); |
| 528 | return false; |
| 529 | } |
| 530 | options->output_format = OUTPUT_PS3; |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 531 | } else if (cur_arg == "--bmp") { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 532 | if (options->output_format != OUTPUT_NONE) { |
| 533 | fprintf(stderr, "Duplicate or conflicting --bmp argument\n"); |
| 534 | return false; |
| 535 | } |
| 536 | options->output_format = OUTPUT_BMP; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 537 | #endif // _WIN32 |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 538 | |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 539 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 540 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 541 | } else if (cur_arg.size() > 10 && |
| 542 | cur_arg.compare(0, 10, "--bin-dir=") == 0) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 543 | if (!options->bin_directory.empty()) { |
| 544 | fprintf(stderr, "Duplicate --bin-dir argument\n"); |
| 545 | return false; |
| 546 | } |
| 547 | options->bin_directory = cur_arg.substr(10); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 548 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 549 | #endif // PDF_ENABLE_V8 |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 550 | |
| 551 | } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 552 | if (!options->scale_factor_as_string.empty()) { |
| 553 | fprintf(stderr, "Duplicate --scale argument\n"); |
| 554 | return false; |
| 555 | } |
| 556 | options->scale_factor_as_string = cur_arg.substr(8); |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 557 | } else if (cur_arg == "--show-structure") { |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 558 | if (options->output_format != OUTPUT_NONE) { |
| 559 | fprintf(stderr, "Duplicate or conflicting --show-structure argument\n"); |
| 560 | return false; |
| 561 | } |
| 562 | options->output_format = OUTPUT_STRUCTURE; |
npm | e3c7315 | 2016-11-14 09:14:52 -0800 | [diff] [blame] | 563 | } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--pages=") == 0) { |
| 564 | if (options->pages) { |
| 565 | fprintf(stderr, "Duplicate --pages argument\n"); |
| 566 | return false; |
| 567 | } |
| 568 | options->pages = true; |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 569 | const std::string pages_string = cur_arg.substr(8); |
| 570 | size_t first_dash = pages_string.find("-"); |
| 571 | if (first_dash == std::string::npos) { |
| 572 | std::stringstream(pages_string) >> options->first_page; |
| 573 | options->last_page = options->first_page; |
npm | e3c7315 | 2016-11-14 09:14:52 -0800 | [diff] [blame] | 574 | } else { |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 575 | std::stringstream(pages_string.substr(0, first_dash)) >> |
| 576 | options->first_page; |
| 577 | std::stringstream(pages_string.substr(first_dash + 1)) >> |
| 578 | options->last_page; |
npm | e3c7315 | 2016-11-14 09:14:52 -0800 | [diff] [blame] | 579 | } |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 580 | } else if (cur_arg == "--md5") { |
| 581 | options->md5 = true; |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 582 | } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') { |
| 583 | fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str()); |
| 584 | return false; |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 585 | } else { |
Vitaly Buka | 8f2c3dc | 2014-08-20 10:32:36 -0700 | [diff] [blame] | 586 | break; |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 587 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 588 | } |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 589 | for (size_t i = cur_idx; i < args.size(); i++) |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 590 | files->push_back(args[i]); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 591 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 592 | return true; |
| 593 | } |
| 594 | |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 595 | FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* avail, size_t offset, size_t size) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 596 | return true; |
| 597 | } |
| 598 | |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 599 | void Add_Segment(FX_DOWNLOADHINTS* hints, size_t offset, size_t size) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 600 | |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 601 | void SendPageEvents(const FPDF_FORMHANDLE& form, |
| 602 | const FPDF_PAGE& page, |
| 603 | const std::string& events) { |
| 604 | auto lines = StringSplit(events, '\n'); |
| 605 | for (auto line : lines) { |
| 606 | auto command = StringSplit(line, '#'); |
| 607 | if (command[0].empty()) |
| 608 | continue; |
| 609 | auto tokens = StringSplit(command[0], ','); |
| 610 | if (tokens[0] == "keycode") { |
| 611 | if (tokens.size() == 2) { |
| 612 | int keycode = atoi(tokens[1].c_str()); |
| 613 | FORM_OnKeyDown(form, page, keycode, 0); |
| 614 | FORM_OnKeyUp(form, page, keycode, 0); |
| 615 | } else { |
| 616 | fprintf(stderr, "keycode: bad args\n"); |
| 617 | } |
| 618 | } else if (tokens[0] == "mousedown") { |
| 619 | if (tokens.size() == 4) { |
| 620 | int x = atoi(tokens[2].c_str()); |
| 621 | int y = atoi(tokens[3].c_str()); |
| 622 | if (tokens[1] == "left") |
| 623 | FORM_OnLButtonDown(form, page, 0, x, y); |
| 624 | #ifdef PDF_ENABLE_XFA |
| 625 | else if (tokens[1] == "right") |
| 626 | FORM_OnRButtonDown(form, page, 0, x, y); |
| 627 | #endif |
| 628 | else |
| 629 | fprintf(stderr, "mousedown: bad button name\n"); |
| 630 | } else { |
| 631 | fprintf(stderr, "mousedown: bad args\n"); |
| 632 | } |
| 633 | } else if (tokens[0] == "mouseup") { |
| 634 | if (tokens.size() == 4) { |
| 635 | int x = atoi(tokens[2].c_str()); |
| 636 | int y = atoi(tokens[3].c_str()); |
| 637 | if (tokens[1] == "left") |
| 638 | FORM_OnLButtonUp(form, page, 0, x, y); |
| 639 | #ifdef PDF_ENABLE_XFA |
| 640 | else if (tokens[1] == "right") |
| 641 | FORM_OnRButtonUp(form, page, 0, x, y); |
| 642 | #endif |
| 643 | else |
| 644 | fprintf(stderr, "mouseup: bad button name\n"); |
| 645 | } else { |
| 646 | fprintf(stderr, "mouseup: bad args\n"); |
| 647 | } |
| 648 | } else if (tokens[0] == "mousemove") { |
| 649 | if (tokens.size() == 3) { |
| 650 | int x = atoi(tokens[1].c_str()); |
| 651 | int y = atoi(tokens[2].c_str()); |
| 652 | FORM_OnMouseMove(form, page, 0, x, y); |
| 653 | } else { |
| 654 | fprintf(stderr, "mousemove: bad args\n"); |
| 655 | } |
| 656 | } else { |
| 657 | fprintf(stderr, "Unrecognized event: %s\n", tokens[0].c_str()); |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame] | 662 | FPDF_PAGE GetPageForIndex(FPDF_FORMFILLINFO* param, |
| 663 | FPDF_DOCUMENT doc, |
| 664 | int index) { |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 665 | FPDF_FORMFILLINFO_PDFiumTest* form_fill_info = |
| 666 | ToPDFiumTestFormFillInfo(param); |
| 667 | auto& loaded_pages = form_fill_info->loaded_pages; |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 668 | auto iter = loaded_pages.find(index); |
| 669 | if (iter != loaded_pages.end()) |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame] | 670 | return iter->second; |
| 671 | |
| 672 | FPDF_PAGE page = FPDF_LoadPage(doc, index); |
| 673 | if (!page) |
| 674 | return nullptr; |
| 675 | |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 676 | FPDF_FORMHANDLE& form_handle = form_fill_info->form_handle; |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 677 | FORM_OnAfterLoadPage(page, form_handle); |
| 678 | FORM_DoPageAAction(page, form_handle, FPDFPAGE_AACTION_OPEN); |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 679 | loaded_pages[index] = page; |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame] | 680 | return page; |
| 681 | } |
| 682 | |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 683 | std::wstring ConvertToWString(const unsigned short* buf, |
| 684 | unsigned long buf_size) { |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 685 | std::wstring result; |
| 686 | result.reserve(buf_size); |
| 687 | std::copy(buf, buf + buf_size, std::back_inserter(result)); |
| 688 | return result; |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 689 | } |
| 690 | |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 691 | void DumpChildStructure(FPDF_STRUCTELEMENT child, int indent) { |
| 692 | static const size_t kBufSize = 1024; |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 693 | unsigned short buf[kBufSize]; |
| 694 | unsigned long len = FPDF_StructElement_GetType(child, buf, kBufSize); |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 695 | printf("%*s%ls", indent * 2, "", ConvertToWString(buf, len).c_str()); |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 696 | |
| 697 | memset(buf, 0, sizeof(buf)); |
dan sinclair | d9dad3a | 2017-04-06 14:44:02 -0400 | [diff] [blame] | 698 | len = FPDF_StructElement_GetTitle(child, buf, kBufSize); |
| 699 | if (len > 0) |
| 700 | printf(": '%ls'", ConvertToWString(buf, len).c_str()); |
| 701 | |
| 702 | memset(buf, 0, sizeof(buf)); |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 703 | len = FPDF_StructElement_GetAltText(child, buf, kBufSize); |
| 704 | if (len > 0) |
| 705 | printf(" (%ls)", ConvertToWString(buf, len).c_str()); |
| 706 | printf("\n"); |
| 707 | |
| 708 | for (int i = 0; i < FPDF_StructElement_CountChildren(child); ++i) { |
| 709 | FPDF_STRUCTELEMENT sub_child = FPDF_StructElement_GetChildAtIndex(child, i); |
| 710 | // If the child is not an Element then this will return null. This can |
| 711 | // happen if the element is things like an object reference or a stream. |
| 712 | if (!sub_child) |
| 713 | continue; |
| 714 | |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 715 | DumpChildStructure(sub_child, indent + 1); |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
| 719 | void DumpPageStructure(FPDF_PAGE page, const int page_idx) { |
| 720 | std::unique_ptr<void, FPDFStructTreeDeleter> tree( |
| 721 | FPDF_StructTree_GetForPage(page)); |
| 722 | if (!tree) { |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 723 | fprintf(stderr, "Failed to load struct tree for page %d\n", page_idx); |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
| 727 | printf("Structure Tree for Page %d\n", page_idx); |
| 728 | for (int i = 0; i < FPDF_StructTree_CountChildren(tree.get()); ++i) { |
| 729 | FPDF_STRUCTELEMENT child = FPDF_StructTree_GetChildAtIndex(tree.get(), i); |
| 730 | if (!child) { |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 731 | fprintf(stderr, "Failed to load child %d for page %d\n", i, page_idx); |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 732 | continue; |
| 733 | } |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 734 | DumpChildStructure(child, 0); |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 735 | } |
| 736 | printf("\n\n"); |
| 737 | } |
| 738 | |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 739 | bool RenderPage(const std::string& name, |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame] | 740 | FPDF_DOCUMENT doc, |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 741 | FPDF_FORMHANDLE form, |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 742 | FPDF_FORMFILLINFO_PDFiumTest& form_fill_info, |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 743 | const int page_index, |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 744 | const Options& options, |
| 745 | const std::string& events) { |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 746 | std::unique_ptr<void, FPDFPageDeleter> page( |
| 747 | GetPageForIndex(&form_fill_info, doc, page_index)); |
| 748 | if (!page.get()) |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 749 | return false; |
Dan Sinclair | 3c67fbd | 2017-04-05 16:07:50 -0400 | [diff] [blame] | 750 | if (options.send_events) |
| 751 | SendPageEvents(form, page.get(), events); |
| 752 | if (options.output_format == OUTPUT_STRUCTURE) { |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 753 | DumpPageStructure(page.get(), page_index); |
| 754 | return true; |
| 755 | } |
| 756 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 757 | std::unique_ptr<void, FPDFTextPageDeleter> text_page( |
| 758 | FPDFText_LoadPage(page.get())); |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 759 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 760 | double scale = 1.0; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 761 | if (!options.scale_factor_as_string.empty()) |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 762 | std::stringstream(options.scale_factor_as_string) >> scale; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 763 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 764 | int width = static_cast<int>(FPDF_GetPageWidth(page.get()) * scale); |
| 765 | int height = static_cast<int>(FPDF_GetPageHeight(page.get()) * scale); |
| 766 | int alpha = FPDFPage_HasTransparency(page.get()) ? 1 : 0; |
| 767 | std::unique_ptr<void, FPDFBitmapDeleter> bitmap( |
| 768 | FPDFBitmap_Create(width, height, alpha)); |
| 769 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 770 | if (bitmap) { |
| 771 | FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 772 | FPDFBitmap_FillRect(bitmap.get(), 0, 0, width, height, fill_color); |
| 773 | FPDF_RenderPageBitmap(bitmap.get(), page.get(), 0, 0, width, height, 0, |
| 774 | FPDF_ANNOT); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 775 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 776 | FPDF_FFLDraw(form, bitmap.get(), page.get(), 0, 0, width, height, 0, |
| 777 | FPDF_ANNOT); |
| 778 | int stride = FPDFBitmap_GetStride(bitmap.get()); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 779 | const char* buffer = |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 780 | reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap.get())); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 781 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 782 | std::string&& image_file_name = ""; |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 783 | switch (options.output_format) { |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 784 | #ifdef _WIN32 |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 785 | case OUTPUT_BMP: |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 786 | image_file_name = |
| 787 | WriteBmp(name.c_str(), page_index, buffer, stride, width, height); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 788 | break; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 789 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 790 | case OUTPUT_EMF: |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 791 | WriteEmf(page.get(), name.c_str(), page_index); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 792 | break; |
Lei Zhang | d1c9b45 | 2017-05-05 17:21:36 -0700 | [diff] [blame^] | 793 | |
| 794 | case OUTPUT_PS2: |
| 795 | case OUTPUT_PS3: |
| 796 | WritePS(page.get(), name.c_str(), page_index); |
| 797 | break; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 798 | #endif |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 799 | case OUTPUT_TEXT: |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 800 | WriteText(page.get(), name.c_str(), page_index); |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 801 | break; |
| 802 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 803 | case OUTPUT_PNG: |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 804 | image_file_name = |
| 805 | WritePng(name.c_str(), page_index, buffer, stride, width, height); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 806 | break; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 807 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 808 | case OUTPUT_PPM: |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 809 | image_file_name = |
| 810 | WritePpm(name.c_str(), page_index, buffer, stride, width, height); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 811 | break; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 812 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 813 | #ifdef PDF_ENABLE_SKIA |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 814 | case OUTPUT_SKP: { |
| 815 | std::unique_ptr<SkPictureRecorder> recorder( |
thestig | b97e07e | 2016-09-28 22:16:40 -0700 | [diff] [blame] | 816 | reinterpret_cast<SkPictureRecorder*>( |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 817 | FPDF_RenderPageSkp(page.get(), width, height))); |
| 818 | FPDF_FFLRecord(form, recorder.get(), page.get(), 0, 0, width, height, 0, |
| 819 | 0); |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 820 | image_file_name = WriteSkp(name.c_str(), page_index, recorder.get()); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 821 | } break; |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 822 | #endif |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 823 | default: |
| 824 | break; |
| 825 | } |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 826 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 827 | // Write the filename and the MD5 of the buffer to stdout if we wrote a |
| 828 | // file. |
| 829 | if (options.md5 && image_file_name != "") |
| 830 | OutputMD5Hash(image_file_name.c_str(), buffer, stride * height); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 831 | } else { |
| 832 | fprintf(stderr, "Page was too large to be rendered.\n"); |
| 833 | } |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame] | 834 | |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 835 | form_fill_info.loaded_pages.erase(page_index); |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 836 | FORM_DoPageAAction(page.get(), form, FPDFPAGE_AACTION_CLOSE); |
| 837 | FORM_OnBeforeClosePage(page.get(), form); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 838 | return !!bitmap; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 839 | } |
| 840 | |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 841 | void RenderPdf(const std::string& name, |
| 842 | const char* pBuf, |
| 843 | size_t len, |
| 844 | const Options& options, |
| 845 | const std::string& events) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 846 | IPDF_JSPLATFORM platform_callbacks; |
| 847 | memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 848 | platform_callbacks.version = 3; |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 849 | platform_callbacks.app_alert = ExampleAppAlert; |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 850 | platform_callbacks.app_response = ExampleAppResponse; |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 851 | platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 852 | platform_callbacks.Doc_mail = ExampleDocMail; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 853 | |
tonikitoo | 81d92f8 | 2016-09-21 12:44:56 -0700 | [diff] [blame] | 854 | FPDF_FORMFILLINFO_PDFiumTest form_callbacks = {}; |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 855 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | ed63138 | 2014-11-18 14:10:25 -0800 | [diff] [blame] | 856 | form_callbacks.version = 2; |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 857 | #else // PDF_ENABLE_XFA |
| 858 | form_callbacks.version = 1; |
| 859 | #endif // PDF_ENABLE_XFA |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame] | 860 | form_callbacks.FFI_GetPage = GetPageForIndex; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 861 | form_callbacks.m_pJsPlatform = &platform_callbacks; |
| 862 | |
| 863 | TestLoader loader(pBuf, len); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 864 | FPDF_FILEACCESS file_access; |
| 865 | memset(&file_access, '\0', sizeof(file_access)); |
John Abd-El-Malek | 7dc5172 | 2014-05-26 12:54:31 -0700 | [diff] [blame] | 866 | file_access.m_FileLen = static_cast<unsigned long>(len); |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 867 | file_access.m_GetBlock = TestLoader::GetBlock; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 868 | file_access.m_Param = &loader; |
| 869 | |
| 870 | FX_FILEAVAIL file_avail; |
| 871 | memset(&file_avail, '\0', sizeof(file_avail)); |
| 872 | file_avail.version = 1; |
| 873 | file_avail.IsDataAvail = Is_Data_Avail; |
| 874 | |
| 875 | FX_DOWNLOADHINTS hints; |
| 876 | memset(&hints, '\0', sizeof(hints)); |
| 877 | hints.version = 1; |
| 878 | hints.AddSegment = Add_Segment; |
| 879 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 880 | int nRet = PDF_DATA_NOTAVAIL; |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 881 | bool bIsLinearized = false; |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 882 | std::unique_ptr<void, FPDFDocumentDeleter> doc; |
| 883 | std::unique_ptr<void, FPDFAvailDeleter> pdf_avail( |
| 884 | FPDFAvail_Create(&file_avail, &file_access)); |
Tom Sepez | c98895c | 2015-11-24 15:30:36 -0800 | [diff] [blame] | 885 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 886 | if (FPDFAvail_IsLinearized(pdf_avail.get()) == PDF_LINEARIZED) { |
| 887 | doc.reset(FPDFAvail_GetDocument(pdf_avail.get(), nullptr)); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 888 | if (doc) { |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 889 | while (nRet == PDF_DATA_NOTAVAIL) |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 890 | nRet = FPDFAvail_IsDocAvail(pdf_avail.get(), &hints); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 891 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 892 | if (nRet == PDF_DATA_ERROR) { |
| 893 | fprintf(stderr, "Unknown error in checking if doc was available.\n"); |
| 894 | return; |
| 895 | } |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 896 | nRet = FPDFAvail_IsFormAvail(pdf_avail.get(), &hints); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 897 | if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { |
| 898 | fprintf(stderr, |
| 899 | "Error %d was returned in checking if form was available.\n", |
| 900 | nRet); |
| 901 | return; |
| 902 | } |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 903 | bIsLinearized = true; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 904 | } |
| 905 | } else { |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 906 | doc.reset(FPDF_LoadCustomDocument(&file_access, nullptr)); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 907 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 908 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 909 | if (!doc) { |
Dan Sinclair | eb815bf | 2015-10-27 13:08:41 -0400 | [diff] [blame] | 910 | unsigned long err = FPDF_GetLastError(); |
| 911 | fprintf(stderr, "Load pdf docs unsuccessful: "); |
| 912 | switch (err) { |
| 913 | case FPDF_ERR_SUCCESS: |
| 914 | fprintf(stderr, "Success"); |
| 915 | break; |
| 916 | case FPDF_ERR_UNKNOWN: |
| 917 | fprintf(stderr, "Unknown error"); |
| 918 | break; |
| 919 | case FPDF_ERR_FILE: |
| 920 | fprintf(stderr, "File not found or could not be opened"); |
| 921 | break; |
| 922 | case FPDF_ERR_FORMAT: |
| 923 | fprintf(stderr, "File not in PDF format or corrupted"); |
| 924 | break; |
| 925 | case FPDF_ERR_PASSWORD: |
| 926 | fprintf(stderr, "Password required or incorrect password"); |
| 927 | break; |
| 928 | case FPDF_ERR_SECURITY: |
| 929 | fprintf(stderr, "Unsupported security scheme"); |
| 930 | break; |
| 931 | case FPDF_ERR_PAGE: |
| 932 | fprintf(stderr, "Page not found or content error"); |
| 933 | break; |
| 934 | default: |
| 935 | fprintf(stderr, "Unknown error %ld", err); |
| 936 | } |
| 937 | fprintf(stderr, ".\n"); |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 938 | return; |
| 939 | } |
| 940 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 941 | (void)FPDF_GetDocPermissions(doc.get()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 942 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 943 | std::unique_ptr<void, FPDFFormHandleDeleter> form( |
| 944 | FPDFDOC_InitFormFillEnvironment(doc.get(), &form_callbacks)); |
| 945 | form_callbacks.form_handle = form.get(); |
tonikitoo | 81d92f8 | 2016-09-21 12:44:56 -0700 | [diff] [blame] | 946 | |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 947 | #ifdef PDF_ENABLE_XFA |
thestig | b97e07e | 2016-09-28 22:16:40 -0700 | [diff] [blame] | 948 | int doc_type = DOCTYPE_PDF; |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 949 | if (FPDF_HasXFAField(doc.get(), &doc_type) && doc_type != DOCTYPE_PDF && |
| 950 | !FPDF_LoadXFA(doc.get())) { |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 951 | fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n"); |
Tom Sepez | 5645138 | 2014-12-05 13:30:51 -0800 | [diff] [blame] | 952 | } |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 953 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 954 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 955 | FPDF_SetFormFieldHighlightColor(form.get(), 0, 0xFFE4DD); |
| 956 | FPDF_SetFormFieldHighlightAlpha(form.get(), 100); |
| 957 | FORM_DoDocumentJSAction(form.get()); |
| 958 | FORM_DoDocumentOpenAction(form.get()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 959 | |
Lei Zhang | d1c9b45 | 2017-05-05 17:21:36 -0700 | [diff] [blame^] | 960 | #if _WIN32 |
| 961 | if (options.output_format == OUTPUT_PS2) |
| 962 | FPDF_SetPrintPostscriptLevel(2); |
| 963 | else if (options.output_format == OUTPUT_PS3) |
| 964 | FPDF_SetPrintPostscriptLevel(3); |
| 965 | #endif |
| 966 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 967 | int page_count = FPDF_GetPageCount(doc.get()); |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 968 | int rendered_pages = 0; |
| 969 | int bad_pages = 0; |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 970 | int first_page = options.pages ? options.first_page : 0; |
| 971 | int last_page = options.pages ? options.last_page + 1 : page_count; |
| 972 | for (int i = first_page; i < last_page; ++i) { |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 973 | if (bIsLinearized) { |
| 974 | nRet = PDF_DATA_NOTAVAIL; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 975 | while (nRet == PDF_DATA_NOTAVAIL) |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 976 | nRet = FPDFAvail_IsPageAvail(pdf_avail.get(), i, &hints); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 977 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 978 | if (nRet == PDF_DATA_ERROR) { |
| 979 | fprintf(stderr, "Unknown error in checking if page %d is available.\n", |
| 980 | i); |
| 981 | return; |
| 982 | } |
| 983 | } |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 984 | if (RenderPage(name, doc.get(), form.get(), form_callbacks, i, options, |
| 985 | events)) |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 986 | ++rendered_pages; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 987 | else |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 988 | ++bad_pages; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Tom Sepez | 1d17a04 | 2017-03-16 13:22:47 -0700 | [diff] [blame] | 991 | FORM_DoDocumentAAction(form.get(), FPDFDOC_AACTION_WC); |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 992 | fprintf(stderr, "Rendered %d pages.\n", rendered_pages); |
tsepez | 10b01bf | 2016-05-04 12:52:42 -0700 | [diff] [blame] | 993 | if (bad_pages) |
| 994 | fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 997 | static void ShowConfig() { |
| 998 | std::string config; |
| 999 | std::string maybe_comma; |
| 1000 | #if PDF_ENABLE_V8 |
| 1001 | config.append(maybe_comma); |
| 1002 | config.append("V8"); |
| 1003 | maybe_comma = ","; |
| 1004 | #endif // PDF_ENABLE_V8 |
| 1005 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 1006 | config.append(maybe_comma); |
| 1007 | config.append("V8_EXTERNAL"); |
| 1008 | maybe_comma = ","; |
| 1009 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 1010 | #ifdef PDF_ENABLE_XFA |
| 1011 | config.append(maybe_comma); |
| 1012 | config.append("XFA"); |
| 1013 | maybe_comma = ","; |
| 1014 | #endif // PDF_ENABLE_XFA |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 1015 | #ifdef PDF_ENABLE_ASAN |
| 1016 | config.append(maybe_comma); |
| 1017 | config.append("ASAN"); |
| 1018 | maybe_comma = ","; |
| 1019 | #endif // PDF_ENABLE_ASAN |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 1020 | printf("%s\n", config.c_str()); |
| 1021 | } |
| 1022 | |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 1023 | static const char kUsageString[] = |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 1024 | "Usage: pdfium_test [OPTION] [FILE]...\n" |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 1025 | " --show-config - print build options and exit\n" |
Dan Sinclair | ddcb6e7 | 2017-04-05 10:30:33 -0400 | [diff] [blame] | 1026 | " --show-structure - print the structure elements from the document\n" |
tsepez | 10b01bf | 2016-05-04 12:52:42 -0700 | [diff] [blame] | 1027 | " --send-events - send input described by .evt file\n" |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 1028 | " --bin-dir=<path> - override path to v8 external data\n" |
| 1029 | " --font-dir=<path> - override path to external fonts\n" |
| 1030 | " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 1031 | " --pages=<number>(-<number>) - only render the given 0-based page(s)\n" |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 1032 | #ifdef _WIN32 |
| 1033 | " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
| 1034 | " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
Lei Zhang | d1c9b45 | 2017-05-05 17:21:36 -0700 | [diff] [blame^] | 1035 | " --ps2 - write page raw PostScript (Lvl 2) <pdf-name>.<page-number>.ps\n" |
| 1036 | " --ps3 - write page raw PostScript (Lvl 3) <pdf-name>.<page-number>.ps\n" |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 1037 | #endif // _WIN32 |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 1038 | " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 1039 | " --png - write page images <pdf-name>.<page-number>.png\n" |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 1040 | " --ppm - write page images <pdf-name>.<page-number>.ppm\n" |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 1041 | #ifdef PDF_ENABLE_SKIA |
| 1042 | " --skp - write page images <pdf-name>.<page-number>.skp\n" |
| 1043 | #endif |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 1044 | " --md5 - write output image paths and their md5 hashes to stdout.\n" |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 1045 | ""; |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 1046 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1047 | int main(int argc, const char* argv[]) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 1048 | std::vector<std::string> args(argv, argv + argc); |
| 1049 | Options options; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 1050 | std::vector<std::string> files; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 1051 | if (!ParseCommandLine(args, &options, &files)) { |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 1052 | fprintf(stderr, "%s", kUsageString); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1053 | return 1; |
| 1054 | } |
| 1055 | |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 1056 | if (options.show_config) { |
| 1057 | ShowConfig(); |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | if (files.empty()) { |
| 1062 | fprintf(stderr, "No input files.\n"); |
| 1063 | return 1; |
| 1064 | } |
| 1065 | |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 1066 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 1067 | v8::Platform* platform; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 1068 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 1069 | v8::StartupData natives; |
| 1070 | v8::StartupData snapshot; |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 1071 | InitializeV8ForPDFium(options.exe_path, options.bin_directory, &natives, |
| 1072 | &snapshot, &platform); |
| 1073 | #else // V8_USE_EXTERNAL_STARTUP_DATA |
jochen | 9e077d2 | 2016-06-09 02:51:13 -0700 | [diff] [blame] | 1074 | InitializeV8ForPDFium(options.exe_path, &platform); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 1075 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 1076 | #endif // PDF_ENABLE_V8 |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 1077 | |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 1078 | FPDF_LIBRARY_CONFIG config; |
| 1079 | config.version = 2; |
| 1080 | config.m_pUserFontPaths = nullptr; |
| 1081 | config.m_pIsolate = nullptr; |
| 1082 | config.m_v8EmbedderSlot = 0; |
| 1083 | |
| 1084 | const char* path_array[2]; |
| 1085 | if (!options.font_directory.empty()) { |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 1086 | path_array[0] = options.font_directory.c_str(); |
| 1087 | path_array[1] = nullptr; |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 1088 | config.m_pUserFontPaths = path_array; |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 1089 | } |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 1090 | FPDF_InitLibraryWithConfig(&config); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1091 | |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 1092 | UNSUPPORT_INFO unsupported_info; |
| 1093 | memset(&unsupported_info, '\0', sizeof(unsupported_info)); |
| 1094 | unsupported_info.version = 1; |
| 1095 | unsupported_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1096 | |
npm | fa20cd5 | 2016-11-14 13:33:40 -0800 | [diff] [blame] | 1097 | FSDK_SetUnSpObjProcessHandler(&unsupported_info); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1098 | |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 1099 | for (const std::string& filename : files) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 1100 | size_t file_length = 0; |
Tom Sepez | 0aa3531 | 2016-01-06 10:16:32 -0800 | [diff] [blame] | 1101 | std::unique_ptr<char, pdfium::FreeDeleter> file_contents = |
| 1102 | GetFileContents(filename.c_str(), &file_length); |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 1103 | if (!file_contents) |
| 1104 | continue; |
tsepez | 10b01bf | 2016-05-04 12:52:42 -0700 | [diff] [blame] | 1105 | fprintf(stderr, "Rendering PDF file %s.\n", filename.c_str()); |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 1106 | std::string events; |
| 1107 | if (options.send_events) { |
| 1108 | std::string event_filename = filename; |
| 1109 | size_t event_length = 0; |
| 1110 | size_t extension_pos = event_filename.find(".pdf"); |
| 1111 | if (extension_pos != std::string::npos) { |
| 1112 | event_filename.replace(extension_pos, 4, ".evt"); |
thestig | f2b940c | 2016-10-13 06:48:47 -0700 | [diff] [blame] | 1113 | if (access(event_filename.c_str(), R_OK) == 0) { |
| 1114 | fprintf(stderr, "Using event file %s.\n", event_filename.c_str()); |
| 1115 | std::unique_ptr<char, pdfium::FreeDeleter> event_contents = |
| 1116 | GetFileContents(event_filename.c_str(), &event_length); |
| 1117 | if (event_contents) { |
| 1118 | fprintf(stderr, "Sending events from: %s\n", |
| 1119 | event_filename.c_str()); |
| 1120 | events = std::string(event_contents.get(), event_length); |
| 1121 | } |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | RenderPdf(filename, file_contents.get(), file_length, options, events); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | FPDF_DestroyLibrary(); |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 1129 | #ifdef PDF_ENABLE_V8 |
John Abd-El-Malek | b045ed2 | 2015-02-10 09:15:12 -0800 | [diff] [blame] | 1130 | v8::V8::ShutdownPlatform(); |
| 1131 | delete platform; |
thestig | c08cd7a | 2016-06-27 09:47:59 -0700 | [diff] [blame] | 1132 | |
| 1133 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 1134 | free(const_cast<char*>(natives.data)); |
| 1135 | free(const_cast<char*>(snapshot.data)); |
| 1136 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 1137 | #endif // PDF_ENABLE_V8 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1138 | |
| 1139 | return 0; |
| 1140 | } |