Chromium Code Reviews| 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 unsigned char bom[] = {0xFF, 0xFE, 0x00, 0x00}; | |
|
hal.canary
2016/06/14 19:27:57
What is the output format? UTF-32-LE?
dsinclair
2016/06/14 20:25:27
Yup, UTF32-LE.
| |
| 133 fwrite(bom, sizeof(unsigned char), sizeof(bom), fp); | |
| 134 | |
| 135 FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page); | |
| 136 for (int i = 0; i < FPDFText_CountChars(textpage); i++) { | |
| 137 wchar_t c = FPDFText_GetUnicode(textpage, i); | |
| 138 fwrite(&c, sizeof(wchar_t), 1, fp); | |
|
hal.canary
2016/06/14 19:23:12
sizeof(wchar_t) is "compiler-dependent and therefo
dsinclair
2016/06/14 20:25:27
Done.
| |
| 139 } | |
| 140 | |
| 141 FPDFText_ClosePage(textpage); | |
| 142 | |
| 143 (void)fclose(fp); | |
| 144 } | |
| 145 | |
| 115 static void WritePng(const char* pdf_name, int num, const void* buffer_void, | 146 static void WritePng(const char* pdf_name, int num, const void* buffer_void, |
| 116 int stride, int width, int height) { | 147 int stride, int width, int height) { |
| 117 if (!CheckDimensions(stride, width, height)) | 148 if (!CheckDimensions(stride, width, height)) |
| 118 return; | 149 return; |
| 119 | 150 |
| 120 std::vector<unsigned char> png_encoding; | 151 std::vector<unsigned char> png_encoding; |
| 121 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); | 152 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); |
| 122 if (!image_diff_png::EncodeBGRAPNG( | 153 if (!image_diff_png::EncodeBGRAPNG( |
| 123 buffer, width, height, stride, false, &png_encoding)) { | 154 buffer, width, height, stride, false, &png_encoding)) { |
| 124 fprintf(stderr, "Failed to convert bitmap to PNG\n"); | 155 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"); | 378 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); |
| 348 return false; | 379 return false; |
| 349 } | 380 } |
| 350 options->output_format = OUTPUT_PPM; | 381 options->output_format = OUTPUT_PPM; |
| 351 } else if (cur_arg == "--png") { | 382 } else if (cur_arg == "--png") { |
| 352 if (options->output_format != OUTPUT_NONE) { | 383 if (options->output_format != OUTPUT_NONE) { |
| 353 fprintf(stderr, "Duplicate or conflicting --png argument\n"); | 384 fprintf(stderr, "Duplicate or conflicting --png argument\n"); |
| 354 return false; | 385 return false; |
| 355 } | 386 } |
| 356 options->output_format = OUTPUT_PNG; | 387 options->output_format = OUTPUT_PNG; |
| 388 } else if (cur_arg == "--text") { | |
| 389 if (options->output_format != OUTPUT_NONE) { | |
| 390 fprintf(stderr, "Duplicate or conflicting --text argument\n"); | |
| 391 return false; | |
| 392 } | |
| 393 options->output_format = OUTPUT_TEXT; | |
| 357 #ifdef PDF_ENABLE_SKIA | 394 #ifdef PDF_ENABLE_SKIA |
| 358 } else if (cur_arg == "--skp") { | 395 } else if (cur_arg == "--skp") { |
| 359 if (options->output_format != OUTPUT_NONE) { | 396 if (options->output_format != OUTPUT_NONE) { |
| 360 fprintf(stderr, "Duplicate or conflicting --skp argument\n"); | 397 fprintf(stderr, "Duplicate or conflicting --skp argument\n"); |
| 361 return false; | 398 return false; |
| 362 } | 399 } |
| 363 options->output_format = OUTPUT_SKP; | 400 options->output_format = OUTPUT_SKP; |
| 364 #endif | 401 #endif |
| 365 } else if (cur_arg.size() > 11 && | 402 } else if (cur_arg.size() > 11 && |
| 366 cur_arg.compare(0, 11, "--font-dir=") == 0) { | 403 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) { | 558 switch (options.output_format) { |
| 522 #ifdef _WIN32 | 559 #ifdef _WIN32 |
| 523 case OUTPUT_BMP: | 560 case OUTPUT_BMP: |
| 524 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); | 561 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); |
| 525 break; | 562 break; |
| 526 | 563 |
| 527 case OUTPUT_EMF: | 564 case OUTPUT_EMF: |
| 528 WriteEmf(page, name.c_str(), page_index); | 565 WriteEmf(page, name.c_str(), page_index); |
| 529 break; | 566 break; |
| 530 #endif | 567 #endif |
| 568 case OUTPUT_TEXT: | |
| 569 WriteText(page, name.c_str(), page_index); | |
| 570 break; | |
| 571 | |
| 531 case OUTPUT_PNG: | 572 case OUTPUT_PNG: |
| 532 WritePng(name.c_str(), page_index, buffer, stride, width, height); | 573 WritePng(name.c_str(), page_index, buffer, stride, width, height); |
| 533 break; | 574 break; |
| 534 | 575 |
| 535 case OUTPUT_PPM: | 576 case OUTPUT_PPM: |
| 536 WritePpm(name.c_str(), page_index, buffer, stride, width, height); | 577 WritePpm(name.c_str(), page_index, buffer, stride, width, height); |
| 537 break; | 578 break; |
| 538 | 579 |
| 539 #ifdef PDF_ENABLE_SKIA | 580 #ifdef PDF_ENABLE_SKIA |
| 540 case OUTPUT_SKP: { | 581 case OUTPUT_SKP: { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 } | 877 } |
| 837 | 878 |
| 838 FPDF_DestroyLibrary(); | 879 FPDF_DestroyLibrary(); |
| 839 #ifdef PDF_ENABLE_V8 | 880 #ifdef PDF_ENABLE_V8 |
| 840 v8::V8::ShutdownPlatform(); | 881 v8::V8::ShutdownPlatform(); |
| 841 delete platform; | 882 delete platform; |
| 842 #endif // PDF_ENABLE_V8 | 883 #endif // PDF_ENABLE_V8 |
| 843 | 884 |
| 844 return 0; | 885 return 0; |
| 845 } | 886 } |
| OLD | NEW |