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

Unified Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 7065011: Change printing of PDFs for preview on Windows to not rasterize. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/ppapi/ppapi_plugin_instance.cc
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index bee7a619635fcfe11a1cdfecc0ec0c3114cf6bfe..e18b11ca63e13ca898a57543c527765561a914df 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -67,7 +67,7 @@
#include "printing/metafile_impl.h"
#endif
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_WIN)
#include "printing/metafile.h"
#include "printing/metafile_skia_wrapper.h"
#endif
@@ -353,9 +353,6 @@ PluginInstance::PluginInstance(PluginDelegate* delegate,
plugin_selection_interface_(NULL),
plugin_zoom_interface_(NULL),
checked_for_plugin_messaging_interface_(false),
-#if defined(OS_LINUX)
- canvas_(NULL),
-#endif // defined(OS_LINUX)
plugin_print_interface_(NULL),
plugin_graphics_3d_interface_(NULL),
always_on_top_(false),
@@ -388,9 +385,6 @@ PluginInstance::~PluginInstance() {
module_->InstanceDeleted(this);
ResourceTracker::Get()->InstanceDeleted(pp_instance_);
-#if defined(OS_LINUX)
- ranges_.clear();
-#endif // defined(OS_LINUX)
}
// static
@@ -1125,10 +1119,10 @@ int PluginInstance::PrintBegin(const gfx::Rect& printable_area,
if (!num_pages)
return 0;
current_print_settings_ = print_settings;
-#if defined(OS_LINUX)
+#if WEBKIT_USING_SKIA
canvas_ = NULL;
ranges_.clear();
-#endif // defined(OS_LINUX)
+#endif // WEBKIT_USING_SKIA
return num_pages;
}
@@ -1136,13 +1130,17 @@ bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) {
DCHECK(plugin_print_interface_.get());
PP_PrintPageNumberRange_Dev page_range;
page_range.first_page_number = page_range.last_page_number = page_number;
-#if defined(OS_LINUX)
- ranges_.push_back(page_range);
- canvas_ = canvas;
- return true;
-#else
- return PrintPageHelper(&page_range, 1, canvas);
-#endif // defined(OS_LINUX)
+#if WEBKIT_USING_SKIA
+ // The canvas only has a metafile on it for print preview.
+ if(printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas)) {
Lei Zhang 2011/05/24 00:24:16 nit: space after if.
vandebo (ex-Chrome) 2011/05/24 05:48:38 Done.
+ ranges_.push_back(page_range);
+ canvas_ = canvas;
+ return true;
+ } else
+#endif // WEBKIT_USING_SKIA
+ {
+ return PrintPageHelper(&page_range, 1, canvas);
+ }
}
bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges,
@@ -1171,13 +1169,12 @@ bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges,
void PluginInstance::PrintEnd() {
// Keep a reference on the stack. See NOTE above.
scoped_refptr<PluginInstance> ref(this);
-#if defined(OS_LINUX)
- // This hack is here because all pages need to be written to PDF at once.
+#if WEBKIT_USING_SKIA
if (!ranges_.empty())
- PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_);
+ PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get());
canvas_ = NULL;
ranges_.clear();
-#endif // defined(OS_LINUX)
+#endif // WEBKIT_USING_SKIA
DCHECK(plugin_print_interface_.get());
if (plugin_print_interface_.get())
@@ -1321,31 +1318,37 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output,
CGContextRestoreGState(canvas);
}
#elif defined(OS_WIN)
- // On Windows, we now need to render the PDF to the DC that backs the
- // supplied canvas.
- HDC dc = skia::BeginPlatformPaint(canvas);
- gfx::Size size_in_pixels;
- size_in_pixels.set_width(
- printing::ConvertUnit(current_print_settings_.printable_area.size.width,
- static_cast<int>(printing::kPointsPerInch),
- current_print_settings_.dpi));
- size_in_pixels.set_height(
- printing::ConvertUnit(current_print_settings_.printable_area.size.height,
- static_cast<int>(printing::kPointsPerInch),
- current_print_settings_.dpi));
- // We need to render using the actual printer DPI (rendering to a smaller
- // set of pixels leads to a blurry output). However, we need to counter the
- // scaling up that will happen in the browser.
- XFORM xform = {0};
- xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) /
- static_cast<float>(current_print_settings_.dpi);
- ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
-
- ret = render_proc(buffer->mapped_buffer(), buffer->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);
- skia::EndPlatformPaint(canvas);
+ printing::Metafile* metafile =
+ printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
+ if (metafile) {
Lei Zhang 2011/05/24 00:24:16 maybe just add a quick comment to say this is the
vandebo (ex-Chrome) 2011/05/24 05:48:38 Done.
+ ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size());
+ } else {
+ // On Windows, we now need to render the PDF to the DC that backs the
+ // supplied canvas.
+ HDC dc = skia::BeginPlatformPaint(canvas);
+ gfx::Size size_in_pixels;
+ size_in_pixels.set_width(printing::ConvertUnit(
+ current_print_settings_.printable_area.size.width,
+ static_cast<int>(printing::kPointsPerInch),
+ current_print_settings_.dpi));
+ size_in_pixels.set_height(printing::ConvertUnit(
+ current_print_settings_.printable_area.size.height,
+ static_cast<int>(printing::kPointsPerInch),
+ current_print_settings_.dpi));
+ // We need to render using the actual printer DPI (rendering to a smaller
+ // set of pixels leads to a blurry output). However, we need to counter the
+ // scaling up that will happen in the browser.
+ XFORM xform = {0};
+ xform.eM11 = xform.eM22 = static_cast<float>(printing::kPointsPerInch) /
+ static_cast<float>(current_print_settings_.dpi);
+ ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
+
+ ret = render_proc(buffer->mapped_buffer(), buffer->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);
+ skia::EndPlatformPaint(canvas);
+ }
#endif // defined(OS_WIN)
return ret;
« webkit/plugins/ppapi/ppapi_plugin_instance.h ('K') | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698