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 <list> | 10 #include <list> |
| 11 #include <sstream> |
11 #include <string> | 12 #include <string> |
12 #include <utility> | 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "../fpdfsdk/include/fpdf_dataavail.h" | 16 #include "../fpdfsdk/include/fpdf_dataavail.h" |
16 #include "../fpdfsdk/include/fpdf_ext.h" | 17 #include "../fpdfsdk/include/fpdf_ext.h" |
17 #include "../fpdfsdk/include/fpdfformfill.h" | 18 #include "../fpdfsdk/include/fpdfformfill.h" |
18 #include "../fpdfsdk/include/fpdftext.h" | 19 #include "../fpdfsdk/include/fpdftext.h" |
19 #include "../fpdfsdk/include/fpdfview.h" | 20 #include "../fpdfsdk/include/fpdfview.h" |
20 #include "../core/include/fxcrt/fx_system.h" | 21 #include "../core/include/fxcrt/fx_system.h" |
(...skipping 12 matching lines...) Expand all Loading... |
33 #ifdef _WIN32 | 34 #ifdef _WIN32 |
34 OUTPUT_BMP, | 35 OUTPUT_BMP, |
35 OUTPUT_EMF, | 36 OUTPUT_EMF, |
36 #endif | 37 #endif |
37 }; | 38 }; |
38 | 39 |
39 struct Options { | 40 struct Options { |
40 Options() : output_format(OUTPUT_NONE) { } | 41 Options() : output_format(OUTPUT_NONE) { } |
41 | 42 |
42 OutputFormat output_format; | 43 OutputFormat output_format; |
| 44 std::string scale_factor_as_string; |
43 std::string exe_path; | 45 std::string exe_path; |
44 std::string bin_directory; | 46 std::string bin_directory; |
45 }; | 47 }; |
46 | 48 |
47 // Reads the entire contents of a file into a newly malloc'd buffer. | 49 // Reads the entire contents of a file into a newly malloc'd buffer. |
48 static char* GetFileContents(const char* filename, size_t* retlen) { | 50 static char* GetFileContents(const char* filename, size_t* retlen) { |
49 FILE* file = fopen(filename, "rb"); | 51 FILE* file = fopen(filename, "rb"); |
50 if (!file) { | 52 if (!file) { |
51 fprintf(stderr, "Failed to open: %s\n", filename); | 53 fprintf(stderr, "Failed to open: %s\n", filename); |
52 return NULL; | 54 return NULL; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 #endif // _WIN32 | 298 #endif // _WIN32 |
297 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 299 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
298 else if (cur_arg.size() > 10 && cur_arg.compare(0, 10, "--bin-dir=") == 0) { | 300 else if (cur_arg.size() > 10 && cur_arg.compare(0, 10, "--bin-dir=") == 0) { |
299 if (!options->bin_directory.empty()) { | 301 if (!options->bin_directory.empty()) { |
300 fprintf(stderr, "Duplicate --bin-dir argument\n"); | 302 fprintf(stderr, "Duplicate --bin-dir argument\n"); |
301 return false; | 303 return false; |
302 } | 304 } |
303 options->bin_directory = cur_arg.substr(10); | 305 options->bin_directory = cur_arg.substr(10); |
304 } | 306 } |
305 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 307 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 308 else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { |
| 309 if (!options->scale_factor_as_string.empty()) { |
| 310 fprintf(stderr, "Duplicate --scale argument\n"); |
| 311 return false; |
| 312 } |
| 313 options->scale_factor_as_string = cur_arg.substr(8); |
| 314 } |
306 else | 315 else |
307 break; | 316 break; |
308 } | 317 } |
309 if (cur_idx >= args.size()) { | 318 if (cur_idx >= args.size()) { |
310 fprintf(stderr, "No input files.\n"); | 319 fprintf(stderr, "No input files.\n"); |
311 return false; | 320 return false; |
312 } | 321 } |
313 for (size_t i = cur_idx; i < args.size(); i++) { | 322 for (size_t i = cur_idx; i < args.size(); i++) { |
314 files->push_back(args[i]); | 323 files->push_back(args[i]); |
315 } | 324 } |
(...skipping 21 matching lines...) Expand all Loading... |
337 } | 346 } |
338 | 347 |
339 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { | 348 bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { |
340 return true; | 349 return true; |
341 } | 350 } |
342 | 351 |
343 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { | 352 void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { |
344 } | 353 } |
345 | 354 |
346 void RenderPdf(const std::string& name, const char* pBuf, size_t len, | 355 void RenderPdf(const std::string& name, const char* pBuf, size_t len, |
347 OutputFormat format) { | 356 const Options& options) { |
348 printf("Rendering PDF file %s.\n", name.c_str()); | 357 printf("Rendering PDF file %s.\n", name.c_str()); |
349 | 358 |
350 IPDF_JSPLATFORM platform_callbacks; | 359 IPDF_JSPLATFORM platform_callbacks; |
351 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 360 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
352 platform_callbacks.version = 1; | 361 platform_callbacks.version = 1; |
353 platform_callbacks.app_alert = Form_Alert; | 362 platform_callbacks.app_alert = Form_Alert; |
354 | 363 |
355 FPDF_FORMFILLINFO form_callbacks; | 364 FPDF_FORMFILLINFO form_callbacks; |
356 memset(&form_callbacks, '\0', sizeof(form_callbacks)); | 365 memset(&form_callbacks, '\0', sizeof(form_callbacks)); |
357 form_callbacks.version = 1; | 366 form_callbacks.version = 1; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (!page) { | 422 if (!page) { |
414 bad_pages ++; | 423 bad_pages ++; |
415 continue; | 424 continue; |
416 } | 425 } |
417 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); | 426 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); |
418 FORM_OnAfterLoadPage(page, form); | 427 FORM_OnAfterLoadPage(page, form); |
419 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); | 428 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); |
420 | 429 |
421 int width = static_cast<int>(FPDF_GetPageWidth(page)); | 430 int width = static_cast<int>(FPDF_GetPageWidth(page)); |
422 int height = static_cast<int>(FPDF_GetPageHeight(page)); | 431 int height = static_cast<int>(FPDF_GetPageHeight(page)); |
| 432 if (!options.scale_factor_as_string.empty()) { |
| 433 double scale = 1.0; |
| 434 std::stringstream(options.scale_factor_as_string) >> scale; |
| 435 width *= scale; |
| 436 height *= scale; |
| 437 } |
| 438 |
423 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); | 439 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); |
424 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); | 440 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); |
425 | |
426 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); | 441 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
427 rendered_pages ++; | 442 rendered_pages ++; |
428 | 443 |
429 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); | 444 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); |
430 int stride = FPDFBitmap_GetStride(bitmap); | 445 int stride = FPDFBitmap_GetStride(bitmap); |
431 const char* buffer = | 446 const char* buffer = |
432 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); | 447 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); |
433 | 448 |
434 switch (format) { | 449 switch (options.output_format) { |
435 #ifdef _WIN32 | 450 #ifdef _WIN32 |
436 case OUTPUT_BMP: | 451 case OUTPUT_BMP: |
437 WriteBmp(name.c_str(), i, buffer, stride, width, height); | 452 WriteBmp(name.c_str(), i, buffer, stride, width, height); |
438 break; | 453 break; |
439 | 454 |
440 case OUTPUT_EMF: | 455 case OUTPUT_EMF: |
441 WriteEmf(page, name.c_str(), i); | 456 WriteEmf(page, name.c_str(), i); |
442 break; | 457 break; |
443 #endif | 458 #endif |
444 case OUTPUT_PPM: | 459 case OUTPUT_PPM: |
(...skipping 20 matching lines...) Expand all Loading... |
465 printf("Skipped %" PRIuS " bad pages.\n", bad_pages); | 480 printf("Skipped %" PRIuS " bad pages.\n", bad_pages); |
466 } | 481 } |
467 | 482 |
468 int main(int argc, const char* argv[]) { | 483 int main(int argc, const char* argv[]) { |
469 std::vector<std::string> args(argv, argv + argc); | 484 std::vector<std::string> args(argv, argv + argc); |
470 Options options; | 485 Options options; |
471 std::list<std::string> files; | 486 std::list<std::string> files; |
472 if (!ParseCommandLine(args, &options, &files)) { | 487 if (!ParseCommandLine(args, &options, &files)) { |
473 printf("Usage: pdfium_test [OPTION] [FILE]...\n"); | 488 printf("Usage: pdfium_test [OPTION] [FILE]...\n"); |
474 printf("--bin-dir=<path> - override path to v8 external data\n"); | 489 printf("--bin-dir=<path> - override path to v8 external data\n"); |
| 490 printf("--scale=<number> - scale output size by number (e.g. 0.5)\n"); |
475 printf("--ppm - write page images <pdf-name>.<page-number>.ppm\n"); | 491 printf("--ppm - write page images <pdf-name>.<page-number>.ppm\n"); |
476 #ifdef _WIN32 | 492 #ifdef _WIN32 |
477 printf("--bmp - write page images <pdf-name>.<page-number>.bmp\n"); | 493 printf("--bmp - write page images <pdf-name>.<page-number>.bmp\n"); |
478 printf("--emf - write page meta files <pdf-name>.<page-number>.emf\n"); | 494 printf("--emf - write page meta files <pdf-name>.<page-number>.emf\n"); |
479 #endif | 495 #endif |
480 return 1; | 496 return 1; |
481 } | 497 } |
482 | 498 |
483 v8::V8::InitializeICU(); | 499 v8::V8::InitializeICU(); |
484 | 500 |
(...skipping 17 matching lines...) Expand all Loading... |
502 | 518 |
503 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); | 519 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
504 | 520 |
505 while (!files.empty()) { | 521 while (!files.empty()) { |
506 std::string filename = files.front(); | 522 std::string filename = files.front(); |
507 files.pop_front(); | 523 files.pop_front(); |
508 size_t file_length = 0; | 524 size_t file_length = 0; |
509 char* file_contents = GetFileContents(filename.c_str(), &file_length); | 525 char* file_contents = GetFileContents(filename.c_str(), &file_length); |
510 if (!file_contents) | 526 if (!file_contents) |
511 continue; | 527 continue; |
512 RenderPdf(filename, file_contents, file_length, options.output_format); | 528 RenderPdf(filename, file_contents, file_length, options); |
513 free(file_contents); | 529 free(file_contents); |
514 } | 530 } |
515 | 531 |
516 FPDF_DestroyLibrary(); | 532 FPDF_DestroyLibrary(); |
517 | 533 |
518 return 0; | 534 return 0; |
519 } | 535 } |
OLD | NEW |