[Libreoffice-commits] core.git: 2 commits - sw/qa sw/source
Jan Holesovsky
kendy at collabora.com
Fri Apr 21 10:40:13 UTC 2017
sw/qa/extras/uiwriter/uiwriter.cxx | 28 +++++++++++++++++++++++++++
sw/source/filter/ww8/docxattributeoutput.cxx | 24 +++++++++++++++++------
2 files changed, 46 insertions(+), 6 deletions(-)
New commits:
commit 26930dfffe791de7d0c88d1a6dcb15498d6f6883
Author: Jan Holesovsky <kendy at collabora.com>
Date: Fri Apr 21 12:12:37 2017 +0200
related tdf#68604: Unit test for writing the plaintext annotations in DOCX.
Change-Id: I8c747e72ca96ffd097c92326210c39740102ec79
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index e9513d1bbf06..bb6c069d7192 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -234,6 +234,7 @@ public:
void testTdf105625();
void testTdf106736();
void testMsWordCompTrailingBlanks();
+ void testCreateDocxAnnotation();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -359,6 +360,7 @@ public:
CPPUNIT_TEST(testTdf105625);
CPPUNIT_TEST(testTdf106736);
CPPUNIT_TEST(testMsWordCompTrailingBlanks);
+ CPPUNIT_TEST(testCreateDocxAnnotation);
CPPUNIT_TEST_SUITE_END();
private:
@@ -4555,6 +4557,32 @@ void SwUiWriterTest::testMsWordCompTrailingBlanks()
CPPUNIT_ASSERT_EQUAL( true, pDoc->getIDocumentSettingAccess().get( DocumentSettingId::MS_WORD_COMP_TRAILING_BLANKS ) );
}
+void SwUiWriterTest::testCreateDocxAnnotation()
+{
+ createDoc();
+
+ // insert an annotation with a text
+ const OUString aSomeText("some text");
+ uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence(
+ {
+ {"Text", uno::makeAny(aSomeText)},
+ {"Author", uno::makeAny(OUString("me"))},
+ });
+ lcl_dispatchCommand(mxComponent, ".uno:InsertAnnotation", aPropertyValues);
+
+ // Save it as DOCX & load it again
+ reload("Office Open XML Text", "create-docx-annotation.docx");
+
+ // get the annotation
+ uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+ uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+ uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), uno::UNO_QUERY);
+
+ // this was empty insetad of "some text"
+ CPPUNIT_ASSERT_EQUAL(aSomeText, xField->getPropertyValue("Content").get<OUString>());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
commit 24fee4879c0df4fb88fad8de4f7d62598888aafe
Author: Jan Holesovsky <kendy at collabora.com>
Date: Fri Apr 21 09:47:13 2017 +0200
related tdf#68604: Write the plaintext version of the annotation...
...if the TextObject is not available. This is perfectly valid situation in
the case when the SwPostItField was created via the .uno:InsertAnnotation API.
Change-Id: I3ae2a529ba7cc13cf5b04d57aa299d79e2044f37
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index b9d2fe38de4e..c59dc7520f5f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -6762,7 +6762,7 @@ void DocxAttributeOutput::WritePostitFieldReference()
void DocxAttributeOutput::WritePostitFields()
{
- for(const std::pair<const SwPostItField*,int> & rPair : m_postitFields)
+ for (const std::pair<const SwPostItField*,int> & rPair : m_postitFields)
{
OString idstr = OString::number( rPair.second);
const SwPostItField* f = rPair.first;
@@ -6770,11 +6770,23 @@ void DocxAttributeOutput::WritePostitFields()
FSNS( XML_w, XML_author ), OUStringToOString( f->GetPar1(), RTL_TEXTENCODING_UTF8 ).getStr(),
FSNS( XML_w, XML_date ), DateTimeToOString(f->GetDateTime()).getStr(),
FSNS( XML_w, XML_initials ), OUStringToOString( f->GetInitials(), RTL_TEXTENCODING_UTF8 ).getStr(), FSEND );
- // Check for the text object existing, it seems that it can be NULL when saving a newly created
- // comment without giving focus back to the main document. As GetText() is empty in that case as well,
- // that is probably a bug in the Writer core.
- if( f->GetTextObject() != nullptr )
- GetExport().WriteOutliner( *f->GetTextObject(), TXT_ATN );
+
+ if (f->GetTextObject() != nullptr)
+ {
+ // richtext
+ GetExport().WriteOutliner(*f->GetTextObject(), TXT_ATN);
+ }
+ else
+ {
+ // just plain text - eg. when the field was created via the
+ // .uno:InsertAnnotation API
+ m_pSerializer->startElementNS(XML_w, XML_p, FSEND);
+ m_pSerializer->startElementNS(XML_w, XML_r, FSEND);
+ RunText(f->GetText());
+ m_pSerializer->endElementNS(XML_w, XML_r);
+ m_pSerializer->endElementNS(XML_w, XML_p);
+ }
+
m_pSerializer->endElementNS( XML_w, XML_comment );
}
}
More information about the Libreoffice-commits
mailing list