summaryrefslogtreecommitdiffstats
path: root/src/core/printing
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2019-05-14 17:02:45 +0200
committerSzabolcs David <davidsz@inf.u-szeged.hu>2019-06-04 15:34:48 +0200
commit7f89badd0e1b71dabb5a88d1330b08ce9d8b6eb7 (patch)
treecc4f7d878a60127c535804299d19e3e500d505dd /src/core/printing
parent8b848e4aee238edb58dba0ded8d773c8b70392f6 (diff)
Workaround for CSS orientation issues
Web content can define its orientation for printing using the @page rule in CSS. This creates some edge cases, for example when the pages are not uniform and some of them has different orientation than the others. The current version of desktop Chromium can't handle this perfectly: sometimes it renders portrait pages to landscape papers by cutting down the extra parts. This patch makes our result similar to Chromium's - by ignoring the user's orientation settings in QPrinter. Task-number: QTBUG-75092 Change-Id: Ifaea69c94b6ee1b6a83609cb15207a58554975f9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/printing')
-rw-r--r--src/core/printing/pdfium_document_wrapper_qt.cpp25
-rw-r--r--src/core/printing/pdfium_document_wrapper_qt.h5
2 files changed, 14 insertions, 16 deletions
diff --git a/src/core/printing/pdfium_document_wrapper_qt.cpp b/src/core/printing/pdfium_document_wrapper_qt.cpp
index 1be27f1c6..6f415b50b 100644
--- a/src/core/printing/pdfium_document_wrapper_qt.cpp
+++ b/src/core/printing/pdfium_document_wrapper_qt.cpp
@@ -50,11 +50,11 @@ int PdfiumDocumentWrapperQt::m_libraryUsers = 0;
class PdfiumPageWrapperQt {
public:
- PdfiumPageWrapperQt(FPDF_DOCUMENT data, int pageIndex, int targetWidth, int targetHeight)
+ PdfiumPageWrapperQt(FPDF_DOCUMENT data, int pageIndex)
: m_pageData(FPDF_LoadPage(data, pageIndex))
, m_width(FPDF_GetPageWidth(m_pageData))
, m_height(FPDF_GetPageHeight(m_pageData))
- , m_image(createImage(targetWidth, targetHeight))
+ , m_image(createImage())
{
}
@@ -77,16 +77,11 @@ public:
}
private:
- QImage createImage(int targetWidth, int targetHeight)
+ QImage createImage()
{
Q_ASSERT(m_pageData);
- if (targetWidth <= 0)
- targetWidth = m_width;
- if (targetHeight <= 0)
- targetHeight = m_height;
-
- QImage image(targetWidth, targetHeight, QImage::Format_ARGB32);
+ QImage image(m_width * 2, m_height * 2, QImage::Format_ARGB32);
Q_ASSERT(!image.isNull());
image.fill(0xFFFFFFFF);
@@ -112,9 +107,7 @@ private:
PdfiumDocumentWrapperQt::PdfiumDocumentWrapperQt(const void *pdfData, size_t size,
- const QSize& imageSize,
const char *password)
- : m_imageSize(imageSize * 2.0)
{
Q_ASSERT(pdfData);
Q_ASSERT(size);
@@ -137,11 +130,17 @@ QImage PdfiumDocumentWrapperQt::pageAsQImage(size_t index)
return QImage();
}
- PdfiumPageWrapperQt pageWrapper((FPDF_DOCUMENT)m_documentHandle, index,
- m_imageSize.width(), m_imageSize.height());
+ PdfiumPageWrapperQt pageWrapper((FPDF_DOCUMENT)m_documentHandle, index);
return pageWrapper.image();
}
+bool PdfiumDocumentWrapperQt::pageIsLandscape(size_t index)
+{
+ double width = 0, height = 0;
+ FPDF_GetPageSizeByIndex((FPDF_DOCUMENT)m_documentHandle, index, &width, &height);
+ return (width > height);
+}
+
PdfiumDocumentWrapperQt::~PdfiumDocumentWrapperQt()
{
FPDF_CloseDocument((FPDF_DOCUMENT)m_documentHandle);
diff --git a/src/core/printing/pdfium_document_wrapper_qt.h b/src/core/printing/pdfium_document_wrapper_qt.h
index 2dab268fc..121742aa3 100644
--- a/src/core/printing/pdfium_document_wrapper_qt.h
+++ b/src/core/printing/pdfium_document_wrapper_qt.h
@@ -61,17 +61,16 @@ class PdfiumPageWrapperQt;
class Q_WEBENGINECORE_PRIVATE_EXPORT PdfiumDocumentWrapperQt
{
public:
- PdfiumDocumentWrapperQt(const void *pdfData, size_t size, const QSize &imageSize,
- const char *password = nullptr);
+ PdfiumDocumentWrapperQt(const void *pdfData, size_t size, const char *password = nullptr);
virtual ~PdfiumDocumentWrapperQt();
QImage pageAsQImage(size_t index);
+ bool pageIsLandscape(size_t index);
int pageCount() const { return m_pageCount; }
private:
static int m_libraryUsers;
int m_pageCount;
void *m_documentHandle;
- QSize m_imageSize;
};
} // namespace QtWebEngineCore