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

Unified Diff: chrome/renderer/print_web_view_helper_win.cc

Issue 8585017: PrintPreview: Honor the print media page size and margin values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix conflicts Created 9 years 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
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 4ee351ba67cfc6c271a6d5aa113560abf9dac663..b3748a74e4259dba3f8571ef5a4313012df874b3 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -109,8 +109,8 @@ void PrintWebViewHelper::PrintPageInternal(
int page_number = params.page_number;
// Calculate the dpi adjustment.
- float scale_factor = static_cast<float>(params.params.desired_dpi /
- params.params.dpi);
+ double scale_factor = static_cast<float>(params.params.desired_dpi /
+ params.params.dpi);
// Render page for printing.
metafile.reset(RenderPage(params.params, &scale_factor, page_number, false,
@@ -146,8 +146,8 @@ void PrintWebViewHelper::PrintPageInternal(
bool PrintWebViewHelper::RenderPreviewPage(int page_number) {
PrintMsg_Print_Params print_params = print_preview_context_.print_params();
// Calculate the dpi adjustment.
- float scale_factor = static_cast<float>(print_params.desired_dpi /
- print_params.dpi);
+ double scale_factor = static_cast<float>(print_params.desired_dpi /
+ print_params.dpi);
scoped_ptr<Metafile> draft_metafile;
printing::Metafile* initial_render_metafile =
print_preview_context_.metafile();
@@ -178,37 +178,30 @@ bool PrintWebViewHelper::RenderPreviewPage(int page_number) {
}
Metafile* PrintWebViewHelper::RenderPage(
- const PrintMsg_Print_Params& params, float* scale_factor, int page_number,
+ const PrintMsg_Print_Params& params, double* scale_factor, int page_number,
bool is_preview, WebFrame* frame, Metafile* metafile) {
printing::PageSizeMargins page_layout_in_points;
+ *scale_factor = frame->getPrintPageShrink(page_number);
vandebo (ex-Chrome) 2011/12/14 19:05:38 Don't we need both scale factors? GetPageSizeANdM
kmadhusu 2011/12/19 09:52:19 Fixed.
GetPageSizeAndMarginsInPoints(frame, page_number, params,
- &page_layout_in_points);
-
- int width;
- int height;
- if (is_preview) {
- int dpi = static_cast<int>(params.dpi);
- int desired_dpi = printing::kPointsPerInch;
- width = ConvertUnit(params.page_size.width(), dpi, desired_dpi);
- height = ConvertUnit(params.page_size.height(), dpi, desired_dpi);
- } else {
+ ignore_css_margins_, fit_to_page_,
+ scale_factor, &page_layout_in_points);
+ gfx::Size page_size;
+ gfx::Rect content_area;
+ UpdatePageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
+ &content_area);
+ if (!is_preview) {
// 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.
- width = static_cast<int>(page_layout_in_points.content_width *
- params.max_shrink);
- height = static_cast<int>(page_layout_in_points.content_height *
- params.max_shrink);
+ page_size = gfx::Size(
+ static_cast<int>(page_layout_in_points.content_width *
+ params.max_shrink),
+ static_cast<int>(page_layout_in_points.content_height *
+ params.max_shrink));
}
- gfx::Size page_size(width, height);
- gfx::Rect content_area(
- static_cast<int>(page_layout_in_points.margin_left),
- static_cast<int>(page_layout_in_points.margin_top),
- static_cast<int>(page_layout_in_points.content_width),
- static_cast<int>(page_layout_in_points.content_height));
SkDevice* device = metafile->StartPageForVectorCanvas(
- page_size, content_area, frame->getPrintPageShrink(page_number));
+ page_size, content_area, *scale_factor);
DCHECK(device);
// The printPage method may take a reference to the canvas we pass down, so it
// can't be a stack object.
@@ -226,7 +219,7 @@ Metafile* PrintWebViewHelper::RenderPage(
// |page_number| is 0-based, so 1 is added.
PrintHeaderAndFooter(canvas.get(), page_number + 1,
print_preview_context_.total_page_count(),
- webkit_scale_factor, page_layout_in_points,
+ *scale_factor, page_layout_in_points,
*header_footer_info_);
}
@@ -264,14 +257,15 @@ Metafile* PrintWebViewHelper::RenderPage(
SetGraphicsMode(bitmap_dc, GM_ADVANCED);
void* bits = NULL;
BITMAPINFO hdr;
- gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader);
+ gfx::CreateBitmapHeader(page_size.width(), page_size.height(),
+ &hdr.bmiHeader);
base::win::ScopedBitmap hbitmap(CreateDIBSection(
bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0));
if (!hbitmap)
NOTREACHED() << "Raster bitmap creation for printing failed";
base::win::ScopedSelectObject selectBitmap(bitmap_dc, hbitmap);
- RECT rect = {0, 0, width, height };
+ RECT rect = { 0, 0, page_size.width(), page_size.height() };
HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
FillRect(bitmap_dc, &rect, whiteBrush);
« chrome/renderer/print_web_view_helper_mac.mm ('K') | « chrome/renderer/print_web_view_helper_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698