OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits.h> | 5 #include <limits.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 24 matching lines...) Expand all Loading... |
35 OUTPUT_NONE, | 35 OUTPUT_NONE, |
36 OUTPUT_PPM, | 36 OUTPUT_PPM, |
37 OUTPUT_PNG, | 37 OUTPUT_PNG, |
38 #ifdef _WIN32 | 38 #ifdef _WIN32 |
39 OUTPUT_BMP, | 39 OUTPUT_BMP, |
40 OUTPUT_EMF, | 40 OUTPUT_EMF, |
41 #endif | 41 #endif |
42 }; | 42 }; |
43 | 43 |
44 struct Options { | 44 struct Options { |
45 Options() : output_format(OUTPUT_NONE) { } | 45 Options() : show_config(false), output_format(OUTPUT_NONE) {} |
46 | 46 |
| 47 bool show_config; |
47 OutputFormat output_format; | 48 OutputFormat output_format; |
48 std::string scale_factor_as_string; | 49 std::string scale_factor_as_string; |
49 std::string exe_path; | 50 std::string exe_path; |
50 std::string bin_directory; | 51 std::string bin_directory; |
51 std::string font_directory; | 52 std::string font_directory; |
52 }; | 53 }; |
53 | 54 |
54 static bool CheckDimensions(int stride, int width, int height) { | 55 static bool CheckDimensions(int stride, int width, int height) { |
55 if (stride < 0 || width < 0 || height < 0) | 56 if (stride < 0 || width < 0 || height < 0) |
56 return false; | 57 return false; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 252 |
252 bool ParseCommandLine(const std::vector<std::string>& args, | 253 bool ParseCommandLine(const std::vector<std::string>& args, |
253 Options* options, std::list<std::string>* files) { | 254 Options* options, std::list<std::string>* files) { |
254 if (args.empty()) { | 255 if (args.empty()) { |
255 return false; | 256 return false; |
256 } | 257 } |
257 options->exe_path = args[0]; | 258 options->exe_path = args[0]; |
258 size_t cur_idx = 1; | 259 size_t cur_idx = 1; |
259 for (; cur_idx < args.size(); ++cur_idx) { | 260 for (; cur_idx < args.size(); ++cur_idx) { |
260 const std::string& cur_arg = args[cur_idx]; | 261 const std::string& cur_arg = args[cur_idx]; |
261 if (cur_arg == "--ppm") { | 262 if (cur_arg == "--show-config") { |
| 263 options->show_config = true; |
| 264 } else if (cur_arg == "--ppm") { |
262 if (options->output_format != OUTPUT_NONE) { | 265 if (options->output_format != OUTPUT_NONE) { |
263 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); | 266 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); |
264 return false; | 267 return false; |
265 } | 268 } |
266 options->output_format = OUTPUT_PPM; | 269 options->output_format = OUTPUT_PPM; |
267 } else if (cur_arg == "--png") { | 270 } else if (cur_arg == "--png") { |
268 if (options->output_format != OUTPUT_NONE) { | 271 if (options->output_format != OUTPUT_NONE) { |
269 fprintf(stderr, "Duplicate or conflicting --png argument\n"); | 272 fprintf(stderr, "Duplicate or conflicting --png argument\n"); |
270 return false; | 273 return false; |
271 } | 274 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 options->bin_directory = cur_arg.substr(10); | 307 options->bin_directory = cur_arg.substr(10); |
305 } | 308 } |
306 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 309 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
307 #endif // PDF_ENABLE_V8 | 310 #endif // PDF_ENABLE_V8 |
308 else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { | 311 else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { |
309 if (!options->scale_factor_as_string.empty()) { | 312 if (!options->scale_factor_as_string.empty()) { |
310 fprintf(stderr, "Duplicate --scale argument\n"); | 313 fprintf(stderr, "Duplicate --scale argument\n"); |
311 return false; | 314 return false; |
312 } | 315 } |
313 options->scale_factor_as_string = cur_arg.substr(8); | 316 options->scale_factor_as_string = cur_arg.substr(8); |
314 } | 317 } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') { |
315 else | 318 fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str()); |
| 319 return false; |
| 320 } else |
316 break; | 321 break; |
317 } | 322 } |
318 if (cur_idx >= args.size()) { | |
319 fprintf(stderr, "No input files.\n"); | |
320 return false; | |
321 } | |
322 for (size_t i = cur_idx; i < args.size(); i++) { | 323 for (size_t i = cur_idx; i < args.size(); i++) { |
323 files->push_back(args[i]); | 324 files->push_back(args[i]); |
324 } | 325 } |
325 return true; | 326 return true; |
326 } | 327 } |
327 | 328 |
328 FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { | 329 FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
329 return true; | 330 return true; |
330 } | 331 } |
331 | 332 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 FPDFDOC_ExitFormFillEnvironment(form); | 547 FPDFDOC_ExitFormFillEnvironment(form); |
547 FPDF_CloseDocument(doc); | 548 FPDF_CloseDocument(doc); |
548 #endif // PDF_ENABLE_XFA | 549 #endif // PDF_ENABLE_XFA |
549 | 550 |
550 FPDFAvail_Destroy(pdf_avail); | 551 FPDFAvail_Destroy(pdf_avail); |
551 | 552 |
552 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); | 553 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); |
553 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); | 554 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); |
554 } | 555 } |
555 | 556 |
| 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 |
556 static const char usage_string[] = | 578 static const char usage_string[] = |
557 "Usage: pdfium_test [OPTION] [FILE]...\n" | 579 "Usage: pdfium_test [OPTION] [FILE]...\n" |
| 580 " --show-config - print build options and exit\n" |
558 " --bin-dir=<path> - override path to v8 external data\n" | 581 " --bin-dir=<path> - override path to v8 external data\n" |
559 " --font-dir=<path> - override path to external fonts\n" | 582 " --font-dir=<path> - override path to external fonts\n" |
560 " --scale=<number> - scale output size by number (e.g. 0.5)\n" | 583 " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
561 #ifdef _WIN32 | 584 #ifdef _WIN32 |
562 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" | 585 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
563 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" | 586 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
564 #endif // _WIN32 | 587 #endif // _WIN32 |
565 " --png - write page images <pdf-name>.<page-number>.png\n" | 588 " --png - write page images <pdf-name>.<page-number>.png\n" |
566 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; | 589 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; |
567 | 590 |
568 int main(int argc, const char* argv[]) { | 591 int main(int argc, const char* argv[]) { |
569 std::vector<std::string> args(argv, argv + argc); | 592 std::vector<std::string> args(argv, argv + argc); |
570 Options options; | 593 Options options; |
571 std::list<std::string> files; | 594 std::list<std::string> files; |
572 if (!ParseCommandLine(args, &options, &files)) { | 595 if (!ParseCommandLine(args, &options, &files)) { |
573 fprintf(stderr, "%s", usage_string); | 596 fprintf(stderr, "%s", usage_string); |
574 return 1; | 597 return 1; |
575 } | 598 } |
576 | 599 |
| 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 |
577 #ifdef PDF_ENABLE_V8 | 610 #ifdef PDF_ENABLE_V8 |
578 v8::Platform* platform; | 611 v8::Platform* platform; |
579 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 612 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
580 v8::StartupData natives; | 613 v8::StartupData natives; |
581 v8::StartupData snapshot; | 614 v8::StartupData snapshot; |
582 InitializeV8ForPDFium(options.exe_path, options.bin_directory, &natives, | 615 InitializeV8ForPDFium(options.exe_path, options.bin_directory, &natives, |
583 &snapshot, &platform); | 616 &snapshot, &platform); |
584 #else // V8_USE_EXTERNAL_STARTUP_DATA | 617 #else // V8_USE_EXTERNAL_STARTUP_DATA |
585 InitializeV8ForPDFium(&platform); | 618 InitializeV8ForPDFium(&platform); |
586 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 619 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 } | 651 } |
619 | 652 |
620 FPDF_DestroyLibrary(); | 653 FPDF_DestroyLibrary(); |
621 #ifdef PDF_ENABLE_V8 | 654 #ifdef PDF_ENABLE_V8 |
622 v8::V8::ShutdownPlatform(); | 655 v8::V8::ShutdownPlatform(); |
623 delete platform; | 656 delete platform; |
624 #endif // PDF_ENABLE_V8 | 657 #endif // PDF_ENABLE_V8 |
625 | 658 |
626 return 0; | 659 return 0; |
627 } | 660 } |
OLD | NEW |