summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2014-05-31 00:03:44 +0200
committerCaolán McNamara <caolanm@redhat.com>2014-06-03 08:50:00 +0000
commit029b24297ade84b6bf72ce1dec37d9ca9ac4b740 (patch)
treea4c30c3d14732a3de82079d30937556d65eb5e32
parent35610714c114e7fcea09dad0e395c69b8a9bdfbe (diff)
fdo#64956: editeng: fix RTF color table export
The editengine RTF export produces this: {\colortbl\red255\green255\blue255;;} ... and then it proceeds to map COL_AUTO to \cf0 i.e. the "white" entry that is the result of erroneously writing out the 0th entry regardless of whether it is COL_AUTO or not. Fix the color table export to always put COL_AUTO first (as the Writer RTF export already does), and simplify the code a bit. (cherry picked from commit 55070972b32e719e4855855797263d6342a3625f) Conflicts: editeng/source/editeng/editdoc.cxx editeng/source/editeng/editdoc.hxx editeng/source/editeng/impedit4.cxx Change-Id: Ia8ce19f387e3627a1b4a26bcc723edcf5b1ffdf8 Reviewed-on: https://gerrit.libreoffice.org/9585 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit edfd206f65afb9afb5b0e9842453ba0cc085a0b5) Reviewed-on: https://gerrit.libreoffice.org/9618 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--editeng/source/editeng/editdoc.cxx39
-rw-r--r--editeng/source/editeng/editdoc.hxx17
-rw-r--r--editeng/source/editeng/impedit.hxx1
-rw-r--r--editeng/source/editeng/impedit4.cxx42
4 files changed, 29 insertions, 70 deletions
diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx
index f02990b283ef..7eb439838e23 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -3011,45 +3011,6 @@ bool CharAttribList::DbgCheckAttribs() const
#endif
-SvxColorList::SvxColorList()
-{
-}
-
-SvxColorList::~SvxColorList()
-{
- for ( size_t i = 0, n = aColorList.size(); i < n; ++i )
- delete aColorList[ i ];
- aColorList.clear();
-}
-
-size_t SvxColorList::GetId( const SvxColorItem& rColorItem )
-{
- for ( size_t i = 0, n = aColorList.size(); i < n; ++i )
- if ( *aColorList[ i ] == rColorItem )
- return i;
- DBG_WARNING( "Color not found: GetId()" );
- return 0;
-}
-
-void SvxColorList::Insert( SvxColorItem* pItem, size_t nIndex )
-{
- if ( nIndex >= aColorList.size() )
- {
- aColorList.push_back( pItem );
- }
- else
- {
- DummyColorList::iterator it = aColorList.begin();
- ::std::advance( it, nIndex );
- aColorList.insert( it, pItem );
- }
-}
-
-SvxColorItem* SvxColorList::GetObject( size_t nIndex )
-{
- return ( nIndex >= aColorList.size() ) ? NULL : aColorList[ nIndex ];
-}
-
EditEngineItemPool::EditEngineItemPool( sal_Bool bPersistenRefCounts )
: SfxItemPool( OUString( "EditEngineItemPool" ), EE_ITEMS_START, EE_ITEMS_END,
aItemInfos, 0, bPersistenRefCounts )
diff --git a/editeng/source/editeng/editdoc.hxx b/editeng/source/editeng/editdoc.hxx
index 40676d5da5c8..dd04503bd5ca 100644
--- a/editeng/source/editeng/editdoc.hxx
+++ b/editeng/source/editeng/editdoc.hxx
@@ -131,23 +131,8 @@ public:
// ----------------------------------------------------------------------
// class SvxColorList
-// ----------------------------------------------------------------------
-
-class SvxColorList
-{
-private:
- typedef std::vector<SvxColorItem*> DummyColorList;
- DummyColorList aColorList;
-public:
- SvxColorList();
- ~SvxColorList();
-
- size_t GetId( const SvxColorItem& rColor );
- size_t Count() { return aColorList.size(); };
- void Insert( SvxColorItem* pItem, size_t nIndex );
- SvxColorItem* GetObject( size_t nIndex );
-};
+typedef std::vector<Color> SvxColorList;
// ----------------------------------------------------------------------
// class ItemList
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 31b72db317df..6efe9212ad9f 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -76,7 +76,6 @@ DBG_NAMEEX( EditEngine )
class EditView;
class EditEngine;
-class SvxColorList;
class SvxSearchItem;
class SvxLRSpaceItem;
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index a0f54dfd66ab..b4ff56ecd93f 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -431,30 +431,40 @@ sal_uInt32 ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel )
// Write out ColorList ...
SvxColorList aColorList;
+ // COL_AUTO should be the default color, always put it first
+ aColorList.push_back(COL_AUTO);
+ SvxColorItem const& rDefault(static_cast<SvxColorItem const&>(
+ aEditDoc.GetItemPool().GetDefaultItem(EE_CHAR_COLOR)));
+ if (rDefault.GetValue() != COL_AUTO) // is the default always AUTO?
+ {
+ aColorList.push_back(rDefault.GetValue());
+ }
sal_uInt32 i = 0;
- SvxColorItem* pColorItem = (SvxColorItem*)aEditDoc.GetItemPool().GetItem2( EE_CHAR_COLOR, i );
+ SvxColorItem const* pColorItem = static_cast<SvxColorItem const*>(
+ aEditDoc.GetItemPool().GetItem2( EE_CHAR_COLOR, i));
while ( pColorItem )
{
- sal_uInt32 nPos = i;
- if ( pColorItem->GetValue() == COL_AUTO )
- nPos = 0;
- aColorList.Insert( new SvxColorItem( *pColorItem ), nPos );
- pColorItem = (SvxColorItem*)aEditDoc.GetItemPool().GetItem2( EE_CHAR_COLOR, ++i );
+ ++i;
+ if ( pColorItem->GetValue() != COL_AUTO )
+ {
+ aColorList.push_back(pColorItem->GetValue());
+ }
+ pColorItem = static_cast<SvxColorItem const*>(
+ aEditDoc.GetItemPool().GetItem2(EE_CHAR_COLOR, i));
}
- aColorList.Insert( new SvxColorItem( (const SvxColorItem&)aEditDoc.GetItemPool().GetDefaultItem( EE_CHAR_COLOR) ), i );
rOutput << '{' << OOO_STRING_SVTOOLS_RTF_COLORTBL;
- for ( j = 0; j < aColorList.Count(); j++ )
+ for ( j = 0; j < aColorList.size(); j++ )
{
- pColorItem = aColorList.GetObject( j );
- if ( !j || ( pColorItem->GetValue() != COL_AUTO ) )
+ Color const color = aColorList[j];
+ if (color != COL_AUTO) // auto is represented by "empty" element
{
rOutput << OOO_STRING_SVTOOLS_RTF_RED;
- rOutput.WriteNumber( static_cast<sal_uInt32>(pColorItem->GetValue().GetRed()) );
+ rOutput.WriteNumber( static_cast<sal_uInt32>(color.GetRed()) );
rOutput << OOO_STRING_SVTOOLS_RTF_GREEN;
- rOutput.WriteNumber( static_cast<sal_uInt32>(pColorItem->GetValue().GetGreen()) );
+ rOutput.WriteNumber( static_cast<sal_uInt32>(color.GetGreen()) );
rOutput << OOO_STRING_SVTOOLS_RTF_BLUE;
- rOutput.WriteNumber( static_cast<sal_uInt32>(pColorItem->GetValue().GetBlue()) );
+ rOutput.WriteNumber( static_cast<sal_uInt32>(color.GetBlue()) );
}
rOutput << ';';
}
@@ -785,7 +795,11 @@ void ImpEditEngine::WriteItemAsRTF( const SfxPoolItem& rItem, SvStream& rOutput,
break;
case EE_CHAR_COLOR:
{
- sal_uInt32 n = rColorList.GetId( (const SvxColorItem&)rItem );
+ SvxColorList::const_iterator const iter = ::std::find(
+ rColorList.begin(), rColorList.end(),
+ static_cast<SvxColorItem const&>(rItem).GetValue());
+ assert(iter != rColorList.end());
+ sal_uInt32 const n = iter - rColorList.begin();
rOutput << OOO_STRING_SVTOOLS_RTF_CF;
rOutput.WriteNumber( n );
}