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 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 kPointsPerInch); | 1437 kPointsPerInch); |
1438 double ratio_y = ConvertUnitDouble(bitmap_size.height(), | 1438 double ratio_y = ConvertUnitDouble(bitmap_size.height(), |
1439 print_settings.dpi, | 1439 print_settings.dpi, |
1440 kPointsPerInch); | 1440 kPointsPerInch); |
1441 | 1441 |
1442 // Add the bitmap to an image object and add the image object to the output | 1442 // Add the bitmap to an image object and add the image object to the output |
1443 // page. | 1443 // page. |
1444 FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImgeObj(temp_doc); | 1444 FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImgeObj(temp_doc); |
1445 | 1445 |
1446 std::vector<uint8_t> compressed_bitmap_data; | 1446 std::vector<uint8_t> compressed_bitmap_data; |
1447 int quality = 40; | 1447 // Use quality = 40 as this does not significantly degrade the printed |
| 1448 // document relative to a normal bitmap and provides better compression than |
| 1449 // a higher quality setting. |
| 1450 const int quality = 40; |
1448 if (!(print_settings.format & PP_PRINTOUTPUTFORMAT_PDF) && | 1451 if (!(print_settings.format & PP_PRINTOUTPUTFORMAT_PDF) && |
1449 (gfx::JPEGCodec::Encode( | 1452 (gfx::JPEGCodec::Encode( |
1450 bitmap_data, gfx::JPEGCodec::FORMAT_BGRA, FPDFBitmap_GetWidth(bitmap), | 1453 bitmap_data, gfx::JPEGCodec::FORMAT_BGRA, FPDFBitmap_GetWidth(bitmap), |
1451 FPDFBitmap_GetHeight(bitmap), FPDFBitmap_GetStride(bitmap), quality, | 1454 FPDFBitmap_GetHeight(bitmap), FPDFBitmap_GetStride(bitmap), quality, |
1452 &compressed_bitmap_data))) { | 1455 &compressed_bitmap_data))) { |
1453 FPDF_FILEACCESS file_access = {}; | 1456 FPDF_FILEACCESS file_access = {}; |
1454 file_access.m_FileLen = | 1457 file_access.m_FileLen = |
1455 static_cast<unsigned long>(compressed_bitmap_data.size()); | 1458 static_cast<unsigned long>(compressed_bitmap_data.size()); |
1456 file_access.m_GetBlock = &GetBlockForJpeg; | 1459 file_access.m_GetBlock = &GetBlockForJpeg; |
1457 file_access.m_Param = &compressed_bitmap_data; | 1460 file_access.m_Param = &compressed_bitmap_data; |
(...skipping 2738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4196 FPDF_DOCUMENT doc = | 4199 FPDF_DOCUMENT doc = |
4197 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4200 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4198 if (!doc) | 4201 if (!doc) |
4199 return false; | 4202 return false; |
4200 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4203 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4201 FPDF_CloseDocument(doc); | 4204 FPDF_CloseDocument(doc); |
4202 return success; | 4205 return success; |
4203 } | 4206 } |
4204 | 4207 |
4205 } // namespace chrome_pdf | 4208 } // namespace chrome_pdf |
OLD | NEW |