diff options
-rw-r--r-- | chrome/common/chrome_utility_messages.h | 6 | ||||
-rw-r--r-- | chrome/service/cloud_print/print_system_win.cc | 14 | ||||
-rw-r--r-- | chrome/service/service_utility_process_host.cc | 6 | ||||
-rw-r--r-- | chrome/service/service_utility_process_host.h | 4 | ||||
-rw-r--r-- | chrome/utility/chrome_content_utility_client.cc | 15 | ||||
-rw-r--r-- | chrome/utility/chrome_content_utility_client.h | 5 | ||||
-rw-r--r-- | printing/pdf_render_settings.h | 44 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 5 |
8 files changed, 76 insertions, 23 deletions
diff --git a/chrome/common/chrome_utility_messages.h b/chrome/common/chrome_utility_messages.h index d808f8d..9e51281 100644 --- a/chrome/common/chrome_utility_messages.h +++ b/chrome/common/chrome_utility_messages.h @@ -17,6 +17,7 @@ #include "ipc/ipc_message_macros.h" #include "printing/backend/print_backend.h" #include "printing/page_range.h" +#include "printing/pdf_render_settings.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/rect.h" @@ -74,11 +75,10 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_DecodeImageBase64, std::string) // base64 encoded image contents // Tell the utility process to render the given PDF into a metafile. -IPC_MESSAGE_CONTROL5(ChromeUtilityMsg_RenderPDFPagesToMetafile, +IPC_MESSAGE_CONTROL4(ChromeUtilityMsg_RenderPDFPagesToMetafile, base::PlatformFile, // PDF file FilePath, // Location for output metafile - gfx::Rect, // Render Area - int, // DPI + printing::PdfRenderSettings, // PDF render settitngs std::vector<printing::PageRange>) // Tell the utility process to parse a JSON string into a Value object. diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc index 5566b1a..9ea4d1f 100644 --- a/chrome/service/cloud_print/print_system_win.cc +++ b/chrome/service/cloud_print/print_system_win.cc @@ -24,6 +24,7 @@ #include "printing/backend/win_helper.h" #include "printing/emf_win.h" #include "printing/page_range.h" +#include "printing/pdf_render_settings.h" #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/rect.h" @@ -548,10 +549,15 @@ class PrintSystemWin : public PrintSystem { BelongsToCurrentThread()); scoped_ptr<ServiceUtilityProcessHost> utility_host( new ServiceUtilityProcessHost(this, client_message_loop_proxy)); - if (utility_host->StartRenderPDFPagesToMetafile(pdf_path, - render_area, - render_dpi, - page_ranges)) { + // TODO(gene): For now we disabling autorotation for CloudPrinting. + // Landscape/Portrait setting is passed in the print ticket and + // server is generating portrait PDF always. + // We should enable autorotation once server will be able to generate + // PDF that matches paper size and orientation. + if (utility_host->StartRenderPDFPagesToMetafile( + pdf_path, + printing::PdfRenderSettings(render_area, render_dpi, false), + page_ranges)) { // The object will self-destruct when the child process dies. utility_host.release(); } diff --git a/chrome/service/service_utility_process_host.cc b/chrome/service/service_utility_process_host.cc index 760fc23..cbdac15 100644 --- a/chrome/service/service_utility_process_host.cc +++ b/chrome/service/service_utility_process_host.cc @@ -38,8 +38,7 @@ ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( const FilePath& pdf_path, - const gfx::Rect& render_area, - int render_dpi, + const printing::PdfRenderSettings& render_settings, const std::vector<printing::PageRange>& page_ranges) { #if !defined(OS_WIN) // This is only implemented on Windows (because currently it is only needed @@ -79,8 +78,7 @@ bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( new ChromeUtilityMsg_RenderPDFPagesToMetafile( pdf_file_in_utility_process, metafile_path_, - render_area, - render_dpi, + render_settings, page_ranges)); #endif // !defined(OS_WIN) } diff --git a/chrome/service/service_utility_process_host.h b/chrome/service/service_utility_process_host.h index f24bd3a..df9fc42 100644 --- a/chrome/service/service_utility_process_host.h +++ b/chrome/service/service_utility_process_host.h @@ -21,6 +21,7 @@ #include "base/task.h" #include "ipc/ipc_channel.h" #include "chrome/service/service_child_process_host.h" +#include "printing/pdf_render_settings.h" class CommandLine; class ScopedTempDir; @@ -97,8 +98,7 @@ class ServiceUtilityProcessHost : public ServiceChildProcessHost { // pages than the specified page ranges, it will render as many as available. bool StartRenderPDFPagesToMetafile( const FilePath& pdf_path, - const gfx::Rect& render_area, - int render_dpi, + const printing::PdfRenderSettings& render_settings, const std::vector<printing::PageRange>& page_ranges); // Starts a process to get capabilities and defaults for the specified diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc index a939f82..39c3dd7 100644 --- a/chrome/utility/chrome_content_utility_client.cc +++ b/chrome/utility/chrome_content_utility_client.cc @@ -171,16 +171,16 @@ void ChromeContentUtilityClient::OnDecodeImageBase64( void ChromeContentUtilityClient::OnRenderPDFPagesToMetafile( base::PlatformFile pdf_file, const FilePath& metafile_path, - const gfx::Rect& render_area, - int render_dpi, + const printing::PdfRenderSettings& pdf_render_settings, const std::vector<printing::PageRange>& page_ranges) { bool succeeded = false; #if defined(OS_WIN) int highest_rendered_page_number = 0; succeeded = RenderPDFToWinMetafile(pdf_file, metafile_path, - render_area, - render_dpi, + pdf_render_settings.area(), + pdf_render_settings.dpi(), + pdf_render_settings.autorotate(), page_ranges, &highest_rendered_page_number); if (succeeded) { @@ -200,7 +200,8 @@ typedef bool (*RenderPDFPageToDCProc)( const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, int bounds_width, int bounds_height, bool fit_to_bounds, - bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds); + bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds, + bool autorotate); typedef bool (*GetPDFDocInfoProc)(const unsigned char* pdf_buffer, int buffer_size, int* page_count, @@ -249,6 +250,7 @@ bool ChromeContentUtilityClient::RenderPDFToWinMetafile( const FilePath& metafile_path, const gfx::Rect& render_area, int render_dpi, + bool autorotate, const std::vector<printing::PageRange>& page_ranges, int* highest_rendered_page_number) { *highest_rendered_page_number = -1; @@ -323,7 +325,8 @@ bool ChromeContentUtilityClient::RenderPDFToWinMetafile( if (render_proc(&buffer.front(), buffer.size(), page_number, metafile.context(), render_dpi, render_dpi, render_area.x(), render_area.y(), render_area.width(), - render_area.height(), true, false, true, true)) + render_area.height(), true, false, true, true, + autorotate)) if (*highest_rendered_page_number < page_number) *highest_rendered_page_number = page_number; ret = true; diff --git a/chrome/utility/chrome_content_utility_client.h b/chrome/utility/chrome_content_utility_client.h index b1ef6c3..005fd5e 100644 --- a/chrome/utility/chrome_content_utility_client.h +++ b/chrome/utility/chrome_content_utility_client.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/platform_file.h" #include "content/utility/content_utility_client.h" +#include "printing/pdf_render_settings.h" class ExternalProcessImporterBridge; class FilePath; @@ -55,8 +56,7 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient { void OnRenderPDFPagesToMetafile( base::PlatformFile pdf_file, const FilePath& metafile_path, - const gfx::Rect& render_area, - int render_dpi, + const printing::PdfRenderSettings& pdf_render_settings, const std::vector<printing::PageRange>& page_ranges); void OnParseJSON(const std::string& json); @@ -68,6 +68,7 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient { const FilePath& metafile_path, const gfx::Rect& render_area, int render_dpi, + bool autorotate, const std::vector<printing::PageRange>& page_ranges, int* highest_rendered_page_number); #endif // defined(OS_WIN) diff --git a/printing/pdf_render_settings.h b/printing/pdf_render_settings.h new file mode 100644 index 0000000..3c788cc --- /dev/null +++ b/printing/pdf_render_settings.h @@ -0,0 +1,44 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PRINTING_PDF_RENDER_SETTINGS_H_ +#define PRINTING_PDF_RENDER_SETTINGS_H_ + +#include "base/tuple.h" +#include "ipc/ipc_param_traits.h" +#include "printing/printing_export.h" +#include "ui/gfx/rect.h" + +namespace printing { + +// Defining PDF rendering settings here as a Tuple as following: +// gfx::Rect - render area +// int - render dpi +// bool - autorotate pages to fit paper +typedef Tuple3<gfx::Rect, int, bool> PdfRenderSettingsBase; + +struct PdfRenderSettings : public PdfRenderSettingsBase { + public: + PdfRenderSettings() : PdfRenderSettingsBase() {} + PdfRenderSettings(gfx::Rect area, int dpi, bool autorotate) + : PdfRenderSettingsBase(area, dpi, autorotate) {} + ~PdfRenderSettings() {} + + const gfx::Rect& area() const { return a; } + int dpi() const { return b; } + bool autorotate() const { return c; } +}; + +} // namespace printing + +namespace IPC { +template <> +struct SimilarTypeTraits<printing::PdfRenderSettings> { + typedefprinting::PdfRenderSettingsBase Type; +}; + +} // namespace IPC + +#endif // PRINTING_PDF_RENDER_SETTINGS_H_ + diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 4ea90fc..6df29ee 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -126,7 +126,8 @@ typedef bool (*RenderPDFPageToDCProc)( const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, int bounds_width, int bounds_height, bool fit_to_bounds, - bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds); + bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds, + bool autorotate); #endif // defined(OS_WIN) namespace { @@ -1158,7 +1159,7 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, ret = render_proc(static_cast<unsigned char*>(mapper.data()), mapper.size(), 0, dc, current_print_settings_.dpi, current_print_settings_.dpi, 0, 0, size_in_pixels.width(), - size_in_pixels.height(), true, false, true, true); + size_in_pixels.height(), true, false, true, true, true); skia::EndPlatformPaint(canvas); } #endif // defined(OS_WIN) |