| 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 #include <wchar.h> | 9 #include <wchar.h> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #endif | 41 #endif |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 struct Options { | 44 struct Options { |
| 45 Options() : output_format(OUTPUT_NONE) { } | 45 Options() : output_format(OUTPUT_NONE) { } |
| 46 | 46 |
| 47 OutputFormat output_format; | 47 OutputFormat output_format; |
| 48 std::string scale_factor_as_string; | 48 std::string scale_factor_as_string; |
| 49 std::string exe_path; | 49 std::string exe_path; |
| 50 std::string bin_directory; | 50 std::string bin_directory; |
| 51 std::string font_directory; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 // Reads the entire contents of a file into a newly malloc'd buffer. | 54 // Reads the entire contents of a file into a newly malloc'd buffer. |
| 54 static char* GetFileContents(const char* filename, size_t* retlen) { | 55 static char* GetFileContents(const char* filename, size_t* retlen) { |
| 55 FILE* file = fopen(filename, "rb"); | 56 FILE* file = fopen(filename, "rb"); |
| 56 if (!file) { | 57 if (!file) { |
| 57 fprintf(stderr, "Failed to open: %s\n", filename); | 58 fprintf(stderr, "Failed to open: %s\n", filename); |
| 58 return nullptr; | 59 return nullptr; |
| 59 } | 60 } |
| 60 (void)fseek(file, 0, SEEK_END); | 61 (void)fseek(file, 0, SEEK_END); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); | 342 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); |
| 342 return false; | 343 return false; |
| 343 } | 344 } |
| 344 options->output_format = OUTPUT_PPM; | 345 options->output_format = OUTPUT_PPM; |
| 345 } else if (cur_arg == "--png") { | 346 } else if (cur_arg == "--png") { |
| 346 if (options->output_format != OUTPUT_NONE) { | 347 if (options->output_format != OUTPUT_NONE) { |
| 347 fprintf(stderr, "Duplicate or conflicting --png argument\n"); | 348 fprintf(stderr, "Duplicate or conflicting --png argument\n"); |
| 348 return false; | 349 return false; |
| 349 } | 350 } |
| 350 options->output_format = OUTPUT_PNG; | 351 options->output_format = OUTPUT_PNG; |
| 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); |
| 351 } | 359 } |
| 352 #ifdef _WIN32 | 360 #ifdef _WIN32 |
| 353 else if (cur_arg == "--emf") { | 361 else if (cur_arg == "--emf") { |
| 354 if (options->output_format != OUTPUT_NONE) { | 362 if (options->output_format != OUTPUT_NONE) { |
| 355 fprintf(stderr, "Duplicate or conflicting --emf argument\n"); | 363 fprintf(stderr, "Duplicate or conflicting --emf argument\n"); |
| 356 return false; | 364 return false; |
| 357 } | 365 } |
| 358 options->output_format = OUTPUT_EMF; | 366 options->output_format = OUTPUT_EMF; |
| 359 } | 367 } |
| 360 else if (cur_arg == "--bmp") { | 368 else if (cur_arg == "--bmp") { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 FPDFDOC_ExitFormFillEnvironment(form); | 579 FPDFDOC_ExitFormFillEnvironment(form); |
| 572 | 580 |
| 573 FPDFAvail_Destroy(pdf_avail); | 581 FPDFAvail_Destroy(pdf_avail); |
| 574 | 582 |
| 575 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); | 583 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); |
| 576 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); | 584 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); |
| 577 } | 585 } |
| 578 | 586 |
| 579 static const char usage_string[] = | 587 static const char usage_string[] = |
| 580 "Usage: pdfium_test [OPTION] [FILE]...\n" | 588 "Usage: pdfium_test [OPTION] [FILE]...\n" |
| 581 " --bin-dir=<path> - override path to v8 external data\n" | 589 " --bin-dir=<path> - override path to v8 external data\n" |
| 582 " --scale=<number> - scale output size by number (e.g. 0.5)\n" | 590 " --font-dir=<path> - override path to external fonts\n" |
| 591 " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
| 583 #ifdef _WIN32 | 592 #ifdef _WIN32 |
| 584 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" | 593 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
| 585 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" | 594 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
| 586 #endif | 595 #endif |
| 587 " --png - write page images <pdf-name>.<page-number>.png\n" | 596 " --png - write page images <pdf-name>.<page-number>.png\n" |
| 588 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; | 597 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; |
| 589 | 598 |
| 590 int main(int argc, const char* argv[]) { | 599 int main(int argc, const char* argv[]) { |
| 591 std::vector<std::string> args(argv, argv + argc); | 600 std::vector<std::string> args(argv, argv + argc); |
| 592 Options options; | 601 Options options; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 605 v8::StartupData natives; | 614 v8::StartupData natives; |
| 606 v8::StartupData snapshot; | 615 v8::StartupData snapshot; |
| 607 if (!GetExternalData(options, "natives_blob.bin", &natives) || | 616 if (!GetExternalData(options, "natives_blob.bin", &natives) || |
| 608 !GetExternalData(options, "snapshot_blob.bin", &snapshot)) { | 617 !GetExternalData(options, "snapshot_blob.bin", &snapshot)) { |
| 609 return 1; | 618 return 1; |
| 610 } | 619 } |
| 611 v8::V8::SetNativesDataBlob(&natives); | 620 v8::V8::SetNativesDataBlob(&natives); |
| 612 v8::V8::SetSnapshotDataBlob(&snapshot); | 621 v8::V8::SetSnapshotDataBlob(&snapshot); |
| 613 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 622 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 614 | 623 |
| 615 FPDF_InitLibrary(); | 624 if (!options.font_directory.empty()) { |
| 625 const char* path_array[2]; |
| 626 path_array[0] = options.font_directory.c_str(); |
| 627 path_array[1] = nullptr; |
| 628 FPDF_LIBRARY_CONFIG config; |
| 629 config.version = 1; |
| 630 config.m_pUserFontPaths = path_array; |
| 631 FPDF_InitLibraryWithConfig(&config); |
| 632 } else { |
| 633 FPDF_InitLibrary(); |
| 634 } |
| 616 | 635 |
| 617 UNSUPPORT_INFO unsuppored_info; | 636 UNSUPPORT_INFO unsuppored_info; |
| 618 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); | 637 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); |
| 619 unsuppored_info.version = 1; | 638 unsuppored_info.version = 1; |
| 620 unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; | 639 unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; |
| 621 | 640 |
| 622 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); | 641 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
| 623 | 642 |
| 624 while (!files.empty()) { | 643 while (!files.empty()) { |
| 625 std::string filename = files.front(); | 644 std::string filename = files.front(); |
| 626 files.pop_front(); | 645 files.pop_front(); |
| 627 size_t file_length = 0; | 646 size_t file_length = 0; |
| 628 char* file_contents = GetFileContents(filename.c_str(), &file_length); | 647 char* file_contents = GetFileContents(filename.c_str(), &file_length); |
| 629 if (!file_contents) | 648 if (!file_contents) |
| 630 continue; | 649 continue; |
| 631 RenderPdf(filename, file_contents, file_length, options); | 650 RenderPdf(filename, file_contents, file_length, options); |
| 632 free(file_contents); | 651 free(file_contents); |
| 633 } | 652 } |
| 634 | 653 |
| 635 FPDF_DestroyLibrary(); | 654 FPDF_DestroyLibrary(); |
| 636 v8::V8::ShutdownPlatform(); | 655 v8::V8::ShutdownPlatform(); |
| 637 delete platform; | 656 delete platform; |
| 638 | 657 |
| 639 return 0; | 658 return 0; |
| 640 } | 659 } |
| OLD | NEW |