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-25 14:29:54 +0200
commit022f6bb1f7ed06edb126a2b85719d8622104bb57 (patch)
treec646fd43f4d30cba1d45ea117fac4a62273110d8 /xmlsecurity
parent798f8c2efac28ff15a2f7aa5e39c3744756de5b2 (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. Change-Id: I63decba98774151e9634ea924c2fed0f7814cb28 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97045 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
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);