| 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);
|
| }
|
|
|