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

Unified Diff: chrome/renderer/print_web_view_helper_win.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: Address comments 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
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | printing/printing.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/print_web_view_helper_win.cc
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index dda6b9681138d1bcd9cd8fa48109492484982915..4151818e1e18d1acc083803c2d740a85f00816d5 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -11,9 +11,11 @@
#include "chrome/common/print_messages.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
+#include "printing/metafile_skia_wrapper.h"
#include "printing/units.h"
#include "skia/ext/vector_canvas.h"
#include "skia/ext/vector_platform_device_emf_win.h"
+#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "ui/gfx/gdi_util.h"
#include "ui/gfx/point.h"
@@ -154,18 +156,24 @@ bool PrintWebViewHelper::CreatePreviewDocument(
break;
float scale_factor = shrink;
RenderPage(print_params, &scale_factor,
- static_cast<int>(params.pages[i]), true, frame, &metafile);
+ static_cast<int>(params.pages[i]), true, frame, &metafile);
}
}
+ // Ensure that printing has finished before we start cleaning up and
+ // allocating buffers; this causes prep_frame_view to flush anything pending
+ // into the metafile. Then we can get the final size and copy it into a
+ // shared segment.
+ prep_frame_view.FinishPrinting();
+
+ if (!metafile->FinishDocument())
+ NOTREACHED();
+
// Calculate the time taken to render the requested page for preview and add
// the net time in the histogram.
UMA_HISTOGRAM_TIMES("PrintPreview.RenderTime",
base::TimeTicks::Now() - begin_time);
- if (!metafile->FinishDocument())
- NOTREACHED();
-
// Get the size of the compiled metafile.
uint32 buf_size = metafile->GetDataSize();
DCHECK_GT(buf_size, 128u);
@@ -223,9 +231,16 @@ void PrintWebViewHelper::RenderPage(
skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas(
page_size, content_area, frame->getPrintPageShrink(page_number));
DCHECK(device);
- skia::VectorCanvas canvas(device);
+ // The printPage method may take a reference to the canvas we pass down, so it
+ // can't be a stack object.
+ SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
+ canvas->unref(); // SkRefPtr and new both took a reference.
+ if (is_preview) {
+ printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(),
+ metafile->get());
+ }
- float webkit_scale_factor = frame->printPage(page_number, &canvas);
+ float webkit_scale_factor = frame->printPage(page_number, canvas.get());
if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
NOTREACHED() << "Printing page " << page_number << " failed.";
} else {
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | printing/printing.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698