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 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 #ifdef PDF_ENABLE_V8 | 25 #ifdef PDF_ENABLE_V8 |
| 26 #include "v8/include/libplatform/libplatform.h" | 26 #include "v8/include/libplatform/libplatform.h" |
| 27 #include "v8/include/v8.h" | 27 #include "v8/include/v8.h" |
| 28 #endif // PDF_ENABLE_V8 | 28 #endif // PDF_ENABLE_V8 |
| 29 | 29 |
| 30 #ifdef _WIN32 | 30 #ifdef _WIN32 |
| 31 #define snprintf _snprintf | 31 #define snprintf _snprintf |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #define _SKP_SUPPORT_ | |
| 35 | |
| 36 #ifdef _SKP_SUPPORT_ | |
| 37 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 38 #include "third_party/skia/include/core/SkStream.h" | |
| 39 #endif | |
| 40 | |
| 34 enum OutputFormat { | 41 enum OutputFormat { |
| 35 OUTPUT_NONE, | 42 OUTPUT_NONE, |
| 36 OUTPUT_PPM, | 43 OUTPUT_PPM, |
| 37 OUTPUT_PNG, | 44 OUTPUT_PNG, |
| 38 #ifdef _WIN32 | 45 #ifdef _WIN32 |
| 39 OUTPUT_BMP, | 46 OUTPUT_BMP, |
| 40 OUTPUT_EMF, | 47 OUTPUT_EMF, |
| 41 #endif | 48 #endif |
| 49 #ifdef _SKP_SUPPORT_ | |
| 50 OUTPUT_SKP, | |
| 51 #endif | |
| 42 }; | 52 }; |
| 43 | 53 |
| 44 struct Options { | 54 struct Options { |
| 45 Options() : show_config(false), output_format(OUTPUT_NONE) {} | 55 Options() : show_config(false), output_format(OUTPUT_NONE) {} |
| 46 | 56 |
| 47 bool show_config; | 57 bool show_config; |
| 48 OutputFormat output_format; | 58 OutputFormat output_format; |
| 49 std::string scale_factor_as_string; | 59 std::string scale_factor_as_string; |
| 50 std::string exe_path; | 60 std::string exe_path; |
| 51 std::string bin_directory; | 61 std::string bin_directory; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. | 198 // If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less. |
| 189 Rectangle(dc, 0, 0, width + 1, height + 1); | 199 Rectangle(dc, 0, 0, width + 1, height + 1); |
| 190 | 200 |
| 191 FPDF_RenderPage(dc, page, 0, 0, width, height, 0, | 201 FPDF_RenderPage(dc, page, 0, 0, width, height, 0, |
| 192 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | 202 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 193 | 203 |
| 194 DeleteEnhMetaFile(CloseEnhMetaFile(dc)); | 204 DeleteEnhMetaFile(CloseEnhMetaFile(dc)); |
| 195 } | 205 } |
| 196 #endif | 206 #endif |
| 197 | 207 |
| 208 #ifdef _SKP_SUPPORT_ | |
| 209 void WriteSkp(const char* pdf_name, int num, const void* recorder) { | |
| 210 char filename[256]; | |
| 211 int chars_formatted = snprintf( | |
| 212 filename, sizeof(filename), "%s.%d.skp", pdf_name, num); | |
| 213 | |
| 214 if (chars_formatted < 0 || | |
| 215 static_cast<size_t>(chars_formatted) >= sizeof(filename)) { | |
| 216 fprintf(stderr, "Filname %s is too long\n", filename); | |
|
dsinclair
2016/03/10 14:38:54
nit: filename
caryclark
2016/03/10 20:44:55
Done.
| |
| 217 return; | |
| 218 } | |
| 219 | |
| 220 SkPictureRecorder* r = (SkPictureRecorder*) recorder; | |
| 221 SkPicture* picture = r->endRecordingAsPicture(); | |
| 222 SkFILEWStream wStream(filename); | |
| 223 picture->serialize(&wStream); | |
| 224 } | |
| 225 #endif | |
| 226 | |
| 198 // These example JS platform callback handlers are entirely optional, | 227 // These example JS platform callback handlers are entirely optional, |
| 199 // and exist here to show the flow of information from a document back | 228 // and exist here to show the flow of information from a document back |
| 200 // to the embedder. | 229 // to the embedder. |
| 201 int ExampleAppAlert(IPDF_JSPLATFORM*, | 230 int ExampleAppAlert(IPDF_JSPLATFORM*, |
| 202 FPDF_WIDESTRING msg, | 231 FPDF_WIDESTRING msg, |
| 203 FPDF_WIDESTRING title, | 232 FPDF_WIDESTRING title, |
| 204 int nType, | 233 int nType, |
| 205 int nIcon) { | 234 int nIcon) { |
| 206 printf("%ls", GetPlatformWString(title).c_str()); | 235 printf("%ls", GetPlatformWString(title).c_str()); |
| 207 if (nIcon || nType) | 236 if (nIcon || nType) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); | 341 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); |
| 313 return false; | 342 return false; |
| 314 } | 343 } |
| 315 options->output_format = OUTPUT_PPM; | 344 options->output_format = OUTPUT_PPM; |
| 316 } else if (cur_arg == "--png") { | 345 } else if (cur_arg == "--png") { |
| 317 if (options->output_format != OUTPUT_NONE) { | 346 if (options->output_format != OUTPUT_NONE) { |
| 318 fprintf(stderr, "Duplicate or conflicting --png argument\n"); | 347 fprintf(stderr, "Duplicate or conflicting --png argument\n"); |
| 319 return false; | 348 return false; |
| 320 } | 349 } |
| 321 options->output_format = OUTPUT_PNG; | 350 options->output_format = OUTPUT_PNG; |
| 351 #ifdef _SKP_SUPPORT_ | |
| 352 } else if (cur_arg == "--skp") { | |
| 353 if (options->output_format != OUTPUT_NONE) { | |
| 354 fprintf(stderr, "Duplicate or conflicting --skp argument\n"); | |
| 355 return false; | |
| 356 } | |
| 357 options->output_format = OUTPUT_SKP; | |
| 358 #endif | |
| 322 } else if (cur_arg.size() > 11 && | 359 } else if (cur_arg.size() > 11 && |
| 323 cur_arg.compare(0, 11, "--font-dir=") == 0) { | 360 cur_arg.compare(0, 11, "--font-dir=") == 0) { |
| 324 if (!options->font_directory.empty()) { | 361 if (!options->font_directory.empty()) { |
| 325 fprintf(stderr, "Duplicate --font-dir argument\n"); | 362 fprintf(stderr, "Duplicate --font-dir argument\n"); |
| 326 return false; | 363 return false; |
| 327 } | 364 } |
| 328 options->font_directory = cur_arg.substr(11); | 365 options->font_directory = cur_arg.substr(11); |
| 329 #ifdef _WIN32 | 366 #ifdef _WIN32 |
| 330 } else if (cur_arg == "--emf") { | 367 } else if (cur_arg == "--emf") { |
| 331 if (options->output_format != OUTPUT_NONE) { | 368 if (options->output_format != OUTPUT_NONE) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; | 438 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; |
| 402 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); | 439 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); |
| 403 if (!bitmap) { | 440 if (!bitmap) { |
| 404 fprintf(stderr, "Page was too large to be rendered.\n"); | 441 fprintf(stderr, "Page was too large to be rendered.\n"); |
| 405 return false; | 442 return false; |
| 406 } | 443 } |
| 407 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; | 444 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; |
| 408 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); | 445 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); |
| 409 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); | 446 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
| 410 | 447 |
| 411 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); | 448 FPDF_FFLDraw(form, bitmap, nullptr, page, 0, 0, width, height, 0, 0); |
| 412 int stride = FPDFBitmap_GetStride(bitmap); | 449 int stride = FPDFBitmap_GetStride(bitmap); |
| 413 const char* buffer = | 450 const char* buffer = |
| 414 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); | 451 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); |
| 415 | 452 |
| 416 switch (options.output_format) { | 453 switch (options.output_format) { |
| 417 #ifdef _WIN32 | 454 #ifdef _WIN32 |
| 418 case OUTPUT_BMP: | 455 case OUTPUT_BMP: |
| 419 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); | 456 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); |
| 420 break; | 457 break; |
| 421 | 458 |
| 422 case OUTPUT_EMF: | 459 case OUTPUT_EMF: |
| 423 WriteEmf(page, name.c_str(), page_index); | 460 WriteEmf(page, name.c_str(), page_index); |
| 424 break; | 461 break; |
| 425 #endif | 462 #endif |
| 426 case OUTPUT_PNG: | 463 case OUTPUT_PNG: |
| 427 WritePng(name.c_str(), page_index, buffer, stride, width, height); | 464 WritePng(name.c_str(), page_index, buffer, stride, width, height); |
| 428 break; | 465 break; |
| 429 | 466 |
| 430 case OUTPUT_PPM: | 467 case OUTPUT_PPM: |
| 431 WritePpm(name.c_str(), page_index, buffer, stride, width, height); | 468 WritePpm(name.c_str(), page_index, buffer, stride, width, height); |
| 432 break; | 469 break; |
| 433 | 470 |
| 471 #ifdef _SKP_SUPPORT_ | |
| 472 case OUTPUT_SKP: { | |
| 473 void* recorder = FPDF_RenderPageSkp(page, width, height); | |
|
dsinclair
2016/03/10 14:38:54
unique_ptr
caryclark
2016/03/10 20:44:55
Done.
| |
| 474 FPDF_FFLDraw(form, nullptr, recorder, page, 0, 0, width, height, 0, 0); | |
| 475 WriteSkp(name.c_str(), page_index, recorder); | |
| 476 delete recorder; | |
| 477 } break; | |
| 478 #endif | |
| 434 default: | 479 default: |
| 435 break; | 480 break; |
| 436 } | 481 } |
| 437 | 482 |
| 438 FPDFBitmap_Destroy(bitmap); | 483 FPDFBitmap_Destroy(bitmap); |
| 439 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); | 484 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); |
| 440 FORM_OnBeforeClosePage(page, form); | 485 FORM_OnBeforeClosePage(page, form); |
| 441 FPDFText_ClosePage(text_page); | 486 FPDFText_ClosePage(text_page); |
| 442 FPDF_ClosePage(page); | 487 FPDF_ClosePage(page); |
| 443 return true; | 488 return true; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 } | 744 } |
| 700 | 745 |
| 701 FPDF_DestroyLibrary(); | 746 FPDF_DestroyLibrary(); |
| 702 #ifdef PDF_ENABLE_V8 | 747 #ifdef PDF_ENABLE_V8 |
| 703 v8::V8::ShutdownPlatform(); | 748 v8::V8::ShutdownPlatform(); |
| 704 delete platform; | 749 delete platform; |
| 705 #endif // PDF_ENABLE_V8 | 750 #endif // PDF_ENABLE_V8 |
| 706 | 751 |
| 707 return 0; | 752 return 0; |
| 708 } | 753 } |
| OLD | NEW |