summaryrefslogtreecommitdiff
path: root/xmloff/source/style/FillStyleContext.cxx
diff options
context:
space:
mode:
authorChr. Rossmanith <ChrRossmanith@gmx.de>2013-01-01 21:38:06 +0100
committerChr. Rossmanith <ChrRossmanith@gmx.de>2013-01-07 19:39:46 +0100
commit6eb0522395c236ae6930a300992ad092449f9592 (patch)
tree0302cf16978c9cc6b91af9735b2ecc0f49b79422 /xmloff/source/style/FillStyleContext.cxx
parentf1043aaed082824ca423eee10be5802873e058f3 (diff)
dummy commit (WIP)
Change-Id: Ibeee6553312323b75b2403ad6832595f228e0e3c
Diffstat (limited to 'xmloff/source/style/FillStyleContext.cxx')
-rw-r--r--xmloff/source/style/FillStyleContext.cxx151
1 files changed, 150 insertions, 1 deletions
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,