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 #include <wchar.h> | 9 #include <wchar.h> |
10 | 10 |
11 #include <list> | 11 #include <list> |
| 12 #include <sstream> |
12 #include <string> | 13 #include <string> |
13 #include <utility> | 14 #include <utility> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "../fpdfsdk/include/fpdf_dataavail.h" | 17 #include "../fpdfsdk/include/fpdf_dataavail.h" |
17 #include "../fpdfsdk/include/fpdf_ext.h" | 18 #include "../fpdfsdk/include/fpdf_ext.h" |
18 #include "../fpdfsdk/include/fpdfformfill.h" | 19 #include "../fpdfsdk/include/fpdfformfill.h" |
19 #include "../fpdfsdk/include/fpdftext.h" | 20 #include "../fpdfsdk/include/fpdftext.h" |
20 #include "../fpdfsdk/include/fpdfview.h" | 21 #include "../fpdfsdk/include/fpdfview.h" |
21 #include "../core/include/fxcrt/fx_system.h" | 22 #include "../core/include/fxcrt/fx_system.h" |
(...skipping 12 matching lines...) Expand all Loading... |
34 #ifdef _WIN32 | 35 #ifdef _WIN32 |
35 OUTPUT_BMP, | 36 OUTPUT_BMP, |
36 OUTPUT_EMF, | 37 OUTPUT_EMF, |
37 #endif | 38 #endif |
38 }; | 39 }; |
39 | 40 |
40 struct Options { | 41 struct Options { |
41 Options() : output_format(OUTPUT_NONE) { } | 42 Options() : output_format(OUTPUT_NONE) { } |
42 | 43 |
43 OutputFormat output_format; | 44 OutputFormat output_format; |
| 45 std::string scale_factor_as_string; |
44 std::string exe_path; | 46 std::string exe_path; |
45 std::string bin_directory; | 47 std::string bin_directory; |
46 }; | 48 }; |
47 | 49 |
48 // Reads the entire contents of a file into a newly malloc'd buffer. | 50 // Reads the entire contents of a file into a newly malloc'd buffer. |
49 static char* GetFileContents(const char* filename, size_t* retlen) { | 51 static char* GetFileContents(const char* filename, size_t* retlen) { |
50 FILE* file = fopen(filename, "rb"); | 52 FILE* file = fopen(filename, "rb"); |
51 if (!file) { | 53 if (!file) { |
52 fprintf(stderr, "Failed to open: %s\n", filename); | 54 fprintf(stderr, "Failed to open: %s\n", filename); |
53 return NULL; | 55 return NULL; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 #endif // _WIN32 | 312 #endif // _WIN32 |
311 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 313 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
312 else if (cur_arg.size() > 10 && cur_arg.compare(0, 10, "--bin-dir=") == 0) { | 314 else if (cur_arg.size() > 10 && cur_arg.compare(0, 10, "--bin-dir=") == 0) { |
313 if (!options->bin_directory.empty()) { | 315 if (!options->bin_directory.empty()) { |
314 fprintf(stderr, "Duplicate --bin-dir argument\n"); | 316 fprintf(stderr, "Duplicate --bin-dir argument\n"); |
315 return false; | 317 return false; |
316 } | 318 } |
317 options->bin_directory = cur_arg.substr(10); | 319 options->bin_directory = cur_arg.substr(10); |
318 } | 320 } |
319 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 321 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 322 else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { |
| 323 if (!options->scale_factor_as_string.empty()) { |
| 324 fprintf(stderr, "Duplicate --scale argument\n"); |
| 325 return false; |
| 326 } |
| 327 options->scale_factor_as_string = cur_arg.substr(8); |
| 328 } |
320 else | 329 else |
321 break; | 330 break; |
322 } | 331 } |
323 if (cur_idx >= args.size()) { | 332 if (cur_idx >= args.size()) { |
324 fprintf(stderr, "No input files.\n"); | 333 fprintf(stderr, "No input files.\n"); |
325 return false; | 334 return false; |
326 } | 335 } |
327 for (size_t i = cur_idx; i < args.size(); i++) { | 336 for (size_t i = cur_idx; i < args.size(); i++) { |
328 files->push_back(args[i]); | 337 files->push_back(args[i]); |
329 } | 338 } |
(...skipping 21 matching lines...) Expand all Loading... |
351 } | 360 } |
352 | 361 |
353 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { | 362 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
354 return true; | 363 return true; |
355 } | 364 } |
356 | 365 |
357 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { | 366 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
358 } | 367 } |
359 | 368 |
360 void RenderPdf(const std::string& name, const char* pBuf, size_t len, | 369 void RenderPdf(const std::string& name, const char* pBuf, size_t len, |
361 OutputFormat format) { | 370 const Options& options) { |
362 printf("Rendering PDF file %s.\n", name.c_str()); | 371 printf("Rendering PDF file %s.\n", name.c_str()); |
363 | 372 |
364 IPDF_JSPLATFORM platform_callbacks; | 373 IPDF_JSPLATFORM platform_callbacks; |
365 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 374 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
366 platform_callbacks.version = 1; | 375 platform_callbacks.version = 1; |
367 platform_callbacks.app_alert = Form_Alert; | 376 platform_callbacks.app_alert = Form_Alert; |
368 | 377 |
369 FPDF_FORMFILLINFO form_callbacks; | 378 FPDF_FORMFILLINFO form_callbacks; |
370 memset(&form_callbacks, '\0', sizeof(form_callbacks)); | 379 memset(&form_callbacks, '\0', sizeof(form_callbacks)); |
371 form_callbacks.version = 2; | 380 form_callbacks.version = 2; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 if (!page) { | 439 if (!page) { |
431 bad_pages ++; | 440 bad_pages ++; |
432 continue; | 441 continue; |
433 } | 442 } |
434 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); | 443 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); |
435 FORM_OnAfterLoadPage(page, form); | 444 FORM_OnAfterLoadPage(page, form); |
436 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); | 445 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); |
437 | 446 |
438 int width = static_cast<int>(FPDF_GetPageWidth(page)); | 447 int width = static_cast<int>(FPDF_GetPageWidth(page)); |
439 int height = static_cast<int>(FPDF_GetPageHeight(page)); | 448 int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 449 if (!options.scale_factor_as_string.empty()) { |
| 450 double scale = 1.0; |
| 451 std::stringstream(options.scale_factor_as_string) >> scale; |
| 452 width *= scale; |
| 453 height *= scale; |
| 454 } |
| 455 |
440 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); | 456 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); |
441 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); | 457 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); |
442 | |
443 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); | 458 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
444 rendered_pages ++; | 459 rendered_pages ++; |
445 | 460 |
446 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); | 461 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); |
447 int stride = FPDFBitmap_GetStride(bitmap); | 462 int stride = FPDFBitmap_GetStride(bitmap); |
448 const char* buffer = | 463 const char* buffer = |
449 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); | 464 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); |
450 | 465 |
451 switch (format) { | 466 switch (options.output_format) { |
452 #ifdef _WIN32 | 467 #ifdef _WIN32 |
453 case OUTPUT_BMP: | 468 case OUTPUT_BMP: |
454 WriteBmp(name.c_str(), i, buffer, stride, width, height); | 469 WriteBmp(name.c_str(), i, buffer, stride, width, height); |
455 break; | 470 break; |
456 | 471 |
457 case OUTPUT_EMF: | 472 case OUTPUT_EMF: |
458 WriteEmf(page, name.c_str(), i); | 473 WriteEmf(page, name.c_str(), i); |
459 break; | 474 break; |
460 #endif | 475 #endif |
461 case OUTPUT_PPM: | 476 case OUTPUT_PPM: |
(...skipping 20 matching lines...) Expand all Loading... |
482 printf("Skipped %" PRIuS " bad pages.\n", bad_pages); | 497 printf("Skipped %" PRIuS " bad pages.\n", bad_pages); |
483 } | 498 } |
484 | 499 |
485 int main(int argc, const char* argv[]) { | 500 int main(int argc, const char* argv[]) { |
486 std::vector<std::string> args(argv, argv + argc); | 501 std::vector<std::string> args(argv, argv + argc); |
487 Options options; | 502 Options options; |
488 std::list<std::string> files; | 503 std::list<std::string> files; |
489 if (!ParseCommandLine(args, &options, &files)) { | 504 if (!ParseCommandLine(args, &options, &files)) { |
490 printf("Usage: pdfium_test [OPTION] [FILE]...\n"); | 505 printf("Usage: pdfium_test [OPTION] [FILE]...\n"); |
491 printf("--bin-dir=<path> - override path to v8 external data\n"); | 506 printf("--bin-dir=<path> - override path to v8 external data\n"); |
| 507 printf("--scale=<number> - scale output size by number (e.g. 0.5)\n"); |
492 printf("--ppm - write page images <pdf-name>.<page-number>.ppm\n"); | 508 printf("--ppm - write page images <pdf-name>.<page-number>.ppm\n"); |
493 #ifdef _WIN32 | 509 #ifdef _WIN32 |
494 printf("--bmp - write page images <pdf-name>.<page-number>.bmp\n"); | 510 printf("--bmp - write page images <pdf-name>.<page-number>.bmp\n"); |
495 printf("--emf - write page meta files <pdf-name>.<page-number>.emf\n"); | 511 printf("--emf - write page meta files <pdf-name>.<page-number>.emf\n"); |
496 #endif | 512 #endif |
497 return 1; | 513 return 1; |
498 } | 514 } |
499 | 515 |
500 v8::V8::InitializeICU(); | 516 v8::V8::InitializeICU(); |
501 | 517 |
(...skipping 17 matching lines...) Expand all Loading... |
519 | 535 |
520 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); | 536 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
521 | 537 |
522 while (!files.empty()) { | 538 while (!files.empty()) { |
523 std::string filename = files.front(); | 539 std::string filename = files.front(); |
524 files.pop_front(); | 540 files.pop_front(); |
525 size_t file_length = 0; | 541 size_t file_length = 0; |
526 char* file_contents = GetFileContents(filename.c_str(), &file_length); | 542 char* file_contents = GetFileContents(filename.c_str(), &file_length); |
527 if (!file_contents) | 543 if (!file_contents) |
528 continue; | 544 continue; |
529 RenderPdf(filename, file_contents, file_length, options.output_format); | 545 RenderPdf(filename, file_contents, file_length, options); |
530 free(file_contents); | 546 free(file_contents); |
531 } | 547 } |
532 | 548 |
533 FPDF_DestroyLibrary(); | 549 FPDF_DestroyLibrary(); |
534 | 550 |
535 return 0; | 551 return 0; |
536 } | 552 } |
OLD | NEW |