| 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 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 if (i == pages_to_print.size()) { | 1522 if (i == pages_to_print.size()) { |
| 1523 FPDF_CopyViewerPreferences(output_doc, doc_); | 1523 FPDF_CopyViewerPreferences(output_doc, doc_); |
| 1524 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); | 1524 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); |
| 1525 // Now flatten all the output pages. | 1525 // Now flatten all the output pages. |
| 1526 buffer = GetFlattenedPrintData(output_doc); | 1526 buffer = GetFlattenedPrintData(output_doc); |
| 1527 } | 1527 } |
| 1528 FPDF_CloseDocument(output_doc); | 1528 FPDF_CloseDocument(output_doc); |
| 1529 return buffer; | 1529 return buffer; |
| 1530 } | 1530 } |
| 1531 | 1531 |
| 1532 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) { | 1532 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(FPDF_DOCUMENT doc) { |
| 1533 pp::Buffer_Dev buffer; | 1533 pp::Buffer_Dev buffer; |
| 1534 ScopedSubstFont scoped_subst_font(this); | 1534 ScopedSubstFont scoped_subst_font(this); |
| 1535 int page_count = FPDF_GetPageCount(doc); | 1535 int page_count = FPDF_GetPageCount(doc); |
| 1536 for (int i = 0; i < page_count; ++i) { | 1536 for (int i = 0; i < page_count; ++i) { |
| 1537 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1537 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
| 1538 DCHECK(page); | 1538 DCHECK(page); |
| 1539 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); | 1539 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); |
| 1540 FPDF_ClosePage(page); | 1540 FPDF_ClosePage(page); |
| 1541 if (flatten_ret == FLATTEN_FAIL) | 1541 if (flatten_ret == FLATTEN_FAIL) |
| 1542 return buffer; | 1542 return buffer; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 | 1598 |
| 1599 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); | 1599 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); |
| 1600 | 1600 |
| 1601 // Now flatten all the output pages. | 1601 // Now flatten all the output pages. |
| 1602 pp::Buffer_Dev buffer = GetFlattenedPrintData(output_doc); | 1602 pp::Buffer_Dev buffer = GetFlattenedPrintData(output_doc); |
| 1603 FPDF_CloseDocument(output_doc); | 1603 FPDF_CloseDocument(output_doc); |
| 1604 return buffer; | 1604 return buffer; |
| 1605 } | 1605 } |
| 1606 | 1606 |
| 1607 void PDFiumEngine::FitContentsToPrintableAreaIfRequired( | 1607 void PDFiumEngine::FitContentsToPrintableAreaIfRequired( |
| 1608 const FPDF_DOCUMENT& doc, | 1608 FPDF_DOCUMENT doc, |
| 1609 const PP_PrintSettings_Dev& print_settings) { | 1609 const PP_PrintSettings_Dev& print_settings) { |
| 1610 // Check to see if we need to fit pdf contents to printer paper size. | 1610 // Check to see if we need to fit pdf contents to printer paper size. |
| 1611 if (print_settings.print_scaling_option != | 1611 if (print_settings.print_scaling_option != |
| 1612 PP_PRINTSCALINGOPTION_SOURCE_SIZE) { | 1612 PP_PRINTSCALINGOPTION_SOURCE_SIZE) { |
| 1613 int num_pages = FPDF_GetPageCount(doc); | 1613 int num_pages = FPDF_GetPageCount(doc); |
| 1614 // In-place transformation is more efficient than creating a new | 1614 // In-place transformation is more efficient than creating a new |
| 1615 // transformed document from the source document. Therefore, transform | 1615 // transformed document from the source document. Therefore, transform |
| 1616 // every page to fit the contents in the selected printer paper. | 1616 // every page to fit the contents in the selected printer paper. |
| 1617 for (int i = 0; i < num_pages; ++i) { | 1617 for (int i = 0; i < num_pages; ++i) { |
| 1618 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1618 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
| (...skipping 2516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4135 FPDF_DOCUMENT doc = | 4135 FPDF_DOCUMENT doc = |
| 4136 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4136 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 4137 if (!doc) | 4137 if (!doc) |
| 4138 return false; | 4138 return false; |
| 4139 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4139 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 4140 FPDF_CloseDocument(doc); | 4140 FPDF_CloseDocument(doc); |
| 4141 return success; | 4141 return success; |
| 4142 } | 4142 } |
| 4143 | 4143 |
| 4144 } // namespace chrome_pdf | 4144 } // namespace chrome_pdf |
| OLD | NEW |