sw/qa/extras/ooxmlexport/data/comments-nested.odt |binary sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 9 +++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 20 +++++++++++++++----- sw/source/filter/ww8/docxattributeoutput.hxx | 4 +++- 4 files changed, 27 insertions(+), 6 deletions(-)
New commits: commit 9ae3ad21422da1ed9693bdc9d14a06b15657c11f Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Mon Jan 13 09:48:48 2014 +0100 DOCX export: fix nested comments Change-Id: I9e252ab5645de8f88d0d4c6c0023402d86dd2e9e diff --git a/sw/qa/extras/ooxmlexport/data/comments-nested.odt b/sw/qa/extras/ooxmlexport/data/comments-nested.odt new file mode 100644 index 0000000..e768605 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/comments-nested.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index e570ff1..fb09a20 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -272,6 +272,15 @@ DECLARE_OOXMLEXPORT_TEST(testFdo38244, "fdo38244.docx") CPPUNIT_ASSERT_EQUAL(true, bCaught); } +DECLARE_OOXMLEXPORT_TEST(testCommentsNested, "comments-nested.odt") +{ + uno::Reference<beans::XPropertySet> xOuter(getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 2), "TextField"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Outer"), getProperty<OUString>(xOuter, "Content")); + + uno::Reference<beans::XPropertySet> xInner(getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 4), "TextField"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Inner"), getProperty<OUString>(xInner, "Content")); +} + DECLARE_OOXMLEXPORT_TEST(testMathEscape, "math-escape.docx") { CPPUNIT_ASSERT_EQUAL(OUString("\\{ left [ right ] left ( right ) \\}"), getFormula(getRun(getParagraph(1), 1))); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 4ad9c9b..0b04ccb 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -4670,18 +4670,28 @@ void DocxAttributeOutput::HiddenField( const SwField& /*rFld*/ ) void DocxAttributeOutput::PostitField( const SwField* pFld ) { assert( dynamic_cast< const SwPostItField* >( pFld )); - m_postitFields.push_back( static_cast< const SwPostItField* >( pFld )); + const SwPostItField* pPostItFld = static_cast<const SwPostItField*>(pFld); + OString aName = OUStringToOString(pPostItFld->GetName(), RTL_TEXTENCODING_UTF8); + sal_Int32 nId = 0; + std::map< OString, sal_uInt16 >::iterator it = m_rOpenedAnnotationMarksIds.find(aName); + if (it != m_rOpenedAnnotationMarksIds.end()) + // If the postit field has an annotation mark associated, we already have an id. + nId = it->second; + else + // Otherwise get a new one. + nId = m_nNextAnnotationMarkId++; + m_postitFields.push_back(std::make_pair(pPostItFld, nId)); } void DocxAttributeOutput::WritePostitFieldReference() { while( m_postitFieldsMaxId < m_postitFields.size()) { - OString idstr = OString::number( m_postitFieldsMaxId); + OString idstr = OString::number(m_postitFields[m_postitFieldsMaxId].second); // In case this file is inside annotation marks, we want to write the // comment reference after the annotation mark is closed, not here. - OString idname = OUStringToOString(m_postitFields[m_postitFieldsMaxId]->GetName(), RTL_TEXTENCODING_UTF8); + OString idname = OUStringToOString(m_postitFields[m_postitFieldsMaxId].first->GetName(), RTL_TEXTENCODING_UTF8); std::map< OString, sal_uInt16 >::iterator it = m_rOpenedAnnotationMarksIds.find( idname ); if ( it == m_rOpenedAnnotationMarksIds.end( ) ) m_pSerializer->singleElementNS( XML_w, XML_commentReference, FSNS( XML_w, XML_id ), idstr.getStr(), FSEND ); @@ -4695,8 +4705,8 @@ void DocxAttributeOutput::WritePostitFields() i < m_postitFields.size(); ++i ) { - OString idstr = OString::number( i); - const SwPostItField* f = m_postitFields[ i ]; + OString idstr = OString::number( m_postitFields[ i ].second); + const SwPostItField* f = m_postitFields[ i ].first; m_pSerializer->startElementNS( XML_w, XML_comment, FSNS( XML_w, XML_id ), idstr.getStr(), FSNS( XML_w, XML_author ), OUStringToOString( f->GetPar1(), RTL_TEXTENCODING_UTF8 ).getStr(), FSNS( XML_w, XML_date ), DateTimeToOString(f->GetDateTime()).getStr(), diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 3375895..87bafdc 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -783,7 +783,9 @@ private: const SdrObject* m_postponedChart; Size m_postponedChartSize; const SwField* pendingPlaceholder; - std::vector< const SwPostItField* > m_postitFields; + /// Maps postit fields to ID's, used in commentRangeStart/End, commentReference and comment.xml. + std::vector< std::pair<const SwPostItField*, sal_Int32> > m_postitFields; + /// Number of postit fields which already have a commentReference written. unsigned int m_postitFieldsMaxId; int m_anchorId; int m_nextFontId; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits