[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - vcl/inc vcl/Library_vcl.mk vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 26 09:46:35 UTC 2021


 vcl/Library_vcl.mk                 |    1 +
 vcl/inc/pdf/PdfConfig.hxx          |   18 ++++++++++++++++++
 vcl/source/filter/ipdf/pdfread.cxx |   20 +++-----------------
 vcl/source/gdi/pdfwriter_impl.cxx  |   10 +++++++---
 vcl/source/pdf/PdfConfig.cxx       |   32 ++++++++++++++++++++++++++++++++
 5 files changed, 61 insertions(+), 20 deletions(-)

New commits:
commit fd3536e78faa0faff850227d12d9ae2460fc15bd
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Aug 26 16:47:31 2021 +0900
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Thu Aug 26 11:45:57 2021 +0200

    Take the PDF graphic rendering DPI into account when exporting
    
    Change-Id: I1d3465fc7357e6991161d5a96bcd70c53c55f244
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121051
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index de66ebdb43f2..44de3999b89f 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/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 899b652049b0..cda9f9d2304b 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -17,6 +17,7 @@
 #include <tools/UnitConversion.hxx>
 #endif
 
+#include <pdf/PdfConfig.hxx>
 #include <vcl/graph.hxx>
 #include <bitmapwriteaccess.hxx>
 #include <unotools/ucbstreamhelper.hxx>
@@ -132,27 +133,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<BitmapEx>& 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 3f5f47961e05..811fdeb14ce3 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -78,6 +78,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"
@@ -8439,11 +8440,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: */


More information about the Libreoffice-commits mailing list