| 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 <map> | 10 #include <map> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 output_format(OUTPUT_NONE) {} | 70 output_format(OUTPUT_NONE) {} |
| 71 | 71 |
| 72 bool show_config; | 72 bool show_config; |
| 73 bool send_events; | 73 bool send_events; |
| 74 bool pages; | 74 bool pages; |
| 75 OutputFormat output_format; | 75 OutputFormat output_format; |
| 76 std::string scale_factor_as_string; | 76 std::string scale_factor_as_string; |
| 77 std::string exe_path; | 77 std::string exe_path; |
| 78 std::string bin_directory; | 78 std::string bin_directory; |
| 79 std::string font_directory; | 79 std::string font_directory; |
| 80 std::string password; |
| 80 // 0-based page numbers to be rendered. | 81 // 0-based page numbers to be rendered. |
| 81 int first_page; | 82 int first_page; |
| 82 int last_page; | 83 int last_page; |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 struct FPDF_FORMFILLINFO_PDFiumTest : public FPDF_FORMFILLINFO { | 86 struct FPDF_FORMFILLINFO_PDFiumTest : public FPDF_FORMFILLINFO { |
| 86 // Hold a map of the currently loaded pages in order to avoid them | 87 // Hold a map of the currently loaded pages in order to avoid them |
| 87 // to get loaded twice. | 88 // to get loaded twice. |
| 88 std::map<int, FPDF_PAGE> loaded_pages; | 89 std::map<int, FPDF_PAGE> loaded_pages; |
| 89 | 90 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 options->bin_directory = cur_arg.substr(10); | 467 options->bin_directory = cur_arg.substr(10); |
| 467 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 468 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 468 #endif // PDF_ENABLE_V8 | 469 #endif // PDF_ENABLE_V8 |
| 469 | 470 |
| 470 } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { | 471 } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { |
| 471 if (!options->scale_factor_as_string.empty()) { | 472 if (!options->scale_factor_as_string.empty()) { |
| 472 fprintf(stderr, "Duplicate --scale argument\n"); | 473 fprintf(stderr, "Duplicate --scale argument\n"); |
| 473 return false; | 474 return false; |
| 474 } | 475 } |
| 475 options->scale_factor_as_string = cur_arg.substr(8); | 476 options->scale_factor_as_string = cur_arg.substr(8); |
| 477 } else if (cur_arg.size() > 27 && |
| 478 cur_arg.compare(0, 27, "--compromise-this-password=") == 0) { |
| 479 if (!options->password.empty()) { |
| 480 fprintf(stderr, "Duplicate --compromise-this-password argument\n"); |
| 481 return false; |
| 482 } |
| 483 options->password = cur_arg.substr(27); |
| 476 } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--pages=") == 0) { | 484 } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--pages=") == 0) { |
| 477 if (options->pages) { | 485 if (options->pages) { |
| 478 fprintf(stderr, "Duplicate --pages argument\n"); | 486 fprintf(stderr, "Duplicate --pages argument\n"); |
| 479 return false; | 487 return false; |
| 480 } | 488 } |
| 481 options->pages = true; | 489 options->pages = true; |
| 482 const std::string pages_string = cur_arg.substr(8); | 490 const std::string pages_string = cur_arg.substr(8); |
| 483 size_t first_dash = pages_string.find("-"); | 491 size_t first_dash = pages_string.find("-"); |
| 484 if (first_dash == std::string::npos) { | 492 if (first_dash == std::string::npos) { |
| 485 std::stringstream(pages_string) >> options->first_page; | 493 std::stringstream(pages_string) >> options->first_page; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 memset(&hints, '\0', sizeof(hints)); | 723 memset(&hints, '\0', sizeof(hints)); |
| 716 hints.version = 1; | 724 hints.version = 1; |
| 717 hints.AddSegment = Add_Segment; | 725 hints.AddSegment = Add_Segment; |
| 718 | 726 |
| 719 FPDF_DOCUMENT doc; | 727 FPDF_DOCUMENT doc; |
| 720 int nRet = PDF_DATA_NOTAVAIL; | 728 int nRet = PDF_DATA_NOTAVAIL; |
| 721 bool bIsLinearized = false; | 729 bool bIsLinearized = false; |
| 722 FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); | 730 FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); |
| 723 std::unique_ptr<void, AvailDeleter> scoped_pdf_avail_deleter(pdf_avail); | 731 std::unique_ptr<void, AvailDeleter> scoped_pdf_avail_deleter(pdf_avail); |
| 724 | 732 |
| 733 const char* password = nullptr; |
| 734 if (!options.password.empty()) |
| 735 password = options.password.c_str(); |
| 736 |
| 725 if (FPDFAvail_IsLinearized(pdf_avail) == PDF_LINEARIZED) { | 737 if (FPDFAvail_IsLinearized(pdf_avail) == PDF_LINEARIZED) { |
| 726 doc = FPDFAvail_GetDocument(pdf_avail, nullptr); | 738 doc = FPDFAvail_GetDocument(pdf_avail, password); |
| 727 if (doc) { | 739 if (doc) { |
| 728 while (nRet == PDF_DATA_NOTAVAIL) | 740 while (nRet == PDF_DATA_NOTAVAIL) |
| 729 nRet = FPDFAvail_IsDocAvail(pdf_avail, &hints); | 741 nRet = FPDFAvail_IsDocAvail(pdf_avail, &hints); |
| 730 | 742 |
| 731 if (nRet == PDF_DATA_ERROR) { | 743 if (nRet == PDF_DATA_ERROR) { |
| 732 fprintf(stderr, "Unknown error in checking if doc was available.\n"); | 744 fprintf(stderr, "Unknown error in checking if doc was available.\n"); |
| 733 FPDF_CloseDocument(doc); | 745 FPDF_CloseDocument(doc); |
| 734 return; | 746 return; |
| 735 } | 747 } |
| 736 nRet = FPDFAvail_IsFormAvail(pdf_avail, &hints); | 748 nRet = FPDFAvail_IsFormAvail(pdf_avail, &hints); |
| 737 if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { | 749 if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { |
| 738 fprintf(stderr, | 750 fprintf(stderr, |
| 739 "Error %d was returned in checking if form was available.\n", | 751 "Error %d was returned in checking if form was available.\n", |
| 740 nRet); | 752 nRet); |
| 741 FPDF_CloseDocument(doc); | 753 FPDF_CloseDocument(doc); |
| 742 return; | 754 return; |
| 743 } | 755 } |
| 744 bIsLinearized = true; | 756 bIsLinearized = true; |
| 745 } | 757 } |
| 746 } else { | 758 } else { |
| 747 doc = FPDF_LoadCustomDocument(&file_access, nullptr); | 759 doc = FPDF_LoadCustomDocument(&file_access, password); |
| 748 } | 760 } |
| 749 | 761 |
| 750 if (!doc) { | 762 if (!doc) { |
| 751 unsigned long err = FPDF_GetLastError(); | 763 unsigned long err = FPDF_GetLastError(); |
| 752 fprintf(stderr, "Load pdf docs unsuccessful: "); | 764 fprintf(stderr, "Load pdf docs unsuccessful: "); |
| 753 switch (err) { | 765 switch (err) { |
| 754 case FPDF_ERR_SUCCESS: | 766 case FPDF_ERR_SUCCESS: |
| 755 fprintf(stderr, "Success"); | 767 fprintf(stderr, "Success"); |
| 756 break; | 768 break; |
| 757 case FPDF_ERR_UNKNOWN: | 769 case FPDF_ERR_UNKNOWN: |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 } | 867 } |
| 856 | 868 |
| 857 static const char kUsageString[] = | 869 static const char kUsageString[] = |
| 858 "Usage: pdfium_test [OPTION] [FILE]...\n" | 870 "Usage: pdfium_test [OPTION] [FILE]...\n" |
| 859 " --show-config - print build options and exit\n" | 871 " --show-config - print build options and exit\n" |
| 860 " --send-events - send input described by .evt file\n" | 872 " --send-events - send input described by .evt file\n" |
| 861 " --bin-dir=<path> - override path to v8 external data\n" | 873 " --bin-dir=<path> - override path to v8 external data\n" |
| 862 " --font-dir=<path> - override path to external fonts\n" | 874 " --font-dir=<path> - override path to external fonts\n" |
| 863 " --scale=<number> - scale output size by number (e.g. 0.5)\n" | 875 " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
| 864 " --pages=<number>(-<number>) - only render the given 0-based page(s)\n" | 876 " --pages=<number>(-<number>) - only render the given 0-based page(s)\n" |
| 877 " --compromise-this-password=<string> - password protected document.\n" |
| 878 " (unsafe since cmd line usage compromises password, testing only)\n" |
| 865 #ifdef _WIN32 | 879 #ifdef _WIN32 |
| 866 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" | 880 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
| 867 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" | 881 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
| 868 #endif // _WIN32 | 882 #endif // _WIN32 |
| 869 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" | 883 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" |
| 870 " --png - write page images <pdf-name>.<page-number>.png\n" | 884 " --png - write page images <pdf-name>.<page-number>.png\n" |
| 871 " --ppm - write page images <pdf-name>.<page-number>.ppm\n" | 885 " --ppm - write page images <pdf-name>.<page-number>.ppm\n" |
| 872 #ifdef PDF_ENABLE_SKIA | 886 #ifdef PDF_ENABLE_SKIA |
| 873 " --skp - write page images <pdf-name>.<page-number>.skp\n" | 887 " --skp - write page images <pdf-name>.<page-number>.skp\n" |
| 874 #endif | 888 #endif |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 delete platform; | 975 delete platform; |
| 962 | 976 |
| 963 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 977 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 964 free(const_cast<char*>(natives.data)); | 978 free(const_cast<char*>(natives.data)); |
| 965 free(const_cast<char*>(snapshot.data)); | 979 free(const_cast<char*>(snapshot.data)); |
| 966 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 980 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 967 #endif // PDF_ENABLE_V8 | 981 #endif // PDF_ENABLE_V8 |
| 968 | 982 |
| 969 return 0; | 983 return 0; |
| 970 } | 984 } |
| OLD | NEW |