[Libreoffice-commits] core.git: vcl/inc vcl/Library_vcl.mk vcl/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Fri Aug 27 05:07:32 UTC 2021
vcl/Library_vcl.mk | 1 +
vcl/inc/pdf/PdfConfig.hxx | 18 ++++++++++++++++++
vcl/source/filter/ipdf/pdfread.cxx | 19 ++-----------------
vcl/source/gdi/pdfwriter_impl.cxx | 10 +++++++---
vcl/source/pdf/PdfConfig.cxx | 33 +++++++++++++++++++++++++++++++++
5 files changed, 61 insertions(+), 20 deletions(-)
New commits:
commit 47df2d88d3dee617d76d05e4fcf6063e57a3b199
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Aug 26 16:47:31 2021 +0900
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Aug 27 07:06:58 2021 +0200
Take the PDF graphic rendering DPI into account when exporting
Change-Id: I1d3465fc7357e6991161d5a96bcd70c53c55f244
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121087
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 0f714a0ec9b3..bda2d5c6b872 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -299,6 +299,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/ResourceDict \
vcl/source/pdf/Matrix3 \
vcl/source/pdf/XmpMetadata \
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 e1206e985eaa..9b44a6476878 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -11,6 +11,7 @@
#include <tools/UnitConversion.hxx>
+#include <pdf/PdfConfig.hxx>
#include <vcl/graph.hxx>
#include <bitmap/BitmapWriteAccess.hxx>
#include <unotools/ucbstreamhelper.hxx>
@@ -116,26 +117,10 @@ BinaryDataContainer createBinaryDataContainer(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<BitmapEx>& rBitmaps,
const size_t nFirstPage, int nPages, const basegfx::B2DTuple* pSizeHint)
{
- static const double fResolutionDPI = getDefaultPdfResolutionDpi();
+ static const double fResolutionDPI = vcl::pdf::getDefaultPdfResolutionDpi();
auto pPdfium = vcl::pdf::PDFiumLibrary::get();
if (!pPdfium)
{
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index ed44cdfde1ce..41fc6b88d4ef 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -77,6 +77,7 @@
#include <impglyphitem.hxx>
#include <pdf/XmpMetadata.hxx>
#include <pdf/objectcopier.hxx>
+#include <pdf/PdfConfig.hxx>
#include <o3tl/sorted_vector.hxx>
#include "pdfwriter_impl.hxx"
@@ -8407,11 +8408,14 @@ void PDFWriterImpl::writeReferenceXObject(const 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..e74d30cfe22a
--- /dev/null
+++ b/vcl/source/pdf/PdfConfig.cxx
@@ -0,0 +1,33 @@
+/* -*- 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 <pdf/PdfConfig.hxx>
+#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: */
More information about the Libreoffice-commits
mailing list