include/vcl/pdf/pwdinteract.hxx | 24 ++++++++++++++++++++++++ include/vcl/pdfread.hxx | 13 ++++++++----- sdext/Library_pdfimport.mk | 1 - sdext/source/pdfimport/filterdet.cxx | 6 +++--- sdext/source/pdfimport/inc/pdfihelper.hxx | 9 --------- sdext/source/pdfimport/wrapper/wrapper.cxx | 4 ++-- solenv/clang-format/excludelist | 2 +- vcl/Library_vcl.mk | 1 + vcl/inc/pdf/pdfcompat.hxx | 13 ++++++++++--- vcl/source/filter/graphicfilter.cxx | 4 ++-- vcl/source/filter/ipdf/pdfcompat.cxx | 17 ++++++++++++----- vcl/source/filter/ipdf/pdfread.cxx | 14 ++++++++------ vcl/source/pdf/pwdinteract.cxx | 4 ++-- 13 files changed, 73 insertions(+), 39 deletions(-)
New commits: commit 32534b76eaa95fde79435ff0c325f24234cbe84d Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Sun May 18 02:27:25 2025 +0100 Commit: David Gilbert <d...@treblig.org> CommitDate: Fri Jun 13 22:03:52 2025 +0200 tdf#162826: Move pdf pwdinteract Move sdext's pwdinteract that provides getPassword() into vcl/source/pdf so it can also be used for the PDFium based import. Change-Id: Iab0f6fd0814986622624cdb2c523f1c60caddcc2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185470 Reviewed-by: David Gilbert <freedesk...@treblig.org> Tested-by: Jenkins diff --git a/include/vcl/pdf/pwdinteract.hxx b/include/vcl/pdf/pwdinteract.hxx new file mode 100644 index 000000000000..6a13a62b0b7b --- /dev/null +++ b/include/vcl/pdf/pwdinteract.hxx @@ -0,0 +1,24 @@ +/* -*- 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 + +#include <vcl/dllapi.h> +#include <com/sun/star/task/InteractionHandler.hpp> + +namespace vcl::pdf +{ +/** retrieve password from user + */ +bool VCL_DLLPUBLIC getPassword(const css::uno::Reference<css::task::XInteractionHandler>& xHandler, + OUString& rOutPwd, bool bFirstTry, const OUString& rDocName); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/Library_pdfimport.mk b/sdext/Library_pdfimport.mk index a1d4d0b5aceb..0843bd867977 100644 --- a/sdext/Library_pdfimport.mk +++ b/sdext/Library_pdfimport.mk @@ -55,7 +55,6 @@ $(eval $(call gb_Library_add_defs,pdfimport, \ $(eval $(call gb_Library_add_exception_objects,pdfimport,\ sdext/source/pdfimport/filterdet \ sdext/source/pdfimport/misc/pdfihelper \ - sdext/source/pdfimport/misc/pwdinteract \ sdext/source/pdfimport/odf/odfemitter \ sdext/source/pdfimport/pdfiadaptor \ sdext/source/pdfimport/pdfparse/pdfentries \ diff --git a/sdext/source/pdfimport/filterdet.cxx b/sdext/source/pdfimport/filterdet.cxx index 65a4c6a15a83..95face19665d 100644 --- a/sdext/source/pdfimport/filterdet.cxx +++ b/sdext/source/pdfimport/filterdet.cxx @@ -19,7 +19,6 @@ #include "filterdet.hxx" -#include "inc/pdfihelper.hxx" #include "inc/pdfparse.hxx" #include <osl/file.h> @@ -38,6 +37,7 @@ #include <comphelper/diagnose_ex.hxx> #include <tools/stream.hxx> #include <vcl/filter/PDFiumLibrary.hxx> +#include <vcl/pdf/pwdinteract.hxx> #include <memory> #include <utility> #include <string.h> @@ -366,7 +366,7 @@ uno::Reference<io::XStream> getEmbeddedFile(const OUString& rInPDFFileURL, if (bMayUseUI && xIntHdl.is()) { OUString aDocName(rInPDFFileURL.copy(rInPDFFileURL.lastIndexOf('/') + 1)); - bAgain = getPassword(xIntHdl, io_rPwd, !bAgain, aDocName); + bAgain = vcl::pdf::getPassword(xIntHdl, io_rPwd, !bAgain, aDocName); SAL_INFO("sdext.pdfimport", "getEmbeddedFile pdfium Pass result: " << bAgain); continue; } @@ -812,7 +812,7 @@ uno::Reference< io::XStream > getAdditionalStream( const OUString& bool bEntered = false; do { - bEntered = getPassword( xIntHdl, io_rPwd, ! bEntered, aDocName ); + bEntered = vcl::pdf::getPassword( xIntHdl, io_rPwd, ! bEntered, aDocName ); OString aIsoPwd = OUStringToOString( io_rPwd, RTL_TEXTENCODING_ISO_8859_1 ); bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd ); diff --git a/sdext/source/pdfimport/inc/pdfihelper.hxx b/sdext/source/pdfimport/inc/pdfihelper.hxx index bc8e04a70253..9cb8760bc12a 100644 --- a/sdext/source/pdfimport/inc/pdfihelper.hxx +++ b/sdext/source/pdfimport/inc/pdfihelper.hxx @@ -214,15 +214,6 @@ namespace pdfi return seed; } }; - - /** retrieve password from user - */ - bool getPassword( const css::uno::Reference< - css::task::XInteractionHandler >& xHandler, - OUString& rOutPwd, - bool bFirstTry, - const OUString& rDocName - ); } #endif diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx index fcac1cdacfa2..5c9ec116dec7 100644 --- a/sdext/source/pdfimport/wrapper/wrapper.cxx +++ b/sdext/source/pdfimport/wrapper/wrapper.cxx @@ -20,7 +20,6 @@ #include <config_folders.h> #include <contentsink.hxx> -#include <pdfihelper.hxx> #include <wrapper.hxx> #include <o3tl/string_view.hxx> @@ -54,6 +53,7 @@ #include <vcl/metric.hxx> #include <vcl/font.hxx> +#include <vcl/pdf/pwdinteract.hxx> #include <vcl/virdev.hxx> #include <cstddef> @@ -1137,7 +1137,7 @@ bool xpdf_ImportFromFile(const OUString& rURL, // already got one (e.g. if the hybrid detect prompted for one) if (!bPasswordOnEntry) { - bEntered = getPassword(xIHdl, aPwd, !bEntered, aDocName); + bEntered = vcl::pdf::getPassword(xIHdl, aPwd, !bEntered, aDocName); if (!bEntered) { // User cancelled password input diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 178e885130fc..83e205857453 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -9977,7 +9977,6 @@ sdext/source/pdfimport/inc/treevisitorfactory.hxx sdext/source/pdfimport/inc/wrapper.hxx sdext/source/pdfimport/inc/xmlemitter.hxx sdext/source/pdfimport/misc/pdfihelper.cxx -sdext/source/pdfimport/misc/pwdinteract.cxx sdext/source/pdfimport/odf/odfemitter.cxx sdext/source/pdfimport/pdfiadaptor.cxx sdext/source/pdfimport/pdfiadaptor.hxx @@ -14768,6 +14767,7 @@ vcl/source/outdev/textline.cxx vcl/source/outdev/transparent.cxx vcl/source/outdev/vclreferencebase.cxx vcl/source/outdev/wallpaper.cxx +vcl/source/pdf/pwdinteract.cxx vcl/source/text/ImplLayoutRuns.cxx vcl/source/text/textlayout.cxx vcl/source/toolkit/group.cxx diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 07537ccdfc71..dc0a081fc5b9 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -566,6 +566,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/pdf/PDFEncryptor \ vcl/source/pdf/PDFEncryptorR6 \ vcl/source/pdf/PdfConfig \ + vcl/source/pdf/pwdinteract \ vcl/source/pdf/ResourceDict \ vcl/source/pdf/Matrix3 \ vcl/source/pdf/XmpMetadata \ diff --git a/sdext/source/pdfimport/misc/pwdinteract.cxx b/vcl/source/pdf/pwdinteract.cxx similarity index 98% rename from sdext/source/pdfimport/misc/pwdinteract.cxx rename to vcl/source/pdf/pwdinteract.cxx index 44214ac70ac3..65a7664754c7 100644 --- a/sdext/source/pdfimport/misc/pwdinteract.cxx +++ b/vcl/source/pdf/pwdinteract.cxx @@ -22,7 +22,7 @@ #include <cassert> #include <mutex> -#include <pdfihelper.hxx> +#include <vcl/pdf/pwdinteract.hxx> #include <com/sun/star/task/ErrorCodeRequest.hpp> #include <com/sun/star/task/XInteractionHandler.hpp> @@ -117,7 +117,7 @@ void PDFPasswordRequest::select() } // namespace -namespace pdfi +namespace vcl::pdf { bool getPassword( const uno::Reference< task::XInteractionHandler >& xHandler, commit 894fccf8c518ecc12e6430a6ff93c27a4967255b Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Sat May 17 22:46:06 2025 +0100 Commit: David Gilbert <d...@treblig.org> CommitDate: Fri Jun 13 22:03:42 2025 +0200 tdf#162826: vcl: ipdf: Plumb InteractionHandler through ipdf Carry on the plumbing of InteractionHandler, starting from GraphicFilter::readPDF where we left it in previous patches ImportPDF importPdfVectorGraphicData createBinaryDataContainer getCompatibleStream convertToHighestSupported which is where PDFium is used to open the file. Change-Id: Ie97ff3602b7e5bb3a3e82d74efdff8a3d60cdec9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185469 Tested-by: Jenkins Reviewed-by: David Gilbert <freedesk...@treblig.org> diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx index 894cf8af0d85..8bd116b9f3b7 100644 --- a/include/vcl/pdfread.hxx +++ b/include/vcl/pdfread.hxx @@ -17,6 +17,7 @@ #include <vcl/graph.hxx> #include <basegfx/range/b2drectangle.hxx> #include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/task/InteractionHandler.hpp> #include <vcl/pdf/PDFAnnotationSubType.hxx> #include <vcl/pdf/PDFAnnotationMarker.hxx> @@ -29,13 +30,15 @@ VCL_DLLPUBLIC size_t RenderPDFBitmaps(const void* pBuffer, int nSize, int nPages = 1, const basegfx::B2DTuple* pSizeHint = nullptr); /// Imports a PDF stream as a VectorGraphicData. -VCL_DLLPUBLIC bool -importPdfVectorGraphicData(SvStream& rStream, - std::shared_ptr<VectorGraphicData>& rVectorGraphicData, - sal_Int32 nPageIndex = -1); +VCL_DLLPUBLIC bool importPdfVectorGraphicData( + SvStream& rStream, std::shared_ptr<VectorGraphicData>& rVectorGraphicData, + sal_Int32 nPageIndex = -1, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler = nullptr); /// Imports a PDF stream into rGraphic. -VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic, sal_Int32 nPageIndex = -1); +VCL_DLLPUBLIC bool +ImportPDF(SvStream& rStream, Graphic& rGraphic, sal_Int32 nPageIndex = -1, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler = nullptr); // When inserting a PDF file as an image or pasting PDF data from the clipboard, at least on a // Retina iMac, the resulting rendered image does not look sharp without this surprisingly large diff --git a/vcl/inc/pdf/pdfcompat.hxx b/vcl/inc/pdf/pdfcompat.hxx index 0664a400f90e..610924f5e672 100644 --- a/vcl/inc/pdf/pdfcompat.hxx +++ b/vcl/inc/pdf/pdfcompat.hxx @@ -12,6 +12,7 @@ #include <o3tl/unit_conversion.hxx> #include <tools/stream.hxx> #include <vcl/BinaryDataContainer.hxx> +#include <com/sun/star/task/InteractionHandler.hpp> namespace vcl::pdf { @@ -27,13 +28,19 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, sal_uInt64 nSize); /// Converts to highest supported format version (currently 1.6). /// Usually used to deal with missing referenced objects in the /// source pdf stream. -bool convertToHighestSupported(SvStream& rInStream, SvStream& rOutStream); +bool convertToHighestSupported( + SvStream& rInStream, SvStream& rOutStream, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler = nullptr); /// Takes care of transparently downgrading the version of the PDF stream in /// case it's too new for our PDF export. -bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream); +bool getCompatibleStream( + SvStream& rInStream, SvStream& rOutStream, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler); -BinaryDataContainer createBinaryDataContainer(SvStream& rStream); +BinaryDataContainer createBinaryDataContainer( + SvStream& rStream, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler = nullptr); } // end of vcl::filter::ipdf namespace diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 383d3696ed8f..61b0a95ee9ba 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -1137,9 +1137,9 @@ ErrCode GraphicFilter::readEMF(SvStream & rStream, Graphic & rGraphic, GfxLinkTy ErrCode GraphicFilter::readPDF( SvStream& rStream, Graphic& rGraphic, GfxLinkType& rLinkType, sal_Int32 nPageIndex, - const css::uno::Reference<css::task::XInteractionHandler>& /*xInteractionHandler*/) + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler) { - if (vcl::ImportPDF(rStream, rGraphic, nPageIndex)) + if (vcl::ImportPDF(rStream, rGraphic, nPageIndex, xInteractionHandler)) { rLinkType = GfxLinkType::NativePdf; return ERRCODE_NONE; diff --git a/vcl/source/filter/ipdf/pdfcompat.cxx b/vcl/source/filter/ipdf/pdfcompat.cxx index 2710b97a788c..727c4d7e1fbc 100644 --- a/vcl/source/filter/ipdf/pdfcompat.cxx +++ b/vcl/source/filter/ipdf/pdfcompat.cxx @@ -41,7 +41,10 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, sal_uInt64 nSize) /// Converts to highest supported format version (1.6). /// Usually used to deal with missing referenced objects in source /// pdf stream. -bool convertToHighestSupported(SvStream& rInStream, SvStream& rOutStream) + +bool convertToHighestSupported( + SvStream& rInStream, SvStream& rOutStream, + const css::uno::Reference<css::task::XInteractionHandler>& /*xInteractionHandler*/) { sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN; sal_uInt64 nSize = STREAM_SEEK_TO_END; @@ -76,7 +79,9 @@ bool convertToHighestSupported(SvStream& rInStream, SvStream& rOutStream) /// Takes care of transparently downgrading the version of the PDF stream in /// case it's too new for our PDF export. -bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream) +bool getCompatibleStream( + SvStream& rInStream, SvStream& rOutStream, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler) { sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN; sal_uInt64 nSize = STREAM_SEEK_TO_END; @@ -86,16 +91,18 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream) // Not converting. rOutStream.WriteStream(rInStream, nSize); else - convertToHighestSupported(rInStream, rOutStream); + convertToHighestSupported(rInStream, rOutStream, xInteractionHandler); return rOutStream.good(); } -BinaryDataContainer createBinaryDataContainer(SvStream& rStream) +BinaryDataContainer createBinaryDataContainer( + SvStream& rStream, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler) { // Save the original PDF stream for later use. SvMemoryStream aMemoryStream; - if (!getCompatibleStream(rStream, aMemoryStream)) + if (!getCompatibleStream(rStream, aMemoryStream, xInteractionHandler)) return {}; const sal_uInt64 nStreamLength = aMemoryStream.TellEnd(); diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 1a1bf2217f1a..574c53e959b7 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -101,11 +101,12 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<BitmapEx>& r return rBitmaps.size(); } -bool importPdfVectorGraphicData(SvStream& rStream, - std::shared_ptr<VectorGraphicData>& rVectorGraphicData, - sal_Int32 nPageIndex) +bool importPdfVectorGraphicData( + SvStream& rStream, std::shared_ptr<VectorGraphicData>& rVectorGraphicData, sal_Int32 nPageIndex, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler) { - BinaryDataContainer aDataContainer = vcl::pdf::createBinaryDataContainer(rStream); + BinaryDataContainer aDataContainer + = vcl::pdf::createBinaryDataContainer(rStream, xInteractionHandler); if (aDataContainer.isEmpty()) { SAL_WARN("vcl.filter", "ImportPDF: empty PDF data array"); @@ -118,10 +119,11 @@ bool importPdfVectorGraphicData(SvStream& rStream, return true; } -bool ImportPDF(SvStream& rStream, Graphic& rGraphic, sal_Int32 nPageIndex) +bool ImportPDF(SvStream& rStream, Graphic& rGraphic, sal_Int32 nPageIndex, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler) { std::shared_ptr<VectorGraphicData> pVectorGraphicData; - if (!importPdfVectorGraphicData(rStream, pVectorGraphicData, nPageIndex)) + if (!importPdfVectorGraphicData(rStream, pVectorGraphicData, nPageIndex, xInteractionHandler)) return false; rGraphic = Graphic(pVectorGraphicData); return true;