| 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 |
| (...skipping 3867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3878 int rotate = CalculatePosition(page, new_settings, &dest); | 3878 int rotate = CalculatePosition(page, new_settings, &dest); |
| 3879 | 3879 |
| 3880 int save_state = SaveDC(dc); | 3880 int save_state = SaveDC(dc); |
| 3881 // The caller wanted all drawing to happen within the bounds specified. | 3881 // The caller wanted all drawing to happen within the bounds specified. |
| 3882 // Based on scale calculations, our destination rect might be larger | 3882 // Based on scale calculations, our destination rect might be larger |
| 3883 // than the bounds. Set the clip rect to the bounds. | 3883 // than the bounds. Set the clip rect to the bounds. |
| 3884 IntersectClipRect(dc, settings.bounds.x(), settings.bounds.y(), | 3884 IntersectClipRect(dc, settings.bounds.x(), settings.bounds.y(), |
| 3885 settings.bounds.x() + settings.bounds.width(), | 3885 settings.bounds.x() + settings.bounds.width(), |
| 3886 settings.bounds.y() + settings.bounds.height()); | 3886 settings.bounds.y() + settings.bounds.height()); |
| 3887 | 3887 |
| 3888 // A temporary hack. PDFs generated by Cairo (used by Chrome OS to generate | 3888 // A "temporary" hack. Some PDFs seems to render very slowly if |
| 3889 // a PDF output from a webpage) result in very large metafiles and the | 3889 // FPDF_RenderPage() is directly used on a printer DC. I suspect it is |
| 3890 // rendering using FPDF_RenderPage is incorrect. In this case, render as a | |
| 3891 // bitmap. Note that this code does not kick in for PDFs printed from Chrome | |
| 3892 // because in that case we create a temp PDF first before printing and this | |
| 3893 // temp PDF does not have a creator string that starts with "cairo". | |
| 3894 bool use_bitmap = false; | |
| 3895 if (base::StartsWith(GetDocumentMetadata(doc, "Creator"), "cairo", | |
| 3896 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 3897 use_bitmap = true; | |
| 3898 } | |
| 3899 | |
| 3900 // Another temporary hack. Some PDFs seems to render very slowly if | |
| 3901 // FPDF_RenderPage is directly used on a printer DC. I suspect it is | |
| 3902 // because of the code to talk Postscript directly to the printer if | 3890 // because of the code to talk Postscript directly to the printer if |
| 3903 // the printer supports this. Need to discuss this with PDFium. For now, | 3891 // the printer supports this. Need to discuss this with PDFium. For now, |
| 3904 // render to a bitmap and then blit the bitmap to the DC if we have been | 3892 // render to a bitmap and then blit the bitmap to the DC if we have been |
| 3905 // supplied a printer DC. | 3893 // supplied a printer DC. |
| 3906 int device_type = GetDeviceCaps(dc, TECHNOLOGY); | 3894 int device_type = GetDeviceCaps(dc, TECHNOLOGY); |
| 3907 if (use_bitmap || | 3895 if (device_type == DT_RASPRINTER || device_type == DT_PLOTTER) { |
| 3908 (device_type == DT_RASPRINTER) || (device_type == DT_PLOTTER)) { | |
| 3909 FPDF_BITMAP bitmap = FPDFBitmap_Create(dest.width(), dest.height(), | 3896 FPDF_BITMAP bitmap = FPDFBitmap_Create(dest.width(), dest.height(), |
| 3910 FPDFBitmap_BGRx); | 3897 FPDFBitmap_BGRx); |
| 3911 // Clear the bitmap | 3898 // Clear the bitmap |
| 3912 FPDFBitmap_FillRect(bitmap, 0, 0, dest.width(), dest.height(), 0xFFFFFFFF); | 3899 FPDFBitmap_FillRect(bitmap, 0, 0, dest.width(), dest.height(), 0xFFFFFFFF); |
| 3913 FPDF_RenderPageBitmap( | 3900 FPDF_RenderPageBitmap( |
| 3914 bitmap, page, 0, 0, dest.width(), dest.height(), rotate, | 3901 bitmap, page, 0, 0, dest.width(), dest.height(), rotate, |
| 3915 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); | 3902 FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH); |
| 3916 int stride = FPDFBitmap_GetStride(bitmap); | 3903 int stride = FPDFBitmap_GetStride(bitmap); |
| 3917 BITMAPINFO bmi; | 3904 BITMAPINFO bmi; |
| 3918 memset(&bmi, 0, sizeof(bmi)); | 3905 memset(&bmi, 0, sizeof(bmi)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4008 double* height) { | 3995 double* height) { |
| 4009 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3996 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 4010 if (!doc) | 3997 if (!doc) |
| 4011 return false; | 3998 return false; |
| 4012 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3999 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4013 FPDF_CloseDocument(doc); | 4000 FPDF_CloseDocument(doc); |
| 4014 return success; | 4001 return success; |
| 4015 } | 4002 } |
| 4016 | 4003 |
| 4017 } // namespace chrome_pdf | 4004 } // namespace chrome_pdf |
| OLD | NEW |