Commit 0437a171 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Add generic text printing

Depends on https://pdfium-review.googlesource.com/c/7194

BUG=734850

Review-Url: https://codereview.chromium.org/2970473002
Cr-Commit-Position: refs/heads/master@{#486892}
parent 4272e0fd
...@@ -228,7 +228,8 @@ PdfConverterUtilityProcessHostClient::GetFileFromTemp( ...@@ -228,7 +228,8 @@ PdfConverterUtilityProcessHostClient::GetFileFromTemp(
std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread> std::unique_ptr<base::File, content::BrowserThread::DeleteOnFileThread>
temp_file) { temp_file) {
if (settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 || if (settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 ||
settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3) { settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3 ||
settings_.mode == PdfRenderSettings::Mode::TEXTONLY) {
return base::MakeUnique<PostScriptMetaFile>(temp_dir_, return base::MakeUnique<PostScriptMetaFile>(temp_dir_,
std::move(temp_file)); std::move(temp_file));
} }
......
...@@ -318,6 +318,21 @@ void PrintJob::OnPdfPageConverted(int page_number, ...@@ -318,6 +318,21 @@ void PrintJob::OnPdfPageConverted(int page_number,
base::Bind(&PrintJob::OnPdfPageConverted, this)); base::Bind(&PrintJob::OnPdfPageConverted, this));
} }
void PrintJob::StartPdfToTextConversion(
const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Size& page_size) {
DCHECK(!pdf_conversion_state_);
pdf_conversion_state_ =
base::MakeUnique<PdfConversionState>(gfx::Size(), gfx::Rect());
const int kPrinterDpi = settings().dpi();
gfx::Rect page_area = gfx::Rect(0, 0, page_size.width(), page_size.height());
PdfRenderSettings settings(page_area, gfx::Point(0, 0), kPrinterDpi,
/*autorotate=*/true,
PdfRenderSettings::Mode::TEXTONLY);
pdf_conversion_state_->Start(
bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this));
}
void PrintJob::StartPdfToPostScriptConversion( void PrintJob::StartPdfToPostScriptConversion(
const scoped_refptr<base::RefCountedMemory>& bytes, const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Rect& content_area, const gfx::Rect& content_area,
......
...@@ -105,6 +105,10 @@ class PrintJob : public PrintJobWorkerOwner, ...@@ -105,6 +105,10 @@ class PrintJob : public PrintJobWorkerOwner,
const gfx::Rect& content_area, const gfx::Rect& content_area,
const gfx::Point& physical_offset, const gfx::Point& physical_offset,
bool ps_level2); bool ps_level2);
void StartPdfToTextConversion(
const scoped_refptr<base::RefCountedMemory>& bytes,
const gfx::Size& page_size);
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
protected: protected:
......
...@@ -189,8 +189,11 @@ void PrintViewManagerBase::OnDidPrintPage( ...@@ -189,8 +189,11 @@ void PrintViewManagerBase::OnDidPrintPage(
document->DebugDumpData(bytes.get(), FILE_PATH_LITERAL(".pdf")); document->DebugDumpData(bytes.get(), FILE_PATH_LITERAL(".pdf"));
const auto& settings = document->settings(); const auto& settings = document->settings();
if ((settings.printer_is_ps2() || settings.printer_is_ps3()) && if (settings.printer_is_textonly()) {
!base::FeatureList::IsEnabled(features::kDisablePostScriptPrinting)) { print_job_->StartPdfToTextConversion(bytes, params.page_size);
} else if ((settings.printer_is_ps2() || settings.printer_is_ps3()) &&
!base::FeatureList::IsEnabled(
features::kDisablePostScriptPrinting)) {
print_job_->StartPdfToPostScriptConversion(bytes, params.content_area, print_job_->StartPdfToPostScriptConversion(bytes, params.content_area,
params.physical_offsets, params.physical_offsets,
settings.printer_is_ps2()); settings.printer_is_ps2());
......
...@@ -91,18 +91,22 @@ void PrintingHandler::OnRenderPDFPagesToMetafile( ...@@ -91,18 +91,22 @@ void PrintingHandler::OnRenderPDFPagesToMetafile(
pdf_rendering_settings_ = settings; pdf_rendering_settings_ = settings;
chrome_pdf::SetPDFUseGDIPrinting(pdf_rendering_settings_.mode == chrome_pdf::SetPDFUseGDIPrinting(pdf_rendering_settings_.mode ==
PdfRenderSettings::Mode::GDI_TEXT); PdfRenderSettings::Mode::GDI_TEXT);
int postscript_level; int printing_mode;
switch (pdf_rendering_settings_.mode) { switch (pdf_rendering_settings_.mode) {
case PdfRenderSettings::Mode::TEXTONLY:
printing_mode = chrome_pdf::PrintingMode::kTextOnly;
break;
case PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2: case PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2:
postscript_level = 2; printing_mode = chrome_pdf::PrintingMode::kPostScript2;
break; break;
case PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3: case PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3:
postscript_level = 3; printing_mode = chrome_pdf::PrintingMode::kPostScript3;
break; break;
default: default:
postscript_level = 0; // Not using postscript. // Not using postscript or text only.
printing_mode = chrome_pdf::PrintingMode::kEmf;
} }
chrome_pdf::SetPDFPostscriptPrintingLevel(postscript_level); chrome_pdf::SetPDFUsePrintMode(printing_mode);
base::File pdf_file = IPC::PlatformFileForTransitToFile(pdf_transit); base::File pdf_file = IPC::PlatformFileForTransitToFile(pdf_transit);
int page_count = LoadPDF(std::move(pdf_file)); int page_count = LoadPDF(std::move(pdf_file));
......
...@@ -122,8 +122,8 @@ void SetPDFUseGDIPrinting(bool enable) { ...@@ -122,8 +122,8 @@ void SetPDFUseGDIPrinting(bool enable) {
PDFEngineExports::Get()->SetPDFUseGDIPrinting(enable); PDFEngineExports::Get()->SetPDFUseGDIPrinting(enable);
} }
void SetPDFPostscriptPrintingLevel(int postscript_level) { void SetPDFUsePrintMode(int mode) {
PDFEngineExports::Get()->SetPDFPostscriptPrintingLevel(postscript_level); PDFEngineExports::Get()->SetPDFUsePrintMode(mode);
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
......
...@@ -36,6 +36,14 @@ void PPP_ShutdownModule(); ...@@ -36,6 +36,14 @@ void PPP_ShutdownModule();
const void* PPP_GetInterface(const char* interface_name); const void* PPP_GetInterface(const char* interface_name);
#if defined(OS_WIN) #if defined(OS_WIN)
// Printing modes - type to convert PDF to for printing
enum PrintingMode {
kEmf = 0,
kTextOnly = 1,
kPostScript2 = 2,
kPostScript3 = 3,
};
// |pdf_buffer| is the buffer that contains the entire PDF document to be // |pdf_buffer| is the buffer that contains the entire PDF document to be
// rendered. // rendered.
// |buffer_size| is the size of |pdf_buffer| in bytes. // |buffer_size| is the size of |pdf_buffer| in bytes.
...@@ -83,7 +91,7 @@ void SetPDFEnsureTypefaceCharactersAccessible( ...@@ -83,7 +91,7 @@ void SetPDFEnsureTypefaceCharactersAccessible(
void SetPDFUseGDIPrinting(bool enable); void SetPDFUseGDIPrinting(bool enable);
void SetPDFPostscriptPrintingLevel(int postscript_level); void SetPDFUsePrintMode(int mode);
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
// |page_count| and |max_page_width| are optional and can be NULL. // |page_count| and |max_page_width| are optional and can be NULL.
......
...@@ -347,8 +347,7 @@ class PDFEngineExports { ...@@ -347,8 +347,7 @@ class PDFEngineExports {
PDFEnsureTypefaceCharactersAccessible func) = 0; PDFEnsureTypefaceCharactersAccessible func) = 0;
virtual void SetPDFUseGDIPrinting(bool enable) = 0; virtual void SetPDFUseGDIPrinting(bool enable) = 0;
virtual void SetPDFUsePrintMode(int mode) = 0;
virtual void SetPDFPostscriptPrintingLevel(int postscript_level) = 0;
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
// See the definition of RenderPDFPageToBitmap in pdf.cc for details. // See the definition of RenderPDFPageToBitmap in pdf.cc for details.
......
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "build/build_config.h"
#include "pdf/pdf.h"
#include "ppapi/c/pp_input_event.h" #include "ppapi/c/pp_input_event.h"
#include "ppapi/c/private/ppb_pdf.h" #include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/c/private/ppp_pdf.h" #include "ppapi/c/private/ppp_pdf.h"
#include "third_party/pdfium/public/fpdf_edit.h"
#include "third_party/pdfium/public/fpdf_fwlevent.h" #include "third_party/pdfium/public/fpdf_fwlevent.h"
#include "third_party/pdfium/public/fpdf_sysfontinfo.h" #include "third_party/pdfium/public/fpdf_sysfontinfo.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
...@@ -210,3 +213,10 @@ STATIC_ASSERT_ENUM(PP_PRIVATEDUPLEXMODE_NONE, DuplexUndefined); ...@@ -210,3 +213,10 @@ STATIC_ASSERT_ENUM(PP_PRIVATEDUPLEXMODE_NONE, DuplexUndefined);
STATIC_ASSERT_ENUM(PP_PRIVATEDUPLEXMODE_SIMPLEX, Simplex); STATIC_ASSERT_ENUM(PP_PRIVATEDUPLEXMODE_SIMPLEX, Simplex);
STATIC_ASSERT_ENUM(PP_PRIVATEDUPLEXMODE_SHORT_EDGE, DuplexFlipShortEdge); STATIC_ASSERT_ENUM(PP_PRIVATEDUPLEXMODE_SHORT_EDGE, DuplexFlipShortEdge);
STATIC_ASSERT_ENUM(PP_PRIVATEDUPLEXMODE_LONG_EDGE, DuplexFlipLongEdge); STATIC_ASSERT_ENUM(PP_PRIVATEDUPLEXMODE_LONG_EDGE, DuplexFlipLongEdge);
#if defined(OS_WIN)
STATIC_ASSERT_ENUM(chrome_pdf::kEmf, FPDF_PRINTMODE_EMF);
STATIC_ASSERT_ENUM(chrome_pdf::kTextOnly, FPDF_PRINTMODE_TEXTONLY);
STATIC_ASSERT_ENUM(chrome_pdf::kPostScript2, FPDF_PRINTMODE_POSTSCRIPT2);
STATIC_ASSERT_ENUM(chrome_pdf::kPostScript3, FPDF_PRINTMODE_POSTSCRIPT3);
#endif
...@@ -4154,10 +4154,9 @@ void PDFiumEngineExports::SetPDFUseGDIPrinting(bool enable) { ...@@ -4154,10 +4154,9 @@ void PDFiumEngineExports::SetPDFUseGDIPrinting(bool enable) {
FPDF_SetPrintTextWithGDI(enable); FPDF_SetPrintTextWithGDI(enable);
} }
void PDFiumEngineExports::SetPDFPostscriptPrintingLevel(int postscript_level) { void PDFiumEngineExports::SetPDFUsePrintMode(int mode) {
FPDF_SetPrintPostscriptLevel(postscript_level); FPDF_SetPrintMode(mode);
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
bool PDFiumEngineExports::RenderPDFPageToBitmap( bool PDFiumEngineExports::RenderPDFPageToBitmap(
......
...@@ -808,8 +808,7 @@ class PDFiumEngineExports : public PDFEngineExports { ...@@ -808,8 +808,7 @@ class PDFiumEngineExports : public PDFEngineExports {
PDFEnsureTypefaceCharactersAccessible func) override; PDFEnsureTypefaceCharactersAccessible func) override;
void SetPDFUseGDIPrinting(bool enable) override; void SetPDFUseGDIPrinting(bool enable) override;
void SetPDFUsePrintMode(int mode) override;
void SetPDFPostscriptPrintingLevel(int postscript_level) override;
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
bool RenderPDFPageToBitmap(const void* pdf_buffer, bool RenderPDFPageToBitmap(const void* pdf_buffer,
int pdf_buffer_size, int pdf_buffer_size,
......
...@@ -16,6 +16,7 @@ struct PdfRenderSettings { ...@@ -16,6 +16,7 @@ struct PdfRenderSettings {
enum Mode { enum Mode {
NORMAL = 0, NORMAL = 0,
#if defined(OS_WIN) #if defined(OS_WIN)
TEXTONLY,
GDI_TEXT, GDI_TEXT,
POSTSCRIPT_LEVEL2, POSTSCRIPT_LEVEL2,
POSTSCRIPT_LEVEL3, POSTSCRIPT_LEVEL3,
......
...@@ -37,6 +37,7 @@ class PRINTING_EXPORT PrintSettings { ...@@ -37,6 +37,7 @@ class PRINTING_EXPORT PrintSettings {
#if defined(OS_WIN) #if defined(OS_WIN)
enum PrinterType { enum PrinterType {
TYPE_NONE = 0, TYPE_NONE = 0,
TYPE_TEXTONLY,
TYPE_XPS, TYPE_XPS,
TYPE_POSTSCRIPT_LEVEL2, TYPE_POSTSCRIPT_LEVEL2,
TYPE_POSTSCRIPT_LEVEL3 TYPE_POSTSCRIPT_LEVEL3
...@@ -171,6 +172,9 @@ class PRINTING_EXPORT PrintSettings { ...@@ -171,6 +172,9 @@ class PRINTING_EXPORT PrintSettings {
bool print_text_with_gdi() const { return print_text_with_gdi_; } bool print_text_with_gdi() const { return print_text_with_gdi_; }
void set_printer_type(PrinterType type) { printer_type_ = type; } void set_printer_type(PrinterType type) { printer_type_ = type; }
bool printer_is_textonly() const {
return printer_type_ == PrinterType::TYPE_TEXTONLY;
}
bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS;} bool printer_is_xps() const { return printer_type_ == PrinterType::TYPE_XPS;}
bool printer_is_ps2() const { bool printer_is_ps2() const {
return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2; return printer_type_ == PrinterType::TYPE_POSTSCRIPT_LEVEL2;
......
...@@ -92,6 +92,9 @@ bool IsPrinterXPS(HDC hdc) { ...@@ -92,6 +92,9 @@ bool IsPrinterXPS(HDC hdc) {
return IsTechnology(hdc, kXPSDriver); return IsTechnology(hdc, kXPSDriver);
} }
bool IsPrinterTextOnly(HDC hdc) {
return ::GetDeviceCaps(hdc, TECHNOLOGY) == DT_CHARSTREAM;
}
} // namespace } // namespace
// static // static
...@@ -153,6 +156,11 @@ void PrintSettingsInitializerWin::InitPrintSettings( ...@@ -153,6 +156,11 @@ void PrintSettingsInitializerWin::InitPrintSettings(
PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL3); PrintSettings::PrinterType::TYPE_POSTSCRIPT_LEVEL3);
return; return;
} }
// Detects the generic / text only driver.
if (IsPrinterTextOnly(hdc)) {
print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_TEXTONLY);
return;
}
if (IsPrinterXPS(hdc)) { if (IsPrinterXPS(hdc)) {
print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_XPS); print_settings->set_printer_type(PrintSettings::PrinterType::TYPE_XPS);
return; return;
......
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