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

Unified Diff: components/printing/renderer/print_web_view_helper.cc

Issue 2719443003: Reland of Add automated testing to check for page size with scaling (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | components/printing/test/mock_printer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/printing/renderer/print_web_view_helper.cc
diff --git a/components/printing/renderer/print_web_view_helper.cc b/components/printing/renderer/print_web_view_helper.cc
index b5e829ca1eeff6845049355eabb99c6d81a057b7..a793497bed148446d8f7829485c1d3bc41ee64d0 100644
--- a/components/printing/renderer/print_web_view_helper.cc
+++ b/components/printing/renderer/print_web_view_helper.cc
@@ -1843,9 +1843,15 @@
double css_scale_factor = 1.0f;
#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
- if (params.params.scale_factor >= kEpsilon)
- css_scale_factor = params.params.scale_factor;
+ if (params.params.scale_factor >= kEpsilon)
+ css_scale_factor = params.params.scale_factor;
#endif
+
+ // Save the original page size here to avoid rounding errors incurred by
+ // converting to pixels and back and by scaling the page for reflow and
+ // scaling back. Windows uses |page_size_in_dpi| for the actual page size
+ // so requires an accurate value.
+ gfx::Size original_page_size = params.params.page_size;
ComputePageLayoutInPointsForCss(frame, params.page_number, params.params,
ignore_css_margins_, &css_scale_factor,
&page_layout_in_points);
@@ -1853,19 +1859,10 @@
gfx::Rect content_area;
GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
&content_area);
- int dpi = static_cast<int>(params.params.dpi);
+
// Calculate the actual page size and content area in dpi.
if (page_size_in_dpi) {
- // Windows uses this for the actual page size. We have scaled page size
- // to get blink to reflow the page, so scale it back to the real size
- // before returning it.
- *page_size_in_dpi =
- gfx::Size(static_cast<int>(ConvertUnitDouble(page_size.width(),
- kPointsPerInch, dpi) *
- css_scale_factor),
- static_cast<int>(ConvertUnitDouble(page_size.height(),
- kPointsPerInch, dpi) *
- css_scale_factor));
+ *page_size_in_dpi = original_page_size;
}
if (content_area_in_dpi) {
« no previous file with comments | « no previous file | components/printing/test/mock_printer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698