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

Side by Side Diff: samples/pdfium_test.cc

Issue 1268323004: Allow external font-path configuration from pdfium_test. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove python driver changes Created 5 years, 4 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
« fpdfsdk/src/fpdfview.cpp ('K') | « public/fpdfview.h ('k') | 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 28 matching lines...) Expand all
39 #endif 39 #endif
40 }; 40 };
41 41
42 struct Options { 42 struct Options {
43 Options() : output_format(OUTPUT_NONE) { } 43 Options() : output_format(OUTPUT_NONE) { }
44 44
45 OutputFormat output_format; 45 OutputFormat output_format;
46 std::string scale_factor_as_string; 46 std::string scale_factor_as_string;
47 std::string exe_path; 47 std::string exe_path;
48 std::string bin_directory; 48 std::string bin_directory;
49 std::string font_directory;
49 }; 50 };
50 51
51 // Reads the entire contents of a file into a newly malloc'd buffer. 52 // Reads the entire contents of a file into a newly malloc'd buffer.
52 static char* GetFileContents(const char* filename, size_t* retlen) { 53 static char* GetFileContents(const char* filename, size_t* retlen) {
53 FILE* file = fopen(filename, "rb"); 54 FILE* file = fopen(filename, "rb");
54 if (!file) { 55 if (!file) {
55 fprintf(stderr, "Failed to open: %s\n", filename); 56 fprintf(stderr, "Failed to open: %s\n", filename);
56 return NULL; 57 return NULL;
57 } 58 }
58 (void) fseek(file, 0, SEEK_END); 59 (void) fseek(file, 0, SEEK_END);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); 341 fprintf(stderr, "Duplicate or conflicting --ppm argument\n");
341 return false; 342 return false;
342 } 343 }
343 options->output_format = OUTPUT_PPM; 344 options->output_format = OUTPUT_PPM;
344 } else if (cur_arg == "--png") { 345 } else if (cur_arg == "--png") {
345 if (options->output_format != OUTPUT_NONE) { 346 if (options->output_format != OUTPUT_NONE) {
346 fprintf(stderr, "Duplicate or conflicting --png argument\n"); 347 fprintf(stderr, "Duplicate or conflicting --png argument\n");
347 return false; 348 return false;
348 } 349 }
349 options->output_format = OUTPUT_PNG; 350 options->output_format = OUTPUT_PNG;
351 } else if (cur_arg.size() > 11 &&
352 cur_arg.compare(0, 11, "--font-dir=") == 0) {
353 if (!options->font_directory.empty()) {
354 fprintf(stderr, "Duplicate --font-dir argument\n");
355 return false;
356 }
357 options->font_directory = cur_arg.substr(11);
350 } 358 }
359
351 #ifdef _WIN32 360 #ifdef _WIN32
352 else if (cur_arg == "--emf") { 361 else if (cur_arg == "--emf") {
353 if (options->output_format != OUTPUT_NONE) { 362 if (options->output_format != OUTPUT_NONE) {
354 fprintf(stderr, "Duplicate or conflicting --emf argument\n"); 363 fprintf(stderr, "Duplicate or conflicting --emf argument\n");
355 return false; 364 return false;
356 } 365 }
357 options->output_format = OUTPUT_EMF; 366 options->output_format = OUTPUT_EMF;
358 } 367 }
359 else if (cur_arg == "--bmp") { 368 else if (cur_arg == "--bmp") {
360 if (options->output_format != OUTPUT_NONE) { 369 if (options->output_format != OUTPUT_NONE) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 FPDFDOC_ExitFormFillEnvironment(form); 562 FPDFDOC_ExitFormFillEnvironment(form);
554 FPDF_CloseDocument(doc); 563 FPDF_CloseDocument(doc);
555 FPDFAvail_Destroy(pdf_avail); 564 FPDFAvail_Destroy(pdf_avail);
556 565
557 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); 566 fprintf(stderr, "Rendered %d pages.\n", rendered_pages);
558 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); 567 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages);
559 } 568 }
560 569
561 static const char usage_string[] = 570 static const char usage_string[] =
562 "Usage: pdfium_test [OPTION] [FILE]...\n" 571 "Usage: pdfium_test [OPTION] [FILE]...\n"
563 " --bin-dir=<path> - override path to v8 external data\n" 572 " --bin-dir=<path> - override path to v8 external data\n"
564 " --scale=<number> - scale output size by number (e.g. 0.5)\n" 573 " --font-dir=<path> - override path to external fonts\n"
574 " --scale=<number> - scale output size by number (e.g. 0.5)\n"
565 #ifdef _WIN32 575 #ifdef _WIN32
566 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" 576 " --bmp - write page images <pdf-name>.<page-number>.bmp\n"
567 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" 577 " --emf - write page meta files <pdf-name>.<page-number>.emf\n"
568 #endif 578 #endif
569 " --png - write page images <pdf-name>.<page-number>.png\n" 579 " --png - write page images <pdf-name>.<page-number>.png\n"
570 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; 580 " --ppm - write page images <pdf-name>.<page-number>.ppm\n";
571 581
572 int main(int argc, const char* argv[]) { 582 int main(int argc, const char* argv[]) {
573 std::vector<std::string> args(argv, argv + argc); 583 std::vector<std::string> args(argv, argv + argc);
574 Options options; 584 Options options;
(...skipping 17 matching lines...) Expand all
592 v8::StartupData natives; 602 v8::StartupData natives;
593 v8::StartupData snapshot; 603 v8::StartupData snapshot;
594 if (!GetExternalData(options, "natives_blob.bin", &natives) || 604 if (!GetExternalData(options, "natives_blob.bin", &natives) ||
595 !GetExternalData(options, "snapshot_blob.bin", &snapshot)) { 605 !GetExternalData(options, "snapshot_blob.bin", &snapshot)) {
596 return 1; 606 return 1;
597 } 607 }
598 v8::V8::SetNativesDataBlob(&natives); 608 v8::V8::SetNativesDataBlob(&natives);
599 v8::V8::SetSnapshotDataBlob(&snapshot); 609 v8::V8::SetSnapshotDataBlob(&snapshot);
600 #endif // V8_USE_EXTERNAL_STARTUP_DATA 610 #endif // V8_USE_EXTERNAL_STARTUP_DATA
601 611
602 FPDF_InitLibrary(); 612 if (!options.font_directory.empty()) {
613 const char* path_array[2];
614 path_array[0] = options.font_directory.c_str();
615 path_array[1] = nullptr;
616 FPDF_LIBRARY_CONFIG config;
617 config.version = 1;
618 config.m_pUserFontPaths = path_array;
619 FPDF_InitLibraryWithConfig(&config);
620 } else {
621 FPDF_InitLibrary();
622 }
603 623
604 UNSUPPORT_INFO unsuppored_info; 624 UNSUPPORT_INFO unsuppored_info;
605 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); 625 memset(&unsuppored_info, '\0', sizeof(unsuppored_info));
606 unsuppored_info.version = 1; 626 unsuppored_info.version = 1;
607 unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; 627 unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler;
608 628
609 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); 629 FSDK_SetUnSpObjProcessHandler(&unsuppored_info);
610 630
611 while (!files.empty()) { 631 while (!files.empty()) {
612 std::string filename = files.front(); 632 std::string filename = files.front();
613 files.pop_front(); 633 files.pop_front();
614 size_t file_length = 0; 634 size_t file_length = 0;
615 char* file_contents = GetFileContents(filename.c_str(), &file_length); 635 char* file_contents = GetFileContents(filename.c_str(), &file_length);
616 if (!file_contents) 636 if (!file_contents)
617 continue; 637 continue;
618 RenderPdf(filename, file_contents, file_length, options); 638 RenderPdf(filename, file_contents, file_length, options);
619 free(file_contents); 639 free(file_contents);
620 } 640 }
621 641
622 FPDF_DestroyLibrary(); 642 FPDF_DestroyLibrary();
623 v8::V8::ShutdownPlatform(); 643 v8::V8::ShutdownPlatform();
624 delete platform; 644 delete platform;
625 645
626 return 0; 646 return 0;
627 } 647 }
OLDNEW
« fpdfsdk/src/fpdfview.cpp ('K') | « public/fpdfview.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698