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