include/vcl/graphicfilter.hxx | 5 +++-- vcl/source/filter/graphicfilter.cxx | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-)
New commits: commit 1f30bcbbddf0677450ba167ba74c75b57527b505 Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Mon May 26 00:30:54 2025 +0100 Commit: David Gilbert <d...@treblig.org> CommitDate: Fri Jun 13 22:07:07 2025 +0200 tdf#162826: vcl: Make readPDF stash unencrypted pdf On an insert of a PDF document which is encrypted, make sure that the unencrypted version is the one we save in the combined LO document. The user can always add a password on that. There's no sane way to ask for, potentially multiple, embedded PDFs, and since we have the bitmap anyway there's no point. Change-Id: I06f3a406f8664a9fba21a1b26a3bc35e7492b37b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185759 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> Reviewed-by: David Gilbert <freedesk...@treblig.org> diff --git a/include/vcl/graphicfilter.hxx b/include/vcl/graphicfilter.hxx index a37328d6380f..0e1d26cf64c6 100644 --- a/include/vcl/graphicfilter.hxx +++ b/include/vcl/graphicfilter.hxx @@ -323,8 +323,9 @@ public: SAL_DLLPRIVATE static ErrCode readEMF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType); SAL_DLLPRIVATE static ErrCode readPDF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, - sal_Int32 nPageIndex = -1, - const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler = nullptr); + sal_Int32 nPageIndex, + const css::uno::Reference<css::task::XInteractionHandler>& xInteractionHandler, + BinaryDataContainer & rpGraphicContent); SAL_DLLPRIVATE static ErrCode readTIFF(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType); SAL_DLLPRIVATE static ErrCode readWithTypeSerializer(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType, std::u16string_view aFilterName); SAL_DLLPRIVATE static ErrCode readBMP(SvStream & rStream, Graphic & rGraphic, GfxLinkType & rLinkType); diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 9e8e604354c7..563e6b63d485 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -1137,12 +1137,27 @@ 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, + BinaryDataContainer& rpGraphicContent) { bool bEncrypted; if (vcl::ImportPDF(rStream, rGraphic, nPageIndex, xInteractionHandler, bEncrypted)) { + // ImportPDF put a modified version of the PDF in the Graphic, but + // by default we stash the original in the Link rLinkType = GfxLinkType::NativePdf; + if (bEncrypted) + { + // However, when we load an encrypted PDF, we want the modified PDF + // to stash into the Link as well, so that when the user opens a odg etc + // they don't need to enter multiple PDF passwords + auto const &rVectorGraphicDataPtr(rGraphic.getVectorGraphicData()); + if (rVectorGraphicDataPtr && + !rVectorGraphicDataPtr->getBinaryDataContainer().isEmpty()) + { + rpGraphicContent = rVectorGraphicDataPtr->getBinaryDataContainer(); + } + } return ERRCODE_NONE; } else @@ -1413,7 +1428,7 @@ ErrCode GraphicFilter::ImportGraphic(Graphic& rGraphic, std::u16string_view rPat } else if (aFilterName.equalsIgnoreAsciiCase(IMP_PDF)) { - nStatus = readPDF(rIStream, rGraphic, eLinkType, nPageIndex, xInteractionHandler); + nStatus = readPDF(rIStream, rGraphic, eLinkType, nPageIndex, xInteractionHandler, aGraphicContent); } else if (aFilterName.equalsIgnoreAsciiCase(IMP_TIFF) ) {