summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 16:12:13 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 16:12:13 +0000
commit220cf4d0b875b6c066e3a9bcab152f5572834d4f (patch)
treea187f00660f6c0f5a8f1c2f3a9eddd65db256d51 /webkit
parente2ca8cc8afff4e85bdb090e487c9b1ff70b677c8 (diff)
downloadchromium_src-220cf4d0b875b6c066e3a9bcab152f5572834d4f.zip
chromium_src-220cf4d0b875b6c066e3a9bcab152f5572834d4f.tar.gz
chromium_src-220cf4d0b875b6c066e3a9bcab152f5572834d4f.tar.bz2
Change printing of PDFs for preview on Windows to not rasterize.
Also cleaned up a few hacks. BUG=80220 TEST=Navigate to a PDF and start print preview. Review URL: http://codereview.chromium.org/7065011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86431 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc95
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h16
2 files changed, 59 insertions, 52 deletions
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index bee7a61..787393a 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)) {
+ 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,39 @@ 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) {
+ // We only have a metafile when doing print preview, so we just want to
+ // pass the PDF off to preview.
+ 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;
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index 5ce4fcf..58a1186 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -24,6 +24,7 @@
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h"
#include "ui/gfx/rect.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
@@ -375,20 +376,21 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
// to keep the pixels valid until CGContextEndPage is called. We use this
// variable to hold on to the pixels.
scoped_refptr<PPB_ImageData_Impl> last_printed_page_;
-#elif defined(OS_LINUX)
- // On Linux, all pages need to be written to a PDF file in one shot. However,
- // when users print only a subset of all the pages, it is impossible to know
- // if a call to PrintPage() is the last call. Thus in PrintPage(), just store
- // the page number in |ranges_|.
+#endif // defined(OS_MACOSX)
+#if WEBKIT_USING_SKIA
+ // When printing to PDF (print preview, Linux) the entire document goes into
+ // one metafile. However, when users print only a subset of all the pages,
+ // it is impossible to know if a call to PrintPage() is the last call.
+ // Thus in PrintPage(), just store the page number in |ranges_|.
// The hack is in PrintEnd(), where a valid |canvas_| is preserved in
// PrintWebViewHelper::PrintPages. This makes it possible to generate the
// entire PDF given the variables below:
//
// The most recently used WebCanvas, guaranteed to be valid.
- WebKit::WebCanvas* canvas_;
+ SkRefPtr<WebKit::WebCanvas> canvas_;
// An array of page ranges.
std::vector<PP_PrintPageNumberRange_Dev> ranges_;
-#endif // defined(OS_LINUX)
+#endif // WEBKIT_USING_SKIA
// The plugin print interface. This nested struct adds functions needed for
// backwards compatibility.