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> |
Tom Sepez | fb94728 | 2014-12-08 09:55:11 -0800 | [diff] [blame] | 9 | #include <wchar.h> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 10 | |
| 11 | #include <list> |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 12 | #include <sstream> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <utility> |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 15 | #include <vector> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 16 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 17 | #include "../public/fpdf_dataavail.h" |
| 18 | #include "../public/fpdf_ext.h" |
| 19 | #include "../public/fpdf_formfill.h" |
| 20 | #include "../public/fpdf_text.h" |
| 21 | #include "../public/fpdfview.h" |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 22 | #include "image_diff_png.h" |
John Abd-El-Malek | b045ed2 | 2015-02-10 09:15:12 -0800 | [diff] [blame] | 23 | #include "v8/include/libplatform/libplatform.h" |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 24 | #include "v8/include/v8.h" |
John Abd-El-Malek | b045ed2 | 2015-02-10 09:15:12 -0800 | [diff] [blame] | 25 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | |
| 27 | #ifdef _WIN32 |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 28 | #define snprintf _snprintf |
| 29 | #define PATH_SEPARATOR '\\' |
| 30 | #else |
| 31 | #define PATH_SEPARATOR '/' |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | #endif |
| 33 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 34 | enum OutputFormat { |
| 35 | OUTPUT_NONE, |
| 36 | OUTPUT_PPM, |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 37 | OUTPUT_PNG, |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 38 | #ifdef _WIN32 |
| 39 | OUTPUT_BMP, |
| 40 | OUTPUT_EMF, |
| 41 | #endif |
| 42 | }; |
| 43 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 44 | struct Options { |
| 45 | Options() : output_format(OUTPUT_NONE) { } |
| 46 | |
| 47 | OutputFormat output_format; |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 48 | std::string scale_factor_as_string; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 49 | std::string exe_path; |
| 50 | std::string bin_directory; |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 51 | std::string font_directory; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | // Reads the entire contents of a file into a newly malloc'd buffer. |
| 55 | static char* GetFileContents(const char* filename, size_t* retlen) { |
| 56 | FILE* file = fopen(filename, "rb"); |
| 57 | if (!file) { |
| 58 | fprintf(stderr, "Failed to open: %s\n", filename); |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 59 | return nullptr; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 60 | } |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 61 | (void)fseek(file, 0, SEEK_END); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 62 | size_t file_length = ftell(file); |
| 63 | if (!file_length) { |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 64 | (void)fclose(file); |
| 65 | return nullptr; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 66 | } |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 67 | (void)fseek(file, 0, SEEK_SET); |
| 68 | char* buffer = static_cast<char*>(malloc(file_length)); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 69 | if (!buffer) { |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 70 | (void)fclose(file); |
| 71 | return nullptr; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 72 | } |
| 73 | size_t bytes_read = fread(buffer, 1, file_length, file); |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 74 | (void)fclose(file); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 75 | if (bytes_read != file_length) { |
| 76 | fprintf(stderr, "Failed to read: %s\n", filename); |
| 77 | free(buffer); |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 78 | return nullptr; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 79 | } |
| 80 | *retlen = bytes_read; |
| 81 | return buffer; |
| 82 | } |
| 83 | |
| 84 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 85 | // Returns the full path for an external V8 data file based on either |
| 86 | // the currect exectuable path or an explicit override. |
| 87 | static std::string GetFullPathForSnapshotFile(const Options& options, |
| 88 | const std::string& filename) { |
| 89 | std::string result; |
| 90 | if (!options.bin_directory.empty()) { |
| 91 | result = options.bin_directory; |
| 92 | if (*options.bin_directory.rbegin() != PATH_SEPARATOR) { |
| 93 | result += PATH_SEPARATOR; |
| 94 | } |
| 95 | } else if (!options.exe_path.empty()) { |
| 96 | size_t last_separator = options.exe_path.rfind(PATH_SEPARATOR); |
| 97 | if (last_separator != std::string::npos) { |
| 98 | result = options.exe_path.substr(0, last_separator + 1); |
| 99 | } |
| 100 | } |
| 101 | result += filename; |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | // Reads an extenal V8 data file from the |options|-indicated location, |
| 106 | // returing true on success and false on error. |
| 107 | static bool GetExternalData(const Options& options, |
| 108 | const std::string& bin_filename, |
| 109 | v8::StartupData* result_data) { |
| 110 | std::string full_path = GetFullPathForSnapshotFile(options, bin_filename); |
| 111 | size_t data_length = 0; |
| 112 | char* data_buffer = GetFileContents(full_path.c_str(), &data_length); |
| 113 | if (!data_buffer) { |
| 114 | return false; |
| 115 | } |
| 116 | result_data->data = const_cast<const char*>(data_buffer); |
| 117 | result_data->raw_size = data_length; |
| 118 | return true; |
| 119 | } |
| 120 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 121 | |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 122 | static bool CheckDimensions(int stride, int width, int height) { |
| 123 | if (stride < 0 || width < 0 || height < 0) |
| 124 | return false; |
| 125 | if (height > 0 && width > INT_MAX / height) |
| 126 | return false; |
| 127 | return true; |
| 128 | } |
| 129 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 130 | static void WritePpm(const char* pdf_name, int num, const void* buffer_void, |
| 131 | int stride, int width, int height) { |
| 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)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [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) |
| 139 | return; |
| 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) |
| 146 | return; |
| 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. |
| 150 | char* result = new char[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); |
| 153 | char* dest_line = result + (width * h * 3); |
| 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 | } |
Lei Zhang | e00660b | 2015-08-13 15:40:18 -0700 | [diff] [blame] | 163 | fwrite(result, out_len, 1, fp); |
| 164 | delete[] result; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 165 | fclose(fp); |
| 166 | } |
| 167 | |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 168 | static void WritePng(const char* pdf_name, int num, const void* buffer_void, |
| 169 | int stride, int width, int height) { |
| 170 | if (!CheckDimensions(stride, width, height)) |
| 171 | return; |
| 172 | |
| 173 | std::vector<unsigned char> png_encoding; |
| 174 | const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); |
| 175 | if (!image_diff_png::EncodeBGRAPNG( |
| 176 | buffer, width, height, stride, false, &png_encoding)) { |
| 177 | fprintf(stderr, "Failed to convert bitmap to PNG\n"); |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | char filename[256]; |
| 182 | int chars_formatted = snprintf( |
| 183 | filename, sizeof(filename), "%s.%d.png", pdf_name, num); |
| 184 | if (chars_formatted < 0 || |
| 185 | static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
| 186 | fprintf(stderr, "Filname %s is too long\n", filename); |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | FILE* fp = fopen(filename, "wb"); |
| 191 | if (!fp) { |
| 192 | fprintf(stderr, "Failed to open %s for output\n", filename); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | size_t bytes_written = fwrite( |
| 197 | &png_encoding.front(), 1, png_encoding.size(), fp); |
| 198 | if (bytes_written != png_encoding.size()) |
| 199 | fprintf(stderr, "Failed to write to %s\n", filename); |
| 200 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 201 | (void)fclose(fp); |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 204 | #ifdef _WIN32 |
| 205 | static void WriteBmp(const char* pdf_name, int num, const void* buffer, |
| 206 | int stride, int width, int height) { |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 207 | if (!CheckDimensions(stride, width, height)) |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 208 | return; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 209 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 210 | int out_len = stride * height; |
| 211 | if (out_len > INT_MAX / 3) |
| 212 | return; |
| 213 | |
| 214 | char filename[256]; |
| 215 | snprintf(filename, sizeof(filename), "%s.%d.bmp", pdf_name, num); |
| 216 | FILE* fp = fopen(filename, "wb"); |
| 217 | if (!fp) |
| 218 | return; |
| 219 | |
Nico Weber | 2827bdd | 2015-07-01 14:08:08 -0700 | [diff] [blame] | 220 | BITMAPINFO bmi = {}; |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 221 | bmi.bmiHeader.biSize = sizeof(bmi) - sizeof(RGBQUAD); |
| 222 | bmi.bmiHeader.biWidth = width; |
| 223 | bmi.bmiHeader.biHeight = -height; // top-down image |
| 224 | bmi.bmiHeader.biPlanes = 1; |
| 225 | bmi.bmiHeader.biBitCount = 32; |
| 226 | bmi.bmiHeader.biCompression = BI_RGB; |
| 227 | bmi.bmiHeader.biSizeImage = 0; |
| 228 | |
Nico Weber | 2827bdd | 2015-07-01 14:08:08 -0700 | [diff] [blame] | 229 | BITMAPFILEHEADER file_header = {}; |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 230 | file_header.bfType = 0x4d42; |
| 231 | file_header.bfSize = sizeof(file_header) + bmi.bmiHeader.biSize + out_len; |
| 232 | file_header.bfOffBits = file_header.bfSize - out_len; |
| 233 | |
| 234 | fwrite(&file_header, sizeof(file_header), 1, fp); |
| 235 | fwrite(&bmi, bmi.bmiHeader.biSize, 1, fp); |
| 236 | fwrite(buffer, out_len, 1, fp); |
| 237 | fclose(fp); |
| 238 | } |
| 239 | |
| 240 | void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) { |
| 241 | int width = static_cast<int>(FPDF_GetPageWidth(page)); |
| 242 | int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 243 | |
| 244 | char filename[256]; |
| 245 | snprintf(filename, sizeof(filename), "%s.%d.emf", pdf_name, num); |
| 246 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 247 | HDC dc = CreateEnhMetaFileA(nullptr, filename, nullptr, nullptr); |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 248 | |
| 249 | HRGN rgn = CreateRectRgn(0, 0, width, height); |
| 250 | SelectClipRgn(dc, rgn); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 251 | DeleteObject(rgn); |
| 252 | |
| 253 | SelectObject(dc, GetStockObject(NULL_PEN)); |
| 254 | SelectObject(dc, GetStockObject(WHITE_BRUSH)); |
| 255 | // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. |
| 256 | Rectangle(dc, 0, 0, width + 1, height + 1); |
| 257 | |
| 258 | FPDF_RenderPage(dc, page, 0, 0, width, height, 0, |
| 259 | FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 260 | |
| 261 | DeleteEnhMetaFile(CloseEnhMetaFile(dc)); |
| 262 | } |
| 263 | #endif |
| 264 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 265 | int ExampleAppAlert(IPDF_JSPLATFORM*, FPDF_WIDESTRING msg, FPDF_WIDESTRING, |
| 266 | int, int) { |
Tom Sepez | fb94728 | 2014-12-08 09:55:11 -0800 | [diff] [blame] | 267 | // Deal with differences between UTF16LE and wchar_t on this platform. |
| 268 | size_t characters = 0; |
| 269 | while (msg[characters]) { |
| 270 | ++characters; |
| 271 | } |
| 272 | wchar_t* platform_string = |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 273 | static_cast<wchar_t*>(malloc((characters + 1) * sizeof(wchar_t))); |
Tom Sepez | fb94728 | 2014-12-08 09:55:11 -0800 | [diff] [blame] | 274 | for (size_t i = 0; i < characters + 1; ++i) { |
| 275 | unsigned char* ptr = (unsigned char*)&msg[i]; |
| 276 | platform_string[i] = ptr[0] + 256 * ptr[1]; |
| 277 | } |
| 278 | printf("Alert: %ls\n", platform_string); |
| 279 | free(platform_string); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 283 | void ExampleDocGotoPage(IPDF_JSPLATFORM*, int pageNumber) { |
| 284 | printf("Goto Page: %d\n", pageNumber); |
| 285 | } |
| 286 | |
| 287 | void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | std::string feature = "Unknown"; |
| 289 | switch (type) { |
| 290 | case FPDF_UNSP_DOC_XFAFORM: |
| 291 | feature = "XFA"; |
| 292 | break; |
| 293 | case FPDF_UNSP_DOC_PORTABLECOLLECTION: |
| 294 | feature = "Portfolios_Packages"; |
| 295 | break; |
| 296 | case FPDF_UNSP_DOC_ATTACHMENT: |
| 297 | case FPDF_UNSP_ANNOT_ATTACHMENT: |
| 298 | feature = "Attachment"; |
| 299 | break; |
| 300 | case FPDF_UNSP_DOC_SECURITY: |
| 301 | feature = "Rights_Management"; |
| 302 | break; |
| 303 | case FPDF_UNSP_DOC_SHAREDREVIEW: |
| 304 | feature = "Shared_Review"; |
| 305 | break; |
| 306 | case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT: |
| 307 | case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM: |
| 308 | case FPDF_UNSP_DOC_SHAREDFORM_EMAIL: |
| 309 | feature = "Shared_Form"; |
| 310 | break; |
| 311 | case FPDF_UNSP_ANNOT_3DANNOT: |
| 312 | feature = "3D"; |
| 313 | break; |
| 314 | case FPDF_UNSP_ANNOT_MOVIE: |
| 315 | feature = "Movie"; |
| 316 | break; |
| 317 | case FPDF_UNSP_ANNOT_SOUND: |
| 318 | feature = "Sound"; |
| 319 | break; |
| 320 | case FPDF_UNSP_ANNOT_SCREEN_MEDIA: |
| 321 | case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA: |
| 322 | feature = "Screen"; |
| 323 | break; |
| 324 | case FPDF_UNSP_ANNOT_SIG: |
| 325 | feature = "Digital_Signature"; |
| 326 | break; |
| 327 | } |
| 328 | printf("Unsupported feature: %s.\n", feature.c_str()); |
| 329 | } |
| 330 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 331 | bool ParseCommandLine(const std::vector<std::string>& args, |
| 332 | Options* options, std::list<std::string>* files) { |
| 333 | if (args.empty()) { |
| 334 | return false; |
| 335 | } |
| 336 | options->exe_path = args[0]; |
Bo Xu | d44e392 | 2014-12-19 02:27:25 -0800 | [diff] [blame] | 337 | size_t cur_idx = 1; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 338 | for (; cur_idx < args.size(); ++cur_idx) { |
| 339 | const std::string& cur_arg = args[cur_idx]; |
| 340 | if (cur_arg == "--ppm") { |
| 341 | if (options->output_format != OUTPUT_NONE) { |
| 342 | fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); |
| 343 | return false; |
| 344 | } |
| 345 | options->output_format = OUTPUT_PPM; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 346 | } else if (cur_arg == "--png") { |
| 347 | if (options->output_format != OUTPUT_NONE) { |
| 348 | fprintf(stderr, "Duplicate or conflicting --png argument\n"); |
| 349 | return false; |
| 350 | } |
| 351 | options->output_format = OUTPUT_PNG; |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 352 | } else if (cur_arg.size() > 11 && |
| 353 | cur_arg.compare(0, 11, "--font-dir=") == 0) { |
| 354 | if (!options->font_directory.empty()) { |
| 355 | fprintf(stderr, "Duplicate --font-dir argument\n"); |
| 356 | return false; |
| 357 | } |
| 358 | options->font_directory = cur_arg.substr(11); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 359 | } |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 360 | #ifdef _WIN32 |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 361 | else if (cur_arg == "--emf") { |
| 362 | if (options->output_format != OUTPUT_NONE) { |
| 363 | fprintf(stderr, "Duplicate or conflicting --emf argument\n"); |
| 364 | return false; |
| 365 | } |
| 366 | options->output_format = OUTPUT_EMF; |
| 367 | } |
| 368 | else if (cur_arg == "--bmp") { |
| 369 | if (options->output_format != OUTPUT_NONE) { |
| 370 | fprintf(stderr, "Duplicate or conflicting --bmp argument\n"); |
| 371 | return false; |
| 372 | } |
| 373 | options->output_format = OUTPUT_BMP; |
| 374 | } |
| 375 | #endif // _WIN32 |
| 376 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 377 | else if (cur_arg.size() > 10 && cur_arg.compare(0, 10, "--bin-dir=") == 0) { |
| 378 | if (!options->bin_directory.empty()) { |
| 379 | fprintf(stderr, "Duplicate --bin-dir argument\n"); |
| 380 | return false; |
| 381 | } |
| 382 | options->bin_directory = cur_arg.substr(10); |
| 383 | } |
| 384 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 385 | else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { |
| 386 | if (!options->scale_factor_as_string.empty()) { |
| 387 | fprintf(stderr, "Duplicate --scale argument\n"); |
| 388 | return false; |
| 389 | } |
| 390 | options->scale_factor_as_string = cur_arg.substr(8); |
| 391 | } |
Vitaly Buka | 8f2c3dc | 2014-08-20 10:32:36 -0700 | [diff] [blame] | 392 | else |
| 393 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 394 | } |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 395 | if (cur_idx >= args.size()) { |
| 396 | fprintf(stderr, "No input files.\n"); |
Vitaly Buka | 8f2c3dc | 2014-08-20 10:32:36 -0700 | [diff] [blame] | 397 | return false; |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 398 | } |
Bo Xu | d44e392 | 2014-12-19 02:27:25 -0800 | [diff] [blame] | 399 | for (size_t i = cur_idx; i < args.size(); i++) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 400 | files->push_back(args[i]); |
| 401 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 402 | return true; |
| 403 | } |
| 404 | |
| 405 | class TestLoader { |
| 406 | public: |
| 407 | TestLoader(const char* pBuf, size_t len); |
| 408 | |
| 409 | const char* m_pBuf; |
| 410 | size_t m_Len; |
| 411 | }; |
| 412 | |
| 413 | TestLoader::TestLoader(const char* pBuf, size_t len) |
| 414 | : m_pBuf(pBuf), m_Len(len) { |
| 415 | } |
| 416 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 417 | int GetBlock(void* param, |
| 418 | unsigned long pos, |
| 419 | unsigned char* pBuf, |
| 420 | unsigned long size) { |
| 421 | TestLoader* pLoader = static_cast<TestLoader*>(param); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 422 | if (pos + size < pos || pos + size > pLoader->m_Len) return 0; |
| 423 | memcpy(pBuf, pLoader->m_pBuf + pos, size); |
| 424 | return 1; |
| 425 | } |
| 426 | |
Tom Sepez | cf22eb8 | 2015-05-12 17:28:08 -0700 | [diff] [blame] | 427 | 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] | 428 | return true; |
| 429 | } |
| 430 | |
| 431 | void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
| 432 | } |
| 433 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 434 | void RenderPdf(const std::string& name, const char* pBuf, size_t len, |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 435 | const Options& options) { |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 436 | fprintf(stderr, "Rendering PDF file %s.\n", name.c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 437 | |
| 438 | IPDF_JSPLATFORM platform_callbacks; |
| 439 | memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
Jochen Eisinger | 06b6002 | 2015-07-30 17:44:35 +0200 | [diff] [blame] | 440 | platform_callbacks.version = 2; |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 441 | platform_callbacks.app_alert = ExampleAppAlert; |
| 442 | platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 443 | |
| 444 | FPDF_FORMFILLINFO form_callbacks; |
| 445 | memset(&form_callbacks, '\0', sizeof(form_callbacks)); |
Tom Sepez | ed63138 | 2014-11-18 14:10:25 -0800 | [diff] [blame] | 446 | form_callbacks.version = 2; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 447 | form_callbacks.m_pJsPlatform = &platform_callbacks; |
| 448 | |
| 449 | TestLoader loader(pBuf, len); |
| 450 | |
| 451 | FPDF_FILEACCESS file_access; |
| 452 | memset(&file_access, '\0', sizeof(file_access)); |
John Abd-El-Malek | 7dc5172 | 2014-05-26 12:54:31 -0700 | [diff] [blame] | 453 | file_access.m_FileLen = static_cast<unsigned long>(len); |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 454 | file_access.m_GetBlock = GetBlock; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 455 | file_access.m_Param = &loader; |
| 456 | |
| 457 | FX_FILEAVAIL file_avail; |
| 458 | memset(&file_avail, '\0', sizeof(file_avail)); |
| 459 | file_avail.version = 1; |
| 460 | file_avail.IsDataAvail = Is_Data_Avail; |
| 461 | |
| 462 | FX_DOWNLOADHINTS hints; |
| 463 | memset(&hints, '\0', sizeof(hints)); |
| 464 | hints.version = 1; |
| 465 | hints.AddSegment = Add_Segment; |
| 466 | |
| 467 | FPDF_DOCUMENT doc; |
| 468 | FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); |
| 469 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 470 | (void)FPDFAvail_IsDocAvail(pdf_avail, &hints); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 471 | |
Lei Zhang | 600d407 | 2015-09-23 15:35:25 -0700 | [diff] [blame^] | 472 | if (FPDFAvail_IsLinearized(pdf_avail)) { |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 473 | fprintf(stderr, "Linearized path...\n"); |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 474 | doc = FPDFAvail_GetDocument(pdf_avail, nullptr); |
Lei Zhang | 600d407 | 2015-09-23 15:35:25 -0700 | [diff] [blame^] | 475 | } else { |
| 476 | fprintf(stderr, "Non-linearized path...\n"); |
| 477 | doc = FPDF_LoadCustomDocument(&file_access, nullptr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 480 | if (!doc) { |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 481 | fprintf(stderr, "Load pdf docs unsuccessful.\n"); |
| 482 | return; |
| 483 | } |
| 484 | |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 485 | (void)FPDF_GetDocPermissions(doc); |
| 486 | (void)FPDFAvail_IsFormAvail(pdf_avail, &hints); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 487 | |
Bo Xu | 2b7a49d | 2014-11-14 17:40:50 -0800 | [diff] [blame] | 488 | FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); |
JUN FANG | 827a172 | 2015-03-05 13:39:21 -0800 | [diff] [blame] | 489 | int docType = DOCTYPE_PDF; |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 490 | if (FPDF_HasXFAField(doc, &docType) && docType != DOCTYPE_PDF && |
| 491 | !FPDF_LoadXFA(doc)) { |
| 492 | fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n"); |
Tom Sepez | 5645138 | 2014-12-05 13:30:51 -0800 | [diff] [blame] | 493 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 494 | FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); |
| 495 | FPDF_SetFormFieldHighlightAlpha(form, 100); |
| 496 | |
| 497 | int first_page = FPDFAvail_GetFirstPageNum(doc); |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 498 | (void)FPDFAvail_IsPageAvail(pdf_avail, first_page, &hints); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 499 | |
| 500 | int page_count = FPDF_GetPageCount(doc); |
| 501 | for (int i = 0; i < page_count; ++i) { |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 502 | (void)FPDFAvail_IsPageAvail(pdf_avail, i, &hints); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | FORM_DoDocumentJSAction(form); |
| 506 | FORM_DoDocumentOpenAction(form); |
| 507 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 508 | int rendered_pages = 0; |
| 509 | int bad_pages = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 510 | for (int i = 0; i < page_count; ++i) { |
| 511 | FPDF_PAGE page = FPDF_LoadPage(doc, i); |
Jun Fang | aeacba4 | 2014-08-22 17:04:29 -0700 | [diff] [blame] | 512 | if (!page) { |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 513 | ++bad_pages; |
| 514 | continue; |
Jun Fang | aeacba4 | 2014-08-22 17:04:29 -0700 | [diff] [blame] | 515 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 516 | FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); |
| 517 | FORM_OnAfterLoadPage(page, form); |
| 518 | FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); |
| 519 | |
John Abd-El-Malek | 8a7b669 | 2015-02-25 11:08:16 -0800 | [diff] [blame] | 520 | double scale = 1.0; |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 521 | if (!options.scale_factor_as_string.empty()) { |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 522 | std::stringstream(options.scale_factor_as_string) >> scale; |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 523 | } |
John Abd-El-Malek | 8a7b669 | 2015-02-25 11:08:16 -0800 | [diff] [blame] | 524 | int width = static_cast<int>(FPDF_GetPageWidth(page) * scale); |
| 525 | int height = static_cast<int>(FPDF_GetPageHeight(page) * scale); |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 526 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 527 | FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); |
Tom Sepez | bad79b3 | 2015-05-08 12:02:05 -0700 | [diff] [blame] | 528 | if (!bitmap) { |
| 529 | fprintf(stderr, "Page was too large to be rendered.\n"); |
| 530 | bad_pages++; |
| 531 | continue; |
| 532 | } |
| 533 | |
Lei Zhang | 532a6a7 | 2014-07-09 11:47:15 -0700 | [diff] [blame] | 534 | FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 535 | FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
Lei Zhang | 5377ebf | 2015-09-23 14:52:53 -0700 | [diff] [blame] | 536 | ++rendered_pages; |
Jun Fang | aeacba4 | 2014-08-22 17:04:29 -0700 | [diff] [blame] | 537 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 538 | FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 539 | int stride = FPDFBitmap_GetStride(bitmap); |
| 540 | const char* buffer = |
| 541 | reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); |
| 542 | |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 543 | switch (options.output_format) { |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 544 | #ifdef _WIN32 |
| 545 | case OUTPUT_BMP: |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 546 | WriteBmp(name.c_str(), i, buffer, stride, width, height); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 547 | break; |
| 548 | |
| 549 | case OUTPUT_EMF: |
Tom Sepez | c151fbb | 2014-12-18 11:14:19 -0800 | [diff] [blame] | 550 | WriteEmf(page, name.c_str(), i); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 551 | break; |
| 552 | #endif |
| 553 | case OUTPUT_PPM: |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 554 | WritePpm(name.c_str(), i, buffer, stride, width, height); |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 555 | break; |
Tom Sepez | af18cb3 | 2015-02-05 15:06:01 -0800 | [diff] [blame] | 556 | |
| 557 | case OUTPUT_PNG: |
| 558 | WritePng(name.c_str(), i, buffer, stride, width, height); |
| 559 | break; |
| 560 | |
Vitaly Buka | 9e0177a | 2014-07-22 18:15:42 -0700 | [diff] [blame] | 561 | default: |
| 562 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | FPDFBitmap_Destroy(bitmap); |
| 566 | |
| 567 | FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); |
| 568 | FORM_OnBeforeClosePage(page, form); |
| 569 | FPDFText_ClosePage(text_page); |
| 570 | FPDF_ClosePage(page); |
| 571 | } |
| 572 | |
| 573 | FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); |
Lei Zhang | ba02691 | 2015-07-16 10:06:11 -0700 | [diff] [blame] | 574 | |
| 575 | // Note: The shut down order here is the reverse of the non-XFA branch order. |
| 576 | // Need to work out if this is required, and if it is, the lifetimes of |
| 577 | // objects owned by |doc| that |form| reference. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 578 | FPDF_CloseDocument(doc); |
Bo Xu | 2b7a49d | 2014-11-14 17:40:50 -0800 | [diff] [blame] | 579 | FPDFDOC_ExitFormFillEnvironment(form); |
Lei Zhang | ba02691 | 2015-07-16 10:06:11 -0700 | [diff] [blame] | 580 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 581 | FPDFAvail_Destroy(pdf_avail); |
| 582 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 583 | fprintf(stderr, "Rendered %d pages.\n", rendered_pages); |
| 584 | fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 587 | static const char usage_string[] = |
| 588 | "Usage: pdfium_test [OPTION] [FILE]...\n" |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 589 | " --bin-dir=<path> - override path to v8 external data\n" |
| 590 | " --font-dir=<path> - override path to external fonts\n" |
| 591 | " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 592 | #ifdef _WIN32 |
| 593 | " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
| 594 | " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
| 595 | #endif |
| 596 | " --png - write page images <pdf-name>.<page-number>.png\n" |
| 597 | " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; |
| 598 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 599 | int main(int argc, const char* argv[]) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 600 | std::vector<std::string> args(argv, argv + argc); |
| 601 | Options options; |
| 602 | std::list<std::string> files; |
| 603 | if (!ParseCommandLine(args, &options, &files)) { |
Tom Sepez | 23b4e3f | 2015-02-06 16:05:23 -0800 | [diff] [blame] | 604 | fprintf(stderr, "%s", usage_string); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 605 | return 1; |
| 606 | } |
| 607 | |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 608 | v8::V8::InitializeICU(); |
John Abd-El-Malek | b045ed2 | 2015-02-10 09:15:12 -0800 | [diff] [blame] | 609 | v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 610 | v8::V8::InitializePlatform(platform); |
| 611 | v8::V8::Initialize(); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 612 | |
| 613 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 614 | v8::StartupData natives; |
| 615 | v8::StartupData snapshot; |
| 616 | if (!GetExternalData(options, "natives_blob.bin", &natives) || |
| 617 | !GetExternalData(options, "snapshot_blob.bin", &snapshot)) { |
| 618 | return 1; |
| 619 | } |
| 620 | v8::V8::SetNativesDataBlob(&natives); |
| 621 | v8::V8::SetSnapshotDataBlob(&snapshot); |
| 622 | #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 623 | |
Lei Zhang | 600d407 | 2015-09-23 15:35:25 -0700 | [diff] [blame^] | 624 | if (options.font_directory.empty()) { |
| 625 | FPDF_InitLibrary(); |
| 626 | } else { |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 627 | const char* path_array[2]; |
| 628 | path_array[0] = options.font_directory.c_str(); |
| 629 | path_array[1] = nullptr; |
| 630 | FPDF_LIBRARY_CONFIG config; |
| 631 | config.version = 1; |
| 632 | config.m_pUserFontPaths = path_array; |
| 633 | FPDF_InitLibraryWithConfig(&config); |
Lei Zhang | 6f62d53 | 2015-09-23 15:31:44 -0700 | [diff] [blame] | 634 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | |
| 636 | UNSUPPORT_INFO unsuppored_info; |
| 637 | memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); |
| 638 | unsuppored_info.version = 1; |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 639 | unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 640 | |
| 641 | FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
| 642 | |
| 643 | while (!files.empty()) { |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 644 | std::string filename = files.front(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 645 | files.pop_front(); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 646 | size_t file_length = 0; |
| 647 | char* file_contents = GetFileContents(filename.c_str(), &file_length); |
| 648 | if (!file_contents) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 649 | continue; |
Tom Sepez | daa2e84 | 2015-01-29 15:44:37 -0800 | [diff] [blame] | 650 | RenderPdf(filename, file_contents, file_length, options); |
Tom Sepez | 5ee12d7 | 2014-12-17 16:24:01 -0800 | [diff] [blame] | 651 | free(file_contents); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | FPDF_DestroyLibrary(); |
John Abd-El-Malek | b045ed2 | 2015-02-10 09:15:12 -0800 | [diff] [blame] | 655 | v8::V8::ShutdownPlatform(); |
| 656 | delete platform; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 657 | |
| 658 | return 0; |
| 659 | } |