summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2013-11-27 12:40:59 +0100
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2013-12-04 18:52:03 +0100
commit9e47df8fd7c3cb1dcf556e009cec2d37b928d9b0 (patch)
tree990df0689fcf26555d1067a79069e4d6bfbda552 /sw
parent0fa60a7f5c1d3510c4fe1ea3d2a51527baf102bc (diff)
fdo#64232: Save font theme attributes back to the docx
Font theme attributes were saved to an InteropGrabBag on import, and they have to be saved back to the document when exporting to docx. If the user modified the font in a text fragment during edition, the theme attribute should be discarded in favour of the font attribute. The attributes in the grab bag are processed in the last place so we can compare the font attributes with the original fonts to know if they have changed. Change-Id: I2502b4aa96213e74b46fccd1a20f99421f7cf98b
Diffstat (limited to 'sw')
-rw-r--r--sw/source/filter/ww8/attributeoutputbase.hxx3
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx67
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx3
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx4
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.hxx3
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx6
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx7
-rw-r--r--sw/source/filter/ww8/ww8attributeoutput.hxx3
8 files changed, 96 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx
index f37ebff1fa1c..8060368d11d2 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -588,6 +588,9 @@ protected:
/// Sfx item RES_PARATR_GRABBAG
virtual void ParaGrabBag( const SfxGrabBagItem& ) = 0;
+ /// Sfx item RES_CHRATR_GRABBAG
+ virtual void CharGrabBag( const SfxGrabBagItem& ) = 0;
+
/// Sfx item RES_PARATR_OUTLINELEVEL
virtual void ParaOutlineLevel( const SfxUInt16Item& ) = 0;
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index a01788e7dd7a..3cb24aef5ef4 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -6235,6 +6235,73 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem)
}
}
+void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem )
+{
+ const std::map< OUString, com::sun::star::uno::Any >& rMap = rItem.GetGrabBag();
+
+ // get original font names and check if they have changed during the edition
+ sal_Bool bWriteCSTheme = sal_True;
+ sal_Bool bWriteAsciiTheme = sal_True;
+ if ( m_pFontsAttrList )
+ {
+ OUString sFontName;
+ for ( std::map< OUString, com::sun::star::uno::Any >::const_iterator i = rMap.begin(); i != rMap.end(); i++ )
+ {
+ if ( i->first == "CharThemeFontNameCs" )
+ {
+ if ( i->second >>= sFontName )
+ bWriteCSTheme =
+ ( m_pFontsAttrList->getOptionalValue( FSNS( XML_w, XML_cs ) ) == sFontName );
+ }
+ else if ( i->first == "CharThemeFontNameAscii" )
+ {
+ if ( i->second >>= sFontName )
+ bWriteAsciiTheme =
+ ( m_pFontsAttrList->getOptionalValue( FSNS( XML_w, XML_ascii ) ) == sFontName );
+ }
+ }
+ }
+
+ // save theme attributes back to the run properties
+ OUString str;
+ for ( std::map< OUString, com::sun::star::uno::Any >::const_iterator i = rMap.begin(); i != rMap.end(); i++ )
+ {
+ if ( i->first == "CharThemeNameAscii" && bWriteAsciiTheme )
+ {
+ i->second >>= str;
+ if (!m_pFontsAttrList)
+ m_pFontsAttrList = m_pSerializer->createAttrList();
+ m_pFontsAttrList->add( FSNS( XML_w, XML_asciiTheme ),
+ OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+ }
+ else if ( i->first == "CharThemeNameCs" && bWriteCSTheme )
+ {
+ i->second >>= str;
+ if (!m_pFontsAttrList)
+ m_pFontsAttrList = m_pSerializer->createAttrList();
+ m_pFontsAttrList->add( FSNS( XML_w, XML_cstheme ),
+ OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+ }
+ else if ( i->first == "CharThemeNameHAnsi" && bWriteAsciiTheme )
+ // this is not a mistake: in LibO we don't directly support the hAnsi family
+ // of attributes so we save the same value from ascii attributes instead
+ {
+ i->second >>= str;
+ if (!m_pFontsAttrList)
+ m_pFontsAttrList = m_pSerializer->createAttrList();
+ m_pFontsAttrList->add( FSNS( XML_w, XML_hAnsiTheme ),
+ OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+ }
+ else if( i->first == "CharThemeFontNameCs" ||
+ i->first == "CharThemeFontNameAscii" )
+ {
+ // just skip these, they were processed before
+ }
+ else
+ SAL_INFO("sw.ww8", "DocxAttributeOutput::CharGrabBag: unhandled grab bag property " << i->first);
+ }
+}
+
DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSerializer, oox::drawingml::DrawingML* pDrawingML )
: m_rExport( rExport ),
m_pSerializer( pSerializer ),
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 18d6c81e23fa..65416af4a99b 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -609,6 +609,9 @@ protected:
/// Sfx item RES_PARATR_GRABBAG
virtual void ParaGrabBag( const SfxGrabBagItem& );
+ /// Sfx item RES_CHRATR_GRABBAG
+ virtual void CharGrabBag( const SfxGrabBagItem& );
+
// Sfx item RES_PARATR_OUTLINELEVEL
virtual void ParaOutlineLevel( const SfxUInt16Item& );
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 174acb6783eb..fd1eca3dece6 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -3132,6 +3132,10 @@ void RtfAttributeOutput::ParaGrabBag(const SfxGrabBagItem& /*rItem*/)
{
}
+void RtfAttributeOutput::CharGrabBag(const SfxGrabBagItem& /*rItem*/)
+{
+}
+
void RtfAttributeOutput::ParaOutlineLevel(const SfxUInt16Item& /*rItem*/)
{
}
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index e92388f86b9c..46a2562fd140 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -419,6 +419,9 @@ protected:
/// Sfx item RES_PARATR_GRABBAG
virtual void ParaGrabBag( const SfxGrabBagItem& );
+ /// Sfx item RES_CHRATR_GRABBAG
+ virtual void CharGrabBag( const SfxGrabBagItem& );
+
/// Sfx item RES_PARATR_OUTLINELEVEL
virtual void ParaOutlineLevel( const SfxUInt16Item& );
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 695c11382dcc..6899165a7ea4 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -393,6 +393,7 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bRuby )
const SvxFontItem &rParentFont = ItemGet<SvxFontItem>(
(const SwTxtFmtColl&)rNd.GetAnyFmtColl(), nFontId);
const SvxFontItem *pFont = &rParentFont;
+ const SfxPoolItem *aGrabBag;
SfxItemSet aExportSet(*rNd.GetSwAttrSet().GetPool(),
RES_CHRATR_BEGIN, RES_TXTATR_END - 1);
@@ -436,6 +437,8 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bRuby )
{
if (nWhichId == nFontId)
pFont = &(item_cast<SvxFontItem>(*pItem));
+ else if (nWhichId == RES_CHRATR_GRABBAG)
+ aGrabBag = pItem;
else
aRangeItems[nWhichId] = pItem;
}
@@ -510,6 +513,9 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bRuby )
if ( rParentFont != aFont )
m_rExport.AttrOutput().OutputItem( aFont );
}
+
+ // Output grab bag attributes
+ m_rExport.AttrOutput().OutputItem( *aGrabBag );
}
void SwWW8AttrIter::OutFlys(sal_Int32 nSwPos)
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 349596cc6913..e0a64f80527b 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -4733,6 +4733,10 @@ void WW8AttributeOutput::ParaGrabBag(const SfxGrabBagItem& /*rItem*/)
{
}
+void WW8AttributeOutput::CharGrabBag(const SfxGrabBagItem& /*rItem*/)
+{
+}
+
void WW8AttributeOutput::ParaOutlineLevel(const SfxUInt16Item& /*rItem*/)
{
}
@@ -5284,6 +5288,9 @@ void AttributeOutputBase::OutputItem( const SfxPoolItem& rHt )
case RES_PARATR_OUTLINELEVEL:
ParaOutlineLevel(static_cast<const SfxUInt16Item&>(rHt));
break;
+ case RES_CHRATR_GRABBAG:
+ CharGrabBag(static_cast<const SfxGrabBagItem&>(rHt));
+ break;
default:
SAL_INFO("sw.ww8", "Unhandled SfxPoolItem with id " << rHt.Which() );
diff --git a/sw/source/filter/ww8/ww8attributeoutput.hxx b/sw/source/filter/ww8/ww8attributeoutput.hxx
index cea26ef2147b..ef844ea7273b 100644
--- a/sw/source/filter/ww8/ww8attributeoutput.hxx
+++ b/sw/source/filter/ww8/ww8attributeoutput.hxx
@@ -402,6 +402,9 @@ protected:
/// Sfx item RES_PARATR_GRABBAG
virtual void ParaGrabBag( const SfxGrabBagItem& );
+ /// Sfx item RES_TXTATR_GRABBAG
+ virtual void CharGrabBag( const SfxGrabBagItem& );
+
// Sfx item RES_PARATR_OUTLINELEVEL
virtual void ParaOutlineLevel( const SfxUInt16Item& );