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 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1436 FPDF_CopyViewerPreferences(output_doc, doc_); | 1436 FPDF_CopyViewerPreferences(output_doc, doc_); |
1437 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); | 1437 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); |
1438 // Now flatten all the output pages. | 1438 // Now flatten all the output pages. |
1439 buffer = GetFlattenedPrintData(output_doc); | 1439 buffer = GetFlattenedPrintData(output_doc); |
1440 } | 1440 } |
1441 FPDF_CloseDocument(output_doc); | 1441 FPDF_CloseDocument(output_doc); |
1442 return buffer; | 1442 return buffer; |
1443 } | 1443 } |
1444 | 1444 |
1445 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) { | 1445 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) { |
1446 pp::Buffer_Dev buffer; | |
1446 int page_count = FPDF_GetPageCount(doc); | 1447 int page_count = FPDF_GetPageCount(doc); |
1447 bool flatten_succeeded = true; | |
1448 for (int i = 0; i < page_count; ++i) { | 1448 for (int i = 0; i < page_count; ++i) { |
1449 FPDF_PAGE page = FPDF_LoadPage(doc, i); | 1449 FPDF_PAGE page = FPDF_LoadPage(doc, i); |
1450 DCHECK(page); | 1450 DCHECK(page); |
1451 if (page) { | 1451 if (!page) |
1452 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); | 1452 return buffer; |
raymes
2016/01/04 00:19:56
I think we should probably remove the if (!page) c
Lei Zhang
2016/01/04 20:03:03
Done.
| |
1453 FPDF_ClosePage(page); | 1453 |
1454 if (flatten_ret == FLATTEN_FAIL) { | 1454 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); |
1455 flatten_succeeded = false; | 1455 FPDF_ClosePage(page); |
1456 break; | 1456 if (flatten_ret == FLATTEN_FAIL) |
1457 } | 1457 return buffer; |
1458 } else { | |
1459 flatten_succeeded = false; | |
1460 break; | |
1461 } | |
1462 } | |
1463 if (!flatten_succeeded) { | |
1464 FPDF_CloseDocument(doc); | |
Lei Zhang
2015/12/24 08:00:56
No need, all the callers do it.
| |
1465 return pp::Buffer_Dev(); | |
1466 } | 1458 } |
1467 | 1459 |
1468 pp::Buffer_Dev buffer; | |
1469 PDFiumMemBufferFileWrite output_file_write; | 1460 PDFiumMemBufferFileWrite output_file_write; |
1470 if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) { | 1461 if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) { |
1471 buffer = pp::Buffer_Dev( | 1462 buffer = pp::Buffer_Dev( |
1472 client_->GetPluginInstance(), output_file_write.size()); | 1463 client_->GetPluginInstance(), output_file_write.size()); |
1473 if (!buffer.is_null()) { | 1464 if (!buffer.is_null()) { |
1474 memcpy(buffer.data(), output_file_write.buffer().c_str(), | 1465 memcpy(buffer.data(), output_file_write.buffer().c_str(), |
1475 output_file_write.size()); | 1466 output_file_write.size()); |
1476 } | 1467 } |
1477 } | 1468 } |
1478 return buffer; | 1469 return buffer; |
(...skipping 2520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3999 double* height) { | 3990 double* height) { |
4000 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3991 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
4001 if (!doc) | 3992 if (!doc) |
4002 return false; | 3993 return false; |
4003 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3994 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4004 FPDF_CloseDocument(doc); | 3995 FPDF_CloseDocument(doc); |
4005 return success; | 3996 return success; |
4006 } | 3997 } |
4007 | 3998 |
4008 } // namespace chrome_pdf | 3999 } // namespace chrome_pdf |
OLD | NEW |