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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 SendPageEvents(form, page, events); | 501 SendPageEvents(form, page, events); |
502 | 502 |
503 double scale = 1.0; | 503 double scale = 1.0; |
504 if (!options.scale_factor_as_string.empty()) { | 504 if (!options.scale_factor_as_string.empty()) { |
505 std::stringstream(options.scale_factor_as_string) >> scale; | 505 std::stringstream(options.scale_factor_as_string) >> scale; |
506 } | 506 } |
507 int width = static_cast<int>(FPDF_GetPageWidth(page) * scale); | 507 int width = static_cast<int>(FPDF_GetPageWidth(page) * scale); |
508 int height = static_cast<int>(FPDF_GetPageHeight(page) * scale); | 508 int height = static_cast<int>(FPDF_GetPageHeight(page) * scale); |
509 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; | 509 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; |
510 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); | 510 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); |
511 if (!bitmap) { | 511 if (bitmap) { |
512 fprintf(stderr, "Page was too large to be rendered.\n"); | 512 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; |
513 return false; | 513 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); |
514 } | 514 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
515 FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; | |
516 FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); | |
517 FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); | |
518 | 515 |
519 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); | 516 FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); |
520 int stride = FPDFBitmap_GetStride(bitmap); | 517 int stride = FPDFBitmap_GetStride(bitmap); |
521 const char* buffer = | 518 const char* buffer = |
522 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); | 519 reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); |
523 | 520 |
524 switch (options.output_format) { | 521 switch (options.output_format) { |
525 #ifdef _WIN32 | 522 #ifdef _WIN32 |
526 case OUTPUT_BMP: | 523 case OUTPUT_BMP: |
527 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); | 524 WriteBmp(name.c_str(), page_index, buffer, stride, width, height); |
528 break; | 525 break; |
529 | 526 |
530 case OUTPUT_EMF: | 527 case OUTPUT_EMF: |
531 WriteEmf(page, name.c_str(), page_index); | 528 WriteEmf(page, name.c_str(), page_index); |
532 break; | 529 break; |
533 #endif | 530 #endif |
534 case OUTPUT_PNG: | 531 case OUTPUT_PNG: |
535 WritePng(name.c_str(), page_index, buffer, stride, width, height); | 532 WritePng(name.c_str(), page_index, buffer, stride, width, height); |
536 break; | 533 break; |
537 | 534 |
538 case OUTPUT_PPM: | 535 case OUTPUT_PPM: |
539 WritePpm(name.c_str(), page_index, buffer, stride, width, height); | 536 WritePpm(name.c_str(), page_index, buffer, stride, width, height); |
540 break; | 537 break; |
541 | 538 |
542 #ifdef PDF_ENABLE_SKIA | 539 #ifdef PDF_ENABLE_SKIA |
543 case OUTPUT_SKP: { | 540 case OUTPUT_SKP: { |
544 std::unique_ptr<SkPictureRecorder> recorder( | 541 std::unique_ptr<SkPictureRecorder> recorder( |
545 (SkPictureRecorder*)FPDF_RenderPageSkp(page, width, height)); | 542 (SkPictureRecorder*)FPDF_RenderPageSkp(page, width, height)); |
546 FPDF_FFLRecord(form, recorder.get(), page, 0, 0, width, height, 0, 0); | 543 FPDF_FFLRecord(form, recorder.get(), page, 0, 0, width, height, 0, 0); |
547 WriteSkp(name.c_str(), page_index, recorder.get()); | 544 WriteSkp(name.c_str(), page_index, recorder.get()); |
548 } break; | 545 } break; |
549 #endif | 546 #endif |
550 default: | 547 default: |
551 break; | 548 break; |
| 549 } |
| 550 |
| 551 FPDFBitmap_Destroy(bitmap); |
| 552 } else { |
| 553 fprintf(stderr, "Page was too large to be rendered.\n"); |
552 } | 554 } |
553 | |
554 FPDFBitmap_Destroy(bitmap); | |
555 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); | 555 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE); |
556 FORM_OnBeforeClosePage(page, form); | 556 FORM_OnBeforeClosePage(page, form); |
557 FPDFText_ClosePage(text_page); | 557 FPDFText_ClosePage(text_page); |
558 FPDF_ClosePage(page); | 558 FPDF_ClosePage(page); |
559 return true; | 559 return !!bitmap; |
560 } | 560 } |
561 | 561 |
562 void RenderPdf(const std::string& name, | 562 void RenderPdf(const std::string& name, |
563 const char* pBuf, | 563 const char* pBuf, |
564 size_t len, | 564 size_t len, |
565 const Options& options, | 565 const Options& options, |
566 const std::string& events) { | 566 const std::string& events) { |
567 IPDF_JSPLATFORM platform_callbacks; | 567 IPDF_JSPLATFORM platform_callbacks; |
568 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 568 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
569 platform_callbacks.version = 3; | 569 platform_callbacks.version = 3; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 } | 836 } |
837 | 837 |
838 FPDF_DestroyLibrary(); | 838 FPDF_DestroyLibrary(); |
839 #ifdef PDF_ENABLE_V8 | 839 #ifdef PDF_ENABLE_V8 |
840 v8::V8::ShutdownPlatform(); | 840 v8::V8::ShutdownPlatform(); |
841 delete platform; | 841 delete platform; |
842 #endif // PDF_ENABLE_V8 | 842 #endif // PDF_ENABLE_V8 |
843 | 843 |
844 return 0; | 844 return 0; |
845 } | 845 } |
OLD | NEW |