Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 OUTPUT_BMP, | 57 OUTPUT_BMP, |
| 58 OUTPUT_EMF, | 58 OUTPUT_EMF, |
| 59 #endif | 59 #endif |
| 60 #ifdef PDF_ENABLE_SKIA | 60 #ifdef PDF_ENABLE_SKIA |
| 61 OUTPUT_SKP, | 61 OUTPUT_SKP, |
| 62 #endif | 62 #endif |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 struct Options { | 65 struct Options { |
| 66 Options() | 66 Options() |
| 67 : show_config(false), send_events(false), output_format(OUTPUT_NONE) {} | 67 : show_config(false), |
| 68 send_events(false), | |
| 69 pages(false), | |
| 70 output_format(OUTPUT_NONE) {} | |
| 68 | 71 |
| 69 bool show_config; | 72 bool show_config; |
| 70 bool send_events; | 73 bool send_events; |
| 74 bool pages; | |
| 71 OutputFormat output_format; | 75 OutputFormat output_format; |
| 72 std::string scale_factor_as_string; | 76 std::string scale_factor_as_string; |
| 73 std::string exe_path; | 77 std::string exe_path; |
| 74 std::string bin_directory; | 78 std::string bin_directory; |
| 75 std::string font_directory; | 79 std::string font_directory; |
| 80 int firstP; | |
|
dsinclair
2016/11/14 16:35:27
size_t?
npm
2016/11/14 16:40:14
RenderPage receives an int param. I don't think ch
| |
| 81 int lastP; | |
| 76 }; | 82 }; |
| 77 | 83 |
| 78 struct FPDF_FORMFILLINFO_PDFiumTest : public FPDF_FORMFILLINFO { | 84 struct FPDF_FORMFILLINFO_PDFiumTest : public FPDF_FORMFILLINFO { |
| 79 // Hold a map of the currently loaded pages in order to avoid them | 85 // Hold a map of the currently loaded pages in order to avoid them |
| 80 // to get loaded twice. | 86 // to get loaded twice. |
| 81 std::map<int, FPDF_PAGE> loadedPages; | 87 std::map<int, FPDF_PAGE> loadedPages; |
| 82 | 88 |
| 83 // Hold a pointer of FPDF_FORMHANDLE so that PDFium app hooks can | 89 // Hold a pointer of FPDF_FORMHANDLE so that PDFium app hooks can |
| 84 // make use of it. | 90 // make use of it. |
| 85 FPDF_FORMHANDLE formHandle; | 91 FPDF_FORMHANDLE formHandle; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 options->bin_directory = cur_arg.substr(10); | 465 options->bin_directory = cur_arg.substr(10); |
| 460 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 466 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 461 #endif // PDF_ENABLE_V8 | 467 #endif // PDF_ENABLE_V8 |
| 462 | 468 |
| 463 } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { | 469 } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { |
| 464 if (!options->scale_factor_as_string.empty()) { | 470 if (!options->scale_factor_as_string.empty()) { |
| 465 fprintf(stderr, "Duplicate --scale argument\n"); | 471 fprintf(stderr, "Duplicate --scale argument\n"); |
| 466 return false; | 472 return false; |
| 467 } | 473 } |
| 468 options->scale_factor_as_string = cur_arg.substr(8); | 474 options->scale_factor_as_string = cur_arg.substr(8); |
| 475 } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--pages=") == 0) { | |
| 476 if (options->pages) { | |
| 477 fprintf(stderr, "Duplicate --pages argument\n"); | |
| 478 return false; | |
| 479 } | |
| 480 options->pages = true; | |
| 481 const std::string pagesstring = cur_arg.substr(8); | |
| 482 size_t firstdash = pagesstring.find("-"); | |
| 483 if (firstdash == std::string::npos) { | |
| 484 std::stringstream(pagesstring) >> options->firstP; | |
| 485 options->lastP = options->firstP; | |
| 486 } | |
|
dsinclair
2016/11/14 16:35:27
Doesn't this need an else?
npm
2016/11/14 16:40:14
Done.
| |
| 487 std::stringstream(pagesstring.substr(0, firstdash)) >> options->firstP; | |
| 488 std::stringstream(pagesstring.substr(firstdash + 1)) >> options->lastP; | |
| 469 } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') { | 489 } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') { |
| 470 fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str()); | 490 fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str()); |
| 471 return false; | 491 return false; |
| 472 } else { | 492 } else { |
| 473 break; | 493 break; |
| 474 } | 494 } |
| 475 } | 495 } |
| 476 for (size_t i = cur_idx; i < args.size(); i++) | 496 for (size_t i = cur_idx; i < args.size(); i++) |
| 477 files->push_back(args[i]); | 497 files->push_back(args[i]); |
| 478 | 498 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 #endif // PDF_ENABLE_XFA | 790 #endif // PDF_ENABLE_XFA |
| 771 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); | 791 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); |
| 772 FPDF_SetFormFieldHighlightAlpha(form, 100); | 792 FPDF_SetFormFieldHighlightAlpha(form, 100); |
| 773 | 793 |
| 774 FORM_DoDocumentJSAction(form); | 794 FORM_DoDocumentJSAction(form); |
| 775 FORM_DoDocumentOpenAction(form); | 795 FORM_DoDocumentOpenAction(form); |
| 776 | 796 |
| 777 int page_count = FPDF_GetPageCount(doc); | 797 int page_count = FPDF_GetPageCount(doc); |
| 778 int rendered_pages = 0; | 798 int rendered_pages = 0; |
| 779 int bad_pages = 0; | 799 int bad_pages = 0; |
| 780 for (int i = 0; i < page_count; ++i) { | 800 int firstPage = options.pages ? options.firstP : 0; |
| 801 int lastPage = options.pages ? options.lastP + 1 : page_count; | |
|
dsinclair
2016/11/14 16:35:27
Why +1?
npm
2016/11/14 16:40:14
To make the range inclusive. See the "i < lastPage
| |
| 802 for (int i = firstPage; i < lastPage; ++i) { | |
| 781 if (bIsLinearized) { | 803 if (bIsLinearized) { |
| 782 nRet = PDF_DATA_NOTAVAIL; | 804 nRet = PDF_DATA_NOTAVAIL; |
| 783 while (nRet == PDF_DATA_NOTAVAIL) | 805 while (nRet == PDF_DATA_NOTAVAIL) |
| 784 nRet = FPDFAvail_IsPageAvail(pdf_avail, i, &hints); | 806 nRet = FPDFAvail_IsPageAvail(pdf_avail, i, &hints); |
| 785 | 807 |
| 786 if (nRet == PDF_DATA_ERROR) { | 808 if (nRet == PDF_DATA_ERROR) { |
| 787 fprintf(stderr, "Unknown error in checking if page %d is available.\n", | 809 fprintf(stderr, "Unknown error in checking if page %d is available.\n", |
| 788 i); | 810 i); |
| 789 FPDFDOC_ExitFormFillEnvironment(form); | 811 FPDFDOC_ExitFormFillEnvironment(form); |
| 790 FPDF_CloseDocument(doc); | 812 FPDF_CloseDocument(doc); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 828 printf("%s\n", config.c_str()); | 850 printf("%s\n", config.c_str()); |
| 829 } | 851 } |
| 830 | 852 |
| 831 static const char kUsageString[] = | 853 static const char kUsageString[] = |
| 832 "Usage: pdfium_test [OPTION] [FILE]...\n" | 854 "Usage: pdfium_test [OPTION] [FILE]...\n" |
| 833 " --show-config - print build options and exit\n" | 855 " --show-config - print build options and exit\n" |
| 834 " --send-events - send input described by .evt file\n" | 856 " --send-events - send input described by .evt file\n" |
| 835 " --bin-dir=<path> - override path to v8 external data\n" | 857 " --bin-dir=<path> - override path to v8 external data\n" |
| 836 " --font-dir=<path> - override path to external fonts\n" | 858 " --font-dir=<path> - override path to external fonts\n" |
| 837 " --scale=<number> - scale output size by number (e.g. 0.5)\n" | 859 " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
| 860 " --pages=<number>(-<number>) - only render the given page(s)\n" | |
| 838 #ifdef _WIN32 | 861 #ifdef _WIN32 |
| 839 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" | 862 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
| 840 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" | 863 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
| 841 #endif // _WIN32 | 864 #endif // _WIN32 |
| 842 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" | 865 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" |
| 843 " --png - write page images <pdf-name>.<page-number>.png\n" | 866 " --png - write page images <pdf-name>.<page-number>.png\n" |
| 844 " --ppm - write page images <pdf-name>.<page-number>.ppm\n" | 867 " --ppm - write page images <pdf-name>.<page-number>.ppm\n" |
| 845 #ifdef PDF_ENABLE_SKIA | 868 #ifdef PDF_ENABLE_SKIA |
| 846 " --skp - write page images <pdf-name>.<page-number>.skp\n" | 869 " --skp - write page images <pdf-name>.<page-number>.skp\n" |
| 847 #endif | 870 #endif |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 934 delete platform; | 957 delete platform; |
| 935 | 958 |
| 936 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 959 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 937 free(const_cast<char*>(natives.data)); | 960 free(const_cast<char*>(natives.data)); |
| 938 free(const_cast<char*>(snapshot.data)); | 961 free(const_cast<char*>(snapshot.data)); |
| 939 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 962 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 940 #endif // PDF_ENABLE_V8 | 963 #endif // PDF_ENABLE_V8 |
| 941 | 964 |
| 942 return 0; | 965 return 0; |
| 943 } | 966 } |
| OLD | NEW |