1ddde725dSArmin Le Grand /************************************************************** 2ddde725dSArmin Le Grand * 3ddde725dSArmin Le Grand * Licensed to the Apache Software Foundation (ASF) under one 4ddde725dSArmin Le Grand * or more contributor license agreements. See the NOTICE file 5ddde725dSArmin Le Grand * distributed with this work for additional information 6ddde725dSArmin Le Grand * regarding copyright ownership. The ASF licenses this file 7ddde725dSArmin Le Grand * to you under the Apache License, Version 2.0 (the 8ddde725dSArmin Le Grand * "License"); you may not use this file except in compliance 9ddde725dSArmin Le Grand * with the License. You may obtain a copy of the License at 10ddde725dSArmin Le Grand * 11ddde725dSArmin Le Grand * http://www.apache.org/licenses/LICENSE-2.0 12ddde725dSArmin Le Grand * 13ddde725dSArmin Le Grand * Unless required by applicable law or agreed to in writing, 14ddde725dSArmin Le Grand * software distributed under the License is distributed on an 15ddde725dSArmin Le Grand * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ddde725dSArmin Le Grand * KIND, either express or implied. See the License for the 17ddde725dSArmin Le Grand * specific language governing permissions and limitations 18ddde725dSArmin Le Grand * under the License. 19ddde725dSArmin Le Grand * 20ddde725dSArmin Le Grand *************************************************************/ 21ddde725dSArmin Le Grand 22ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove 23ddde725dSArmin Le Grand #include "precompiled_svgio.hxx" 24ddde725dSArmin Le Grand 25ddde725dSArmin Le Grand #include <svgio/svgreader/svgstylenode.hxx> 26ddde725dSArmin Le Grand #include <svgio/svgreader/svgdocument.hxx> 27ddde725dSArmin Le Grand 28ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 29ddde725dSArmin Le Grand 30ddde725dSArmin Le Grand namespace svgio 31ddde725dSArmin Le Grand { 32ddde725dSArmin Le Grand namespace svgreader 33ddde725dSArmin Le Grand { SvgStyleNode(SvgDocument & rDocument,SvgNode * pParent)34ddde725dSArmin Le Grand SvgStyleNode::SvgStyleNode( 35ddde725dSArmin Le Grand SvgDocument& rDocument, 36ddde725dSArmin Le Grand SvgNode* pParent) 37ddde725dSArmin Le Grand : SvgNode(SVGTokenStyle, rDocument, pParent), 38ddde725dSArmin Le Grand maSvgStyleAttributes(), 39ddde725dSArmin Le Grand mbTextCss(false) 40ddde725dSArmin Le Grand { 41ddde725dSArmin Le Grand } 42ddde725dSArmin Le Grand ~SvgStyleNode()43ddde725dSArmin Le Grand SvgStyleNode::~SvgStyleNode() 44ddde725dSArmin Le Grand { 45ddde725dSArmin Le Grand while(!maSvgStyleAttributes.empty()) 46ddde725dSArmin Le Grand { 47ddde725dSArmin Le Grand delete *(maSvgStyleAttributes.end() - 1); 48ddde725dSArmin Le Grand maSvgStyleAttributes.pop_back(); 49ddde725dSArmin Le Grand } 50ddde725dSArmin Le Grand } 51ddde725dSArmin Le Grand 52*b3ba8dd4SArmin Le Grand // #125258# no parent when we are a CssStyle holder to break potential loops because 53*b3ba8dd4SArmin Le Grand // when using CssStyles we jump uncontrolled inside the node tree hierarchy supportsParentStyle() const54*b3ba8dd4SArmin Le Grand bool SvgStyleNode::supportsParentStyle() const 55*b3ba8dd4SArmin Le Grand { 56*b3ba8dd4SArmin Le Grand if(isTextCss()) 57*b3ba8dd4SArmin Le Grand { 58*b3ba8dd4SArmin Le Grand return false; 59*b3ba8dd4SArmin Le Grand } 60*b3ba8dd4SArmin Le Grand 61*b3ba8dd4SArmin Le Grand // call parent 62*b3ba8dd4SArmin Le Grand return SvgNode::supportsParentStyle(); 63*b3ba8dd4SArmin Le Grand } 64*b3ba8dd4SArmin Le Grand parseAttribute(const rtl::OUString & rTokenName,SVGToken aSVGToken,const rtl::OUString & aContent)65ddde725dSArmin Le Grand void SvgStyleNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent) 66ddde725dSArmin Le Grand { 67ddde725dSArmin Le Grand // call parent 68ddde725dSArmin Le Grand SvgNode::parseAttribute(rTokenName, aSVGToken, aContent); 69ddde725dSArmin Le Grand 70ddde725dSArmin Le Grand // parse own 71ddde725dSArmin Le Grand switch(aSVGToken) 72ddde725dSArmin Le Grand { 73ddde725dSArmin Le Grand case SVGTokenType: 74ddde725dSArmin Le Grand { 75ddde725dSArmin Le Grand if(aContent.getLength()) 76ddde725dSArmin Le Grand { 77ddde725dSArmin Le Grand static rtl::OUString aStrTextCss(rtl::OUString::createFromAscii("text/css")); 78ddde725dSArmin Le Grand 79ddde725dSArmin Le Grand if(aContent.match(aStrTextCss)) 80ddde725dSArmin Le Grand { 81ddde725dSArmin Le Grand setTextCss(true); 82ddde725dSArmin Le Grand } 83ddde725dSArmin Le Grand } 84ddde725dSArmin Le Grand break; 85ddde725dSArmin Le Grand } 86e2bf1e9dSArmin Le Grand default: 87e2bf1e9dSArmin Le Grand { 88e2bf1e9dSArmin Le Grand break; 89e2bf1e9dSArmin Le Grand } 90ddde725dSArmin Le Grand } 91ddde725dSArmin Le Grand } 92ddde725dSArmin Le Grand addCssStyleSheet(const rtl::OUString & aContent)93ddde725dSArmin Le Grand void SvgStyleNode::addCssStyleSheet(const rtl::OUString& aContent) 94ddde725dSArmin Le Grand { 95ddde725dSArmin Le Grand const sal_Int32 nLen(aContent.getLength()); 96ddde725dSArmin Le Grand 97ddde725dSArmin Le Grand if(nLen) 98ddde725dSArmin Le Grand { 99ddde725dSArmin Le Grand sal_Int32 nPos(0); 100ddde725dSArmin Le Grand rtl::OUStringBuffer aTokenValue; 101ddde725dSArmin Le Grand 102311ea6abSArmin Le Grand while(nPos < nLen) 103ddde725dSArmin Le Grand { 104311ea6abSArmin Le Grand const sal_Int32 nInitPos(nPos); 105311ea6abSArmin Le Grand skip_char(aContent, sal_Unicode(' '), sal_Unicode('#'), nPos, nLen); 106311ea6abSArmin Le Grand copyToLimiter(aContent, sal_Unicode('{'), nPos, aTokenValue, nLen); 107311ea6abSArmin Le Grand const rtl::OUString aStyleName = aTokenValue.makeStringAndClear().trim(); 108ddde725dSArmin Le Grand 109311ea6abSArmin Le Grand if(aStyleName.getLength() && nPos < nLen) 110ddde725dSArmin Le Grand { 111311ea6abSArmin Le Grand skip_char(aContent, sal_Unicode(' '), sal_Unicode('{'), nPos, nLen); 112311ea6abSArmin Le Grand copyToLimiter(aContent, sal_Unicode('}'), nPos, aTokenValue, nLen); 113311ea6abSArmin Le Grand skip_char(aContent, sal_Unicode(' '), sal_Unicode('}'), nPos, nLen); 114311ea6abSArmin Le Grand const rtl::OUString aStyleContent = aTokenValue.makeStringAndClear().trim(); 115311ea6abSArmin Le Grand 116311ea6abSArmin Le Grand if(aStyleContent.getLength()) 117311ea6abSArmin Le Grand { 118311ea6abSArmin Le Grand // create new style 119311ea6abSArmin Le Grand SvgStyleAttributes* pNewStyle = new SvgStyleAttributes(*this); 120311ea6abSArmin Le Grand maSvgStyleAttributes.push_back(pNewStyle); 121ddde725dSArmin Le Grand 122311ea6abSArmin Le Grand // fill with content 123311ea6abSArmin Le Grand pNewStyle->readStyle(aStyleContent); 124ddde725dSArmin Le Grand 125311ea6abSArmin Le Grand // register new style at document 126311ea6abSArmin Le Grand const_cast< SvgDocument& >(getDocument()).addSvgStyleAttributesToMapper(aStyleName, *pNewStyle); 127311ea6abSArmin Le Grand } 128311ea6abSArmin Le Grand } 129311ea6abSArmin Le Grand 130311ea6abSArmin Le Grand if(nInitPos == nPos) 131311ea6abSArmin Le Grand { 132311ea6abSArmin Le Grand OSL_ENSURE(false, "Could not interpret on current position (!)"); 133311ea6abSArmin Le Grand nPos++; 134ddde725dSArmin Le Grand } 135ddde725dSArmin Le Grand } 136ddde725dSArmin Le Grand } 137ddde725dSArmin Le Grand } 138ddde725dSArmin Le Grand 139ddde725dSArmin Le Grand } // end of namespace svgreader 140ddde725dSArmin Le Grand } // end of namespace svgio 141ddde725dSArmin Le Grand 142ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 143ddde725dSArmin Le Grand // eof 144