1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_svgio.hxx" 24 25 #include <svgio/svgreader/svgstylenode.hxx> 26 #include <svgio/svgreader/svgdocument.hxx> 27 28 ////////////////////////////////////////////////////////////////////////////// 29 30 namespace svgio 31 { 32 namespace svgreader 33 { 34 SvgStyleNode::SvgStyleNode( 35 SvgDocument& rDocument, 36 SvgNode* pParent) 37 : SvgNode(SVGTokenStyle, rDocument, pParent), 38 maSvgStyleAttributes(), 39 mbTextCss(false) 40 { 41 } 42 43 SvgStyleNode::~SvgStyleNode() 44 { 45 while(!maSvgStyleAttributes.empty()) 46 { 47 delete *(maSvgStyleAttributes.end() - 1); 48 maSvgStyleAttributes.pop_back(); 49 } 50 } 51 52 void SvgStyleNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent) 53 { 54 // call parent 55 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent); 56 57 // parse own 58 switch(aSVGToken) 59 { 60 case SVGTokenType: 61 { 62 if(aContent.getLength()) 63 { 64 static rtl::OUString aStrTextCss(rtl::OUString::createFromAscii("text/css")); 65 66 if(aContent.match(aStrTextCss)) 67 { 68 setTextCss(true); 69 } 70 } 71 break; 72 } 73 default: 74 { 75 break; 76 } 77 } 78 } 79 80 void SvgStyleNode::addCssStyleSheet(const rtl::OUString& aContent) 81 { 82 const sal_Int32 nLen(aContent.getLength()); 83 84 if(nLen) 85 { 86 sal_Int32 nPos(0); 87 rtl::OUStringBuffer aTokenValue; 88 89 skip_char(aContent, sal_Unicode(' '), sal_Unicode('#'), nPos, nLen); 90 copyToLimiter(aContent, sal_Unicode('{'), nPos, aTokenValue, nLen); 91 const rtl::OUString aStyleName = aTokenValue.makeStringAndClear().trim(); 92 93 if(aStyleName.getLength()) 94 { 95 skip_char(aContent, sal_Unicode(' '), sal_Unicode('{'), nPos, nLen); 96 copyToLimiter(aContent, sal_Unicode('}'), nPos, aTokenValue, nLen); 97 const rtl::OUString aStyleContent = aTokenValue.makeStringAndClear().trim(); 98 99 if(aStyleContent.getLength()) 100 { 101 // create new style 102 SvgStyleAttributes* pNewStyle = new SvgStyleAttributes(*this); 103 maSvgStyleAttributes.push_back(pNewStyle); 104 105 // fill with content 106 pNewStyle->readStyle(aStyleContent); 107 108 // register new style at document 109 const_cast< SvgDocument& >(getDocument()).addSvgStyleAttributesToMapper(aStyleName, *pNewStyle); 110 } 111 } 112 } 113 } 114 115 } // end of namespace svgreader 116 } // end of namespace svgio 117 118 ////////////////////////////////////////////////////////////////////////////// 119 // eof 120