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

Side by Side Diff: samples/pdfium_test.cc

Issue 1587023005: Make pdfium_test report build options. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: And back to comma. Created 4 years, 11 months 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 <list> 10 #include <list>
(...skipping 24 matching lines...) Expand all
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
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
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 526
526 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); 527 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC);
527 FPDFDOC_ExitFormFillEnvironment(form); 528 FPDFDOC_ExitFormFillEnvironment(form);
528 FPDF_CloseDocument(doc); 529 FPDF_CloseDocument(doc);
529 FPDFAvail_Destroy(pdf_avail); 530 FPDFAvail_Destroy(pdf_avail);
530 531
531 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); 532 fprintf(stderr, "Rendered %d pages.\n", rendered_pages);
532 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); 533 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages);
533 } 534 }
534 535
536 static void ShowConfig() {
537 std::string config;
538 std::string maybe_comma;
539 #if PDF_ENABLE_V8
540 config.append(maybe_comma);
541 config.append("V8");
542 maybe_comma = ",";
543 #endif // PDF_ENABLE_V8
544 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
545 config.append(maybe_comma);
546 config.append("V8_EXTERNAL");
547 maybe_comma = ",";
548 #endif // V8_USE_EXTERNAL_STARTUP_DATA
549 printf("%s\n", config.c_str());
550 }
551
535 static const char usage_string[] = 552 static const char usage_string[] =
536 "Usage: pdfium_test [OPTION] [FILE]...\n" 553 "Usage: pdfium_test [OPTION] [FILE]...\n"
554 " --show-config - print build options and exit\n"
537 " --bin-dir=<path> - override path to v8 external data\n" 555 " --bin-dir=<path> - override path to v8 external data\n"
538 " --font-dir=<path> - override path to external fonts\n" 556 " --font-dir=<path> - override path to external fonts\n"
539 " --scale=<number> - scale output size by number (e.g. 0.5)\n" 557 " --scale=<number> - scale output size by number (e.g. 0.5)\n"
540 #ifdef _WIN32 558 #ifdef _WIN32
541 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" 559 " --bmp - write page images <pdf-name>.<page-number>.bmp\n"
542 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" 560 " --emf - write page meta files <pdf-name>.<page-number>.emf\n"
543 #endif 561 #endif
544 " --png - write page images <pdf-name>.<page-number>.png\n" 562 " --png - write page images <pdf-name>.<page-number>.png\n"
545 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; 563 " --ppm - write page images <pdf-name>.<page-number>.ppm\n";
546 564
547 int main(int argc, const char* argv[]) { 565 int main(int argc, const char* argv[]) {
548 std::vector<std::string> args(argv, argv + argc); 566 std::vector<std::string> args(argv, argv + argc);
549 Options options; 567 Options options;
550 std::list<std::string> files; 568 std::list<std::string> files;
551 if (!ParseCommandLine(args, &options, &files)) { 569 if (!ParseCommandLine(args, &options, &files)) {
552 fprintf(stderr, "%s", usage_string); 570 fprintf(stderr, "%s", usage_string);
553 return 1; 571 return 1;
554 } 572 }
555 573
574 if (options.show_config) {
575 ShowConfig();
576 return 0;
577 }
578
579 if (files.empty()) {
580 fprintf(stderr, "No input files.\n");
581 return 1;
582 }
583
556 #ifdef PDF_ENABLE_V8 584 #ifdef PDF_ENABLE_V8
557 v8::Platform* platform; 585 v8::Platform* platform;
558 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 586 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
559 v8::StartupData natives; 587 v8::StartupData natives;
560 v8::StartupData snapshot; 588 v8::StartupData snapshot;
561 InitializeV8ForPDFium(options.exe_path, options.bin_directory, &natives, 589 InitializeV8ForPDFium(options.exe_path, options.bin_directory, &natives,
562 &snapshot, &platform); 590 &snapshot, &platform);
563 #else // V8_USE_EXTERNAL_STARTUP_DATA 591 #else // V8_USE_EXTERNAL_STARTUP_DATA
564 InitializeV8ForPDFium(&platform); 592 InitializeV8ForPDFium(&platform);
565 #endif // V8_USE_EXTERNAL_STARTUP_DATA 593 #endif // V8_USE_EXTERNAL_STARTUP_DATA
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 } 625 }
598 626
599 FPDF_DestroyLibrary(); 627 FPDF_DestroyLibrary();
600 #ifdef PDF_ENABLE_V8 628 #ifdef PDF_ENABLE_V8
601 v8::V8::ShutdownPlatform(); 629 v8::V8::ShutdownPlatform();
602 delete platform; 630 delete platform;
603 #endif // PDF_ENABLE_V8 631 #endif // PDF_ENABLE_V8
604 632
605 return 0; 633 return 0;
606 } 634 }
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