summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-06-25 10:58:25 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-06-29 09:11:32 +0200
commitb95e3b573085a3f240e3a160a6405f8105feef7b (patch)
tree490c09e764464a3bda502173533841b9b0e3ed11 /xmlsecurity
parent1634699551b9267c16f673707624b15e1dba8acd (diff)
sd signature line: place shape on the correct page
PDFDocument::Sign() had this hardcoded to always place the signature widget on the first page, add a way so that xmlsecurity/ can tell the pdf signing code to put it on an other page. This way in case the user created the signature line shape on the Nth page, it'll end up on the Nth page of the PDF result as well, as expected. (cherry picked from commit 022f6bb1f7ed06edb126a2b85719d8622104bb57) Conflicts: vcl/Module_vcl.mk Change-Id: I63decba98774151e9634ea924c2fed0f7814cb28 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97256 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/source/helper/pdfsignaturehelper.cxx34
1 files changed, 32 insertions, 2 deletions
diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx
index beb5b7e800bb..79979c715bff 100644
--- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/XDrawView.hpp>
#include <comphelper/propertysequence.hxx>
#include <sal/log.hxx>
@@ -37,8 +38,26 @@ using namespace ::com::sun::star;
namespace
{
+/// Gets the current page of the current view from xModel and puts it to the 1-based rPage.
+bool GetSignatureLinePage(const uno::Reference<frame::XModel>& xModel, sal_Int32& rPage)
+{
+ uno::Reference<drawing::XDrawView> xController(xModel->getCurrentController(), uno::UNO_QUERY);
+ if (!xController.is())
+ {
+ return false;
+ }
+
+ uno::Reference<beans::XPropertySet> xPage(xController->getCurrentPage(), uno::UNO_QUERY);
+ if (!xPage.is())
+ {
+ return false;
+ }
+
+ return xPage->getPropertyValue("Number") >>= rPage;
+}
+
/// If the currently selected shape is a Draw signature line, export that to PDF.
-void GetSignatureLineShape(std::vector<sal_Int8>& rSignatureLineShape)
+void GetSignatureLineShape(sal_Int32& rPage, std::vector<sal_Int8>& rSignatureLineShape)
{
SfxObjectShell* pObjectShell = SfxObjectShell::Current();
if (!pObjectShell)
@@ -52,6 +71,11 @@ void GetSignatureLineShape(std::vector<sal_Int8>& rSignatureLineShape)
return;
}
+ if (!GetSignatureLinePage(xModel, rPage))
+ {
+ return;
+ }
+
uno::Reference<drawing::XShapes> xShapes(xModel->getCurrentSelection(), uno::UNO_QUERY);
if (!xShapes.is() || xShapes->getCount() < 1)
{
@@ -200,8 +224,14 @@ bool PDFSignatureHelper::Sign(const uno::Reference<io::XInputStream>& xInputStre
return false;
}
+ sal_Int32 nPage = 0;
std::vector<sal_Int8> aSignatureLineShape;
- GetSignatureLineShape(aSignatureLineShape);
+ GetSignatureLineShape(nPage, aSignatureLineShape);
+ if (nPage > 0)
+ {
+ // UNO page number is 1-based.
+ aDocument.SetSignaturePage(nPage - 1);
+ }
if (!aSignatureLineShape.empty())
{
aDocument.SetSignatureLine(aSignatureLineShape);