| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "pdf/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "base/i18n/icu_encoding_detection.h" | 11 #include "base/i18n/icu_encoding_detection.h" |
| 12 #include "base/i18n/icu_string_conversions.h" | 12 #include "base/i18n/icu_string_conversions.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/lazy_instance.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
| 18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/values.h" | 24 #include "base/values.h" |
| (...skipping 3746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3770 | 3771 |
| 3771 ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine) | 3772 ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine) |
| 3772 : engine_(engine), old_engine_(g_engine_for_unsupported) { | 3773 : engine_(engine), old_engine_(g_engine_for_unsupported) { |
| 3773 g_engine_for_unsupported = engine_; | 3774 g_engine_for_unsupported = engine_; |
| 3774 } | 3775 } |
| 3775 | 3776 |
| 3776 ScopedUnsupportedFeature::~ScopedUnsupportedFeature() { | 3777 ScopedUnsupportedFeature::~ScopedUnsupportedFeature() { |
| 3777 g_engine_for_unsupported = old_engine_; | 3778 g_engine_for_unsupported = old_engine_; |
| 3778 } | 3779 } |
| 3779 | 3780 |
| 3780 PDFEngineExports* PDFEngineExports::Create() { | |
| 3781 return new PDFiumEngineExports; | |
| 3782 } | |
| 3783 | |
| 3784 namespace { | 3781 namespace { |
| 3785 | 3782 |
| 3783 base::LazyInstance<PDFiumEngineExports>::Leaky g_pdf_engine_exports = |
| 3784 LAZY_INSTANCE_INITIALIZER; |
| 3785 |
| 3786 int CalculatePosition(FPDF_PAGE page, | 3786 int CalculatePosition(FPDF_PAGE page, |
| 3787 const PDFiumEngineExports::RenderingSettings& settings, | 3787 const PDFiumEngineExports::RenderingSettings& settings, |
| 3788 pp::Rect* dest) { | 3788 pp::Rect* dest) { |
| 3789 int page_width = static_cast<int>(ConvertUnitDouble(FPDF_GetPageWidth(page), | 3789 int page_width = static_cast<int>(ConvertUnitDouble(FPDF_GetPageWidth(page), |
| 3790 kPointsPerInch, | 3790 kPointsPerInch, |
| 3791 settings.dpi_x)); | 3791 settings.dpi_x)); |
| 3792 int page_height = static_cast<int>(ConvertUnitDouble(FPDF_GetPageHeight(page), | 3792 int page_height = static_cast<int>(ConvertUnitDouble(FPDF_GetPageHeight(page), |
| 3793 kPointsPerInch, | 3793 kPointsPerInch, |
| 3794 settings.dpi_y)); | 3794 settings.dpi_y)); |
| 3795 | 3795 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3841 if (settings.center_in_bounds) { | 3841 if (settings.center_in_bounds) { |
| 3842 pp::Point offset((settings.bounds.width() - dest->width()) / 2, | 3842 pp::Point offset((settings.bounds.width() - dest->width()) / 2, |
| 3843 (settings.bounds.height() - dest->height()) / 2); | 3843 (settings.bounds.height() - dest->height()) / 2); |
| 3844 dest->Offset(offset); | 3844 dest->Offset(offset); |
| 3845 } | 3845 } |
| 3846 return rotate; | 3846 return rotate; |
| 3847 } | 3847 } |
| 3848 | 3848 |
| 3849 } // namespace | 3849 } // namespace |
| 3850 | 3850 |
| 3851 PDFEngineExports* PDFEngineExports::Get() { |
| 3852 return g_pdf_engine_exports.Pointer(); |
| 3853 } |
| 3854 |
| 3851 #if defined(OS_WIN) | 3855 #if defined(OS_WIN) |
| 3852 bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer, | 3856 bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer, |
| 3853 int buffer_size, | 3857 int buffer_size, |
| 3854 int page_number, | 3858 int page_number, |
| 3855 const RenderingSettings& settings, | 3859 const RenderingSettings& settings, |
| 3856 HDC dc) { | 3860 HDC dc) { |
| 3857 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, NULL); | 3861 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, NULL); |
| 3858 if (!doc) | 3862 if (!doc) |
| 3859 return false; | 3863 return false; |
| 3860 FPDF_PAGE page = FPDF_LoadPage(doc, page_number); | 3864 FPDF_PAGE page = FPDF_LoadPage(doc, page_number); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3924 FPDFBitmap_Destroy(bitmap); | 3928 FPDFBitmap_Destroy(bitmap); |
| 3925 } else { | 3929 } else { |
| 3926 FPDF_RenderPage(dc, page, dest.x(), dest.y(), dest.width(), dest.height(), | 3930 FPDF_RenderPage(dc, page, dest.x(), dest.y(), dest.width(), dest.height(), |
| 3927 rotate, FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | 3931 rotate, FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 3928 } | 3932 } |
| 3929 RestoreDC(dc, save_state); | 3933 RestoreDC(dc, save_state); |
| 3930 FPDF_ClosePage(page); | 3934 FPDF_ClosePage(page); |
| 3931 FPDF_CloseDocument(doc); | 3935 FPDF_CloseDocument(doc); |
| 3932 return true; | 3936 return true; |
| 3933 } | 3937 } |
| 3934 #endif // OS_WIN | 3938 #endif // defined(OS_WIN) |
| 3935 | 3939 |
| 3936 bool PDFiumEngineExports::RenderPDFPageToBitmap( | 3940 bool PDFiumEngineExports::RenderPDFPageToBitmap( |
| 3937 const void* pdf_buffer, | 3941 const void* pdf_buffer, |
| 3938 int pdf_buffer_size, | 3942 int pdf_buffer_size, |
| 3939 int page_number, | 3943 int page_number, |
| 3940 const RenderingSettings& settings, | 3944 const RenderingSettings& settings, |
| 3941 void* bitmap_buffer) { | 3945 void* bitmap_buffer) { |
| 3942 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3946 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3943 if (!doc) | 3947 if (!doc) |
| 3944 return false; | 3948 return false; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4003 double* height) { | 4007 double* height) { |
| 4004 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 4008 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 4005 if (!doc) | 4009 if (!doc) |
| 4006 return false; | 4010 return false; |
| 4007 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4011 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4008 FPDF_CloseDocument(doc); | 4012 FPDF_CloseDocument(doc); |
| 4009 return success; | 4013 return success; |
| 4010 } | 4014 } |
| 4011 | 4015 |
| 4012 } // namespace chrome_pdf | 4016 } // namespace chrome_pdf |
| OLD | NEW |