diff options
author | Chr. Rossmanith <ChrRossmanith@gmx.de> | 2013-01-01 21:38:06 +0100 |
---|---|---|
committer | Chr. Rossmanith <ChrRossmanith@gmx.de> | 2013-01-07 19:39:46 +0100 |
commit | 6eb0522395c236ae6930a300992ad092449f9592 (patch) | |
tree | 0302cf16978c9cc6b91af9735b2ecc0f49b79422 /xmloff | |
parent | added token for handling of svg:linearGradient and svg:radialGradient (diff) | |
download | core-6eb0522395c236ae6930a300992ad092449f9592.tar.gz core-6eb0522395c236ae6930a300992ad092449f9592.zip |
dummy commit (WIP)
Change-Id: Ibeee6553312323b75b2403ad6832595f228e0e3c
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/Library_xo.mk | 1 | ||||
-rw-r--r-- | xmloff/Package_inc.mk | 1 | ||||
-rw-r--r-- | xmloff/inc/xmloff/xmlstyle.hxx | 5 | ||||
-rw-r--r-- | xmloff/source/style/FillStyleContext.cxx | 151 | ||||
-rw-r--r-- | xmloff/source/style/FillStyleContext.hxx | 67 | ||||
-rw-r--r-- | xmloff/source/style/GradientStyle.cxx | 12 | ||||
-rw-r--r-- | xmloff/source/style/xmlstyle.cxx | 5 |
7 files changed, 233 insertions, 9 deletions
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index b8164826f2df..4b9e68dbaa77 100644 --- a/xmloff/Library_xo.mk +++ b/xmloff/Library_xo.mk @@ -196,6 +196,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ xmloff/source/style/EnumPropertyHdl \ xmloff/source/style/FillStyleContext \ xmloff/source/style/GradientStyle \ + xmloff/source/style/SvgGradientStyle \ xmloff/source/style/HatchStyle \ xmloff/source/style/ImageStyle \ xmloff/source/style/MarkerStyle \ diff --git a/xmloff/Package_inc.mk b/xmloff/Package_inc.mk index 9b3628b691db..dd324302bf81 100644 --- a/xmloff/Package_inc.mk +++ b/xmloff/Package_inc.mk @@ -22,6 +22,7 @@ $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/DashStyle.hxx,xmloff/Das $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/DocumentSettingsContext.hxx,xmloff/DocumentSettingsContext.hxx)) $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/EnumPropertyHdl.hxx,xmloff/EnumPropertyHdl.hxx)) $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/GradientStyle.hxx,xmloff/GradientStyle.hxx)) +$(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/SvgGradientStyle.hxx,xmloff/SvgGradientStyle.hxx)) $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/HatchStyle.hxx,xmloff/HatchStyle.hxx)) $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/ImageStyle.hxx,xmloff/ImageStyle.hxx)) $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/MarkerStyle.hxx,xmloff/MarkerStyle.hxx)) diff --git a/xmloff/inc/xmloff/xmlstyle.hxx b/xmloff/inc/xmloff/xmlstyle.hxx index 8296b24799a0..74c7b0223917 100644 --- a/xmloff/inc/xmloff/xmlstyle.hxx +++ b/xmloff/inc/xmloff/xmlstyle.hxx @@ -45,6 +45,7 @@ enum XMLStyleStylesElemTokens XML_TOK_TEXT_LIST_STYLE, XML_TOK_TEXT_OUTLINE, XML_TOK_STYLES_GRADIENTSTYLES, + XML_TOK_STYLES_LINEARGRADIENTSTYLES, XML_TOK_STYLES_HATCHSTYLES, XML_TOK_STYLES_BITMAPSTYLES, XML_TOK_STYLES_TRANSGRADIENTSTYLES, @@ -74,8 +75,8 @@ class XMLOFF_DLLPUBLIC SvXMLStyleContext : public SvXMLImportContext sal_Bool mbValid : 1; // Set this to false in CreateAndInsert // if the style shouldn't be processed - // by Finish() or si somehow invalid. - sal_Bool mbNew : 1; // Set this to false in CreateAnsInsert + // by Finish() or is somehow invalid. + sal_Bool mbNew : 1; // Set this to false in CreateAndInsert // if the style is already existing. sal_Bool mbDefaultStyle : 1; diff --git a/xmloff/source/style/FillStyleContext.cxx b/xmloff/source/style/FillStyleContext.cxx index 563da21714eb..330573cf0ece 100644 --- a/xmloff/source/style/FillStyleContext.cxx +++ b/xmloff/source/style/FillStyleContext.cxx @@ -18,9 +18,11 @@ */ #include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/awt/SvgGradient.hpp> #include "FillStyleContext.hxx" #include <xmloff/xmlimp.hxx> #include "xmloff/GradientStyle.hxx" +#include "xmloff/SvgGradientStyle.hxx" #include "xmloff/HatchStyle.hxx" #include "xmloff/ImageStyle.hxx" #include "TransGradientStyle.hxx" @@ -30,6 +32,8 @@ #include <xmloff/nmspmap.hxx> #include "xmloff/xmlnmspe.hxx" #include <xmloff/XMLBase64ImportContext.hxx> +#include <sax/tools/converter.hxx> +#include <comphelper/sequence.hxx> using namespace ::com::sun::star; using ::rtl::OUString; @@ -46,7 +50,6 @@ XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt const uno::Reference< xml::sax::XAttributeList >& xAttrList) : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList) { - // start import XMLGradientStyleImport aGradientStyle( GetImport() ); aGradientStyle.importXML( xAttrList, maAny, maStrName ); @@ -86,6 +89,152 @@ sal_Bool XMLGradientStyleContext::IsTransient() const ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// +TYPEINIT1( XMLLinearGradientStyleContext, SvXMLStyleContext ); + +XMLLinearGradientStyleContext::XMLLinearGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList) +{ + // start import + XMLSvgGradientStyleImport aGradientStyle( GetImport() ); + aGradientStyle.importXML( xAttrList, maAny, maStrName ); +} + +XMLLinearGradientStyleContext::~XMLLinearGradientStyleContext() +{ +} + + +SvXMLImportContext* XMLLinearGradientStyleContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + if( (XML_NAMESPACE_SVG == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_STOP ) ) + { + return new XMLSvgGradientStopImportContext(GetImport(), + nPrefix, rLocalName, + *this); + } + else + { + return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList ); + } +} + +void XMLLinearGradientStyleContext::EndElement() +{ + uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() ); + + try + { + if(xGradient.is()) + { + if( xGradient->hasByName( maStrName ) ) + { + xGradient->replaceByName( maStrName, maAny ); + } + else + { + xGradient->insertByName( maStrName, maAny ); + } + } + } + catch( container::ElementExistException& ) + {} +} + +sal_Bool XMLLinearGradientStyleContext::IsTransient() const +{ + return sal_True; +} + +void XMLLinearGradientStyleContext::SetGradientStop( ::com::sun::star::util::Color aColor, double aOffset) +{ + mStopColors.push_back( aColor ); + mStopOffsets.push_back( aOffset ); +} + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +TYPEINIT1( XMLSvgGradientStopImportContext, SvXMLImportContext ); + +XMLSvgGradientStopImportContext::XMLSvgGradientStopImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + XMLLinearGradientStyleContext& rGradientStyle) + : SvXMLImportContext(rImport, nPrfx, rLName), + rGradientStyleContext(rGradientStyle) +{ +} + +XMLSvgGradientStopImportContext::~XMLSvgGradientStopImportContext() +{ +} + +void XMLSvgGradientStopImportContext::StartElement( + const uno::Reference<xml::sax::XAttributeList> & xAttrList) +{ + sal_Int16 nLength = xAttrList->getLength(); + ::util::Color aColor; + OUString colorString("black"); + double opacity = 1; + double offset=0; + double nTmp; + + for(sal_Int16 i=0; i<nLength; i++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName ); + + if ( nPrefix == XML_NAMESPACE_SVG ) + { + if ( xmloff::token::IsXMLToken(sLocalName, xmloff::token::XML_OFFSET) ) + { + SAL_INFO("svg", "offset " << sLocalName << " " << xAttrList->getValueByIndex(i)); + OUString value = xAttrList->getValueByIndex( i ); + // using convertDouble instead of convertPercent because the latter expects sal_Int32& as its first arg + if ((value.indexOf( "%" ) != -1) && ::sax::Converter::convertDouble( nTmp, value )) + { + SAL_INFO("svg", "offset converted " << nTmp/100); + offset = nTmp * 0.01; + } + else if ( ::sax::Converter::convertDouble( nTmp, value ) ) { + SAL_INFO("svg", "offset converted " << nTmp); + offset = nTmp; + } + else + { + SAL_WARN("svg", "Could not convert gradient offset " << value); + } + } + else if ( xmloff::token::IsXMLToken(sLocalName, xmloff::token::XML_STOPCOLOR) ) + { + colorString = xAttrList->getValueByIndex(i); + SAL_INFO("svg", "stop color " << sLocalName << " " << xAttrList->getValueByIndex(i)); + } + else if ( xmloff::token::IsXMLToken(sLocalName, xmloff::token::XML_STOPOPACITY) ) + { + SAL_INFO("svg", "stop opacity " << sLocalName << " " << xAttrList->getValueByIndex(i)); + ::sax::Converter::convertDouble( nTmp, xAttrList->getValueByIndex(i) ); + opacity = nTmp; + } + } + } + bool bColorSet; + bColorSet = ::sax::Converter::convertColor( aColor, colorString, opacity ); + rGradientStyleContext.SetGradientStop( aColor, offset ); +} + +void XMLSvgGradientStopImportContext::EndElement() +{ + // uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() ); + + SAL_INFO("svgb", "EndElement"); +} + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext ); XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, diff --git a/xmloff/source/style/FillStyleContext.hxx b/xmloff/source/style/FillStyleContext.hxx index b8d1d795864b..f90c100e3017 100644 --- a/xmloff/source/style/FillStyleContext.hxx +++ b/xmloff/source/style/FillStyleContext.hxx @@ -21,11 +21,12 @@ #define _XMLOFF_FILLSTYLECONTEXTS_HXX_ #include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/util/Color.hpp> #include <xmloff/xmlstyle.hxx> -#include<rtl/ustring.hxx> +#include <rtl/ustring.hxx> ////////////////////////////////////////////////////////////////////////////// -// draw:gardient context +// draw:gradient context class XMLGradientStyleContext: public SvXMLStyleContext { @@ -46,6 +47,68 @@ public: }; ////////////////////////////////////////////////////////////////////////////// +// svg:linearGradient context +class XMLLinearGradientStyleContext: public SvXMLStyleContext +{ +private: + ::com::sun::star::uno::Any maAny; + rtl::OUString maStrName; + ::std::vector< ::com::sun::star::util::Color > mStopColors; + ::std::vector< double > mStopOffsets; + +public: + TYPEINFO(); + + XMLLinearGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName, + const com::sun::star::uno::Reference< + com::sun::star::xml::sax::XAttributeList> & xAttrList ); + virtual ~XMLLinearGradientStyleContext(); + + virtual void EndElement(); + + virtual sal_Bool IsTransient() const; + + void SetGradientStop( ::com::sun::star::util::Color aColor, double aOffset); + +protected: + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +////////////////////////////////////////////////////////////////////////////// +// import svg:stop elements +class XMLSvgGradientStopImportContext : public SvXMLImportContext +{ + XMLLinearGradientStyleContext& rGradientStyleContext; + +private: + ::com::sun::star::uno::Any maAny; + +public: + + TYPEINFO(); + + XMLSvgGradientStopImportContext( + SvXMLImport& rImport, + sal_uInt16 nPrfx, + const ::rtl::OUString& rLocalName, + XMLLinearGradientStyleContext& rGradientStyle); + + ~XMLSvgGradientStopImportContext(); + +protected: + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList); + + virtual void EndElement(); +}; + +////////////////////////////////////////////////////////////////////////////// // draw:hatch context class XMLHatchStyleContext: public SvXMLStyleContext diff --git a/xmloff/source/style/GradientStyle.cxx b/xmloff/source/style/GradientStyle.cxx index eb432e7dba01..0be3650be642 100644 --- a/xmloff/source/style/GradientStyle.cxx +++ b/xmloff/source/style/GradientStyle.cxx @@ -90,6 +90,8 @@ sal_Bool XMLGradientStyleImport::importXML( uno::Any& rValue, OUString& rStrName ) { + SAL_INFO ("svg", "importXML"); + sal_Bool bRet = sal_False; sal_Bool bHasName = sal_False; sal_Bool bHasStyle = sal_False; @@ -107,7 +109,7 @@ sal_Bool XMLGradientStyleImport::importXML( { static SvXMLTokenMapEntry aGradientAttrTokenMap[] = -{ + { { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_GRADIENT_NAME }, { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_GRADIENT_DISPLAY_NAME }, { XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_GRADIENT_STYLE }, @@ -126,13 +128,14 @@ sal_Bool XMLGradientStyleImport::importXML( SvXMLNamespaceMap& rNamespaceMap = rImport.GetNamespaceMap(); sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + SAL_INFO ("svg", "nAttrCount " << nAttrCount); for( sal_Int16 i=0; i < nAttrCount; i++ ) { const OUString& rFullAttrName = xAttrList->getNameByIndex( i ); OUString aStrAttrName; sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rFullAttrName, &aStrAttrName ); const OUString& rStrValue = xAttrList->getValueByIndex( i ); - + SAL_INFO ("svg", "FullAttrName: " << rFullAttrName << " rStrValue: " << rStrValue << " aStrAttrName: " << aStrAttrName); sal_Int32 nTmpValue; switch( aTokenMap.Get( nPrefix, aStrAttrName ) ) @@ -199,8 +202,8 @@ sal_Bool XMLGradientStyleImport::importXML( break; default: - DBG_WARNING( "Unknown token at import gradient style" ) - ; + SAL_INFO("svg", "Unknown token at import gradient style"); + DBG_WARNING( "Unknown token at import gradient style" ); } } @@ -242,6 +245,7 @@ sal_Bool XMLGradientStyleExport::exportXML( sal_Bool bRet = sal_False; awt::Gradient aGradient; + if( !rStrName.isEmpty() ) { if( rValue >>= aGradient ) diff --git a/xmloff/source/style/xmlstyle.cxx b/xmloff/source/style/xmlstyle.cxx index b69f3f6b97f6..da698c0aa557 100644 --- a/xmloff/source/style/xmlstyle.cxx +++ b/xmloff/source/style/xmlstyle.cxx @@ -490,6 +490,11 @@ SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( sal_uInt16 p_nPr pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); break; } + case XML_TOK_STYLES_LINEARGRADIENTSTYLES: + { + pStyle = new XMLLinearGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); + break; + } case XML_TOK_STYLES_HATCHSTYLES: { pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); |