xmloff/qa/unit/data/comment-table-border.fodt | 16 ++++++++++++++++ xmloff/qa/unit/text.cxx | 8 ++++++++ xmloff/source/text/txtfldi.cxx | 15 +++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-)
New commits: commit 4f4452f6a74201e862971a79ba5bdcd06f3ba9ce Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Aug 30 20:12:46 2021 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Aug 31 09:29:40 2021 +0200 tdf#126126 ODT import: improve import of cross-table commented text range Regression from commit d4b473dd9ba77427b28d97847067b8877c2033d9 (office:annotation-end import, 2012-07-20), the problem was that XMLAnnotationImportContext::EndElement() assumed that we can always call gotoRange() to go from the annotation start and end points, but this is not true: an annotation may start inside a table and end outside a table, which is not a valid selection, so gotoRange() fails. Fix the regression part by just creating a text range for the anchor of the comment, so the comment is attached to the end of the range, and this way the rest of the comment & the document can be at least opened. [ It seems bookmarks behave similarly: they don't block the whole import, but don't work cross table boundaries, either. ] Change-Id: I1b5a2e2e7501ce3054379fc79d2045c3439c52e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121322 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/xmloff/qa/unit/data/comment-table-border.fodt b/xmloff/qa/unit/data/comment-table-border.fodt new file mode 100644 index 000000000000..29f54da9afe3 --- /dev/null +++ b/xmloff/qa/unit/data/comment-table-border.fodt @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <table:table> + <table:table-column table:style-name="Table1.A"/> + <table:table-row> + <table:table-cell table:style-name="Table1.A1" office:value-type="string"> + <text:p>A<office:annotation office:name="0"><text:p>x</text:p></office:annotation>b</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p>b<office:annotation-end office:name="0"/><text:span>Z</text:span></text:p> + </office:text> + </office:body> +</office:document> diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index 22d1d3c15fcf..9a177099b8a3 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -153,6 +153,14 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testBibliographyLocalUrl) CPPUNIT_ASSERT_EQUAL(OUString("file:///home/me/test.pdf"), aActual); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentTableBorder) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "comment-table-border.fodt"; + // Without the accompanying fix in place, this failed to load, as a comment that started in a + // table and ended outside a table aborted the whole importer. + getComponent() = loadFromDesktop(aURL); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index dda0e0c8bf5a..59ea8856e05e 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -69,7 +69,7 @@ #include <rtl/math.hxx> #include <tools/debug.hxx> #include <osl/diagnose.h> - +#include <tools/diagnose_ex.h> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -3257,7 +3257,18 @@ void XMLAnnotationImportContext::endFastElement(sal_Int32 /*nElement*/) uno::Reference<text::XText> xText = GetImportHelper().GetText(); uno::Reference<text::XTextCursor> xCursor = xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange()); - xCursor->gotoRange(xPrevField->getAnchor(), true); + try + { + xCursor->gotoRange(xPrevField->getAnchor(), true); + } + catch (const uno::RuntimeException&) + { + // Loosing the start of the anchor is better than not opening the document at + // all. + TOOLS_WARN_EXCEPTION( + "xmloff.text", + "XMLAnnotationImportContext::endFastElement: gotoRange() failed: "); + } xText->insertTextContent(xCursor, xPrevField, !xCursor->isCollapsed()); }