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             }
74         }
75 
76         void SvgStyleNode::addCssStyleSheet(const rtl::OUString& aContent)
77         {
78             const sal_Int32 nLen(aContent.getLength());
79 
80             if(nLen)
81             {
82                 sal_Int32 nPos(0);
83                 rtl::OUStringBuffer aTokenValue;
84 
85                 skip_char(aContent, sal_Unicode(' '), sal_Unicode('#'), nPos, nLen);
86                 copyToLimiter(aContent, sal_Unicode('{'), nPos, aTokenValue, nLen);
87                 const rtl::OUString aStyleName = aTokenValue.makeStringAndClear().trim();
88 
89                 if(aStyleName.getLength())
90                 {
91                     skip_char(aContent, sal_Unicode(' '), sal_Unicode('{'), nPos, nLen);
92                     copyToLimiter(aContent, sal_Unicode('}'), nPos, aTokenValue, nLen);
93                     const rtl::OUString aStyleContent = aTokenValue.makeStringAndClear().trim();
94 
95                     if(aStyleContent.getLength())
96                     {
97                         // create new style
98                         SvgStyleAttributes* pNewStyle = new SvgStyleAttributes(*this);
99                         maSvgStyleAttributes.push_back(pNewStyle);
100 
101                         // fill with content
102                         pNewStyle->readStyle(aStyleContent);
103 
104                         // register new style at document
105                         const_cast< SvgDocument& >(getDocument()).addSvgStyleAttributesToMapper(aStyleName, *pNewStyle);
106                     }
107                 }
108             }
109         }
110 
111     } // end of namespace svgreader
112 } // end of namespace svgio
113 
114 //////////////////////////////////////////////////////////////////////////////
115 // eof
116