Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1549013003: Simplify PDFiumEngine::GetFlattenedPrintData(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 FPDF_CopyViewerPreferences(output_doc, doc_); 1438 FPDF_CopyViewerPreferences(output_doc, doc_);
1439 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); 1439 FitContentsToPrintableAreaIfRequired(output_doc, print_settings);
1440 // Now flatten all the output pages. 1440 // Now flatten all the output pages.
1441 buffer = GetFlattenedPrintData(output_doc); 1441 buffer = GetFlattenedPrintData(output_doc);
1442 } 1442 }
1443 FPDF_CloseDocument(output_doc); 1443 FPDF_CloseDocument(output_doc);
1444 return buffer; 1444 return buffer;
1445 } 1445 }
1446 1446
1447 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) { 1447 pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) {
1448 pp::Buffer_Dev buffer;
1448 int page_count = FPDF_GetPageCount(doc); 1449 int page_count = FPDF_GetPageCount(doc);
1449 bool flatten_succeeded = true;
1450 for (int i = 0; i < page_count; ++i) { 1450 for (int i = 0; i < page_count; ++i) {
1451 FPDF_PAGE page = FPDF_LoadPage(doc, i); 1451 FPDF_PAGE page = FPDF_LoadPage(doc, i);
1452 DCHECK(page); 1452 DCHECK(page);
1453 if (page) { 1453 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT);
1454 int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT); 1454 FPDF_ClosePage(page);
1455 FPDF_ClosePage(page); 1455 if (flatten_ret == FLATTEN_FAIL)
1456 if (flatten_ret == FLATTEN_FAIL) { 1456 return buffer;
1457 flatten_succeeded = false;
1458 break;
1459 }
1460 } else {
1461 flatten_succeeded = false;
1462 break;
1463 }
1464 }
1465 if (!flatten_succeeded) {
1466 FPDF_CloseDocument(doc);
1467 return pp::Buffer_Dev();
1468 } 1457 }
1469 1458
1470 pp::Buffer_Dev buffer;
1471 PDFiumMemBufferFileWrite output_file_write; 1459 PDFiumMemBufferFileWrite output_file_write;
1472 if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) { 1460 if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) {
1473 buffer = pp::Buffer_Dev( 1461 buffer = pp::Buffer_Dev(
1474 client_->GetPluginInstance(), output_file_write.size()); 1462 client_->GetPluginInstance(), output_file_write.size());
1475 if (!buffer.is_null()) { 1463 if (!buffer.is_null()) {
1476 memcpy(buffer.data(), output_file_write.buffer().c_str(), 1464 memcpy(buffer.data(), output_file_write.buffer().c_str(),
1477 output_file_write.size()); 1465 output_file_write.size());
1478 } 1466 }
1479 } 1467 }
1480 return buffer; 1468 return buffer;
(...skipping 2527 matching lines...) Expand 10 before | Expand all | Expand 10 after
4008 double* height) { 3996 double* height) {
4009 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3997 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4010 if (!doc) 3998 if (!doc)
4011 return false; 3999 return false;
4012 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4000 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4013 FPDF_CloseDocument(doc); 4001 FPDF_CloseDocument(doc);
4014 return success; 4002 return success;
4015 } 4003 }
4016 4004
4017 } // namespace chrome_pdf 4005 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698