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 d925b64ac552348e3862a6b8b61ecd751a8f3a9e
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu Jan 9 11:52:47 2025 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Jan 10 15:54:16 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/+/180065
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins

diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi
index e2cc2c705b46..5a19a4155e9c 100644
--- a/sd/sdi/_drvwsh.sdi
+++ b/sd/sdi/_drvwsh.sdi
@@ -2962,6 +2962,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 12cdd6093f20..6cf4c6bc10f3 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 <extendedprimitive2dxmldump.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(u"svx/qa/unit/data/"_ustr)
     {
     }
 
+    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(m_xContext);
+    mxSecurityContext = mxSEInitializer->createSecurityContext(OUString());
+}
+
 SdrPage* SvdrawTest::getFirstDrawPageWithAssert()
 {
     uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
@@ -800,6 +826,62 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testTdf161724)
     CPPUNIT_ASSERT_EQUAL(sal_Int16(9901), nBmpWidth);
     CPPUNIT_ASSERT_EQUAL(sal_Int16(12693), nBmpHeight);
 }
+
+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 051e559c94cd..9b05f0206539 100644
--- a/svx/source/svdraw/svddrgv.cxx
+++ b/svx/source/svdraw/svddrgv.cxx
@@ -38,6 +38,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 96bd7be18b7b..8ba5583853a1 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>
@@ -1111,6 +1112,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;

Reply via email to