Commit af05a799 authored by kmadhusu@chromium.org's avatar kmadhusu@chromium.org

Clean up windows printing workflow.

BUG=none
TEST=printing works after code change.

Review URL: http://codereview.chromium.org/6374004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71960 0039d316-1c4b-4281-b951-d872f2087c98
parent fa810229
...@@ -401,13 +401,16 @@ void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( ...@@ -401,13 +401,16 @@ void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters(
static_cast<int>(ConvertUnitDouble(content_height_in_points, static_cast<int>(ConvertUnitDouble(content_height_in_points,
printing::kPointsPerInch, dpi))); printing::kPointsPerInch, dpi)));
double page_width_in_points = content_width_in_points +
margin_left_in_points + margin_right_in_points;
double page_height_in_points = content_height_in_points +
margin_top_in_points + margin_bottom_in_points;
params->page_size = gfx::Size( params->page_size = gfx::Size(
static_cast<int>(ConvertUnitDouble(content_width_in_points + static_cast<int>(ConvertUnitDouble(
margin_left_in_points + margin_right_in_points, page_width_in_points, printing::kPointsPerInch, dpi)),
printing::kPointsPerInch, dpi)), static_cast<int>(ConvertUnitDouble(
static_cast<int>(ConvertUnitDouble(content_height_in_points + page_height_in_points, printing::kPointsPerInch, dpi)));
margin_top_in_points + margin_bottom_in_points,
printing::kPointsPerInch, dpi)));
params->margin_top = static_cast<int>(ConvertUnitDouble( params->margin_top = static_cast<int>(ConvertUnitDouble(
margin_top_in_points, printing::kPointsPerInch, dpi)); margin_top_in_points, printing::kPointsPerInch, dpi));
......
...@@ -73,59 +73,53 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, ...@@ -73,59 +73,53 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
DCHECK(hdc); DCHECK(hdc);
skia::PlatformDevice::InitializeDC(hdc); skia::PlatformDevice::InitializeDC(hdc);
int page_number = params.page_number;
double content_width_in_points; double content_width_in_points;
double content_height_in_points; double content_height_in_points;
double margin_top_in_points; GetPageSizeAndMarginsInPoints(frame, page_number, params.params,
double margin_right_in_points; &content_width_in_points, &content_height_in_points, NULL, NULL, NULL,
double margin_bottom_in_points; NULL);
double margin_left_in_points;
GetPageSizeAndMarginsInPoints(frame,
params.page_number,
params.params,
&content_width_in_points,
&content_height_in_points,
&margin_top_in_points,
&margin_right_in_points,
&margin_bottom_in_points,
&margin_left_in_points);
// 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>(content_width_in_points *
params.params.max_shrink);
int size_y = static_cast<int>(content_height_in_points *
params.params.max_shrink);
// Calculate the dpi adjustment. // Calculate the dpi adjustment.
float shrink = static_cast<float>(params.params.desired_dpi / float scale_factor = static_cast<float>(params.params.desired_dpi /
params.params.dpi); params.params.dpi);
// Since WebKit extends the page width depending on the magical |scale_factor|
// we make sure the canvas covers the worst case scenario (x2.0 currently).
// PrintContext will then set the correct clipping region.
int width = static_cast<int>(content_width_in_points *
params.params.max_shrink);
int height = static_cast<int>(content_height_in_points *
params.params.max_shrink);
#if 0 #if 0
// TODO(maruel): This code is kept for testing until the 100% GDI drawing // TODO(maruel): This code is kept for testing until the 100% GDI drawing
// code is stable. maruels use this code's output as a reference when the // code is stable. maruels use this code's output as a reference when the
// GDI drawing code fails. // GDI drawing code fails.
// Mix of Skia and GDI based. // Mix of Skia and GDI based.
skia::PlatformCanvas canvas(size_x, size_y, true); skia::PlatformCanvas canvas(width, height, true);
canvas.drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); canvas.drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
float webkit_shrink = frame->printPage(params.page_number, &canvas); float webkit_scale_factor = frame->printPage(page_number, &canvas);
if (shrink <= 0 || webkit_shrink <= 0) { if (scale_factor <= 0 || webkit_scale_factor <= 0) {
NOTREACHED() << "Printing page " << params.page_number << " failed."; NOTREACHED() << "Printing page " << page_number << " failed.";
} else { } else {
// Update the dpi adjustment with the "page shrink" calculated in webkit. // Update the dpi adjustment with the "page |scale_factor|" calculated
shrink /= webkit_shrink; // in webkit.
scale_factor /= webkit_scale_factor;
} }
// Create a BMP v4 header that we can serialize. // Create a BMP v4 header that we can serialize.
BITMAPV4HEADER bitmap_header; BITMAPV4HEADER bitmap_header;
gfx::CreateBitmapV4Header(size_x, size_y, &bitmap_header); gfx::CreateBitmapV4Header(width, height, &bitmap_header);
const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true); const SkBitmap& src_bmp = canvas.getDevice()->accessBitmap(true);
SkAutoLockPixels src_lock(src_bmp); SkAutoLockPixels src_lock(src_bmp);
int retval = StretchDIBits(hdc, int retval = StretchDIBits(hdc,
0, 0,
0, 0,
size_x, size_y, width, height,
0, 0, 0, 0,
size_x, size_y, width, height,
src_bmp.getPixels(), src_bmp.getPixels(),
reinterpret_cast<BITMAPINFO*>(&bitmap_header), reinterpret_cast<BITMAPINFO*>(&bitmap_header),
DIB_RGB_COLORS, DIB_RGB_COLORS,
...@@ -133,13 +127,14 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, ...@@ -133,13 +127,14 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
DCHECK(retval != GDI_ERROR); DCHECK(retval != GDI_ERROR);
#else #else
// 100% GDI based. // 100% GDI based.
skia::VectorCanvas canvas(hdc, size_x, size_y); skia::VectorCanvas canvas(hdc, width, height);
float webkit_shrink = frame->printPage(params.page_number, &canvas); float webkit_scale_factor = frame->printPage(page_number, &canvas);
if (shrink <= 0 || webkit_shrink <= 0) { if (scale_factor <= 0 || webkit_scale_factor <= 0) {
NOTREACHED() << "Printing page " << params.page_number << " failed."; NOTREACHED() << "Printing page " << page_number << " failed.";
} else { } else {
// Update the dpi adjustment with the "page shrink" calculated in webkit. // Update the dpi adjustment with the "page scale_factor" calculated
shrink /= webkit_shrink; // in webkit.
scale_factor /= webkit_scale_factor;
} }
#endif #endif
...@@ -163,7 +158,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, ...@@ -163,7 +158,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
SetGraphicsMode(bitmap_dc, GM_ADVANCED); SetGraphicsMode(bitmap_dc, GM_ADVANCED);
void* bits = NULL; void* bits = NULL;
BITMAPINFO hdr; BITMAPINFO hdr;
gfx::CreateBitmapHeader(size_x, size_y, &hdr.bmiHeader); gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader);
HBITMAP hbitmap = CreateDIBSection( HBITMAP hbitmap = CreateDIBSection(
bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0); bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0);
if (!hbitmap) { if (!hbitmap) {
...@@ -171,7 +166,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, ...@@ -171,7 +166,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
} }
HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap);
RECT rect = {0, 0, size_x, size_y }; RECT rect = {0, 0, width, height };
HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
FillRect(bitmap_dc, &rect, whiteBrush); FillRect(bitmap_dc, &rect, whiteBrush);
...@@ -204,29 +199,14 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, ...@@ -204,29 +199,14 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
ViewHostMsg_DidPrintPage_Params page_params; ViewHostMsg_DidPrintPage_Params page_params;
page_params.data_size = 0; page_params.data_size = 0;
page_params.metafile_data_handle = NULL; page_params.metafile_data_handle = NULL;
page_params.page_number = params.page_number; page_params.page_number = page_number;
page_params.document_cookie = params.params.document_cookie; page_params.document_cookie = params.params.document_cookie;
page_params.actual_shrink = shrink; page_params.actual_shrink = scale_factor;
page_params.page_size = gfx::Size( page_params.page_size = params.params.page_size;
static_cast<int>(ConvertUnitDouble( page_params.content_area = gfx::Rect(params.params.margin_left,
content_width_in_points + params.params.margin_top, params.params.printable_size.width(),
margin_left_in_points + margin_right_in_points, params.params.printable_size.height());
kPointsPerInch, params.params.dpi)), page_params.has_visible_overlays = frame->isPageBoxVisible(page_number);
static_cast<int>(ConvertUnitDouble(
content_height_in_points +
margin_top_in_points + margin_bottom_in_points,
kPointsPerInch, params.params.dpi)));
page_params.content_area = gfx::Rect(
static_cast<int>(ConvertUnitDouble(
margin_left_in_points, kPointsPerInch, params.params.dpi)),
static_cast<int>(ConvertUnitDouble(
margin_top_in_points, kPointsPerInch, params.params.dpi)),
static_cast<int>(ConvertUnitDouble(
content_width_in_points, kPointsPerInch, params.params.dpi)),
static_cast<int>(ConvertUnitDouble(
content_height_in_points, kPointsPerInch, params.params.dpi)));
page_params.has_visible_overlays =
frame->isPageBoxVisible(params.page_number);
base::SharedMemory shared_buf; base::SharedMemory shared_buf;
// http://msdn2.microsoft.com/en-us/library/ms535522.aspx // http://msdn2.microsoft.com/en-us/library/ms535522.aspx
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment