[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - sw/qa sw/source
Michael Stahl (via logerrit)
logerrit at kemper.freedesktop.org
Thu Nov 21 08:24:13 UTC 2019
sw/qa/extras/unowriter/unowriter.cxx | 91 +++++++++++++++++++++++++++++++++++
sw/source/core/unocore/unotext.cxx | 14 ++++-
2 files changed, 102 insertions(+), 3 deletions(-)
New commits:
commit bbaf24fb6f2d70389cdfb6c0f47c11814d601d90
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Nov 19 17:33:05 2019 +0100
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Thu Nov 21 09:23:13 2019 +0100
sw: revert change in expanding hints in SwXText::insertTextContent()
The SwXText implementation for inserting text works like this:
* XTextPortionAppend methods appendTextPortion()/insertTextPortion() get
the text properties passed as a parameter, and they should apply only
those properties to the inserted text, not expand any existing
formatting hints at the insert position.
* XSimpleText method insertString() does expand existing formatting
at the insert position, just like editing in the UI does
For inserting XTextContent:
* XTextContentAppend methods
appendTextContent()/insertTextContentWithProperties()
with properties parameter, similar to XTextPortionAppend
* XTextContent::insertTextContent(), without properties
So arguably, by analogy to inserting text, the methods that take
properties should not expand hints, and the insertTextContent() should
follow the insertString and expand hints.
Commit 18cbb8fe699131a234355e1d00fa917fede6ac46 is an important bugfix
for writerfilter import, but the problem is, it added the
DontExpandFormat() call to insertTextContent(), whereas the regression
it was fixing (from commit 232ad2f2588beff50cb5c1f3b689c581ba317583) was
that the call was removed from insertTextContentWithProperties().
So restore the state before 232ad2f2588beff50cb5c1f3b689c581ba317583.
Turns out that SwUiWriterTest2::testTdf126206 was checking how a
bookmark-start is formatted instead of how the text is formatted.
Change-Id: If524409f88a1a36aa062b6e132996d3f9c1bb571
Reviewed-on: https://gerrit.libreoffice.org/83223
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl at cib.de>
(cherry picked from commit 635bd7fbcb1d131627ba98fd9085dd2b11e0d33c)
Reviewed-on: https://gerrit.libreoffice.org/83332
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index 4c5d6c417949..b618dd04c24b 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -12,6 +12,8 @@
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/text/AutoTextContainer.hpp>
#include <com/sun/star/text/XAutoTextGroup.hpp>
+#include <com/sun/star/text/XTextPortionAppend.hpp>
+#include <com/sun/star/text/XTextContentAppend.hpp>
#include <com/sun/star/rdf/URI.hpp>
#include <com/sun/star/rdf/URIs.hpp>
#include <com/sun/star/awt/XDevice.hpp>
@@ -109,6 +111,95 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testDefaultCharStyle)
getProperty<awt::FontSlant>(xCursorProps, "CharPosture"));
}
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testInsertStringExpandsHints)
+{
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<text::XTextDocument> const xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> const xText(xTextDocument->getText());
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ uno::Reference<beans::XPropertySet> const xProps(xCursor, uno::UNO_QUERY);
+
+ xText->insertString(xCursor, "ab", false);
+ xCursor->gotoStart(false);
+ xCursor->goRight(1, true);
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+ xProps->setPropertyValue("CharPosture", uno::Any(awt::FontSlant_ITALIC));
+ xCursor->collapseToEnd();
+ xText->insertString(xCursor, "x", false);
+ xCursor->goLeft(1, true);
+ CPPUNIT_ASSERT_EQUAL(OUString("x"), xCursor->getString());
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+}
+
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testInsertTextPortionNotExpandsHints)
+{
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<text::XTextDocument> const xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> const xText(xTextDocument->getText());
+ uno::Reference<text::XTextPortionAppend> const xTextA(xText, uno::UNO_QUERY);
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ uno::Reference<beans::XPropertySet> const xProps(xCursor, uno::UNO_QUERY);
+
+ xText->insertString(xCursor, "ab", false);
+ xCursor->gotoStart(false);
+ xCursor->goRight(1, true);
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+ xProps->setPropertyValue("CharPosture", uno::Any(awt::FontSlant_ITALIC));
+ xCursor->collapseToEnd();
+ xTextA->insertTextPortion("x", uno::Sequence<beans::PropertyValue>(), xCursor);
+ xCursor->goLeft(1, true);
+ CPPUNIT_ASSERT_EQUAL(OUString("x"), xCursor->getString());
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+}
+
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testInsertTextContentExpandsHints)
+{
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<text::XTextDocument> const xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<lang::XMultiServiceFactory> const xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> const xText(xTextDocument->getText());
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ uno::Reference<beans::XPropertySet> const xProps(xCursor, uno::UNO_QUERY);
+
+ xText->insertString(xCursor, "ab", false);
+ xCursor->gotoStart(false);
+ xCursor->goRight(1, true);
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+ xProps->setPropertyValue("CharPosture", uno::Any(awt::FontSlant_ITALIC));
+ xCursor->collapseToEnd();
+ uno::Reference<text::XTextContent> const xContent(
+ xFactory->createInstance("com.sun.star.text.Footnote"), uno::UNO_QUERY);
+ xText->insertTextContent(xCursor, xContent, false);
+ xCursor->goLeft(1, true);
+ CPPUNIT_ASSERT_EQUAL(OUString("1"), xCursor->getString());
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_ITALIC, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+}
+
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testInsertTextContentWithPropertiesNotExpandsHints)
+{
+ loadURL("private:factory/swriter", nullptr);
+ uno::Reference<text::XTextDocument> const xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<lang::XMultiServiceFactory> const xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> const xText(xTextDocument->getText());
+ uno::Reference<text::XTextContentAppend> const xTextA(xText, uno::UNO_QUERY);
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ uno::Reference<beans::XPropertySet> const xProps(xCursor, uno::UNO_QUERY);
+
+ xText->insertString(xCursor, "ab", false);
+ xCursor->gotoStart(false);
+ xCursor->goRight(1, true);
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+ xProps->setPropertyValue("CharPosture", uno::Any(awt::FontSlant_ITALIC));
+ xCursor->collapseToEnd();
+ uno::Reference<text::XTextContent> const xContent(
+ xFactory->createInstance("com.sun.star.text.Footnote"), uno::UNO_QUERY);
+ xTextA->insertTextContentWithProperties(xContent, uno::Sequence<beans::PropertyValue>(),
+ xCursor);
+ xCursor->goLeft(1, true);
+ CPPUNIT_ASSERT_EQUAL(OUString("1"), xCursor->getString());
+ CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, getProperty<awt::FontSlant>(xProps, "CharPosture"));
+}
+
CPPUNIT_TEST_FIXTURE(SwUnoWriter, testGraphicDesciptorURL)
{
loadURL("private:factory/swriter", nullptr);
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 727d6ec7aacf..2c62d942aab6 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -532,9 +532,6 @@ SwXText::insertTextContent(
aIllegal.Message = "first parameter invalid";
throw aIllegal;
}
- // Any direct formatting ending at the insert position (xRange) should not
- // be expanded to cover the inserted content (xContent)
- GetDoc()->DontExpandFormat( *aPam.Start() );
// first test if the range is at the right position, then call
// xContent->attach
@@ -1439,8 +1436,19 @@ SwXText::insertTextContentWithProperties(
throw uno::RuntimeException();
}
+ SwUnoInternalPaM aPam(*GetDoc());
+ if (!::sw::XTextRangeToSwPaM(aPam, xInsertPosition))
+ {
+ throw lang::IllegalArgumentException("invalid position", nullptr, 2);
+ }
+
m_pImpl->m_pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr);
+ // Any direct formatting ending at the insert position (xRange) should not
+ // be expanded to cover the inserted content (xContent)
+ // (insertTextContent() shouldn't do this, only ...WithProperties()!)
+ GetDoc()->DontExpandFormat( *aPam.Start() );
+
// now attach the text content here
insertTextContent( xInsertPosition, xTextContent, false );
// now apply the properties to the anchor
More information about the Libreoffice-commits
mailing list