sd/sdi/_drvwsh.sdi | 1 svx/qa/unit/data/empty.pdf |binary svx/qa/unit/svdraw.cxx | 82 ++++++++++++++++++++++++++++++++++++++++++ svx/source/svdraw/svddrgv.cxx | 12 +++++- svx/source/svdraw/svdmrkv.cxx | 11 +++++ 5 files changed, 105 insertions(+), 1 deletion(-)
New commits: commit 26f08f48d414e95a08f8e0e8c6e2c7cf638af5f1 Author: Miklos Vajna <[email protected]> AuthorDate: Thu Jan 9 11:52:47 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Thu Jan 9 12:33:32 2025 +0100 cool#10630 lok doc sign: allow setting the size of the Impress sign line Insert a signature line in LOK mode when PEM certs are configured, moving the just inserted shape works (even in the read-only PDF view), but you can't resize the shape. This is because moving goes via .uno:TransformDialog, while resizing uses .uno:MoveShapeHandle. Fix this similar to moving, by allowing the operation when the shape is a just inserted signature line. Allowing the command in read-only mode is meant to be safe, since the command implementation again checks if the resize is allowed, and there we allow this only for signature lines. Also expose the "is signature line" info on the LOK API, so it can show the graphic selection handles conditionally (only when resize will be allowed). Change-Id: Ie85aa1211564758dc24ff83b4241de78a8e69ffc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179994 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi index ff760bf82d57..f8c3a26d9717 100644 --- a/sd/sdi/_drvwsh.sdi +++ b/sd/sdi/_drvwsh.sdi @@ -2937,6 +2937,7 @@ interface DrawView SID_MOVE_SHAPE_HANDLE [ ExecMethod = FuTemporary ; + ReadOnlyDoc = TRUE ; ] SID_ATTR_TEXTCOLUMNS_NUMBER [ diff --git a/svx/qa/unit/data/empty.pdf b/svx/qa/unit/data/empty.pdf new file mode 100644 index 000000000000..d6142103184b Binary files /dev/null and b/svx/qa/unit/data/empty.pdf differ diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index 66f4528d889f..9b015e1a858f 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -17,6 +17,9 @@ #include <com/sun/star/drawing/LineStyle.hpp> #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> #include <com/sun/star/drawing/HomogenMatrix3.hpp> +#include <com/sun/star/drawing/XDrawView.hpp> +#include <com/sun/star/xml/crypto/SEInitializer.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> #include <drawinglayer/tools/primitive2dxmldump.hxx> #include <rtl/ustring.hxx> @@ -35,6 +38,10 @@ #include <svl/itempool.hxx> #include <svx/svdomedia.hxx> #include <vcl/filter/PDFiumLibrary.hxx> +#include <comphelper/sequenceashashmap.hxx> +#include <sfx2/sfxbasemodel.hxx> +#include <svx/signaturelinehelper.hxx> +#include <sfx2/objsh.hxx> #include <sdr/contact/objectcontactofobjlistpainter.hxx> @@ -45,16 +52,35 @@ namespace /// Tests for svx/source/svdraw/ code. class SvdrawTest : public UnoApiXmlTest { +private: + uno::Reference<xml::crypto::XSEInitializer> mxSEInitializer; + uno::Reference<xml::crypto::XXMLSecurityContext> mxSecurityContext; + public: SvdrawTest() : UnoApiXmlTest("svx/qa/unit/data/") { } + void setUp() override; + uno::Reference<xml::crypto::XXMLSecurityContext>& getSecurityContext() + { + return mxSecurityContext; + } + protected: SdrPage* getFirstDrawPageWithAssert(); }; +void SvdrawTest::setUp() +{ + UnoApiTest::setUp(); + MacrosTest::setUpX509(m_directories, "svx_unit"); + + mxSEInitializer = xml::crypto::SEInitializer::create(mxComponentContext); + mxSecurityContext = mxSEInitializer->createSecurityContext(OUString()); +} + SdrPage* SvdrawTest::getFirstDrawPageWithAssert() { uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, @@ -754,6 +780,62 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testClipVerticalTextOverflow) assertXPath(pDocument, "((//sdrblocktext)[7]//textsimpleportion)[1]"_ostr, "x"_ostr, "25417"); assertXPath(pDocument, "((//sdrblocktext)[7]//textsimpleportion)[3]"_ostr, "x"_ostr, "23893"); } + +CPPUNIT_TEST_FIXTURE(SvdrawTest, testVisualSignResize) +{ + // Given a read-only document with a just inserted signature line: + uno::Sequence<beans::PropertyValue> aArgs = { comphelper::makePropertyValue("ReadOnly", true) }; + loadWithParams(createFileURL(u"empty.pdf"), aArgs); + SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + CPPUNIT_ASSERT(pBaseModel); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT(pObjectShell); + CPPUNIT_ASSERT(pObjectShell->IsReadOnly()); + // Add a signature line to the 2nd page. + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape( + xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY); + xShape->setPosition(awt::Point(1000, 1000)); + xShape->setSize(awt::Size(10000, 10000)); + uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPages> xDrawPages = xSupplier->getDrawPages(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xDrawPages->getCount()); + + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawView> xController(xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY); + xController->setCurrentPage(xDrawPage); + xDrawPage->add(xShape); + // Select it and assign a certificate. + uno::Reference<view::XSelectionSupplier> xSelectionSupplier(pBaseModel->getCurrentController(), + uno::UNO_QUERY); + xSelectionSupplier->select(uno::Any(xShape)); + auto xEnv = getSecurityContext()->getSecurityEnvironment(); + auto xCert = GetValidCertificate(xEnv->getPersonalCertificates(), xEnv); + if (!xCert) + { + return; + } + SdrView* pView = SfxViewShell::Current()->GetDrawView(); + svx::SignatureLineHelper::setShapeCertificate(pView, xCert); + pObjectShell->SetModified(false); + + // When resizing the shape by moving the bottom right (last) handle towards top right: + aArgs = { + comphelper::makePropertyValue("HandleNum", static_cast<sal_Int32>(7)), + comphelper::makePropertyValue("NewPosX", static_cast<sal_Int32>(1500)), + comphelper::makePropertyValue("NewPosY", static_cast<sal_Int32>(1500)), + }; + dispatchCommand(mxComponent, ".uno:MoveShapeHandle", aArgs); + + // Then make sure the size decreases: + // Without the accompanying fix in place, this test would have failed with: + // - Expected less than: 10000 + // - Actual : 10000 + // i.e. you could not resize even a just inserted signature line in a read-only view. + CPPUNIT_ASSERT_LESS(static_cast<sal_Int32>(10000), xShape->getSize().Width); + CPPUNIT_ASSERT_LESS(static_cast<sal_Int32>(10000), xShape->getSize().Height); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svddrgv.cxx b/svx/source/svdraw/svddrgv.cxx index c0cd0988d8ad..c2c90496a327 100644 --- a/svx/source/svdraw/svddrgv.cxx +++ b/svx/source/svdraw/svddrgv.cxx @@ -39,6 +39,8 @@ #include <unotools/configmgr.hxx> #include <comphelper/lok.hxx> #include <officecfg/Office/Common.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/viewsh.hxx> using namespace sdr; @@ -410,7 +412,15 @@ bool SdrDragView::BegDragObj(const Point& rPnt, OutputDevice* pOut, SdrHdl* pHdl } else { - if(!IsResizeAllowed(true)) + bool bResizeAllowed = IsResizeAllowed(true); + SfxViewShell* pViewShell = GetSfxViewShell(); + SfxObjectShell* pObjectShell = pViewShell ? pViewShell->GetObjectShell() : nullptr; + if (!bResizeAllowed && pObjectShell && pObjectShell->GetSignPDFCertificate().is()) + { + // If the just added signature line shape is selected, allow resizing it. + bResizeAllowed = true; + } + if(!bResizeAllowed) { return false; } diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx index 67df22bd05ad..4f74a40433cc 100644 --- a/svx/source/svdraw/svdmrkv.cxx +++ b/svx/source/svdraw/svdmrkv.cxx @@ -61,6 +61,7 @@ #include <sfx2/lokhelper.hxx> #include <sfx2/lokcomponenthelpers.hxx> #include <sfx2/viewsh.hxx> +#include <sfx2/objsh.hxx> #include <svtools/optionsdrawinglayer.hxx> #include <drawinglayer/processor2d/textextractor2d.hxx> @@ -1106,6 +1107,16 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle const & rRect, const S } } } + else + { + SfxObjectShell* pObjectShell = pViewShell ? pViewShell->GetObjectShell() : nullptr; + if (pObjectShell && pObjectShell->IsSignPDF() && pObjectShell->GetSignPDFCertificate().is()) + { + // Expose the info that this is the special signature widget that is OK to + // move/resize. + aExtraInfo.append(", \"isSignature\": true"); + } + } if (!bTableSelection && !pOtherShell && maHdlList.GetHdlCount()) { boost::property_tree::ptree responseJSON;
