summaryrefslogtreecommitdiffstats
path: root/src/core/print_view_manager_qt.cpp
diff options
context:
space:
mode:
authorMichael Brüning <michael.bruning@qt.io>2018-02-26 14:38:13 +0100
committerKai Koehne <kai.koehne@qt.io>2018-03-06 07:26:35 +0000
commit66a6518422bb32a85a481088a213a790ffd48785 (patch)
tree920945700398fa97a6f8e734137971ca16c1d910 /src/core/print_view_manager_qt.cpp
parent0d9ba4179245d89e163494ea0a3652e790ec08a0 (diff)
Explicitly use custom margins for printing to pdf
3cec2ccb0ffdd41a41ab55d4c1ba88d4866e71d1 introduced a regression because it was assumed that the page was only printed to pdf when a filename was given. This is not the case when the pdf data is handed to the callback, though. Correct this by explicitly stating when margins should be used. Task-number: QTBUG-66654 Change-Id: I663f578ff5d01c77cc62e6f3756a17f78168a9aa Reviewed-by: Szabolcs David <davidsz@inf.u-szeged.hu> Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/print_view_manager_qt.cpp')
-rw-r--r--src/core/print_view_manager_qt.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/core/print_view_manager_qt.cpp b/src/core/print_view_manager_qt.cpp
index fef2cf51a..627afb01a 100644
--- a/src/core/print_view_manager_qt.cpp
+++ b/src/core/print_view_manager_qt.cpp
@@ -154,13 +154,14 @@ static base::DictionaryValue *createPrintSettings()
return printSettings;
}
-static base::DictionaryValue *createPrintSettingsFromQPageLayout(const QPageLayout &pageLayout, bool printToPdf)
+static base::DictionaryValue *createPrintSettingsFromQPageLayout(const QPageLayout &pageLayout,
+ bool useCustomMargins)
{
base::DictionaryValue *printSettings = createPrintSettings();
//Set page size attributes, chromium expects these in micrometers
QRectF pageSizeInMillimeter = pageLayout.pageSize().rect(QPageSize::Millimeter);
- if (!printToPdf) {
+ if (!useCustomMargins) {
// QPrinter will extend this size with its margins
QMarginsF margins = pageLayout.margins(QPageLayout::Millimeter);
pageSizeInMillimeter = pageSizeInMillimeter.marginsRemoved(margins);
@@ -170,7 +171,7 @@ static base::DictionaryValue *createPrintSettingsFromQPageLayout(const QPageLayo
sizeDict->SetInteger(printing::kSettingMediaSizeHeightMicrons, pageSizeInMillimeter.height() * kMicronsToMillimeter);
printSettings->Set(printing::kSettingMediaSize, std::move(sizeDict));
- if (printToPdf) {
+ if (useCustomMargins) {
// Apply page margins when printing to PDF
QMargins pageMarginsInPoints = pageLayout.marginsPoints();
std::unique_ptr<base::DictionaryValue> marginsDict(new base::DictionaryValue);
@@ -201,7 +202,8 @@ PrintViewManagerQt::~PrintViewManagerQt()
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
void PrintViewManagerQt::PrintToPDFFileWithCallback(const QPageLayout &pageLayout,
- bool printInColor, const QString &filePath,
+ bool printInColor,
+ const QString &filePath,
const PrintToPDFFileCallback& callback)
{
if (callback.is_null())
@@ -226,6 +228,7 @@ void PrintViewManagerQt::PrintToPDFFileWithCallback(const QPageLayout &pageLayou
void PrintViewManagerQt::PrintToPDFWithCallback(const QPageLayout &pageLayout,
bool printInColor,
+ bool useCustomMargins,
const PrintToPDFCallback& callback)
{
if (callback.is_null())
@@ -240,7 +243,7 @@ void PrintViewManagerQt::PrintToPDFWithCallback(const QPageLayout &pageLayout,
}
m_pdfPrintCallback = callback;
- if (!PrintToPDFInternal(pageLayout, printInColor)) {
+ if (!PrintToPDFInternal(pageLayout, printInColor, useCustomMargins)) {
content::BrowserThread::PostTask(content::BrowserThread::UI,
FROM_HERE,
base::Bind(callback, std::vector<char>()));
@@ -249,12 +252,14 @@ void PrintViewManagerQt::PrintToPDFWithCallback(const QPageLayout &pageLayout,
}
}
-bool PrintViewManagerQt::PrintToPDFInternal(const QPageLayout &pageLayout, bool printInColor)
+bool PrintViewManagerQt::PrintToPDFInternal(const QPageLayout &pageLayout,
+ const bool printInColor,
+ const bool useCustomMargins)
{
if (!pageLayout.isValid())
return false;
- m_printSettings.reset(createPrintSettingsFromQPageLayout(pageLayout, !m_pdfOutputPath.empty()));
+ m_printSettings.reset(createPrintSettingsFromQPageLayout(pageLayout, useCustomMargins));
m_printSettings->SetBoolean(printing::kSettingShouldPrintBackgrounds
, web_contents()->GetRenderViewHost()->GetWebkitPreferences().should_print_backgrounds);
m_printSettings->SetInteger(printing::kSettingColor,