Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <svgio/svgreader/svgstylenode.hxx>
21 : #include <svgio/svgreader/svgdocument.hxx>
22 :
23 : //////////////////////////////////////////////////////////////////////////////
24 :
25 : namespace svgio
26 : {
27 : namespace svgreader
28 : {
29 0 : SvgStyleNode::SvgStyleNode(
30 : SvgDocument& rDocument,
31 : SvgNode* pParent)
32 : : SvgNode(SVGTokenStyle, rDocument, pParent),
33 : maSvgStyleAttributes(),
34 0 : mbTextCss(false)
35 : {
36 0 : }
37 :
38 0 : SvgStyleNode::~SvgStyleNode()
39 : {
40 0 : while(!maSvgStyleAttributes.empty())
41 : {
42 0 : delete *(maSvgStyleAttributes.end() - 1);
43 0 : maSvgStyleAttributes.pop_back();
44 : }
45 0 : }
46 :
47 0 : void SvgStyleNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
48 : {
49 : // call parent
50 0 : SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
51 :
52 : // parse own
53 0 : switch(aSVGToken)
54 : {
55 : case SVGTokenType:
56 : {
57 0 : if(aContent.getLength())
58 : {
59 0 : static rtl::OUString aStrTextCss(rtl::OUString::createFromAscii("text/css"));
60 :
61 0 : if(aContent.match(aStrTextCss))
62 : {
63 0 : setTextCss(true);
64 : }
65 : }
66 0 : break;
67 : }
68 : default:
69 : {
70 0 : break;
71 : }
72 : }
73 0 : }
74 :
75 0 : void SvgStyleNode::addCssStyleSheet(const rtl::OUString& aContent)
76 : {
77 0 : const sal_Int32 nLen(aContent.getLength());
78 :
79 0 : if(nLen)
80 : {
81 0 : sal_Int32 nPos(0);
82 0 : rtl::OUStringBuffer aTokenValue;
83 :
84 0 : while(nPos < nLen)
85 : {
86 0 : const sal_Int32 nInitPos(nPos);
87 0 : skip_char(aContent, sal_Unicode(' '), sal_Unicode('#'), nPos, nLen);
88 0 : copyToLimiter(aContent, sal_Unicode('{'), nPos, aTokenValue, nLen);
89 0 : const rtl::OUString aStyleName = aTokenValue.makeStringAndClear().trim();
90 :
91 0 : if(aStyleName.getLength() && nPos < nLen)
92 : {
93 0 : skip_char(aContent, sal_Unicode(' '), sal_Unicode('{'), nPos, nLen);
94 0 : copyToLimiter(aContent, sal_Unicode('}'), nPos, aTokenValue, nLen);
95 0 : skip_char(aContent, sal_Unicode(' '), sal_Unicode('}'), nPos, nLen);
96 0 : const rtl::OUString aStyleContent = aTokenValue.makeStringAndClear().trim();
97 :
98 0 : if(aStyleContent.getLength())
99 : {
100 : // create new style
101 0 : SvgStyleAttributes* pNewStyle = new SvgStyleAttributes(*this);
102 0 : maSvgStyleAttributes.push_back(pNewStyle);
103 :
104 : // fill with content
105 0 : pNewStyle->readStyle(aStyleContent);
106 :
107 : // register new style at document
108 0 : const_cast< SvgDocument& >(getDocument()).addSvgStyleAttributesToMapper(aStyleName, *pNewStyle);
109 0 : }
110 : }
111 :
112 0 : if(nInitPos == nPos)
113 : {
114 : OSL_ENSURE(false, "Could not interpret on current position (!)");
115 0 : nPos++;
116 : }
117 0 : }
118 : }
119 0 : }
120 :
121 : } // end of namespace svgreader
122 : } // end of namespace svgio
123 :
124 : //////////////////////////////////////////////////////////////////////////////
125 : // eof
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|