summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2019-11-19 17:33:05 +0100
committerMichael Stahl <michael.stahl@cib.de>2019-11-20 11:59:40 +0100
commit635bd7fbcb1d131627ba98fd9085dd2b11e0d33c (patch)
tree4fd059487a946c099febc78d583382f923ac8314
parent73524467b9a6a7c4e6d5173aba79d80632ef46e2 (diff)
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@cib.de>
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx6
-rw-r--r--sw/qa/extras/unowriter/unowriter.cxx91
-rw-r--r--sw/source/core/unocore/unotext.cxx14
3 files changed, 106 insertions, 5 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 912695cc03d4..4a317d194ad5 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1307,8 +1307,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf126206)
auto xText = getParagraph(1)->getText();
CPPUNIT_ASSERT(xText.is());
{
- auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 2)));
+ auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 4)));
CPPUNIT_ASSERT(xCursor.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("ipsum"), xCursor->getString());
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, getProperty<float>(xCursor, "CharWeight"));
}
@@ -1319,8 +1320,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf126206)
xText = getParagraph(1)->getText();
CPPUNIT_ASSERT(xText.is());
{
- auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 2)));
+ auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 3)));
CPPUNIT_ASSERT(xCursor.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("ipsum"), xCursor->getString());
CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(xCursor, "CharWeight"));
}
}
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index d44bee733ab6..630a72afa6b1 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>
@@ -115,6 +117,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 e012e630198f..d49b07e35cb9 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -534,9 +534,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
@@ -1434,11 +1431,22 @@ SwXText::insertTextContentWithProperties(
throw uno::RuntimeException();
}
+ SwUnoInternalPaM aPam(*GetDoc());
+ if (!::sw::XTextRangeToSwPaM(aPam, xInsertPosition))
+ {
+ throw lang::IllegalArgumentException("invalid position", nullptr, 2);
+ }
+
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, SwResId(STR_UNDO_INSERT_TEXTBOX));
m_pImpl->m_pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, &aRewriter);
+ // 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