update credits
[LibreOffice.git] / svgio / source / svgreader / svgstylenode.cxx
blob13d5085d98cb57d8a9aa4474e912418ddcab5f7a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svgio/svgreader/svgstylenode.hxx>
21 #include <svgio/svgreader/svgdocument.hxx>
23 //////////////////////////////////////////////////////////////////////////////
25 namespace svgio
27 namespace svgreader
29 SvgStyleNode::SvgStyleNode(
30 SvgDocument& rDocument,
31 SvgNode* pParent)
32 : SvgNode(SVGTokenStyle, rDocument, pParent),
33 maSvgStyleAttributes(),
34 mbTextCss(false)
38 SvgStyleNode::~SvgStyleNode()
40 while(!maSvgStyleAttributes.empty())
42 delete *(maSvgStyleAttributes.end() - 1);
43 maSvgStyleAttributes.pop_back();
47 void SvgStyleNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
49 // call parent
50 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
52 // parse own
53 switch(aSVGToken)
55 case SVGTokenType:
57 if(aContent.getLength())
59 static OUString aStrTextCss(OUString::createFromAscii("text/css"));
61 if(aContent.match(aStrTextCss))
63 setTextCss(true);
66 break;
68 default:
70 break;
75 void SvgStyleNode::addCssStyleSheet(const OUString& aContent)
77 const sal_Int32 nLen(aContent.getLength());
79 if(nLen)
81 sal_Int32 nPos(0);
82 OUStringBuffer aTokenValue;
84 while(nPos < nLen)
86 const sal_Int32 nInitPos(nPos);
87 skip_char(aContent, sal_Unicode(' '), sal_Unicode('#'), nPos, nLen);
88 copyToLimiter(aContent, sal_Unicode('{'), nPos, aTokenValue, nLen);
89 const OUString aStyleName = aTokenValue.makeStringAndClear().trim();
91 if(aStyleName.getLength() && nPos < nLen)
93 skip_char(aContent, sal_Unicode(' '), sal_Unicode('{'), nPos, nLen);
94 copyToLimiter(aContent, sal_Unicode('}'), nPos, aTokenValue, nLen);
95 skip_char(aContent, sal_Unicode(' '), sal_Unicode('}'), nPos, nLen);
96 const OUString aStyleContent = aTokenValue.makeStringAndClear().trim();
98 if(aStyleContent.getLength())
100 // create new style
101 SvgStyleAttributes* pNewStyle = new SvgStyleAttributes(*this);
102 maSvgStyleAttributes.push_back(pNewStyle);
104 // fill with content
105 pNewStyle->readStyle(aStyleContent);
107 // register new style at document
108 const_cast< SvgDocument& >(getDocument()).addSvgStyleAttributesToMapper(aStyleName, *pNewStyle);
112 if(nInitPos == nPos)
114 OSL_ENSURE(false, "Could not interpret on current position (!)");
115 nPos++;
121 } // end of namespace svgreader
122 } // end of namespace svgio
124 //////////////////////////////////////////////////////////////////////////////
125 // eof
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */