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

Unified Diff: src/chrome/renderer/print_web_view_helper.cc

Issue 196021: Implement PrintPageAsJPEG feature for Print Preview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/
Patch Set: '' Created 11 years, 3 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 | « src/chrome/renderer/print_web_view_helper.h ('k') | src/chrome/renderer/render_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/chrome/renderer/print_web_view_helper.cc
===================================================================
--- src/chrome/renderer/print_web_view_helper.cc (revision 25428)
+++ src/chrome/renderer/print_web_view_helper.cc (working copy)
@@ -5,6 +5,7 @@
#include "chrome/renderer/print_web_view_helper.h"
#include "app/l10n_util.h"
+#include "base/gfx/jpeg_codec.h"
#include "base/logging.h"
#include "chrome/common/render_messages.h"
#include "chrome/renderer/render_view.h"
@@ -139,6 +140,41 @@
}
}
+void PrintWebViewHelper::PrintPageAsJPEG(
+ const ViewMsg_PrintPage_Params& params,
+ WebFrame* frame,
+ float zoom_factor,
+ std::vector<unsigned char>* image_data) {
+ PrepareFrameAndViewForPrint prep_frame_view(params.params,
+ frame,
+ frame->view());
+ const gfx::Size& canvas_size(prep_frame_view.GetPrintCanvasSize());
+
+ // Since WebKit extends the page width depending on the magical shrink
+ // factor we make sure the canvas covers the worst case scenario
+ // (x2.0 currently). PrintContext will then set the correct clipping region.
+ int size_x = static_cast<int>(canvas_size.width() * params.params.max_shrink);
+ int size_y = static_cast<int>(canvas_size.height() *
+ params.params.max_shrink);
+
+ // Access the bitmap from the canvas device.
+ skia::PlatformCanvas canvas(size_x, size_y, true);
+ frame->printPage(params.page_number, &canvas);
+ const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false);
+
+ // Encode the SkBitmap to jpeg.
+ SkAutoLockPixels image_lock(bitmap);
+ bool encoded = JPEGCodec::Encode(
+ reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
+ JPEGCodec::FORMAT_BGRA,
+ static_cast<int>(bitmap.width() * zoom_factor),
+ static_cast<int>(bitmap.height() * zoom_factor),
+ static_cast<int>(bitmap.rowBytes()),
+ 90,
+ image_data);
+ DCHECK(encoded);
+}
+
bool PrintWebViewHelper::Send(IPC::Message* msg) {
return render_view_->Send(msg);
}
« no previous file with comments | « src/chrome/renderer/print_web_view_helper.h ('k') | src/chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698