summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-08-26 16:47:31 +0900
committerAndras Timar <andras.timar@collabora.com>2021-08-29 08:59:13 +0200
commit825b08a9b5df984bf5091ec94fbfe78721c15a45 (patch)
tree29f2a9331a083a2aed6ffa743841123ecb1fbdb1 /vcl
parent2eca9fda89bb200cd1f34f5a272f2197a564a364 (diff)
Take the PDF graphic rendering DPI into account when exporting
Change-Id: I1d3465fc7357e6991161d5a96bcd70c53c55f244 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121072 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/inc/pdf/PdfConfig.hxx18
-rw-r--r--vcl/source/filter/ipdf/pdfread.cxx20
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx10
-rw-r--r--vcl/source/pdf/PdfConfig.cxx32
5 files changed, 61 insertions, 20 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 082cc64dcef4..1916292b5c36 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -318,6 +318,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/gdi/scrptrun \
vcl/source/gdi/CommonSalLayout \
vcl/source/gdi/TypeSerializer \
+ vcl/source/pdf/PdfConfig \
vcl/source/pdf/PDFiumLibrary \
vcl/source/pdf/ExternalPDFStreams \
vcl/source/graphic/GraphicID \
diff --git a/vcl/inc/pdf/PdfConfig.hxx b/vcl/inc/pdf/PdfConfig.hxx
new file mode 100644
index 000000000000..235fd008ea2b
--- /dev/null
+++ b/vcl/inc/pdf/PdfConfig.hxx
@@ -0,0 +1,18 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+namespace vcl::pdf
+{
+double getDefaultPdfResolutionDpi();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index acc45bc4d9e4..ef8862c0d1a3 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -18,6 +18,7 @@
#include <fpdf_formfill.h>
#endif
+#include <pdf/PdfConfig.hxx>
#include <vcl/graph.hxx>
#include <bitmapwriteaccess.hxx>
#include <unotools/ucbstreamhelper.hxx>
@@ -147,27 +148,12 @@ VectorGraphicDataArray createVectorGraphicDataArray(SvStream& rStream)
namespace vcl
{
-/// Get the default PDF rendering resolution in DPI.
-static double getDefaultPdfResolutionDpi()
-{
- // If an overriding default is set, use it.
- const char* envar = ::getenv("PDFIMPORT_RESOLUTION_DPI");
- if (envar)
- {
- const double dpi = atof(envar);
- if (dpi > 0)
- return dpi;
- }
-
- // Fallback to a sensible default.
- return 96.;
-}
-
size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBitmaps,
const size_t nFirstPage, int nPages, const basegfx::B2DTuple* pSizeHint)
{
#if HAVE_FEATURE_PDFIUM
- static const double fResolutionDPI = getDefaultPdfResolutionDpi();
+ static const double fResolutionDPI = vcl::pdf::getDefaultPdfResolutionDpi();
+
auto pPdfium = vcl::pdf::PDFiumLibrary::get();
// Load the buffer using pdfium.
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 70038fa3fb2d..8b435678f93d 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -75,6 +75,7 @@
#include <bitmapwriteaccess.hxx>
#include <impglyphitem.hxx>
#include <pdf/objectcopier.hxx>
+#include <pdf/PdfConfig.hxx>
#include "pdfwriter_impl.hxx"
@@ -8666,11 +8667,14 @@ void PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
return;
// Count /Matrix and /BBox.
- // vcl::ImportPDF() works with 96 DPI so use the same values here, too.
+ // vcl::ImportPDF() uses getDefaultPdfResolutionDpi to set the desired
+ // rendering DPI so we have to take into account that here too.
+ static const double fResolutionDPI = vcl::pdf::getDefaultPdfResolutionDpi();
+
sal_Int32 nOldDPIX = GetDPIX();
- SetDPIX(96);
sal_Int32 nOldDPIY = GetDPIY();
- SetDPIY(96);
+ SetDPIX(fResolutionDPI);
+ SetDPIY(fResolutionDPI);
Size aSize = PixelToLogic(rEmit.m_aPixelSize, MapMode(m_aMapMode.GetMapUnit()));
SetDPIX(nOldDPIX);
SetDPIY(nOldDPIY);
diff --git a/vcl/source/pdf/PdfConfig.cxx b/vcl/source/pdf/PdfConfig.cxx
new file mode 100644
index 000000000000..52859c7b1f6e
--- /dev/null
+++ b/vcl/source/pdf/PdfConfig.cxx
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <cstdlib>
+
+namespace vcl::pdf
+{
+/// Get the default PDF rendering resolution in DPI.
+double getDefaultPdfResolutionDpi()
+{
+ // If an overriding default is set, use it.
+ const char* envar = ::getenv("PDFIMPORT_RESOLUTION_DPI");
+ if (envar)
+ {
+ const double dpi = atof(envar);
+ if (dpi > 0)
+ return dpi;
+ }
+
+ // Fallback to a sensible default.
+ return 96.;
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */