Commit 27dea3a9 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Simplify code in PDFiumEngine.

Change-Id: I3510dcafacab2471b02762670527dc299411c7b2
Reviewed-on: https://chromium-review.googlesource.com/683616
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatardsinclair <dsinclair@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504453}
parent 320aa651
...@@ -1038,16 +1038,14 @@ int PDFiumEngine::GetBlock(void* param, ...@@ -1038,16 +1038,14 @@ int PDFiumEngine::GetBlock(void* param,
FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param,
size_t offset, size_t offset,
size_t size) { size_t size) {
PDFiumEngine::FileAvail* file_avail = auto* file_avail = static_cast<FileAvail*>(param);
static_cast<PDFiumEngine::FileAvail*>(param);
return file_avail->engine->doc_loader_->IsDataAvailable(offset, size); return file_avail->engine->doc_loader_->IsDataAvailable(offset, size);
} }
void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param, void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param,
size_t offset, size_t offset,
size_t size) { size_t size) {
PDFiumEngine::DownloadHints* download_hints = auto* download_hints = static_cast<DownloadHints*>(param);
static_cast<PDFiumEngine::DownloadHints*>(param);
return download_hints->engine->doc_loader_->RequestData(offset, size); return download_hints->engine->doc_loader_->RequestData(offset, size);
} }
...@@ -1105,7 +1103,6 @@ void PDFiumEngine::Paint(const pp::Rect& rect, ...@@ -1105,7 +1103,6 @@ void PDFiumEngine::Paint(const pp::Rect& rect,
pp::Rect leftover = rect; pp::Rect leftover = rect;
for (size_t i = 0; i < visible_pages_.size(); ++i) { for (size_t i = 0; i < visible_pages_.size(); ++i) {
int index = visible_pages_[i]; int index = visible_pages_[i];
pp::Rect page_rect = pages_[index]->rect();
// Convert the current page's rectangle to screen rectangle. We do this // Convert the current page's rectangle to screen rectangle. We do this
// instead of the reverse (converting the dirty rectangle from screen to // instead of the reverse (converting the dirty rectangle from screen to
// page coordinates) because then we'd have to convert back to screen // page coordinates) because then we'd have to convert back to screen
...@@ -1444,9 +1441,9 @@ bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) { ...@@ -1444,9 +1441,9 @@ bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
} }
uint32_t PDFiumEngine::QuerySupportedPrintOutputFormats() { uint32_t PDFiumEngine::QuerySupportedPrintOutputFormats() {
if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) if (HasPermission(PERMISSION_PRINT_HIGH_QUALITY))
return PP_PRINTOUTPUTFORMAT_PDF | PP_PRINTOUTPUTFORMAT_RASTER; return PP_PRINTOUTPUTFORMAT_PDF | PP_PRINTOUTPUTFORMAT_RASTER;
if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) if (HasPermission(PERMISSION_PRINT_LOW_QUALITY))
return PP_PRINTOUTPUTFORMAT_RASTER; return PP_PRINTOUTPUTFORMAT_RASTER;
return 0; return 0;
} }
...@@ -1460,11 +1457,11 @@ pp::Resource PDFiumEngine::PrintPages( ...@@ -1460,11 +1457,11 @@ pp::Resource PDFiumEngine::PrintPages(
uint32_t page_range_count, uint32_t page_range_count,
const PP_PrintSettings_Dev& print_settings) { const PP_PrintSettings_Dev& print_settings) {
ScopedSubstFont scoped_subst_font(this); ScopedSubstFont scoped_subst_font(this);
if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY) && if ((print_settings.format & PP_PRINTOUTPUTFORMAT_PDF) &&
(print_settings.format & PP_PRINTOUTPUTFORMAT_PDF)) { HasPermission(PERMISSION_PRINT_HIGH_QUALITY)) {
return PrintPagesAsPDF(page_ranges, page_range_count, print_settings); return PrintPagesAsPDF(page_ranges, page_range_count, print_settings);
} }
if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) if (HasPermission(PERMISSION_PRINT_LOW_QUALITY))
return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings); return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings);
return pp::Resource(); return pp::Resource();
} }
...@@ -1643,12 +1640,10 @@ pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(FPDF_DOCUMENT doc) { ...@@ -1643,12 +1640,10 @@ pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(FPDF_DOCUMENT doc) {
PDFiumMemBufferFileWrite output_file_write; PDFiumMemBufferFileWrite output_file_write;
if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) { if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) {
buffer = size_t size = output_file_write.size();
pp::Buffer_Dev(client_->GetPluginInstance(), output_file_write.size()); buffer = pp::Buffer_Dev(client_->GetPluginInstance(), size);
if (!buffer.is_null()) { if (!buffer.is_null())
memcpy(buffer.data(), output_file_write.buffer().c_str(), memcpy(buffer.data(), output_file_write.buffer().c_str(), size);
output_file_write.size());
}
} }
return buffer; return buffer;
} }
...@@ -1671,13 +1666,11 @@ pp::Buffer_Dev PDFiumEngine::PrintPagesAsPDF( ...@@ -1671,13 +1666,11 @@ pp::Buffer_Dev PDFiumEngine::PrintPagesAsPDF(
for (uint32_t index = 0; index < page_range_count; ++index) { for (uint32_t index = 0; index < page_range_count; ++index) {
if (!page_number_str.empty()) if (!page_number_str.empty())
page_number_str.append(","); page_number_str.append(",");
page_number_str.append( const PP_PrintPageNumberRange_Dev& range = page_ranges[index];
base::UintToString(page_ranges[index].first_page_number + 1)); page_number_str.append(base::UintToString(range.first_page_number + 1));
if (page_ranges[index].first_page_number != if (range.first_page_number != range.last_page_number) {
page_ranges[index].last_page_number) {
page_number_str.append("-"); page_number_str.append("-");
page_number_str.append( page_number_str.append(base::UintToString(range.last_page_number + 1));
base::UintToString(page_ranges[index].last_page_number + 1));
} }
} }
...@@ -2665,8 +2658,7 @@ int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { ...@@ -2665,8 +2658,7 @@ int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) {
FPDF_WIDESTRING destination_pdf_wide = FPDF_WIDESTRING destination_pdf_wide =
reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str());
FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide);
if (!bookmark) if (bookmark)
return -1;
dest = FPDFBookmark_GetDest(doc_, bookmark); dest = FPDFBookmark_GetDest(doc_, bookmark);
} }
return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment