Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: samples/pdfium_test.cc

Issue 2495333002: Add --pages option in pdfium_test so it renders only some of the pages. (Closed)
Patch Set: Rename firstP, lastP Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 firstPage;
Lei Zhang 2016/11/14 19:09:23 first_page, last_page
npm 2016/11/14 20:14:15 Hmm I missed the format
81 int lastPage;
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
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->firstPage;
485 options->lastPage = options->firstPage;
486 } else {
487 std::stringstream(pagesstring.substr(0, firstdash)) >>
488 options->firstPage;
489 std::stringstream(pagesstring.substr(firstdash + 1)) >>
490 options->lastPage;
491 }
469 } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') { 492 } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') {
470 fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str()); 493 fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str());
471 return false; 494 return false;
472 } else { 495 } else {
473 break; 496 break;
474 } 497 }
475 } 498 }
476 for (size_t i = cur_idx; i < args.size(); i++) 499 for (size_t i = cur_idx; i < args.size(); i++)
477 files->push_back(args[i]); 500 files->push_back(args[i]);
478 501
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 #endif // PDF_ENABLE_XFA 793 #endif // PDF_ENABLE_XFA
771 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); 794 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD);
772 FPDF_SetFormFieldHighlightAlpha(form, 100); 795 FPDF_SetFormFieldHighlightAlpha(form, 100);
773 796
774 FORM_DoDocumentJSAction(form); 797 FORM_DoDocumentJSAction(form);
775 FORM_DoDocumentOpenAction(form); 798 FORM_DoDocumentOpenAction(form);
776 799
777 int page_count = FPDF_GetPageCount(doc); 800 int page_count = FPDF_GetPageCount(doc);
778 int rendered_pages = 0; 801 int rendered_pages = 0;
779 int bad_pages = 0; 802 int bad_pages = 0;
780 for (int i = 0; i < page_count; ++i) { 803 int firstPage = options.pages ? options.firstPage : 0;
Lei Zhang 2016/11/14 19:09:23 If the user passes in --pages=1-2, they actually g
npm 2016/11/14 20:14:15 This is because it is 0-indexed. This is consisten
804 int lastPage = options.pages ? options.lastPage + 1 : page_count;
805 for (int i = firstPage; i < lastPage; ++i) {
781 if (bIsLinearized) { 806 if (bIsLinearized) {
782 nRet = PDF_DATA_NOTAVAIL; 807 nRet = PDF_DATA_NOTAVAIL;
783 while (nRet == PDF_DATA_NOTAVAIL) 808 while (nRet == PDF_DATA_NOTAVAIL)
784 nRet = FPDFAvail_IsPageAvail(pdf_avail, i, &hints); 809 nRet = FPDFAvail_IsPageAvail(pdf_avail, i, &hints);
785 810
786 if (nRet == PDF_DATA_ERROR) { 811 if (nRet == PDF_DATA_ERROR) {
787 fprintf(stderr, "Unknown error in checking if page %d is available.\n", 812 fprintf(stderr, "Unknown error in checking if page %d is available.\n",
788 i); 813 i);
789 FPDFDOC_ExitFormFillEnvironment(form); 814 FPDFDOC_ExitFormFillEnvironment(form);
790 FPDF_CloseDocument(doc); 815 FPDF_CloseDocument(doc);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 printf("%s\n", config.c_str()); 853 printf("%s\n", config.c_str());
829 } 854 }
830 855
831 static const char kUsageString[] = 856 static const char kUsageString[] =
832 "Usage: pdfium_test [OPTION] [FILE]...\n" 857 "Usage: pdfium_test [OPTION] [FILE]...\n"
833 " --show-config - print build options and exit\n" 858 " --show-config - print build options and exit\n"
834 " --send-events - send input described by .evt file\n" 859 " --send-events - send input described by .evt file\n"
835 " --bin-dir=<path> - override path to v8 external data\n" 860 " --bin-dir=<path> - override path to v8 external data\n"
836 " --font-dir=<path> - override path to external fonts\n" 861 " --font-dir=<path> - override path to external fonts\n"
837 " --scale=<number> - scale output size by number (e.g. 0.5)\n" 862 " --scale=<number> - scale output size by number (e.g. 0.5)\n"
863 " --pages=<number>(-<number>) - only render the given page(s)\n"
838 #ifdef _WIN32 864 #ifdef _WIN32
839 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" 865 " --bmp - write page images <pdf-name>.<page-number>.bmp\n"
840 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" 866 " --emf - write page meta files <pdf-name>.<page-number>.emf\n"
841 #endif // _WIN32 867 #endif // _WIN32
842 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" 868 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n"
843 " --png - write page images <pdf-name>.<page-number>.png\n" 869 " --png - write page images <pdf-name>.<page-number>.png\n"
844 " --ppm - write page images <pdf-name>.<page-number>.ppm\n" 870 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"
845 #ifdef PDF_ENABLE_SKIA 871 #ifdef PDF_ENABLE_SKIA
846 " --skp - write page images <pdf-name>.<page-number>.skp\n" 872 " --skp - write page images <pdf-name>.<page-number>.skp\n"
847 #endif 873 #endif
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 delete platform; 960 delete platform;
935 961
936 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 962 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
937 free(const_cast<char*>(natives.data)); 963 free(const_cast<char*>(natives.data));
938 free(const_cast<char*>(snapshot.data)); 964 free(const_cast<char*>(snapshot.data));
939 #endif // V8_USE_EXTERNAL_STARTUP_DATA 965 #endif // V8_USE_EXTERNAL_STARTUP_DATA
940 #endif // PDF_ENABLE_V8 966 #endif // PDF_ENABLE_V8
941 967
942 return 0; 968 return 0;
943 } 969 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698