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 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 20 | #include "public/fpdf_dataavail.h" |
Lei Zhang | 453d96b | 2015-12-31 13:13:10 -0800 | [diff] [blame] | 21 | #include "public/fpdf_edit.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 22 | #include "public/fpdf_ext.h" |
| 23 | #include "public/fpdf_formfill.h" |
| 24 | #include "public/fpdf_text.h" |
| 25 | #include "public/fpdfview.h" |
Dan Sinclair | efbc191 | 2016-02-17 16:54:43 -0500 | [diff] [blame] | 26 | #include "samples/image_diff_png.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 27 | #include "testing/test_support.h" |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 28 | |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 29 | #ifdef PDF_ENABLE_V8 |
John Abd-El-Malek | b045ed2 | 2015-02-10 09:15:12 -0800 | [diff] [blame] | 30 | #include "v8/include/libplatform/libplatform.h" |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 31 | #include "v8/include/v8.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 32 | #endif // PDF_ENABLE_V8 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 33 | |
| 34 | #ifdef _WIN32 |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 35 | #define snprintf _snprintf |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | #endif |
| 37 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 38 | #ifdef PDF_ENABLE_SKIA |
| 39 | #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 40 | #include "third_party/skia/include/core/SkStream.h" |
| 41 | #endif |
| 42 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 43 | enum OutputFormat { |
| 44 | OUTPUT_NONE, |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 45 | OUTPUT_TEXT, |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 46 | OUTPUT_PPM, |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 47 | OUTPUT_PNG, |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 48 | #ifdef _WIN32 |
| 49 | OUTPUT_BMP, |
| 50 | OUTPUT_EMF, |
| 51 | #endif |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 52 | #ifdef PDF_ENABLE_SKIA |
| 53 | OUTPUT_SKP, |
| 54 | #endif |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame^] | 57 | // Hold a map of the currently loaded pages in order to avoid them |
| 58 | // to get loaded twice. |
| 59 | std::map<int, FPDF_PAGE> g_loadedPages; |
| 60 | |
| 61 | // Hold a global pointer of FPDF_FORMHANDLE so that PDFium |
| 62 | // app hooks can made use of it. |
| 63 | FPDF_FORMHANDLE g_formHandle; |
| 64 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 65 | struct Options { |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 66 | Options() |
| 67 | : show_config(false), send_events(false), output_format(OUTPUT_NONE) {} |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 68 | |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 69 | bool show_config; |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 70 | bool send_events; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 71 | OutputFormat output_format; |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 72 | std::string scale_factor_as_string; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 73 | std::string exe_path; |
| 74 | std::string bin_directory; |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 75 | std::string font_directory; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 78 | static bool CheckDimensions(int stride, int width, int height) { |
| 79 | if (stride < 0 || width < 0 || height < 0) |
| 80 | return false; |
| 81 | if (height > 0 && width > INT_MAX / height) |
| 82 | return false; |
| 83 | return true; |
| 84 | } |
| 85 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 86 | static void WritePpm(const char* pdf_name, int num, const void* buffer_void, |
| 87 | int stride, int width, int height) { |
| 88 | const char* buffer = reinterpret_cast<const char*>(buffer_void); |
| 89 | |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 90 | if (!CheckDimensions(stride, width, height)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 91 | return; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 92 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | int out_len = width * height; |
| 94 | if (out_len > INT_MAX / 3) |
| 95 | return; |
| 96 | out_len *= 3; |
| 97 | |
| 98 | char filename[256]; |
| 99 | snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num); |
John Abd-El-Malek | a548d30 | 2014-06-26 10:18:11 -0700 | [diff] [blame] | 100 | FILE* fp = fopen(filename, "wb"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | if (!fp) |
| 102 | return; |
| 103 | fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height); |
| 104 | // Source data is B, G, R, unused. |
| 105 | // Dest data is R, G, B. |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 106 | std::vector<char> result(out_len); |
Lei Zhang | e00660b | 2015-08-13 15:40:18 -0700 | [diff] [blame] | 107 | for (int h = 0; h < height; ++h) { |
| 108 | const char* src_line = buffer + (stride * h); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 109 | char* dest_line = result.data() + (width * h * 3); |
Lei Zhang | e00660b | 2015-08-13 15:40:18 -0700 | [diff] [blame] | 110 | for (int w = 0; w < width; ++w) { |
| 111 | // R |
| 112 | dest_line[w * 3] = src_line[(w * 4) + 2]; |
| 113 | // G |
| 114 | dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; |
| 115 | // B |
| 116 | dest_line[(w * 3) + 2] = src_line[w * 4]; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 117 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 118 | } |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 119 | fwrite(result.data(), out_len, 1, fp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | fclose(fp); |
| 121 | } |
| 122 | |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 123 | void WriteText(FPDF_PAGE page, const char* pdf_name, int num) { |
| 124 | char filename[256]; |
| 125 | int chars_formatted = |
| 126 | snprintf(filename, sizeof(filename), "%s.%d.txt", pdf_name, num); |
| 127 | if (chars_formatted < 0 || |
| 128 | static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
| 129 | fprintf(stderr, "Filename %s is too long\n", filename); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | FILE* fp = fopen(filename, "w"); |
| 134 | if (!fp) { |
| 135 | fprintf(stderr, "Failed to open %s for output\n", filename); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | // Output in UTF32-LE. |
| 140 | uint32_t bom = 0x0000FEFF; |
| 141 | fwrite(&bom, sizeof(bom), 1, fp); |
| 142 | |
| 143 | FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
| 144 | for (int i = 0; i < FPDFText_CountChars(textpage); i++) { |
| 145 | uint32_t c = FPDFText_GetUnicode(textpage, i); |
| 146 | fwrite(&c, sizeof(c), 1, fp); |
| 147 | } |
| 148 | |
| 149 | FPDFText_ClosePage(textpage); |
| 150 | |
| 151 | (void)fclose(fp); |
| 152 | } |
| 153 | |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 154 | static void WritePng(const char* pdf_name, int num, const void* buffer_void, |
| 155 | int stride, int width, int height) { |
| 156 | if (!CheckDimensions(stride, width, height)) |
| 157 | return; |
| 158 | |
| 159 | std::vector<unsigned char> png_encoding; |
| 160 | const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); |
| 161 | if (!image_diff_png::EncodeBGRAPNG( |
| 162 | buffer, width, height, stride, false, &png_encoding)) { |
| 163 | fprintf(stderr, "Failed to convert bitmap to PNG\n"); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | char filename[256]; |
| 168 | int chars_formatted = snprintf( |
| 169 | filename, sizeof(filename), "%s.%d.png", pdf_name, num); |
| 170 | if (chars_formatted < 0 || |
| 171 | static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 172 | fprintf(stderr, "Filename %s is too long\n", filename); |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | |
| 176 | FILE* fp = fopen(filename, "wb"); |
| 177 | if (!fp) { |
| 178 | fprintf(stderr, "Failed to open %s for output\n", filename); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | size_t bytes_written = fwrite( |
| 183 | &png_encoding.front(), 1, png_encoding.size(), fp); |
| 184 | if (bytes_written != png_encoding.size()) |
| 185 | fprintf(stderr, "Failed to write to %s\n", filename); |
| 186 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 187 | (void)fclose(fp); |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 190 | #ifdef _WIN32 |
| 191 | static void WriteBmp(const char* pdf_name, int num, const void* buffer, |
| 192 | int stride, int width, int height) { |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 193 | if (!CheckDimensions(stride, width, height)) |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 194 | return; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 195 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 196 | int out_len = stride * height; |
| 197 | if (out_len > INT_MAX / 3) |
| 198 | return; |
| 199 | |
| 200 | char filename[256]; |
| 201 | snprintf(filename, sizeof(filename), "%s.%d.bmp", pdf_name, num); |
| 202 | FILE* fp = fopen(filename, "wb"); |
| 203 | if (!fp) |
| 204 | return; |
| 205 | |
Nico Weber | 2827bdd | 2015-07-01 14:08:08 -0700 | [diff] [blame] | 206 | BITMAPINFO bmi = {}; |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 207 | bmi.bmiHeader.biSize = sizeof(bmi) - sizeof(RGBQUAD); |
| 208 | bmi.bmiHeader.biWidth = width; |
| 209 | bmi.bmiHeader.biHeight = -height; // top-down image |
| 210 | bmi.bmiHeader.biPlanes = 1; |
| 211 | bmi.bmiHeader.biBitCount = 32; |
| 212 | bmi.bmiHeader.biCompression = BI_RGB; |
| 213 | bmi.bmiHeader.biSizeImage = 0; |
| 214 | |
Nico Weber | 2827bdd | 2015-07-01 14:08:08 -0700 | [diff] [blame] | 215 | BITMAPFILEHEADER file_header = {}; |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 216 | file_header.bfType = 0x4d42; |
| 217 | file_header.bfSize = sizeof(file_header) + bmi.bmiHeader.biSize + out_len; |
| 218 | file_header.bfOffBits = file_header.bfSize - out_len; |
| 219 | |
| 220 | fwrite(&file_header, sizeof(file_header), 1, fp); |
| 221 | fwrite(&bmi, bmi.bmiHeader.biSize, 1, fp); |
| 222 | fwrite(buffer, out_len, 1, fp); |
| 223 | fclose(fp); |
| 224 | } |
| 225 | |
| 226 | void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) { |
| 227 | int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 228 | int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 229 | |
| 230 | char filename[256]; |
| 231 | snprintf(filename, sizeof(filename), "%s.%d.emf", pdf_name, num); |
| 232 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 233 | HDC dc = CreateEnhMetaFileA(nullptr, filename, nullptr, nullptr); |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 234 | |
| 235 | HRGN rgn = CreateRectRgn(0, 0, width, height); |
| 236 | SelectClipRgn(dc, rgn); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 237 | DeleteObject(rgn); |
| 238 | |
| 239 | SelectObject(dc, GetStockObject(NULL_PEN)); |
| 240 | SelectObject(dc, GetStockObject(WHITE_BRUSH)); |
| 241 | // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. |
| 242 | Rectangle(dc, 0, 0, width + 1, height + 1); |
| 243 | |
| 244 | FPDF_RenderPage(dc, page, 0, 0, width, height, 0, |
| 245 | FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 246 | |
| 247 | DeleteEnhMetaFile(CloseEnhMetaFile(dc)); |
| 248 | } |
| 249 | #endif |
| 250 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 251 | #ifdef PDF_ENABLE_SKIA |
| 252 | void WriteSkp(const char* pdf_name, int num, const void* recorder) { |
| 253 | char filename[256]; |
| 254 | int chars_formatted = |
| 255 | snprintf(filename, sizeof(filename), "%s.%d.skp", pdf_name, num); |
| 256 | |
| 257 | if (chars_formatted < 0 || |
| 258 | static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
| 259 | fprintf(stderr, "Filename %s is too long\n", filename); |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | SkPictureRecorder* r = (SkPictureRecorder*)recorder; |
caryclark | 3173543 | 2016-05-11 10:52:53 -0700 | [diff] [blame] | 264 | sk_sp<SkPicture> picture(r->finishRecordingAsPicture()); |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 265 | SkFILEWStream wStream(filename); |
| 266 | picture->serialize(&wStream); |
| 267 | } |
| 268 | #endif |
| 269 | |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 270 | // These example JS platform callback handlers are entirely optional, |
| 271 | // and exist here to show the flow of information from a document back |
| 272 | // to the embedder. |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 273 | int ExampleAppAlert(IPDF_JSPLATFORM*, |
| 274 | FPDF_WIDESTRING msg, |
| 275 | FPDF_WIDESTRING title, |
| 276 | int nType, |
| 277 | int nIcon) { |
| 278 | printf("%ls", GetPlatformWString(title).c_str()); |
| 279 | if (nIcon || nType) |
| 280 | printf("[icon=%d,type=%d]", nIcon, nType); |
| 281 | printf(": %ls\n", GetPlatformWString(msg).c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 282 | return 0; |
| 283 | } |
| 284 | |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 285 | int ExampleAppResponse(IPDF_JSPLATFORM*, |
| 286 | FPDF_WIDESTRING question, |
| 287 | FPDF_WIDESTRING title, |
| 288 | FPDF_WIDESTRING defaultValue, |
| 289 | FPDF_WIDESTRING label, |
| 290 | FPDF_BOOL isPassword, |
| 291 | void* response, |
| 292 | int length) { |
| 293 | printf("%ls: %ls, defaultValue=%ls, label=%ls, isPassword=%d, length=%d\n", |
| 294 | GetPlatformWString(title).c_str(), |
| 295 | GetPlatformWString(question).c_str(), |
| 296 | GetPlatformWString(defaultValue).c_str(), |
| 297 | GetPlatformWString(label).c_str(), isPassword, length); |
| 298 | |
| 299 | // UTF-16, always LE regardless of platform. |
| 300 | uint8_t* ptr = static_cast<uint8_t*>(response); |
| 301 | ptr[0] = 'N'; |
| 302 | ptr[1] = 0; |
| 303 | ptr[2] = 'o'; |
| 304 | ptr[3] = 0; |
| 305 | return 4; |
| 306 | } |
| 307 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 308 | void ExampleDocGotoPage(IPDF_JSPLATFORM*, int pageNumber) { |
| 309 | printf("Goto Page: %d\n", pageNumber); |
| 310 | } |
| 311 | |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 312 | void ExampleDocMail(IPDF_JSPLATFORM*, |
| 313 | void* mailData, |
| 314 | int length, |
| 315 | FPDF_BOOL bUI, |
| 316 | FPDF_WIDESTRING To, |
| 317 | FPDF_WIDESTRING Subject, |
| 318 | FPDF_WIDESTRING CC, |
| 319 | FPDF_WIDESTRING BCC, |
| 320 | FPDF_WIDESTRING Msg) { |
| 321 | printf("Mail Msg: %d, to=%ls, cc=%ls, bcc=%ls, subject=%ls, body=%ls\n", bUI, |
| 322 | GetPlatformWString(To).c_str(), GetPlatformWString(CC).c_str(), |
| 323 | GetPlatformWString(BCC).c_str(), GetPlatformWString(Subject).c_str(), |
| 324 | GetPlatformWString(Msg).c_str()); |
| 325 | } |
| 326 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 327 | void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 328 | std::string feature = "Unknown"; |
| 329 | switch (type) { |
| 330 | case FPDF_UNSP_DOC_XFAFORM: |
| 331 | feature = "XFA"; |
| 332 | break; |
| 333 | case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| 334 | feature = "Portfolios_Packages"; |
| 335 | break; |
| 336 | case FPDF_UNSP_DOC_ATTACHMENT: |
| 337 | case FPDF_UNSP_ANNOT_ATTACHMENT: |
| 338 | feature = "Attachment"; |
| 339 | break; |
| 340 | case FPDF_UNSP_DOC_SECURITY: |
| 341 | feature = "Rights_Management"; |
| 342 | break; |
| 343 | case FPDF_UNSP_DOC_SHAREDREVIEW: |
| 344 | feature = "Shared_Review"; |
| 345 | break; |
| 346 | case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT: |
| 347 | case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM: |
| 348 | case FPDF_UNSP_DOC_SHAREDFORM_EMAIL: |
| 349 | feature = "Shared_Form"; |
| 350 | break; |
| 351 | case FPDF_UNSP_ANNOT_3DANNOT: |
| 352 | feature = "3D"; |
| 353 | break; |
| 354 | case FPDF_UNSP_ANNOT_MOVIE: |
| 355 | feature = "Movie"; |
| 356 | break; |
| 357 | case FPDF_UNSP_ANNOT_SOUND: |
| 358 | feature = "Sound"; |
| 359 | break; |
| 360 | case FPDF_UNSP_ANNOT_SCREEN_MEDIA: |
| 361 | case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA: |
| 362 | feature = "Screen"; |
| 363 | break; |
| 364 | case FPDF_UNSP_ANNOT_SIG: |
| 365 | feature = "Digital_Signature"; |
| 366 | break; |
| 367 | } |
| 368 | printf("Unsupported feature: %s.\n", feature.c_str()); |
| 369 | } |
| 370 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 371 | bool ParseCommandLine(const std::vector<std::string>& args, |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 372 | Options* options, |
| 373 | std::vector<std::string>* files) { |
| 374 | if (args.empty()) |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 375 | return false; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 376 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 377 | options->exe_path = args[0]; |
Bo Xu | d44e392 | 2014-12-19 02:27:25 -0800 | [diff] [blame] | 378 | size_t cur_idx = 1; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 379 | for (; cur_idx < args.size(); ++cur_idx) { |
| 380 | const std::string& cur_arg = args[cur_idx]; |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 381 | if (cur_arg == "--show-config") { |
| 382 | options->show_config = true; |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 383 | } else if (cur_arg == "--send-events") { |
| 384 | options->send_events = true; |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 385 | } else if (cur_arg == "--ppm") { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 386 | if (options->output_format != OUTPUT_NONE) { |
| 387 | fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); |
| 388 | return false; |
| 389 | } |
| 390 | options->output_format = OUTPUT_PPM; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 391 | } else if (cur_arg == "--png") { |
| 392 | if (options->output_format != OUTPUT_NONE) { |
| 393 | fprintf(stderr, "Duplicate or conflicting --png argument\n"); |
| 394 | return false; |
| 395 | } |
| 396 | options->output_format = OUTPUT_PNG; |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 397 | } else if (cur_arg == "--txt") { |
| 398 | if (options->output_format != OUTPUT_NONE) { |
| 399 | fprintf(stderr, "Duplicate or conflicting --txt argument\n"); |
| 400 | return false; |
| 401 | } |
| 402 | options->output_format = OUTPUT_TEXT; |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 403 | #ifdef PDF_ENABLE_SKIA |
| 404 | } else if (cur_arg == "--skp") { |
| 405 | if (options->output_format != OUTPUT_NONE) { |
| 406 | fprintf(stderr, "Duplicate or conflicting --skp argument\n"); |
| 407 | return false; |
| 408 | } |
| 409 | options->output_format = OUTPUT_SKP; |
| 410 | #endif |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 411 | } else if (cur_arg.size() > 11 && |
| 412 | cur_arg.compare(0, 11, "--font-dir=") == 0) { |
| 413 | if (!options->font_directory.empty()) { |
| 414 | fprintf(stderr, "Duplicate --font-dir argument\n"); |
| 415 | return false; |
| 416 | } |
| 417 | options->font_directory = cur_arg.substr(11); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 418 | #ifdef _WIN32 |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 419 | } else if (cur_arg == "--emf") { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 420 | if (options->output_format != OUTPUT_NONE) { |
| 421 | fprintf(stderr, "Duplicate or conflicting --emf argument\n"); |
| 422 | return false; |
| 423 | } |
| 424 | options->output_format = OUTPUT_EMF; |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 425 | } else if (cur_arg == "--bmp") { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 426 | if (options->output_format != OUTPUT_NONE) { |
| 427 | fprintf(stderr, "Duplicate or conflicting --bmp argument\n"); |
| 428 | return false; |
| 429 | } |
| 430 | options->output_format = OUTPUT_BMP; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 431 | #endif // _WIN32 |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 432 | |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 433 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 434 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 435 | } else if (cur_arg.size() > 10 && |
| 436 | cur_arg.compare(0, 10, "--bin-dir=") == 0) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 437 | if (!options->bin_directory.empty()) { |
| 438 | fprintf(stderr, "Duplicate --bin-dir argument\n"); |
| 439 | return false; |
| 440 | } |
| 441 | options->bin_directory = cur_arg.substr(10); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 442 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 443 | #endif // PDF_ENABLE_V8 |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 444 | |
| 445 | } 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] | 446 | if (!options->scale_factor_as_string.empty()) { |
| 447 | fprintf(stderr, "Duplicate --scale argument\n"); |
| 448 | return false; |
| 449 | } |
| 450 | options->scale_factor_as_string = cur_arg.substr(8); |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 451 | } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') { |
| 452 | fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str()); |
| 453 | return false; |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 454 | } else { |
Vitaly Buka | 8f2c3dc | 2014-08-20 10:32:36 -0700 | [diff] [blame] | 455 | break; |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 456 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 457 | } |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 458 | for (size_t i = cur_idx; i < args.size(); i++) |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 459 | files->push_back(args[i]); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 460 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 461 | return true; |
| 462 | } |
| 463 | |
Tom Sepez | cf22eb8 | 2015-05-12 17:28:08 -0700 | [diff] [blame] | 464 | FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 465 | return true; |
| 466 | } |
| 467 | |
| 468 | void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
| 469 | } |
| 470 | |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 471 | void SendPageEvents(const FPDF_FORMHANDLE& form, |
| 472 | const FPDF_PAGE& page, |
| 473 | const std::string& events) { |
| 474 | auto lines = StringSplit(events, '\n'); |
| 475 | for (auto line : lines) { |
| 476 | auto command = StringSplit(line, '#'); |
| 477 | if (command[0].empty()) |
| 478 | continue; |
| 479 | auto tokens = StringSplit(command[0], ','); |
| 480 | if (tokens[0] == "keycode") { |
| 481 | if (tokens.size() == 2) { |
| 482 | int keycode = atoi(tokens[1].c_str()); |
| 483 | FORM_OnKeyDown(form, page, keycode, 0); |
| 484 | FORM_OnKeyUp(form, page, keycode, 0); |
| 485 | } else { |
| 486 | fprintf(stderr, "keycode: bad args\n"); |
| 487 | } |
| 488 | } else if (tokens[0] == "mousedown") { |
| 489 | if (tokens.size() == 4) { |
| 490 | int x = atoi(tokens[2].c_str()); |
| 491 | int y = atoi(tokens[3].c_str()); |
| 492 | if (tokens[1] == "left") |
| 493 | FORM_OnLButtonDown(form, page, 0, x, y); |
| 494 | #ifdef PDF_ENABLE_XFA |
| 495 | else if (tokens[1] == "right") |
| 496 | FORM_OnRButtonDown(form, page, 0, x, y); |
| 497 | #endif |
| 498 | else |
| 499 | fprintf(stderr, "mousedown: bad button name\n"); |
| 500 | } else { |
| 501 | fprintf(stderr, "mousedown: bad args\n"); |
| 502 | } |
| 503 | } else if (tokens[0] == "mouseup") { |
| 504 | if (tokens.size() == 4) { |
| 505 | int x = atoi(tokens[2].c_str()); |
| 506 | int y = atoi(tokens[3].c_str()); |
| 507 | if (tokens[1] == "left") |
| 508 | FORM_OnLButtonUp(form, page, 0, x, y); |
| 509 | #ifdef PDF_ENABLE_XFA |
| 510 | else if (tokens[1] == "right") |
| 511 | FORM_OnRButtonUp(form, page, 0, x, y); |
| 512 | #endif |
| 513 | else |
| 514 | fprintf(stderr, "mouseup: bad button name\n"); |
| 515 | } else { |
| 516 | fprintf(stderr, "mouseup: bad args\n"); |
| 517 | } |
| 518 | } else if (tokens[0] == "mousemove") { |
| 519 | if (tokens.size() == 3) { |
| 520 | int x = atoi(tokens[1].c_str()); |
| 521 | int y = atoi(tokens[2].c_str()); |
| 522 | FORM_OnMouseMove(form, page, 0, x, y); |
| 523 | } else { |
| 524 | fprintf(stderr, "mousemove: bad args\n"); |
| 525 | } |
| 526 | } else { |
| 527 | fprintf(stderr, "Unrecognized event: %s\n", tokens[0].c_str()); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame^] | 532 | FPDF_PAGE GetPageForIndex(FPDF_FORMFILLINFO* param, |
| 533 | FPDF_DOCUMENT doc, |
| 534 | int index) { |
| 535 | auto iter = g_loadedPages.find(index); |
| 536 | if (iter != g_loadedPages.end()) |
| 537 | return iter->second; |
| 538 | |
| 539 | FPDF_PAGE page = FPDF_LoadPage(doc, index); |
| 540 | if (!page) |
| 541 | return nullptr; |
| 542 | |
| 543 | FORM_OnAfterLoadPage(page, g_formHandle); |
| 544 | FORM_DoPageAAction(page, g_formHandle, FPDFPAGE_AACTION_OPEN); |
| 545 | |
| 546 | g_loadedPages[index] = page; |
| 547 | return page; |
| 548 | } |
| 549 | |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 550 | bool RenderPage(const std::string& name, |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame^] | 551 | FPDF_DOCUMENT doc, |
| 552 | FPDF_FORMHANDLE& form, |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 553 | const int page_index, |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 554 | const Options& options, |
| 555 | const std::string& events) { |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame^] | 556 | FPDF_PAGE page = GetPageForIndex(nullptr, doc, page_index); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 557 | if (!page) |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 558 | return false; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 559 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 560 | FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 561 | |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 562 | if (options.send_events) |
tsepez | 10b01bf | 2016-05-04 12:52:42 -0700 | [diff] [blame] | 563 | SendPageEvents(form, page, events); |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 564 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 565 | double scale = 1.0; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 566 | if (!options.scale_factor_as_string.empty()) |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 567 | std::stringstream(options.scale_factor_as_string) >> scale; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 568 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 569 | int width = static_cast<int>(FPDF_GetPageWidth(page) * scale); |
| 570 | int height = static_cast<int>(FPDF_GetPageHeight(page) * scale); |
Lei Zhang | 453d96b | 2015-12-31 13:13:10 -0800 | [diff] [blame] | 571 | int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; |
| 572 | FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 573 | if (bitmap) { |
| 574 | FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; |
| 575 | FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); |
| 576 | FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 577 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 578 | FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); |
| 579 | int stride = FPDFBitmap_GetStride(bitmap); |
| 580 | const char* buffer = |
| 581 | reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 582 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 583 | switch (options.output_format) { |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 584 | #ifdef _WIN32 |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 585 | case OUTPUT_BMP: |
| 586 | WriteBmp(name.c_str(), page_index, buffer, stride, width, height); |
| 587 | break; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 588 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 589 | case OUTPUT_EMF: |
| 590 | WriteEmf(page, name.c_str(), page_index); |
| 591 | break; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 592 | #endif |
dsinclair | b63068f | 2016-06-16 07:58:09 -0700 | [diff] [blame] | 593 | case OUTPUT_TEXT: |
| 594 | WriteText(page, name.c_str(), page_index); |
| 595 | break; |
| 596 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 597 | case OUTPUT_PNG: |
| 598 | WritePng(name.c_str(), page_index, buffer, stride, width, height); |
| 599 | break; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 600 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 601 | case OUTPUT_PPM: |
| 602 | WritePpm(name.c_str(), page_index, buffer, stride, width, height); |
| 603 | break; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 604 | |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 605 | #ifdef PDF_ENABLE_SKIA |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 606 | case OUTPUT_SKP: { |
| 607 | std::unique_ptr<SkPictureRecorder> recorder( |
| 608 | (SkPictureRecorder*)FPDF_RenderPageSkp(page, width, height)); |
| 609 | FPDF_FFLRecord(form, recorder.get(), page, 0, 0, width, height, 0, 0); |
| 610 | WriteSkp(name.c_str(), page_index, recorder.get()); |
| 611 | } break; |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 612 | #endif |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 613 | default: |
| 614 | break; |
| 615 | } |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 616 | |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 617 | FPDFBitmap_Destroy(bitmap); |
| 618 | } else { |
| 619 | fprintf(stderr, "Page was too large to be rendered.\n"); |
| 620 | } |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame^] | 621 | |
| 622 | g_loadedPages.erase(page_index); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 623 | FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); |
| 624 | FORM_OnBeforeClosePage(page, form); |
| 625 | FPDFText_ClosePage(text_page); |
| 626 | FPDF_ClosePage(page); |
thestig | e97ea03 | 2016-05-19 10:59:15 -0700 | [diff] [blame] | 627 | return !!bitmap; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 628 | } |
| 629 | |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 630 | void RenderPdf(const std::string& name, |
| 631 | const char* pBuf, |
| 632 | size_t len, |
| 633 | const Options& options, |
| 634 | const std::string& events) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | IPDF_JSPLATFORM platform_callbacks; |
| 636 | memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 637 | platform_callbacks.version = 3; |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 638 | platform_callbacks.app_alert = ExampleAppAlert; |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 639 | platform_callbacks.app_response = ExampleAppResponse; |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 640 | platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 641 | platform_callbacks.Doc_mail = ExampleDocMail; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 642 | |
| 643 | FPDF_FORMFILLINFO form_callbacks; |
| 644 | memset(&form_callbacks, '\0', sizeof(form_callbacks)); |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 645 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | ed63138 | 2014-11-18 14:10:25 -0800 | [diff] [blame] | 646 | form_callbacks.version = 2; |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 647 | #else // PDF_ENABLE_XFA |
| 648 | form_callbacks.version = 1; |
| 649 | #endif // PDF_ENABLE_XFA |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame^] | 650 | form_callbacks.FFI_GetPage = GetPageForIndex; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 651 | form_callbacks.m_pJsPlatform = &platform_callbacks; |
| 652 | |
| 653 | TestLoader loader(pBuf, len); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 654 | FPDF_FILEACCESS file_access; |
| 655 | memset(&file_access, '\0', sizeof(file_access)); |
John Abd-El-Malek | 7dc5172 | 2014-05-26 12:54:31 -0700 | [diff] [blame] | 656 | file_access.m_FileLen = static_cast<unsigned long>(len); |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 657 | file_access.m_GetBlock = TestLoader::GetBlock; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 658 | file_access.m_Param = &loader; |
| 659 | |
| 660 | FX_FILEAVAIL file_avail; |
| 661 | memset(&file_avail, '\0', sizeof(file_avail)); |
| 662 | file_avail.version = 1; |
| 663 | file_avail.IsDataAvail = Is_Data_Avail; |
| 664 | |
| 665 | FX_DOWNLOADHINTS hints; |
| 666 | memset(&hints, '\0', sizeof(hints)); |
| 667 | hints.version = 1; |
| 668 | hints.AddSegment = Add_Segment; |
| 669 | |
| 670 | FPDF_DOCUMENT doc; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 671 | int nRet = PDF_DATA_NOTAVAIL; |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 672 | bool bIsLinearized = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 673 | FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); |
Tom Sepez | c98895c | 2015-11-24 15:30:36 -0800 | [diff] [blame] | 674 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 675 | if (FPDFAvail_IsLinearized(pdf_avail) == PDF_LINEARIZED) { |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 676 | doc = FPDFAvail_GetDocument(pdf_avail, nullptr); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 677 | if (doc) { |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 678 | while (nRet == PDF_DATA_NOTAVAIL) |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 679 | nRet = FPDFAvail_IsDocAvail(pdf_avail, &hints); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 680 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 681 | if (nRet == PDF_DATA_ERROR) { |
| 682 | fprintf(stderr, "Unknown error in checking if doc was available.\n"); |
| 683 | return; |
| 684 | } |
| 685 | nRet = FPDFAvail_IsFormAvail(pdf_avail, &hints); |
| 686 | if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { |
| 687 | fprintf(stderr, |
| 688 | "Error %d was returned in checking if form was available.\n", |
| 689 | nRet); |
| 690 | return; |
| 691 | } |
Jun Fang | b553bcb | 2015-11-10 18:49:04 +0800 | [diff] [blame] | 692 | bIsLinearized = true; |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 693 | } |
| 694 | } else { |
Lei Zhang | 600d407 | 2015-09-23 15:35:25 -0700 | [diff] [blame] | 695 | doc = FPDF_LoadCustomDocument(&file_access, nullptr); |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 696 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 697 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 698 | if (!doc) { |
Dan Sinclair | eb815bf | 2015-10-27 13:08:41 -0400 | [diff] [blame] | 699 | unsigned long err = FPDF_GetLastError(); |
| 700 | fprintf(stderr, "Load pdf docs unsuccessful: "); |
| 701 | switch (err) { |
| 702 | case FPDF_ERR_SUCCESS: |
| 703 | fprintf(stderr, "Success"); |
| 704 | break; |
| 705 | case FPDF_ERR_UNKNOWN: |
| 706 | fprintf(stderr, "Unknown error"); |
| 707 | break; |
| 708 | case FPDF_ERR_FILE: |
| 709 | fprintf(stderr, "File not found or could not be opened"); |
| 710 | break; |
| 711 | case FPDF_ERR_FORMAT: |
| 712 | fprintf(stderr, "File not in PDF format or corrupted"); |
| 713 | break; |
| 714 | case FPDF_ERR_PASSWORD: |
| 715 | fprintf(stderr, "Password required or incorrect password"); |
| 716 | break; |
| 717 | case FPDF_ERR_SECURITY: |
| 718 | fprintf(stderr, "Unsupported security scheme"); |
| 719 | break; |
| 720 | case FPDF_ERR_PAGE: |
| 721 | fprintf(stderr, "Page not found or content error"); |
| 722 | break; |
| 723 | default: |
| 724 | fprintf(stderr, "Unknown error %ld", err); |
| 725 | } |
| 726 | fprintf(stderr, ".\n"); |
| 727 | |
Qin Zhao | 0522497 | 2015-10-20 18:31:06 -0400 | [diff] [blame] | 728 | FPDFAvail_Destroy(pdf_avail); |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 729 | return; |
| 730 | } |
| 731 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 732 | (void)FPDF_GetDocPermissions(doc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 733 | |
tonikitoo | 3e98158 | 2016-08-26 08:37:10 -0700 | [diff] [blame^] | 734 | FPDF_FORMHANDLE form = g_formHandle = |
| 735 | FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 736 | #ifdef PDF_ENABLE_XFA |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 737 | int docType = DOCTYPE_PDF; |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 738 | if (FPDF_HasXFAField(doc, &docType) && docType != DOCTYPE_PDF && |
| 739 | !FPDF_LoadXFA(doc)) { |
| 740 | fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n"); |
Tom Sepez | 5645138 | 2014-12-05 13:30:51 -0800 | [diff] [blame] | 741 | } |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 742 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 743 | FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); |
| 744 | FPDF_SetFormFieldHighlightAlpha(form, 100); |
| 745 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 746 | FORM_DoDocumentJSAction(form); |
| 747 | FORM_DoDocumentOpenAction(form); |
| 748 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 749 | int page_count = FPDF_GetPageCount(doc); |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 750 | int rendered_pages = 0; |
| 751 | int bad_pages = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 752 | for (int i = 0; i < page_count; ++i) { |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 753 | if (bIsLinearized) { |
| 754 | nRet = PDF_DATA_NOTAVAIL; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 755 | while (nRet == PDF_DATA_NOTAVAIL) |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 756 | nRet = FPDFAvail_IsPageAvail(pdf_avail, i, &hints); |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 757 | |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 758 | if (nRet == PDF_DATA_ERROR) { |
| 759 | fprintf(stderr, "Unknown error in checking if page %d is available.\n", |
| 760 | i); |
| 761 | return; |
| 762 | } |
| 763 | } |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 764 | if (RenderPage(name, doc, form, i, options, events)) |
Jun Fang | df7f366 | 2015-11-10 18:29:18 +0800 | [diff] [blame] | 765 | ++rendered_pages; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 766 | else |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 767 | ++bad_pages; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); |
Lei Zhang | ba02691 | 2015-07-16 10:06:11 -0700 | [diff] [blame] | 771 | |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 772 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | ba02691 | 2015-07-16 10:06:11 -0700 | [diff] [blame] | 773 | // Note: The shut down order here is the reverse of the non-XFA branch order. |
| 774 | // Need to work out if this is required, and if it is, the lifetimes of |
| 775 | // objects owned by |doc| that |form| reference. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 776 | FPDF_CloseDocument(doc); |
Bo Xu | 2b7a49d | 2014-11-14 17:40:50 -0800 | [diff] [blame] | 777 | FPDFDOC_ExitFormFillEnvironment(form); |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 778 | #else // PDF_ENABLE_XFA |
| 779 | FPDFDOC_ExitFormFillEnvironment(form); |
| 780 | FPDF_CloseDocument(doc); |
| 781 | #endif // PDF_ENABLE_XFA |
Lei Zhang | ba02691 | 2015-07-16 10:06:11 -0700 | [diff] [blame] | 782 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 783 | FPDFAvail_Destroy(pdf_avail); |
| 784 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 785 | fprintf(stderr, "Rendered %d pages.\n", rendered_pages); |
tsepez | 10b01bf | 2016-05-04 12:52:42 -0700 | [diff] [blame] | 786 | if (bad_pages) |
| 787 | fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 790 | static void ShowConfig() { |
| 791 | std::string config; |
| 792 | std::string maybe_comma; |
| 793 | #if PDF_ENABLE_V8 |
| 794 | config.append(maybe_comma); |
| 795 | config.append("V8"); |
| 796 | maybe_comma = ","; |
| 797 | #endif // PDF_ENABLE_V8 |
| 798 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 799 | config.append(maybe_comma); |
| 800 | config.append("V8_EXTERNAL"); |
| 801 | maybe_comma = ","; |
| 802 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 803 | #ifdef PDF_ENABLE_XFA |
| 804 | config.append(maybe_comma); |
| 805 | config.append("XFA"); |
| 806 | maybe_comma = ","; |
| 807 | #endif // PDF_ENABLE_XFA |
| 808 | printf("%s\n", config.c_str()); |
| 809 | } |
| 810 | |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 811 | static const char kUsageString[] = |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 812 | "Usage: pdfium_test [OPTION] [FILE]...\n" |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 813 | " --show-config - print build options and exit\n" |
tsepez | 10b01bf | 2016-05-04 12:52:42 -0700 | [diff] [blame] | 814 | " --send-events - send input described by .evt file\n" |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 815 | " --bin-dir=<path> - override path to v8 external data\n" |
| 816 | " --font-dir=<path> - override path to external fonts\n" |
| 817 | " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 818 | #ifdef _WIN32 |
| 819 | " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
| 820 | " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
Tom Sepez | c46d000 | 2015-11-30 15:46:36 -0800 | [diff] [blame] | 821 | #endif // _WIN32 |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 822 | " --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] | 823 | " --png - write page images <pdf-name>.<page-number>.png\n" |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 824 | " --ppm - write page images <pdf-name>.<page-number>.ppm\n" |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 825 | #ifdef PDF_ENABLE_SKIA |
| 826 | " --skp - write page images <pdf-name>.<page-number>.skp\n" |
| 827 | #endif |
| 828 | ""; |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 829 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 830 | int main(int argc, const char* argv[]) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 831 | std::vector<std::string> args(argv, argv + argc); |
| 832 | Options options; |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 833 | std::vector<std::string> files; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 834 | if (!ParseCommandLine(args, &options, &files)) { |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 835 | fprintf(stderr, "%s", kUsageString); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 836 | return 1; |
| 837 | } |
| 838 | |
Tom Sepez | 2991d8d | 2016-01-15 16:02:48 -0800 | [diff] [blame] | 839 | if (options.show_config) { |
| 840 | ShowConfig(); |
| 841 | return 0; |
| 842 | } |
| 843 | |
| 844 | if (files.empty()) { |
| 845 | fprintf(stderr, "No input files.\n"); |
| 846 | return 1; |
| 847 | } |
| 848 | |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 849 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 850 | v8::Platform* platform; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 851 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 852 | v8::StartupData natives; |
| 853 | v8::StartupData snapshot; |
Tom Sepez | d831dc7 | 2015-10-19 16:04:22 -0700 | [diff] [blame] | 854 | InitializeV8ForPDFium(options.exe_path, options.bin_directory, &natives, |
| 855 | &snapshot, &platform); |
| 856 | #else // V8_USE_EXTERNAL_STARTUP_DATA |
jochen | 9e077d2 | 2016-06-09 02:51:13 -0700 | [diff] [blame] | 857 | InitializeV8ForPDFium(options.exe_path, &platform); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 858 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 859 | #endif // PDF_ENABLE_V8 |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 860 | |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 861 | FPDF_LIBRARY_CONFIG config; |
| 862 | config.version = 2; |
| 863 | config.m_pUserFontPaths = nullptr; |
| 864 | config.m_pIsolate = nullptr; |
| 865 | config.m_v8EmbedderSlot = 0; |
| 866 | |
| 867 | const char* path_array[2]; |
| 868 | if (!options.font_directory.empty()) { |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 869 | path_array[0] = options.font_directory.c_str(); |
| 870 | path_array[1] = nullptr; |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 871 | config.m_pUserFontPaths = path_array; |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 872 | } |
Tom Sepez | a72e8e2 | 2015-10-07 10:17:53 -0700 | [diff] [blame] | 873 | FPDF_InitLibraryWithConfig(&config); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 874 | |
| 875 | UNSUPPORT_INFO unsuppored_info; |
| 876 | memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); |
| 877 | unsuppored_info.version = 1; |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 878 | unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 879 | |
| 880 | FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
| 881 | |
thestig | 514e8c9 | 2016-07-15 17:57:54 -0700 | [diff] [blame] | 882 | for (const std::string& filename : files) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 883 | size_t file_length = 0; |
Tom Sepez | 0aa3531 | 2016-01-06 10:16:32 -0800 | [diff] [blame] | 884 | std::unique_ptr<char, pdfium::FreeDeleter> file_contents = |
| 885 | GetFileContents(filename.c_str(), &file_length); |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 886 | if (!file_contents) |
| 887 | continue; |
tsepez | 10b01bf | 2016-05-04 12:52:42 -0700 | [diff] [blame] | 888 | fprintf(stderr, "Rendering PDF file %s.\n", filename.c_str()); |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 889 | std::string events; |
| 890 | if (options.send_events) { |
| 891 | std::string event_filename = filename; |
| 892 | size_t event_length = 0; |
| 893 | size_t extension_pos = event_filename.find(".pdf"); |
| 894 | if (extension_pos != std::string::npos) { |
| 895 | event_filename.replace(extension_pos, 4, ".evt"); |
| 896 | std::unique_ptr<char, pdfium::FreeDeleter> event_contents = |
| 897 | GetFileContents(event_filename.c_str(), &event_length); |
| 898 | if (event_contents) { |
tsepez | 10b01bf | 2016-05-04 12:52:42 -0700 | [diff] [blame] | 899 | fprintf(stderr, "Sending events from: %s\n", event_filename.c_str()); |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 900 | events = std::string(event_contents.get(), event_length); |
tsepez | f09bdfa | 2016-04-18 16:08:26 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | } |
| 904 | RenderPdf(filename, file_contents.get(), file_length, options, events); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | FPDF_DestroyLibrary(); |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 908 | #ifdef PDF_ENABLE_V8 |
John Abd-El-Malek | b045ed2 | 2015-02-10 09:15:12 -0800 | [diff] [blame] | 909 | v8::V8::ShutdownPlatform(); |
| 910 | delete platform; |
thestig | c08cd7a | 2016-06-27 09:47:59 -0700 | [diff] [blame] | 911 | |
| 912 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 913 | free(const_cast<char*>(natives.data)); |
| 914 | free(const_cast<char*>(snapshot.data)); |
| 915 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | 452b4f3 | 2015-10-13 09:27:27 -0700 | [diff] [blame] | 916 | #endif // PDF_ENABLE_V8 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 917 | |
| 918 | return 0; |
| 919 | } |