diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2024-06-20 09:53:00 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-06-21 16:44:57 +0200 |
commit | 37e7adc00c1a3d34be1c7aa74beeab89e2573efb (patch) | |
tree | 2a134dbfdfff89557e7715148d847ed97f5ae2cb /editeng/source | |
parent | f344daa0b8b2c7ff75ae086966fc1ac1894ce1cc (diff) |
tdf#161652 editeng, RTF copy: only write used paragraph styles
Copy a single world from the Impress bugdoc to Writer, number of
paragraph styles increase from 126 to 221, while only +0 or +1 are
expected.
It seems the problem is that the editeng doc of the shape refers to all
styles of the masterpage and we write the style table before the
content, so we export all styles to be on the safe side.
Fix the problem by iterating the paragraphs of the selection in the
"copy" (not "export") case, assuming that typically the selection
doesn't refer to all available styles in the document, and the number of
paragraphs in a shape is not a large amount.
An alternative would be to limit the style import on the RTF reading
side, but not producing those not needed styles in the first place looks
superior.
(cherry picked from commit afb4ea67463d9f0200dc6216cfd932aec0984c82)
Change-Id: I43e4c542e530ff6422357a28399718e89fdbabe9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169318
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'editeng/source')
-rw-r--r-- | editeng/source/editeng/impedit.hxx | 2 | ||||
-rw-r--r-- | editeng/source/editeng/impedit2.cxx | 2 | ||||
-rw-r--r-- | editeng/source/editeng/impedit4.cxx | 54 |
3 files changed, 54 insertions, 4 deletions
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 988c446aca57..6c6ddf43f135 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -727,7 +727,7 @@ private: EditPaM ReadXML( SvStream& rInput, EditSelection aSel ); EditPaM ReadHTML( SvStream& rInput, const OUString& rBaseURL, EditSelection aSel, SvKeyValueIterator* pHTTPHeaderAttrs ); ErrCode WriteText( SvStream& rOutput, EditSelection aSel ); - ErrCode WriteRTF( SvStream& rOutput, EditSelection aSel ); + ErrCode WriteRTF( SvStream& rOutput, EditSelection aSel, bool bClipboard ); void WriteXML(SvStream& rOutput, const EditSelection& rSel); void WriteItemAsRTF( const SfxPoolItem& rItem, SvStream& rOutput, sal_Int32 nPara, sal_Int32 nPos, diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 048226658d4e..50b8a34b0663 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -3839,7 +3839,7 @@ uno::Reference< datatransfer::XTransferable > ImpEditEngine::CreateTransferable( pDataObj->GetString() = convertLineEnd(GetSelected(aSelection), GetSystemLineEnd()); // System specific - WriteRTF( pDataObj->GetRTFStream(), aSelection ); + WriteRTF( pDataObj->GetRTFStream(), aSelection, /*bClipboard=*/true ); pDataObj->GetRTFStream().Seek( 0 ); WriteXML( pDataObj->GetODFStream(), aSelection ); diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 637aebe81f45..d3dc29892d6a 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -77,6 +77,7 @@ #include <memory> #include <unordered_map> #include <vector> +#include <set> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -186,7 +187,7 @@ void ImpEditEngine::Write(SvStream& rOutput, EETextFormat eFormat, const EditSel if ( eFormat == EETextFormat::Text ) WriteText( rOutput, rSel ); else if ( eFormat == EETextFormat::Rtf ) - WriteRTF( rOutput, rSel ); + WriteRTF( rOutput, rSel, /*bClipboard=*/false ); else if ( eFormat == EETextFormat::Xml ) WriteXML( rOutput, rSel ); else if ( eFormat == EETextFormat::Html ) @@ -271,7 +272,7 @@ void ImpEditEngine::WriteXML(SvStream& rOutput, const EditSelection& rSel) SvxWriteXML( *GetEditEnginePtr(), rOutput, aESel ); } -ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel ) +ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel, bool bClipboard ) { assert( IsUpdateLayout() && "WriteRTF for UpdateMode = sal_False!" ); CheckIdleFormatter(); @@ -432,6 +433,50 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel ) nId++; } + // Collect used paragraph styles when copying to the clipboard. + std::set<SfxStyleSheetBase*> aUsedParagraphStyles; + if (bClipboard) + { + for (sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++) + { + ContentNode* pNode = maEditDoc.GetObject(nNode); + if (!pNode) + { + continue; + } + + SfxStyleSheet* pParaStyle = pNode->GetStyleSheet(); + if (!pParaStyle) + { + continue; + } + + aUsedParagraphStyles.insert(pParaStyle); + + const OUString& rParent = pParaStyle->GetParent(); + if (!rParent.isEmpty()) + { + auto pParent = static_cast<SfxStyleSheet*>( + GetStyleSheetPool()->Find(rParent, pParaStyle->GetFamily())); + if (pParent) + { + aUsedParagraphStyles.insert(pParent); + } + } + + const OUString& rFollow = pParaStyle->GetFollow(); + if (!rFollow.isEmpty()) + { + auto pFollow = static_cast<SfxStyleSheet*>( + GetStyleSheetPool()->Find(rFollow, pParaStyle->GetFamily())); + if (pFollow) + { + aUsedParagraphStyles.insert(pFollow); + } + } + } + } + if ( aSSSIterator->Count() ) { @@ -441,6 +486,11 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel ) for ( SfxStyleSheetBase* pStyle = aSSSIterator->First(); pStyle; pStyle = aSSSIterator->Next() ) { + if (bClipboard && !aUsedParagraphStyles.contains(pStyle)) + { + // Don't write unused paragraph styles in the clipboard case. + continue; + } rOutput << endl; rOutput.WriteChar( '{' ).WriteOString( OOO_STRING_SVTOOLS_RTF_S ); |