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

Side by Side Diff: samples/pdfium_test.cc

Issue 2578893004: Gold support in PDFium (Closed)
Patch Set: Incorporated feedback Created 3 years, 12 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
« no previous file with comments | « samples/DEPS ('k') | testing/tools/common.py » ('j') | 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 <map> 10 #include <map>
11 #include <sstream> 11 #include <sstream>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #if defined PDF_ENABLE_SKIA && !defined _SKIA_SUPPORT_ 16 #if defined PDF_ENABLE_SKIA && !defined _SKIA_SUPPORT_
17 #define _SKIA_SUPPORT_ 17 #define _SKIA_SUPPORT_
18 #endif 18 #endif
19 19
20 #include "core/fdrm/crypto/fx_crypt.h"
20 #include "public/fpdf_dataavail.h" 21 #include "public/fpdf_dataavail.h"
21 #include "public/fpdf_edit.h" 22 #include "public/fpdf_edit.h"
22 #include "public/fpdf_ext.h" 23 #include "public/fpdf_ext.h"
23 #include "public/fpdf_formfill.h" 24 #include "public/fpdf_formfill.h"
24 #include "public/fpdf_text.h" 25 #include "public/fpdf_text.h"
25 #include "public/fpdfview.h" 26 #include "public/fpdfview.h"
26 #include "samples/image_diff_png.h" 27 #include "samples/image_diff_png.h"
27 #include "testing/test_support.h" 28 #include "testing/test_support.h"
28 29
29 #ifdef _WIN32 30 #ifdef _WIN32
(...skipping 30 matching lines...) Expand all
60 #ifdef PDF_ENABLE_SKIA 61 #ifdef PDF_ENABLE_SKIA
61 OUTPUT_SKP, 62 OUTPUT_SKP,
62 #endif 63 #endif
63 }; 64 };
64 65
65 struct Options { 66 struct Options {
66 Options() 67 Options()
67 : show_config(false), 68 : show_config(false),
68 send_events(false), 69 send_events(false),
69 pages(false), 70 pages(false),
71 md5(false),
70 output_format(OUTPUT_NONE) {} 72 output_format(OUTPUT_NONE) {}
71 73
72 bool show_config; 74 bool show_config;
73 bool send_events; 75 bool send_events;
74 bool pages; 76 bool pages;
77 bool md5;
75 OutputFormat output_format; 78 OutputFormat output_format;
76 std::string scale_factor_as_string; 79 std::string scale_factor_as_string;
77 std::string exe_path; 80 std::string exe_path;
78 std::string bin_directory; 81 std::string bin_directory;
79 std::string font_directory; 82 std::string font_directory;
80 // 0-based page numbers to be rendered. 83 // 0-based page numbers to be rendered.
81 int first_page; 84 int first_page;
82 int last_page; 85 int last_page;
83 }; 86 };
84 87
(...skipping 17 matching lines...) Expand all
102 } 105 }
103 106
104 static bool CheckDimensions(int stride, int width, int height) { 107 static bool CheckDimensions(int stride, int width, int height) {
105 if (stride < 0 || width < 0 || height < 0) 108 if (stride < 0 || width < 0 || height < 0)
106 return false; 109 return false;
107 if (height > 0 && width > INT_MAX / height) 110 if (height > 0 && width > INT_MAX / height)
108 return false; 111 return false;
109 return true; 112 return true;
110 } 113 }
111 114
112 static void WritePpm(const char* pdf_name, int num, const void* buffer_void, 115 static void OutputMD5Hash(const char* file_name, const char* buffer, int len) {
113 int stride, int width, int height) { 116 // Get the MD5 hash and write it to stdout.
117 uint8_t digest[16];
118 CRYPT_MD5Generate(reinterpret_cast<const uint8_t*>(buffer), len, digest);
119 printf("MD5:%s:", file_name);
120 for (int i = 0; i < 16; i++)
121 printf("%02x", digest[i]);
122 printf("\n");
123 }
124
125 static std::string WritePpm(const char* pdf_name,
126 int num,
127 const void* buffer_void,
128 int stride,
129 int width,
130 int height) {
114 const char* buffer = reinterpret_cast<const char*>(buffer_void); 131 const char* buffer = reinterpret_cast<const char*>(buffer_void);
115 132
116 if (!CheckDimensions(stride, width, height)) 133 if (!CheckDimensions(stride, width, height))
117 return; 134 return "";
118 135
119 int out_len = width * height; 136 int out_len = width * height;
120 if (out_len > INT_MAX / 3) 137 if (out_len > INT_MAX / 3)
121 return; 138 return "";
122 out_len *= 3; 139 out_len *= 3;
123 140
124 char filename[256]; 141 char filename[256];
125 snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num); 142 snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num);
126 FILE* fp = fopen(filename, "wb"); 143 FILE* fp = fopen(filename, "wb");
127 if (!fp) 144 if (!fp)
128 return; 145 return "";
129 fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height); 146 fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height);
130 // Source data is B, G, R, unused. 147 // Source data is B, G, R, unused.
131 // Dest data is R, G, B. 148 // Dest data is R, G, B.
132 std::vector<char> result(out_len); 149 std::vector<char> result(out_len);
133 for (int h = 0; h < height; ++h) { 150 for (int h = 0; h < height; ++h) {
134 const char* src_line = buffer + (stride * h); 151 const char* src_line = buffer + (stride * h);
135 char* dest_line = result.data() + (width * h * 3); 152 char* dest_line = result.data() + (width * h * 3);
136 for (int w = 0; w < width; ++w) { 153 for (int w = 0; w < width; ++w) {
137 // R 154 // R
138 dest_line[w * 3] = src_line[(w * 4) + 2]; 155 dest_line[w * 3] = src_line[(w * 4) + 2];
139 // G 156 // G
140 dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; 157 dest_line[(w * 3) + 1] = src_line[(w * 4) + 1];
141 // B 158 // B
142 dest_line[(w * 3) + 2] = src_line[w * 4]; 159 dest_line[(w * 3) + 2] = src_line[w * 4];
143 } 160 }
144 } 161 }
145 fwrite(result.data(), out_len, 1, fp); 162 fwrite(result.data(), out_len, 1, fp);
146 fclose(fp); 163 fclose(fp);
164 return std::string(filename);
147 } 165 }
148 166
149 void WriteText(FPDF_PAGE page, const char* pdf_name, int num) { 167 void WriteText(FPDF_PAGE page, const char* pdf_name, int num) {
150 char filename[256]; 168 char filename[256];
151 int chars_formatted = 169 int chars_formatted =
152 snprintf(filename, sizeof(filename), "%s.%d.txt", pdf_name, num); 170 snprintf(filename, sizeof(filename), "%s.%d.txt", pdf_name, num);
153 if (chars_formatted < 0 || 171 if (chars_formatted < 0 ||
154 static_cast<size_t>(chars_formatted) >= sizeof(filename)) { 172 static_cast<size_t>(chars_formatted) >= sizeof(filename)) {
155 fprintf(stderr, "Filename %s is too long\n", filename); 173 fprintf(stderr, "Filename %s is too long\n", filename);
156 return; 174 return;
(...skipping 13 matching lines...) Expand all
170 for (int i = 0; i < FPDFText_CountChars(textpage); i++) { 188 for (int i = 0; i < FPDFText_CountChars(textpage); i++) {
171 uint32_t c = FPDFText_GetUnicode(textpage, i); 189 uint32_t c = FPDFText_GetUnicode(textpage, i);
172 fwrite(&c, sizeof(c), 1, fp); 190 fwrite(&c, sizeof(c), 1, fp);
173 } 191 }
174 192
175 FPDFText_ClosePage(textpage); 193 FPDFText_ClosePage(textpage);
176 194
177 (void)fclose(fp); 195 (void)fclose(fp);
178 } 196 }
179 197
180 static void WritePng(const char* pdf_name, int num, const void* buffer_void, 198 static std::string WritePng(const char* pdf_name,
181 int stride, int width, int height) { 199 int num,
200 const void* buffer_void,
201 int stride,
202 int width,
203 int height) {
182 if (!CheckDimensions(stride, width, height)) 204 if (!CheckDimensions(stride, width, height))
183 return; 205 return "";
184 206
185 std::vector<unsigned char> png_encoding; 207 std::vector<unsigned char> png_encoding;
186 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void); 208 const unsigned char* buffer = static_cast<const unsigned char*>(buffer_void);
187 if (!image_diff_png::EncodeBGRAPNG( 209 if (!image_diff_png::EncodeBGRAPNG(
188 buffer, width, height, stride, false, &png_encoding)) { 210 buffer, width, height, stride, false, &png_encoding)) {
189 fprintf(stderr, "Failed to convert bitmap to PNG\n"); 211 fprintf(stderr, "Failed to convert bitmap to PNG\n");
190 return; 212 return "";
191 } 213 }
192 214
193 char filename[256]; 215 char filename[256];
194 int chars_formatted = snprintf( 216 int chars_formatted = snprintf(
195 filename, sizeof(filename), "%s.%d.png", pdf_name, num); 217 filename, sizeof(filename), "%s.%d.png", pdf_name, num);
196 if (chars_formatted < 0 || 218 if (chars_formatted < 0 ||
197 static_cast<size_t>(chars_formatted) >= sizeof(filename)) { 219 static_cast<size_t>(chars_formatted) >= sizeof(filename)) {
198 fprintf(stderr, "Filename %s is too long\n", filename); 220 fprintf(stderr, "Filename %s is too long\n", filename);
199 return; 221 return "";
200 } 222 }
201 223
202 FILE* fp = fopen(filename, "wb"); 224 FILE* fp = fopen(filename, "wb");
203 if (!fp) { 225 if (!fp) {
204 fprintf(stderr, "Failed to open %s for output\n", filename); 226 fprintf(stderr, "Failed to open %s for output\n", filename);
205 return; 227 return "";
206 } 228 }
207 229
208 size_t bytes_written = fwrite( 230 size_t bytes_written = fwrite(
209 &png_encoding.front(), 1, png_encoding.size(), fp); 231 &png_encoding.front(), 1, png_encoding.size(), fp);
210 if (bytes_written != png_encoding.size()) 232 if (bytes_written != png_encoding.size())
211 fprintf(stderr, "Failed to write to %s\n", filename); 233 fprintf(stderr, "Failed to write to %s\n", filename);
212 234
213 (void)fclose(fp); 235 (void)fclose(fp);
236 return std::string(filename);
214 } 237 }
215 238
216 #ifdef _WIN32 239 #ifdef _WIN32
217 static void WriteBmp(const char* pdf_name, int num, const void* buffer, 240 static std::string WriteBmp(const char* pdf_name,
218 int stride, int width, int height) { 241 int num,
242 const void* buffer,
243 int stride,
244 int width,
245 int height) {
219 if (!CheckDimensions(stride, width, height)) 246 if (!CheckDimensions(stride, width, height))
220 return; 247 return "";
221 248
222 int out_len = stride * height; 249 int out_len = stride * height;
223 if (out_len > INT_MAX / 3) 250 if (out_len > INT_MAX / 3)
224 return; 251 return "";
225 252
226 char filename[256]; 253 char filename[256];
227 snprintf(filename, sizeof(filename), "%s.%d.bmp", pdf_name, num); 254 snprintf(filename, sizeof(filename), "%s.%d.bmp", pdf_name, num);
228 FILE* fp = fopen(filename, "wb"); 255 FILE* fp = fopen(filename, "wb");
229 if (!fp) 256 if (!fp)
230 return; 257 return "";
231 258
232 BITMAPINFO bmi = {}; 259 BITMAPINFO bmi = {};
233 bmi.bmiHeader.biSize = sizeof(bmi) - sizeof(RGBQUAD); 260 bmi.bmiHeader.biSize = sizeof(bmi) - sizeof(RGBQUAD);
234 bmi.bmiHeader.biWidth = width; 261 bmi.bmiHeader.biWidth = width;
235 bmi.bmiHeader.biHeight = -height; // top-down image 262 bmi.bmiHeader.biHeight = -height; // top-down image
236 bmi.bmiHeader.biPlanes = 1; 263 bmi.bmiHeader.biPlanes = 1;
237 bmi.bmiHeader.biBitCount = 32; 264 bmi.bmiHeader.biBitCount = 32;
238 bmi.bmiHeader.biCompression = BI_RGB; 265 bmi.bmiHeader.biCompression = BI_RGB;
239 bmi.bmiHeader.biSizeImage = 0; 266 bmi.bmiHeader.biSizeImage = 0;
240 267
241 BITMAPFILEHEADER file_header = {}; 268 BITMAPFILEHEADER file_header = {};
242 file_header.bfType = 0x4d42; 269 file_header.bfType = 0x4d42;
243 file_header.bfSize = sizeof(file_header) + bmi.bmiHeader.biSize + out_len; 270 file_header.bfSize = sizeof(file_header) + bmi.bmiHeader.biSize + out_len;
244 file_header.bfOffBits = file_header.bfSize - out_len; 271 file_header.bfOffBits = file_header.bfSize - out_len;
245 272
246 fwrite(&file_header, sizeof(file_header), 1, fp); 273 fwrite(&file_header, sizeof(file_header), 1, fp);
247 fwrite(&bmi, bmi.bmiHeader.biSize, 1, fp); 274 fwrite(&bmi, bmi.bmiHeader.biSize, 1, fp);
248 fwrite(buffer, out_len, 1, fp); 275 fwrite(buffer, out_len, 1, fp);
249 fclose(fp); 276 fclose(fp);
277 return std::string(filename);
250 } 278 }
251 279
252 void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) { 280 void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) {
253 int width = static_cast<int>(FPDF_GetPageWidth(page)); 281 int width = static_cast<int>(FPDF_GetPageWidth(page));
254 int height = static_cast<int>(FPDF_GetPageHeight(page)); 282 int height = static_cast<int>(FPDF_GetPageHeight(page));
255 283
256 char filename[256]; 284 char filename[256];
257 snprintf(filename, sizeof(filename), "%s.%d.emf", pdf_name, num); 285 snprintf(filename, sizeof(filename), "%s.%d.emf", pdf_name, num);
258 286
259 HDC dc = CreateEnhMetaFileA(nullptr, filename, nullptr, nullptr); 287 HDC dc = CreateEnhMetaFileA(nullptr, filename, nullptr, nullptr);
260 288
261 HRGN rgn = CreateRectRgn(0, 0, width, height); 289 HRGN rgn = CreateRectRgn(0, 0, width, height);
262 SelectClipRgn(dc, rgn); 290 SelectClipRgn(dc, rgn);
263 DeleteObject(rgn); 291 DeleteObject(rgn);
264 292
265 SelectObject(dc, GetStockObject(NULL_PEN)); 293 SelectObject(dc, GetStockObject(NULL_PEN));
266 SelectObject(dc, GetStockObject(WHITE_BRUSH)); 294 SelectObject(dc, GetStockObject(WHITE_BRUSH));
267 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. 295 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less.
268 Rectangle(dc, 0, 0, width + 1, height + 1); 296 Rectangle(dc, 0, 0, width + 1, height + 1);
269 297
270 FPDF_RenderPage(dc, page, 0, 0, width, height, 0, 298 FPDF_RenderPage(dc, page, 0, 0, width, height, 0,
271 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); 299 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH);
272 300
273 DeleteEnhMetaFile(CloseEnhMetaFile(dc)); 301 DeleteEnhMetaFile(CloseEnhMetaFile(dc));
274 } 302 }
275 #endif 303 #endif
276 304
277 #ifdef PDF_ENABLE_SKIA 305 #ifdef PDF_ENABLE_SKIA
278 void WriteSkp(const char* pdf_name, int num, SkPictureRecorder* recorder) { 306 static std::string WriteSkp(const char* pdf_name,
307 int num,
308 SkPictureRecorder* recorder) {
279 char filename[256]; 309 char filename[256];
280 int chars_formatted = 310 int chars_formatted =
281 snprintf(filename, sizeof(filename), "%s.%d.skp", pdf_name, num); 311 snprintf(filename, sizeof(filename), "%s.%d.skp", pdf_name, num);
282 312
283 if (chars_formatted < 0 || 313 if (chars_formatted < 0 ||
284 static_cast<size_t>(chars_formatted) >= sizeof(filename)) { 314 static_cast<size_t>(chars_formatted) >= sizeof(filename)) {
285 fprintf(stderr, "Filename %s is too long\n", filename); 315 fprintf(stderr, "Filename %s is too long\n", filename);
286 return; 316 return "";
287 } 317 }
288 318
289 sk_sp<SkPicture> picture(recorder->finishRecordingAsPicture()); 319 sk_sp<SkPicture> picture(recorder->finishRecordingAsPicture());
290 SkFILEWStream wStream(filename); 320 SkFILEWStream wStream(filename);
291 picture->serialize(&wStream); 321 picture->serialize(&wStream);
322 return std::string(filename);
292 } 323 }
293 #endif 324 #endif
294 325
295 // These example JS platform callback handlers are entirely optional, 326 // These example JS platform callback handlers are entirely optional,
296 // and exist here to show the flow of information from a document back 327 // and exist here to show the flow of information from a document back
297 // to the embedder. 328 // to the embedder.
298 int ExampleAppAlert(IPDF_JSPLATFORM*, 329 int ExampleAppAlert(IPDF_JSPLATFORM*,
299 FPDF_WIDESTRING msg, 330 FPDF_WIDESTRING msg,
300 FPDF_WIDESTRING title, 331 FPDF_WIDESTRING title,
301 int type, 332 int type,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 size_t first_dash = pages_string.find("-"); 514 size_t first_dash = pages_string.find("-");
484 if (first_dash == std::string::npos) { 515 if (first_dash == std::string::npos) {
485 std::stringstream(pages_string) >> options->first_page; 516 std::stringstream(pages_string) >> options->first_page;
486 options->last_page = options->first_page; 517 options->last_page = options->first_page;
487 } else { 518 } else {
488 std::stringstream(pages_string.substr(0, first_dash)) >> 519 std::stringstream(pages_string.substr(0, first_dash)) >>
489 options->first_page; 520 options->first_page;
490 std::stringstream(pages_string.substr(first_dash + 1)) >> 521 std::stringstream(pages_string.substr(first_dash + 1)) >>
491 options->last_page; 522 options->last_page;
492 } 523 }
524 } else if (cur_arg == "--md5") {
525 options->md5 = true;
493 } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') { 526 } else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') {
494 fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str()); 527 fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str());
495 return false; 528 return false;
496 } else { 529 } else {
497 break; 530 break;
498 } 531 }
499 } 532 }
500 for (size_t i = cur_idx; i < args.size(); i++) 533 for (size_t i = cur_idx; i < args.size(); i++)
501 files->push_back(args[i]); 534 files->push_back(args[i]);
502 535
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 if (bitmap) { 654 if (bitmap) {
622 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; 655 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF;
623 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); 656 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color);
624 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, FPDF_ANNOT); 657 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, FPDF_ANNOT);
625 658
626 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, FPDF_ANNOT); 659 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, FPDF_ANNOT);
627 int stride = FPDFBitmap_GetStride(bitmap); 660 int stride = FPDFBitmap_GetStride(bitmap);
628 const char* buffer = 661 const char* buffer =
629 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); 662 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap));
630 663
664 std::string&& image_file_name = "";
631 switch (options.output_format) { 665 switch (options.output_format) {
632 #ifdef _WIN32 666 #ifdef _WIN32
633 case OUTPUT_BMP: 667 case OUTPUT_BMP:
634 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); 668 image_file_name =
669 WriteBmp(name.c_str(), page_index, buffer, stride, width, height);
635 break; 670 break;
636 671
637 case OUTPUT_EMF: 672 case OUTPUT_EMF:
638 WriteEmf(page, name.c_str(), page_index); 673 WriteEmf(page, name.c_str(), page_index);
639 break; 674 break;
640 #endif 675 #endif
641 case OUTPUT_TEXT: 676 case OUTPUT_TEXT:
642 WriteText(page, name.c_str(), page_index); 677 WriteText(page, name.c_str(), page_index);
643 break; 678 break;
644 679
645 case OUTPUT_PNG: 680 case OUTPUT_PNG:
646 WritePng(name.c_str(), page_index, buffer, stride, width, height); 681 image_file_name =
682 WritePng(name.c_str(), page_index, buffer, stride, width, height);
647 break; 683 break;
648 684
649 case OUTPUT_PPM: 685 case OUTPUT_PPM:
650 WritePpm(name.c_str(), page_index, buffer, stride, width, height); 686 image_file_name =
687 WritePpm(name.c_str(), page_index, buffer, stride, width, height);
651 break; 688 break;
652 689
653 #ifdef PDF_ENABLE_SKIA 690 #ifdef PDF_ENABLE_SKIA
654 case OUTPUT_SKP: { 691 case OUTPUT_SKP: {
655 std::unique_ptr<SkPictureRecorder> recorder( 692 std::unique_ptr<SkPictureRecorder> recorder(
656 reinterpret_cast<SkPictureRecorder*>( 693 reinterpret_cast<SkPictureRecorder*>(
657 FPDF_RenderPageSkp(page, width, height))); 694 FPDF_RenderPageSkp(page, width, height)));
658 FPDF_FFLRecord(form, recorder.get(), page, 0, 0, width, height, 0, 0); 695 FPDF_FFLRecord(form, recorder.get(), page, 0, 0, width, height, 0, 0);
659 WriteSkp(name.c_str(), page_index, recorder.get()); 696 image_file_name = WriteSkp(name.c_str(), page_index, recorder.get());
660 } break; 697 } break;
661 #endif 698 #endif
662 default: 699 default:
663 break; 700 break;
664 } 701 }
665 702
703 // Write the filename and the MD5 of the buffer to stdout if we wrote a
704 // file.
705 if (options.md5 && image_file_name != "")
706 OutputMD5Hash(image_file_name.c_str(), buffer, stride * height);
707
666 FPDFBitmap_Destroy(bitmap); 708 FPDFBitmap_Destroy(bitmap);
667 } else { 709 } else {
668 fprintf(stderr, "Page was too large to be rendered.\n"); 710 fprintf(stderr, "Page was too large to be rendered.\n");
669 } 711 }
670 712
671 form_fill_info.loaded_pages.erase(page_index); 713 form_fill_info.loaded_pages.erase(page_index);
672 714
673 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); 715 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE);
674 FORM_OnBeforeClosePage(page, form); 716 FORM_OnBeforeClosePage(page, form);
675 FPDFText_ClosePage(text_page); 717 FPDFText_ClosePage(text_page);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 #ifdef _WIN32 907 #ifdef _WIN32
866 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" 908 " --bmp - write page images <pdf-name>.<page-number>.bmp\n"
867 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" 909 " --emf - write page meta files <pdf-name>.<page-number>.emf\n"
868 #endif // _WIN32 910 #endif // _WIN32
869 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n" 911 " --txt - write page text in UTF32-LE <pdf-name>.<page-number>.txt\n"
870 " --png - write page images <pdf-name>.<page-number>.png\n" 912 " --png - write page images <pdf-name>.<page-number>.png\n"
871 " --ppm - write page images <pdf-name>.<page-number>.ppm\n" 913 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"
872 #ifdef PDF_ENABLE_SKIA 914 #ifdef PDF_ENABLE_SKIA
873 " --skp - write page images <pdf-name>.<page-number>.skp\n" 915 " --skp - write page images <pdf-name>.<page-number>.skp\n"
874 #endif 916 #endif
917 " --md5 - write output image paths and their md5 hashes to stdout.\n"
875 ""; 918 "";
876 919
877 int main(int argc, const char* argv[]) { 920 int main(int argc, const char* argv[]) {
878 std::vector<std::string> args(argv, argv + argc); 921 std::vector<std::string> args(argv, argv + argc);
879 Options options; 922 Options options;
880 std::vector<std::string> files; 923 std::vector<std::string> files;
881 if (!ParseCommandLine(args, &options, &files)) { 924 if (!ParseCommandLine(args, &options, &files)) {
882 fprintf(stderr, "%s", kUsageString); 925 fprintf(stderr, "%s", kUsageString);
883 return 1; 926 return 1;
884 } 927 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 delete platform; 1004 delete platform;
962 1005
963 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 1006 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
964 free(const_cast<char*>(natives.data)); 1007 free(const_cast<char*>(natives.data));
965 free(const_cast<char*>(snapshot.data)); 1008 free(const_cast<char*>(snapshot.data));
966 #endif // V8_USE_EXTERNAL_STARTUP_DATA 1009 #endif // V8_USE_EXTERNAL_STARTUP_DATA
967 #endif // PDF_ENABLE_V8 1010 #endif // PDF_ENABLE_V8
968 1011
969 return 0; 1012 return 0;
970 } 1013 }
OLDNEW
« no previous file with comments | « samples/DEPS ('k') | testing/tools/common.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698