| 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> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #define snprintf _snprintf | 35 #define snprintf _snprintf |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #ifdef PDF_ENABLE_SKIA | 38 #ifdef PDF_ENABLE_SKIA |
| 39 #include "third_party/skia/include/core/SkPictureRecorder.h" | 39 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 40 #include "third_party/skia/include/core/SkStream.h" | 40 #include "third_party/skia/include/core/SkStream.h" |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 enum OutputFormat { | 43 enum OutputFormat { |
| 44 OUTPUT_NONE, | 44 OUTPUT_NONE, |
| 45 OUTPUT_TEXT, |
| 45 OUTPUT_PPM, | 46 OUTPUT_PPM, |
| 46 OUTPUT_PNG, | 47 OUTPUT_PNG, |
| 47 #ifdef _WIN32 | 48 #ifdef _WIN32 |
| 48 OUTPUT_BMP, | 49 OUTPUT_BMP, |
| 49 OUTPUT_EMF, | 50 OUTPUT_EMF, |
| 50 #endif | 51 #endif |
| 51 #ifdef PDF_ENABLE_SKIA | 52 #ifdef PDF_ENABLE_SKIA |
| 52 OUTPUT_SKP, | 53 OUTPUT_SKP, |
| 53 #endif | 54 #endif |
| 54 }; | 55 }; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; | 106 dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; |
| 106 // B | 107 // B |
| 107 dest_line[(w * 3) + 2] = src_line[w * 4]; | 108 dest_line[(w * 3) + 2] = src_line[w * 4]; |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 fwrite(result, out_len, 1, fp); | 111 fwrite(result, out_len, 1, fp); |
| 111 delete[] result; | 112 delete[] result; |
| 112 fclose(fp); | 113 fclose(fp); |
| 113 } | 114 } |
| 114 | 115 |
| 116 void WriteText(FPDF_PAGE page, const char* pdf_name, int num) { |
| 117 char filename[256]; |
| 118 int chars_formatted = |
| 119 snprintf(filename, sizeof(filename), "%s.%d.txt", pdf_name, num); |
| 120 if (chars_formatted < 0 || |
| 121 static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
| 122 fprintf(stderr, "Filename %s is too long\n", filename); |
| 123 return; |
| 124 } |
| 125 |
| 126 FILE* fp = fopen(filename, "w"); |
| 127 if (!fp) { |
| 128 fprintf(stderr, "Failed to open %s for output\n", filename); |
| 129 return; |
| 130 } |
| 131 |
| 132 // Output in UTF32-LE. |
| 133 uint32_t bom = 0x0000FEFF; |
| 134 fwrite(&bom, sizeof(bom), 1, fp); |
| 135 |
| 136 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); |
| 137 for (int i = 0; i < FPDFText_CountChars(textpage); i++) { |
| 138 uint32_t c = FPDFText_GetUnicode(textpage, i); |
| 139 fwrite(&c, sizeof(c), 1, fp); |
| 140 } |
| 141 |
| 142 FPDFText_ClosePage(textpage); |
| 143 |
| 144 (void)fclose(fp); |
| 145 } |
| 146 |
| 115 static void WritePng(const char* pdf_name, int num, const void* buffer_void, | 147 static void WritePng(const char* pdf_name, int num, const void* buffer_void, |
| 116 int stride, int width, int height) { | 148 int stride, int width, int height) { |
| 117 if (!CheckDimensions(stride, width, height)) | 149 if (!CheckDimensions(stride, width, height)) |
| 118 return; | 150 return; |
| 119 | 151 |
| 120 std::vector<unsigned char> png_encoding; | 152 std::vector<unsigned char> png_encoding; |
| 121 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); | 153 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); |
| 122 if (!image_diff_png::EncodeBGRAPNG( | 154 if (!image_diff_png::EncodeBGRAPNG( |
| 123 buffer, width, height, stride, false, &png_encoding)) { | 155 buffer, width, height, stride, false, &png_encoding)) { |
| 124 fprintf(stderr, "Failed to convert bitmap to PNG\n"); | 156 fprintf(stderr, "Failed to convert bitmap to PNG\n"); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); | 379 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); |
| 348 return false; | 380 return false; |
| 349 } | 381 } |
| 350 options->output_format = OUTPUT_PPM; | 382 options->output_format = OUTPUT_PPM; |
| 351 } else if (cur_arg == "--png") { | 383 } else if (cur_arg == "--png") { |
| 352 if (options->output_format != OUTPUT_NONE) { | 384 if (options->output_format != OUTPUT_NONE) { |
| 353 fprintf(stderr, "Duplicate or conflicting --png argument\n"); | 385 fprintf(stderr, "Duplicate or conflicting --png argument\n"); |
| 354 return false; | 386 return false; |
| 355 } | 387 } |
| 356 options->output_format = OUTPUT_PNG; | 388 options->output_format = OUTPUT_PNG; |
| 389 } else if (cur_arg == "--txt") { |
| 390 if (options->output_format != OUTPUT_NONE) { |
| 391 fprintf(stderr, "Duplicate or conflicting --txt argument\n"); |
| 392 return false; |
| 393 } |
| 394 options->output_format = OUTPUT_TEXT; |
| 357 #ifdef PDF_ENABLE_SKIA | 395 #ifdef PDF_ENABLE_SKIA |
| 358 } else if (cur_arg == "--skp") { | 396 } else if (cur_arg == "--skp") { |
| 359 if (options->output_format != OUTPUT_NONE) { | 397 if (options->output_format != OUTPUT_NONE) { |
| 360 fprintf(stderr, "Duplicate or conflicting --skp argument\n"); | 398 fprintf(stderr, "Duplicate or conflicting --skp argument\n"); |
| 361 return false; | 399 return false; |
| 362 } | 400 } |
| 363 options->output_format = OUTPUT_SKP; | 401 options->output_format = OUTPUT_SKP; |
| 364 #endif | 402 #endif |
| 365 } else if (cur_arg.size() > 11 && | 403 } else if (cur_arg.size() > 11 && |
| 366 cur_arg.compare(0, 11, "--font-dir=") == 0) { | 404 cur_arg.compare(0, 11, "--font-dir=") == 0) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 switch (options.output_format) { | 559 switch (options.output_format) { |
| 522 #ifdef _WIN32 | 560 #ifdef _WIN32 |
| 523 case OUTPUT_BMP: | 561 case OUTPUT_BMP: |
| 524 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); | 562 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); |
| 525 break; | 563 break; |
| 526 | 564 |
| 527 case OUTPUT_EMF: | 565 case OUTPUT_EMF: |
| 528 WriteEmf(page, name.c_str(), page_index); | 566 WriteEmf(page, name.c_str(), page_index); |
| 529 break; | 567 break; |
| 530 #endif | 568 #endif |
| 569 case OUTPUT_TEXT: |
| 570 WriteText(page, name.c_str(), page_index); |
| 571 break; |
| 572 |
| 531 case OUTPUT_PNG: | 573 case OUTPUT_PNG: |
| 532 WritePng(name.c_str(), page_index, buffer, stride, width, height); | 574 WritePng(name.c_str(), page_index, buffer, stride, width, height); |
| 533 break; | 575 break; |
| 534 | 576 |
| 535 case OUTPUT_PPM: | 577 case OUTPUT_PPM: |
| 536 WritePpm(name.c_str(), page_index, buffer, stride, width, height); | 578 WritePpm(name.c_str(), page_index, buffer, stride, width, height); |
| 537 break; | 579 break; |
| 538 | 580 |
| 539 #ifdef PDF_ENABLE_SKIA | 581 #ifdef PDF_ENABLE_SKIA |
| 540 case OUTPUT_SKP: { | 582 case OUTPUT_SKP: { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 printf("%s\n", config.c_str()); | 781 printf("%s\n", config.c_str()); |
| 740 } | 782 } |
| 741 | 783 |
| 742 static const char usage_string[] = | 784 static const char usage_string[] = |
| 743 "Usage: pdfium_test [OPTION] [FILE]...\n" | 785 "Usage: pdfium_test [OPTION] [FILE]...\n" |
| 744 " --show-config - print build options and exit\n" | 786 " --show-config - print build options and exit\n" |
| 745 " --send-events - send input described by .evt file\n" | 787 " --send-events - send input described by .evt file\n" |
| 746 " --bin-dir=<path> - override path to v8 external data\n" | 788 " --bin-dir=<path> - override path to v8 external data\n" |
| 747 " --font-dir=<path> - override path to external fonts\n" | 789 " --font-dir=<path> - override path to external fonts\n" |
| 748 " --scale=<number> - scale output size by number (e.g. 0.5)\n" | 790 " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
| 791 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" |
| 749 #ifdef _WIN32 | 792 #ifdef _WIN32 |
| 750 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" | 793 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
| 751 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" | 794 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
| 752 #endif // _WIN32 | 795 #endif // _WIN32 |
| 753 " --png - write page images <pdf-name>.<page-number>.png\n" | 796 " --png - write page images <pdf-name>.<page-number>.png\n" |
| 754 #ifdef PDF_ENABLE_SKIA | 797 #ifdef PDF_ENABLE_SKIA |
| 755 " --skp - write page images <pdf-name>.<page-number>.skp\n" | 798 " --skp - write page images <pdf-name>.<page-number>.skp\n" |
| 756 #endif | 799 #endif |
| 757 ""; | 800 ""; |
| 758 | 801 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 } | 879 } |
| 837 | 880 |
| 838 FPDF_DestroyLibrary(); | 881 FPDF_DestroyLibrary(); |
| 839 #ifdef PDF_ENABLE_V8 | 882 #ifdef PDF_ENABLE_V8 |
| 840 v8::V8::ShutdownPlatform(); | 883 v8::V8::ShutdownPlatform(); |
| 841 delete platform; | 884 delete platform; |
| 842 #endif // PDF_ENABLE_V8 | 885 #endif // PDF_ENABLE_V8 |
| 843 | 886 |
| 844 return 0; | 887 return 0; |
| 845 } | 888 } |
| OLD | NEW |