diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-02-22 20:42:37 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-02-23 17:40:09 +0100 |
commit | ab2b20b66394c1d219caafc380488f5296c1c12c (patch) | |
tree | 0cd8abbd1b80e75b25fe7836151ed2c8f7c828d6 | |
parent | 7f93b4001f3b7266695b46b3a5c95d0b9c66af35 (diff) |
ooxml: handle w14:shadow in import/export
Refactor the code to support an additional main element at processing
of w14 elements for rPr.
Change-Id: Iaf18a11bbda245b0b5b629e5f2e9f1f9682e6d41
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 72 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 27 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyIds.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyIds.hxx | 1 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TextEffectsHandler.cxx | 104 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TextEffectsHandler.hxx | 19 |
7 files changed, 170 insertions, 57 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index b81fcc6f401d..b34ce931ad20 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1123,6 +1123,7 @@ void DocxAttributeOutput::InitCollectedRunProperties() FSNS( XML_w, XML_oMath ), FSNS( XML_w, XML_rPrChange ), FSNS( XML_w14, XML_glow ), + FSNS( XML_w14, XML_shadow ), }; // postpone the output so that we can later [in EndParagraphProperties()] @@ -1145,10 +1146,22 @@ struct NameToId const sal_Int32 maId; }; -const NameToId aNameToIdMapping[] = +const NameToId constNameToIdMapping[] = { + { OUString("glow"), FSNS( XML_w14, XML_glow ) }, + { OUString("shadow"), FSNS( XML_w14, XML_shadow ) }, + { OUString("val"), FSNS( XML_w14, XML_val ) }, { OUString("rad"), FSNS( XML_w14, XML_rad ) }, + { OUString("blurRad"), FSNS( XML_w14, XML_blurRad ) }, + { OUString("dist"), FSNS( XML_w14, XML_dist ) }, + { OUString("dir"), FSNS( XML_w14, XML_dir ) }, + { OUString("sx"), FSNS( XML_w14, XML_sx ) }, + { OUString("sy"), FSNS( XML_w14, XML_sy ) }, + { OUString("kx"), FSNS( XML_w14, XML_kx ) }, + { OUString("ky"), FSNS( XML_w14, XML_ky ) }, + { OUString("algn"), FSNS( XML_w14, XML_algn ) }, + { OUString("schemeClr"), FSNS( XML_w14, XML_schemeClr ) }, { OUString("srgbClr"), FSNS( XML_w14, XML_srgbClr ) }, { OUString("tint"), FSNS( XML_w14, XML_tint ) }, @@ -1163,6 +1176,19 @@ const NameToId aNameToIdMapping[] = { OUString("lumMod"), FSNS( XML_w14, XML_lumMod ) }, }; +boost::optional<sal_Int32> lclGetElementIdForName(OUString aName) +{ + sal_Int32 aLength = sizeof (constNameToIdMapping) / sizeof(NameToId); + for (sal_Int32 i=0; i < aLength; ++i) + { + if(aName == constNameToIdMapping[i].maName) + { + return constNameToIdMapping[i].maId; + } + } + return boost::optional<sal_Int32>(); +} + void lclProcessRecursiveGrabBag(sal_Int32 aElementId, css::uno::Sequence<css::beans::PropertyValue> aElements, sax_fastparser::FSHelperPtr pSerializer) { css::uno::Sequence<css::beans::PropertyValue> aAttributes; @@ -1190,14 +1216,9 @@ void lclProcessRecursiveGrabBag(sal_Int32 aElementId, css::uno::Sequence<css::be aValue = OUStringToOString(aAny.get<OUString>(), RTL_TEXTENCODING_ASCII_US); } - sal_Int32 aLength = sizeof (aNameToIdMapping) / sizeof(NameToId); - for (sal_Int32 i=0; i < aLength; ++i) - { - if(aAttributes[j].Name == aNameToIdMapping[i].maName) - { - pAttributes->add( aNameToIdMapping[i].maId, aValue.getStr()); - } - } + boost::optional<sal_Int32> aSubElementId = lclGetElementIdForName(aAttributes[j].Name); + if(aSubElementId) + pAttributes->add(*aSubElementId, aValue.getStr()); } XFastAttributeListRef xAttributesList( pAttributes ); @@ -1208,14 +1229,11 @@ void lclProcessRecursiveGrabBag(sal_Int32 aElementId, css::uno::Sequence<css::be { css::uno::Sequence<css::beans::PropertyValue> aSumElements; - sal_Int32 aLength = sizeof (aNameToIdMapping) / sizeof(NameToId); - for (sal_Int32 i=0; i < aLength; ++i) + boost::optional<sal_Int32> aSubElementId = lclGetElementIdForName(aElements[j].Name); + if(aSubElementId) { - if( aElements[j].Name == aNameToIdMapping[i].maName) - { - aElements[j].Value >>= aSumElements; - lclProcessRecursiveGrabBag(aNameToIdMapping[i].maId, aSumElements, pSerializer); - } + aElements[j].Value >>= aSumElements; + lclProcessRecursiveGrabBag(*aSubElementId, aSumElements, pSerializer); } } @@ -1261,7 +1279,16 @@ void DocxAttributeOutput::WriteCollectedRunProperties() if (m_aTextEffectsGrabBag.getLength() > 0) { - lclProcessRecursiveGrabBag(FSNS( XML_w14, XML_glow ), m_aTextEffectsGrabBag, m_pSerializer); + for (sal_Int32 i=0; i < m_aTextEffectsGrabBag.getLength(); ++i) + { + boost::optional<sal_Int32> aElementId = lclGetElementIdForName(m_aTextEffectsGrabBag[i].Name); + if(aElementId) + { + uno::Sequence<beans::PropertyValue> aGrabBagSeq; + m_aTextEffectsGrabBag[i].Value >>= aGrabBagSeq; + lclProcessRecursiveGrabBag(*aElementId, aGrabBagSeq, m_pSerializer); + } + } m_aTextEffectsGrabBag.realloc(0); } } @@ -6437,11 +6464,14 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) { // just skip these, they were processed before } - else if (i->first == "CharGlowTextEffect") + else if (i->first == "CharGlowTextEffect" || + i->first == "CharShadowTextEffect") { - uno::Sequence<beans::PropertyValue> aGrabBagSeq; - i->second >>= aGrabBagSeq; - m_aTextEffectsGrabBag = aGrabBagSeq; + beans::PropertyValue aPropertyValue; + i->second >>= aPropertyValue; + sal_Int32 aLength = m_aTextEffectsGrabBag.getLength(); + m_aTextEffectsGrabBag.realloc(m_aTextEffectsGrabBag.getLength() + 1); + m_aTextEffectsGrabBag[aLength] = aPropertyValue; } else SAL_INFO("sw.ww8", "DocxAttributeOutput::CharGrabBag: unhandled grab bag property " << i->first); diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 8463d395ae1e..30474f17b35c 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -736,7 +736,7 @@ private: /// names of these bookmarks for each sequence. std::map<OUString, std::vector<OString> > m_aSeqBookmarksNames; - /// GrabBag for text effexts like glow + /// GrabBag for text effexts like glow, shadow, ... css::uno::Sequence<css::beans::PropertyValue> m_aTextEffectsGrabBag; /// The current table helper diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 80f1ed8fc9d9..8e43ede9eb15 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2336,20 +2336,29 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext, SprmType m_pImpl->m_nTableDepth--; break; case NS_ooxml::LN_glow_glow: + case NS_ooxml::LN_shadow_shadow: + case NS_ooxml::LN_reflection_reflection: + case NS_ooxml::LN_textOutline_textOutline: + case NS_ooxml::LN_textFill_textFill: + case NS_ooxml::LN_scene3d_scene3d: + case NS_ooxml::LN_props3d_props3d: + case NS_ooxml::LN_ligatures_ligatures: + case NS_ooxml::LN_numForm_numForm: + case NS_ooxml::LN_numSpacing_numSpacing: + case NS_ooxml::LN_stylisticSets_stylisticSets: + case NS_ooxml::LN_cntxtAlts_cntxtAlts: { writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps(); if( pProperties.get()) { - TextEffectsHandlerPtr pTextEffectsHandlerPtr( new TextEffectsHandler ); - sal_Bool bEnableTempGrabBag = !pTextEffectsHandlerPtr->isInteropGrabBagEnabled(); - if( bEnableTempGrabBag ) - pTextEffectsHandlerPtr->enableInteropGrabBag( "glow" ); - - pProperties->resolve(*pTextEffectsHandlerPtr); + TextEffectsHandlerPtr pTextEffectsHandlerPtr( new TextEffectsHandler(nSprmId) ); + boost::optional<PropertyIds> aPropertyId = pTextEffectsHandlerPtr->getGrabBagPropertyId(); - rContext->Insert(PROP_CHAR_GLOW_TEXT_EFFECT, pTextEffectsHandlerPtr->getInteropGrabBag().Value, true, CHAR_GRAB_BAG); - if(bEnableTempGrabBag) - pTextEffectsHandlerPtr->disableInteropGrabBag(); + if(aPropertyId) + { + pProperties->resolve(*pTextEffectsHandlerPtr); + rContext->Insert(*aPropertyId, uno::makeAny(pTextEffectsHandlerPtr->getInteropGrabBag()), true, CHAR_GRAB_BAG); + } } } break; diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx index ce007e230e0f..c3792cc89221 100644 --- a/writerfilter/source/dmapper/PropertyIds.cxx +++ b/writerfilter/source/dmapper/PropertyIds.cxx @@ -115,7 +115,6 @@ OUString PropertyNameSupplier::GetName( PropertyIds eId ) const case PROP_CHAR_BOTTOM_BORDER_DISTANCE: sName = "CharBottomBorderDistance"; break; case PROP_CHAR_SHADOW_FORMAT: sName = "CharShadowFormat"; break; case PROP_CHAR_HIGHLIGHT: sName = "CharHighlight"; break; - case PROP_PARA_STYLE_NAME: sName = "ParaStyleName"; break; case PROP_PARA_ADJUST: sName = "ParaAdjust"; break; case PROP_PARA_VERT_ALIGNMENT: sName = "ParaVertAlignment"; break; @@ -377,6 +376,7 @@ OUString PropertyNameSupplier::GetName( PropertyIds eId ) const case PROP_TOC_PARAGRAPH_OUTLINE_LEVEL : sName = "TOCParagraphOutlineLevel"; break; case PROP_CHAR_THEME_COLOR_TINT : sName = "CharThemeColorTint"; break; case PROP_CHAR_GLOW_TEXT_EFFECT : sName = "CharGlowTextEffect"; break; + case PROP_CHAR_SHADOW_TEXT_EFFECT : sName = "CharShadowTextEffect"; break; } ::std::pair<PropertyNameMap_t::iterator,bool> aInsertIt = m_pImpl->aNameMap.insert( PropertyNameMap_t::value_type( eId, sName )); diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx index c8155b1be18d..18ba148e10c2 100644 --- a/writerfilter/source/dmapper/PropertyIds.hxx +++ b/writerfilter/source/dmapper/PropertyIds.hxx @@ -348,6 +348,7 @@ enum PropertyIds ,PROP_TOC_PARAGRAPH_OUTLINE_LEVEL ,PROP_CHAR_THEME_COLOR_TINT ,PROP_CHAR_GLOW_TEXT_EFFECT + ,PROP_CHAR_SHADOW_TEXT_EFFECT }; struct PropertyNameSupplier_Impl; class PropertyNameSupplier diff --git a/writerfilter/source/dmapper/TextEffectsHandler.cxx b/writerfilter/source/dmapper/TextEffectsHandler.cxx index 060a389ae82c..edb219ea6548 100644 --- a/writerfilter/source/dmapper/TextEffectsHandler.cxx +++ b/writerfilter/source/dmapper/TextEffectsHandler.cxx @@ -98,7 +98,7 @@ public: } }; -OUString TextEffectsHandler::getSchemeColorTypeString(sal_Int32 nType) +OUString TextEffectsHandler::getSchemeColorValTypeString(sal_Int32 nType) { switch (nType) { @@ -118,17 +118,70 @@ OUString TextEffectsHandler::getSchemeColorTypeString(sal_Int32 nType) return OUString(); } +OUString TextEffectsHandler::getRectAlignmentString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_RectAlignment_none: return OUString("none"); + case NS_ooxml::LN_ST_RectAlignment_tl: return OUString("tl"); + case NS_ooxml::LN_ST_RectAlignment_t: return OUString("t"); + case NS_ooxml::LN_ST_RectAlignment_tr: return OUString("tr"); + case NS_ooxml::LN_ST_RectAlignment_l: return OUString("l"); + case NS_ooxml::LN_ST_RectAlignment_ctr: return OUString("ctr"); + case NS_ooxml::LN_ST_RectAlignment_r: return OUString("r"); + case NS_ooxml::LN_ST_RectAlignment_bl: return OUString("bl"); + case NS_ooxml::LN_ST_RectAlignment_b: return OUString("b"); + case NS_ooxml::LN_ST_RectAlignment_br: return OUString("br"); -TextEffectsHandler::TextEffectsHandler() : + default: break; + } + return OUString(); +} + +void TextEffectsHandler::convertElementIdToPropertyId(sal_Int32 aElementId) +{ + switch(aElementId) + { + case NS_ooxml::LN_glow_glow: + maPropertyId = PROP_CHAR_GLOW_TEXT_EFFECT; + maElementName = "glow"; + break; + case NS_ooxml::LN_shadow_shadow: + maPropertyId = PROP_CHAR_SHADOW_TEXT_EFFECT; + maElementName = "shadow"; + break; + case NS_ooxml::LN_reflection_reflection: + case NS_ooxml::LN_textOutline_textOutline: + case NS_ooxml::LN_textFill_textFill: + case NS_ooxml::LN_scene3d_scene3d: + case NS_ooxml::LN_props3d_props3d: + case NS_ooxml::LN_ligatures_ligatures: + case NS_ooxml::LN_numForm_numForm: + case NS_ooxml::LN_numSpacing_numSpacing: + case NS_ooxml::LN_stylisticSets_stylisticSets: + case NS_ooxml::LN_cntxtAlts_cntxtAlts: + default: + break; + } +} + +TextEffectsHandler::TextEffectsHandler(sal_uInt32 aElementId) : LoggedProperties(dmapper_logger, "TextEffectsHandler"), mpGrabBagStack(NULL) { + convertElementIdToPropertyId(aElementId); + mpGrabBagStack.reset(new GrabBagStack(maElementName)); } TextEffectsHandler::~TextEffectsHandler() { } +boost::optional<PropertyIds> TextEffectsHandler::getGrabBagPropertyId() +{ + return maPropertyId; +} + void TextEffectsHandler::lcl_attribute(Id aName, Value& aValue) { @@ -147,7 +200,7 @@ void TextEffectsHandler::lcl_attribute(Id aName, Value& aValue) mpGrabBagStack->appendElement("val", makeAny(sal_Int32(aValue.getInt()))); break; case NS_ooxml::LN_CT_SchemeColor_val: - mpGrabBagStack->appendElement("val", makeAny(getSchemeColorTypeString(sal_Int32(aValue.getInt())))); + mpGrabBagStack->appendElement("val", makeAny(getSchemeColorValTypeString(sal_Int32(aValue.getInt())))); break; case NS_ooxml::LN_CT_SRgbColor_val: { @@ -155,12 +208,39 @@ void TextEffectsHandler::lcl_attribute(Id aName, Value& aValue) OUStringBuffer aStr; comphelper::string::padToLength(aStr, 6 - aBuf.getLength(), '0'); aStr.append(aBuf.getStr()); - mpGrabBagStack->appendElement("val", makeAny(aStr.makeStringAndClear())); + mpGrabBagStack->appendElement("val", makeAny(aStr.makeStringAndClear().toAsciiUpperCase())); } break; case NS_ooxml::LN_CT_Glow_rad: mpGrabBagStack->appendElement("rad", makeAny(sal_Int32(aValue.getInt()))); break; + case NS_ooxml::LN_CT_Shadow_blurRad: + mpGrabBagStack->appendElement("blurRad", makeAny(sal_Int32(aValue.getInt()))); + break; + case NS_ooxml::LN_CT_Shadow_dist: + mpGrabBagStack->appendElement("dist", makeAny(sal_Int32(aValue.getInt()))); + break; + case NS_ooxml::LN_CT_Shadow_dir: + mpGrabBagStack->appendElement("dir", makeAny(sal_Int32(aValue.getInt()))); + break; + case NS_ooxml::LN_CT_Shadow_sx: + mpGrabBagStack->appendElement("sx", makeAny(sal_Int32(aValue.getInt()))); + break; + case NS_ooxml::LN_CT_Shadow_sy: + mpGrabBagStack->appendElement("sy", makeAny(sal_Int32(aValue.getInt()))); + break; + case NS_ooxml::LN_CT_Shadow_kx: + mpGrabBagStack->appendElement("kx", makeAny(sal_Int32(aValue.getInt()))); + break; + case NS_ooxml::LN_CT_Shadow_ky: + mpGrabBagStack->appendElement("ky", makeAny(sal_Int32(aValue.getInt()))); + break; + case NS_ooxml::LN_CT_Shadow_algn: + { + uno::Any aAny = makeAny(getRectAlignmentString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("algn", aAny); + } + break; default: break; } @@ -251,22 +331,6 @@ beans::PropertyValue TextEffectsHandler::getInteropGrabBag() return aReturn; } -void TextEffectsHandler::enableInteropGrabBag(OUString aName) -{ - mpGrabBagStack.reset(new GrabBagStack(aName)); -} - -void TextEffectsHandler::disableInteropGrabBag() -{ - mpGrabBagStack.reset(); -} - -bool TextEffectsHandler::isInteropGrabBagEnabled() -{ - return mpGrabBagStack.get() != NULL; -} - - }//namespace dmapper } //namespace writerfilter diff --git a/writerfilter/source/dmapper/TextEffectsHandler.hxx b/writerfilter/source/dmapper/TextEffectsHandler.hxx index f224c63fc9dc..a2d2ca99de3f 100644 --- a/writerfilter/source/dmapper/TextEffectsHandler.hxx +++ b/writerfilter/source/dmapper/TextEffectsHandler.hxx @@ -13,10 +13,15 @@ #include <WriterFilterDllApi.hxx> #include <resourcemodel/LoggedResources.hxx> + #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/lang/XComponent.hpp> #include <i18nlangtag/languagetag.hxx> + +#include <PropertyIds.hxx> + #include <boost/scoped_ptr.hpp> +#include <boost/optional.hpp> namespace writerfilter { namespace dmapper @@ -28,22 +33,26 @@ class GrabBagStack; class TextEffectsHandler : public LoggedProperties { private: + boost::optional<PropertyIds> maPropertyId; + OUString maElementName; boost::scoped_ptr<GrabBagStack> mpGrabBagStack; + void convertElementIdToPropertyId(sal_Int32 aElementId); + // LoggedProperties virtual void lcl_attribute(Id aName, Value& aValue); virtual void lcl_sprm(Sprm& sprm); public: - TextEffectsHandler(); + TextEffectsHandler(sal_uInt32 aElementId); virtual ~TextEffectsHandler(); + boost::optional<PropertyIds> getGrabBagPropertyId(); + css::beans::PropertyValue getInteropGrabBag(); - void enableInteropGrabBag(OUString aName); - void disableInteropGrabBag(); - bool isInteropGrabBagEnabled(); - static OUString getSchemeColorTypeString(sal_Int32 nType); + static OUString getSchemeColorValTypeString(sal_Int32 nType); + static OUString getRectAlignmentString(sal_Int32 nType); }; typedef boost::shared_ptr<TextEffectsHandler> TextEffectsHandlerPtr; |