diff options
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport.cxx | 7 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfattributeoutput.cxx | 59 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfattributeoutput.hxx | 5 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.cxx | 26 |
4 files changed, 85 insertions, 12 deletions
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 2abe9c58874b..2f9a82be9fdd 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -134,8 +134,6 @@ DECLARE_RTFEXPORT_TEST(testFdo48335, "fdo48335.odt") DECLARE_RTFEXPORT_TEST(testFdo38244, "fdo38244.rtf") { -#if 0 - // FIXME port to AnnotationMarks // See ooxmlexport's testFdo38244(). // Test comment range feature. uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); @@ -145,10 +143,10 @@ DECLARE_RTFEXPORT_TEST(testFdo38244, "fdo38244.rtf") uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration(); xRunEnum->nextElement(); uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty<OUString>(xPropertySet, "TextPortionType")); xRunEnum->nextElement(); xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty<OUString>(xPropertySet, "TextPortionType")); // Test initials. uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); @@ -156,7 +154,6 @@ DECLARE_RTFEXPORT_TEST(testFdo38244, "fdo38244.rtf") uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials")); -#endif } DECLARE_RTFEXPORT_TEST(testMathAccents, "math-accents.rtf") diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index b09440efb1c7..06939ffda827 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -1472,6 +1472,48 @@ void RtfAttributeOutput::WriteBookmarks_Impl( std::vector< OUString >& rStarts, rEnds.clear(); } +void RtfAttributeOutput::WriteAnnotationMarks_Impl( std::vector< OUString >& rStarts, std::vector< OUString >& rEnds ) +{ + for ( std::vector< OUString >::const_iterator i = rStarts.begin(), end = rStarts.end(); i != end; ++i ) + { + OString rName = OUStringToOString( *i, RTL_TEXTENCODING_UTF8 ); + + // Output the annotation mark + sal_uInt16 nId = m_nNextAnnotationMarkId++; + const SwPostItField* pField = 0; // This will be set by PostitField(). + m_rOpenedAnnotationMarksIds[rName] = std::make_pair(nId, pField); + m_aRun->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_ATRFSTART " "); + m_aRun->append(OString::number(nId).getStr()); + m_aRun->append('}'); + } + rStarts.clear(); + + for ( std::vector< OUString >::const_iterator i = rEnds.begin(), end = rEnds.end(); i != end; ++i ) + { + OString rName = OUStringToOString( *i, RTL_TEXTENCODING_UTF8 ); + + // Get the id of the annotation mark + std::map< OString, std::pair<sal_uInt16, const SwPostItField*> >::iterator it = m_rOpenedAnnotationMarksIds.find( rName ); + if (it != m_rOpenedAnnotationMarksIds.end()) + { + sal_uInt16 nId = ( *it ).second.first; + const SwPostItField* pField = ( *it ).second.second; + m_aRun->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_ATRFEND " "); + m_aRun->append(OString::number(nId).getStr()); + m_aRun->append('}'); + m_rOpenedAnnotationMarksIds.erase( rName ); + + if (pField) + { + m_aRunText->append("{"); + PostitField(pField); + m_aRunText->append("}"); + } + } + } + rEnds.clear(); +} + void RtfAttributeOutput::WriteHeaderFooter_Impl( const SwFrmFmt& rFmt, bool bHeader, const sal_Char* pStr, bool bTitlepg ) { OStringBuffer aSectionBreaks = m_aSectionBreaks; @@ -3184,6 +3226,16 @@ void RtfAttributeOutput::PostitField( const SwField* pFld ) const SwPostItField& rPFld = *(SwPostItField*)pFld; + OString aName = OUStringToOString(rPFld.GetName(), RTL_TEXTENCODING_UTF8); + std::map< OString, std::pair<sal_uInt16, const SwPostItField*> >::iterator it = m_rOpenedAnnotationMarksIds.find(aName); + if (it != m_rOpenedAnnotationMarksIds.end()) + { + // In case this field is inside annotation marks, we want to write the + // annotation itself after the annotation mark is closed, not here. + it->second.second = &rPFld; + return; + } + m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_ATNID " "); m_aRunText->append(OUStringToOString(OUString(rPFld.GetInitials()), m_rExport.eCurrentEncoding)); m_aRunText->append("}"); @@ -3205,16 +3257,10 @@ void RtfAttributeOutput::PostitField( const SwField* pFld ) void RtfAttributeOutput::WritePostitFieldStart() { - m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_ATRFSTART " "); - m_aRunText->append(sal_Int32(m_nPostitFieldsMaxId)); - m_aRunText->append("}"); } void RtfAttributeOutput::WritePostitFieldEnd() { - m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_ATRFEND " "); - m_aRunText->append(sal_Int32(m_nPostitFieldsMaxId)); - m_aRunText->append("}"); } bool RtfAttributeOutput::DropdownField( const SwField* /*pFld*/ ) @@ -3234,6 +3280,7 @@ bool RtfAttributeOutput::PlaceholderField( const SwField* pField) RtfAttributeOutput::RtfAttributeOutput( RtfExport &rExport ) : m_rExport( rExport ), m_bStrikeDouble( false ), + m_nNextAnnotationMarkId(0), m_pTableWrt( NULL ), m_bTableCellOpen( false ), m_nTableDepth( 0 ), diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx index 426f64335325..d7ce5c8a60db 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.hxx +++ b/sw/source/filter/ww8/rtfattributeoutput.hxx @@ -212,6 +212,7 @@ public: void WriteField_Impl( const SwField* pFld, ww::eField eType, const OUString& rFldCmd, sal_uInt8 nMode ); void WriteBookmarks_Impl( std::vector< OUString >& rStarts, std::vector< OUString >& rEnds ); + void WriteAnnotationMarks_Impl( std::vector< OUString >& rStarts, std::vector< OUString >& rEnds ); void WriteHeaderFooter_Impl( const SwFrmFmt& rFmt, bool bHeader, const sal_Char* pStr, bool bTitlepg ); protected: @@ -502,6 +503,10 @@ private: */ bool m_bStrikeDouble; + sal_Int32 m_nNextAnnotationMarkId; + /// Map of the annotation marks ids + std::map< OString, std::pair<sal_uInt16, const SwPostItField*> > m_rOpenedAnnotationMarksIds; + /* * The current table helper. */ diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 1bc64946db1f..28d05f0230e3 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -163,8 +163,32 @@ void RtfExport::AppendBookmark( const OUString& rName, bool /*bSkip*/ ) m_pAttrOutput->WriteBookmarks_Impl(aStarts, aEnds); } -void RtfExport::AppendAnnotationMarks( const SwTxtNode& /*rNode*/, sal_Int32 /*nAktPos*/, sal_Int32 /*nLen*/ ) +void RtfExport::AppendAnnotationMarks( const SwTxtNode& rNode, sal_Int32 nAktPos, sal_Int32 nLen ) { + SAL_INFO("sw.rtf", OSL_THIS_FUNC); + + std::vector< OUString > aStarts; + std::vector< OUString > aEnds; + + IMarkVector aMarks; + if ( GetAnnotationMarks( rNode, nAktPos, nAktPos + nLen, aMarks ) ) + { + for ( IMarkVector::const_iterator it = aMarks.begin(), end = aMarks.end(); + it != end; ++it ) + { + IMark* pMark = (*it); + const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex(); + const sal_Int32 nEnd = pMark->GetMarkEnd().nContent.GetIndex(); + + if ( nStart == nAktPos ) + aStarts.push_back( pMark->GetName() ); + + if ( nEnd == nAktPos ) + aEnds.push_back( pMark->GetName() ); + } + } + + m_pAttrOutput->WriteAnnotationMarks_Impl( aStarts, aEnds ); } //For i120928,to export graphic of bullet for RTF filter |