summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-04-04 17:19:51 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2022-04-04 20:23:15 +0200
commit8fbe27a53c038cd32c45bad1f0b417e79d483185 (patch)
tree95cfc5261a7f1b9f005d1c72bffeacc2377c45a5 /sw
parent1ad58c77352e418124387b804b18da2aeea22c8b (diff)
forcepoint#101 sw: fix inserting at-page shapes to not set anchor pos
The problem is that for an at-page anchor SwXDrawPage::add() sets an anchor position, but then a fieldmark is inserted and the node with the anchor position is deleted. The code that sets the surprising anchor position for at-page shape was added in commit cf345e026fc0378c4436173c8064717c7db4d538 "Fix #91289#: Draw objects anchored at page but without page number" and is similar to the code for fly-frames added in commit 2e6d999cf8ceacabb94b11feee6ee0808c2a75bc "If no page number is given for page bound frames, calculate it using cursor" except that it is missing a check for GetPageNum() == 0, for no obvious reason. The matching code to replace the anchor position with a page number is in SwFlyFrameFormat::MakeFrames() and was added in commit 572a48cd16f6ce3a68ffead44a975698954dfe11 "Fix #85019#: Insertion of flyframes without correct pagenumber"; it's not clear if this is only needed for shapes inserted via the above 2 UNO APIs or also for shapes inserted via UI. Then there is the issue that the page number is set in XMLTextShapeImportHelper::addShape() only after the shape is inserted, which was added and commented in commit b5fc47fe5c2892dd712e2bda922656eacbd932f1, earlier than all the above commits; testing shows that if the page number is set before inserting the shape, the shape ends up on the expected page anyway. Let's change this: 1. the page number is set before inserting the shape 2. at-page anchor with page number is left as is 3. at-page anchor without page number gets anchor position and is changed to at-char Change-Id: I2f874bec8424de5eee94cf022e3b49382eaa55f0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132479 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/odfimport/data/forcepoint101.fodt13
-rw-r--r--sw/qa/extras/odfimport/odfimport.cxx6
-rw-r--r--sw/source/core/unocore/unodraw.cxx4
-rw-r--r--sw/source/core/unocore/unoframe.cxx1
4 files changed, 23 insertions, 1 deletions
diff --git a/sw/qa/extras/odfimport/data/forcepoint101.fodt b/sw/qa/extras/odfimport/data/forcepoint101.fodt
new file mode 100644
index 000000000000..7210888262dc
--- /dev/null
+++ b/sw/qa/extras/odfimport/data/forcepoint101.fodt
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:officeooo="http://openoffice.org/2009/office" xmlns:css3t="http://www.w3.org/TR/css3-text/" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rpt="http://openoffice.org/2005/report" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+ <office:text>
+ <draw:custom-shape text:anchor-type="page" texnumber="1" draw:z-index="1" draw:name="Shape2" svg:width="2.276cm" svg:height="2.276cm" svg:x="4.752cm" svg:y="2.902cm">
+ <text:p/>
+ </draw:custom-shape>
+ <text:p>
+ <draw:custom-shape draw:z-index="0" draw:name="Shape1" svg:width="3.44cm" svg:height="2.065cm" svg:x="-1.337cm" svg:y="0.912cm"><text:p/></draw:custom-shape>
+ <field:fieldmark-start text:name="__Fieldmark__0_1348794289" field:type="vnd.oasis.opendocument.field.FORMTEXT"/>foobar<field:fieldmark-end/></text:p>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index 4088ceef8c51..0238ffc96a9b 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -1329,5 +1329,11 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf146597)
// This was crashed before.
}
+// just care that it doesn't crash/assert
+CPPUNIT_TEST_FIXTURE(Test, testForcepoint101)
+{
+ load(mpTestDocumentPath, "forcepoint101.fodt");
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index d7032d2da66e..f9467e5e1cb0 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -669,9 +669,11 @@ void SwXDrawPage::add(const uno::Reference< drawing::XShape > & xShape)
{
aAnchor.SetType(RndStdIds::FLY_AS_CHAR);
}
- else if (RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId())
+ else if (RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId()
+ && 0 == aAnchor.GetPageNum())
{
aAnchor.SetAnchor(pInternalPam->Start());
+ aAnchor.SetType(RndStdIds::FLY_AT_CHAR); // convert invalid at-page
}
}
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index fd5989a77606..e16b5540f2f7 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2787,6 +2787,7 @@ void SwXFrame::attachToRange(uno::Reference<text::XTextRange> const& xTextRange,
0 == pItem->GetPageNum() )
{
SwFormatAnchor aAnchor( *pItem );
+ aAnchor.SetType(RndStdIds::FLY_AT_CHAR); // convert invalid at-page
aAnchor.SetAnchor( aPam.GetPoint() );
aFrameSet.Put(aAnchor);
}