From fbf32f1208e6d6556779ac955825ff7b6bf6a807 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Fri, 9 Sep 2016 03:20:17 +0200 Subject: [PATCH] Apply the correct page margins from the QPageLayout to Chromium printing If one passes a QPageLayout to printToPDF, surely one expects the margin settings contained in it to actually get applied. This is a partial backport of the much larger 5.8 commit af2535018b1553e351198f3d9c21538de1c328a1 (by Michael Bruning), limited to only the margin fix. --- src/core/print_view_manager_qt.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/print_view_manager_qt.cpp b/src/core/print_view_manager_qt.cpp index 4cb0e06..b773c24 100644 --- a/src/core/print_view_manager_qt.cpp +++ b/src/core/print_view_manager_qt.cpp @@ -115,6 +115,16 @@ static void applyQPageLayoutSettingsToDictionary(const QPageLayout& pageLayout, sizeDict->SetInteger(printing::kSettingMediaSizeHeightMicrons, pageSizeInMilimeter.height() * kMicronsToMillimeter); print_settings.Set(printing::kSettingMediaSize, std::move(sizeDict)); + // Apply page margins + QMargins pageMarginsInPoints = pageLayout.marginsPoints(); + scoped_ptr marginsDict(new base::DictionaryValue); + marginsDict->SetInteger(printing::kSettingMarginTop, pageMarginsInPoints.top()); + marginsDict->SetInteger(printing::kSettingMarginBottom, pageMarginsInPoints.bottom()); + marginsDict->SetInteger(printing::kSettingMarginLeft, pageMarginsInPoints.left()); + marginsDict->SetInteger(printing::kSettingMarginRight, pageMarginsInPoints.right()); + print_settings.Set(printing::kSettingMarginsCustom, std::move(marginsDict)); + print_settings.SetInteger(printing::kSettingMarginsType, printing::CUSTOM_MARGINS); + print_settings.SetBoolean(printing::kSettingLandscape, pageLayout.orientation() == QPageLayout::Landscape); // The following are standard settings that Chromium expects to be set. -- 2.1.0