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/svgdocument.hxx>
26ddde725dSArmin Le Grand 
27ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
28ddde725dSArmin Le Grand 
29ddde725dSArmin Le Grand namespace svgio
30ddde725dSArmin Le Grand {
31ddde725dSArmin Le Grand     namespace svgreader
32ddde725dSArmin Le Grand     {
SvgDocument(const rtl::OUString & rAbsolutePath)33ddde725dSArmin Le Grand         SvgDocument::SvgDocument(const rtl::OUString& rAbsolutePath)
34ddde725dSArmin Le Grand         :   maNodes(),
35ddde725dSArmin Le Grand             maAbsolutePath(rAbsolutePath),
36ddde725dSArmin Le Grand             maIdTokenMapperList(),
37ddde725dSArmin Le Grand             maIdStyleTokenMapperList()
38ddde725dSArmin Le Grand         {
39ddde725dSArmin Le Grand         }
40ddde725dSArmin Le Grand 
~SvgDocument()41ddde725dSArmin Le Grand         SvgDocument::~SvgDocument()
42ddde725dSArmin Le Grand         {
43ddde725dSArmin Le Grand             while(!maNodes.empty())
44ddde725dSArmin Le Grand             {
45ddde725dSArmin Le Grand                 SvgNode* pCandidate = maNodes[maNodes.size() - 1];
46ddde725dSArmin Le Grand                 delete pCandidate;
47ddde725dSArmin Le Grand                 maNodes.pop_back();
48ddde725dSArmin Le Grand             }
49ddde725dSArmin Le Grand         }
50ddde725dSArmin Le Grand 
appendNode(SvgNode * pNode)51ddde725dSArmin Le Grand         void SvgDocument::appendNode(SvgNode* pNode)
52ddde725dSArmin Le Grand         {
53ddde725dSArmin Le Grand             OSL_ENSURE(pNode, "OOps, empty node added (!)");
54ddde725dSArmin Le Grand             maNodes.push_back(pNode);
55ddde725dSArmin Le Grand         }
56ddde725dSArmin Le Grand 
addSvgNodeToMapper(const rtl::OUString & rStr,const SvgNode & rNode)57ddde725dSArmin Le Grand         void SvgDocument::addSvgNodeToMapper(const rtl::OUString& rStr, const SvgNode& rNode)
58ddde725dSArmin Le Grand         {
59ddde725dSArmin Le Grand             if(rStr.getLength())
60ddde725dSArmin Le Grand             {
61ddde725dSArmin Le Grand                 maIdTokenMapperList.insert(IdTokenValueType(rStr, &rNode));
62ddde725dSArmin Le Grand             }
63ddde725dSArmin Le Grand         }
64ddde725dSArmin Le Grand 
removeSvgNodeFromMapper(const rtl::OUString & rStr)65ddde725dSArmin Le Grand         void SvgDocument::removeSvgNodeFromMapper(const rtl::OUString& rStr)
66ddde725dSArmin Le Grand         {
67ddde725dSArmin Le Grand             if(rStr.getLength())
68ddde725dSArmin Le Grand             {
69ddde725dSArmin Le Grand                 maIdTokenMapperList.erase(rStr);
70ddde725dSArmin Le Grand             }
71ddde725dSArmin Le Grand         }
72ddde725dSArmin Le Grand 
findSvgNodeById(const rtl::OUString & rStr) const73ddde725dSArmin Le Grand         const SvgNode* SvgDocument::findSvgNodeById(const rtl::OUString& rStr) const
74ddde725dSArmin Le Grand         {
75ddde725dSArmin Le Grand             const IdTokenMapper::const_iterator aResult(maIdTokenMapperList.find(rStr));
76ddde725dSArmin Le Grand 
77ddde725dSArmin Le Grand             if(aResult == maIdTokenMapperList.end())
78ddde725dSArmin Le Grand             {
79ddde725dSArmin Le Grand                 return 0;
80ddde725dSArmin Le Grand             }
81ddde725dSArmin Le Grand             else
82ddde725dSArmin Le Grand             {
83ddde725dSArmin Le Grand                 return aResult->second;
84ddde725dSArmin Le Grand             }
85ddde725dSArmin Le Grand         }
86ddde725dSArmin Le Grand 
addSvgStyleAttributesToMapper(const rtl::OUString & rStr,const SvgStyleAttributes & rSvgStyleAttributes)87ddde725dSArmin Le Grand         void SvgDocument::addSvgStyleAttributesToMapper(const rtl::OUString& rStr, const SvgStyleAttributes& rSvgStyleAttributes)
88ddde725dSArmin Le Grand         {
89ddde725dSArmin Le Grand             if(rStr.getLength())
90ddde725dSArmin Le Grand             {
91ddde725dSArmin Le Grand                 maIdStyleTokenMapperList.insert(IdStyleTokenValueType(rStr, &rSvgStyleAttributes));
92ddde725dSArmin Le Grand             }
93ddde725dSArmin Le Grand         }
94ddde725dSArmin Le Grand 
removeSvgStyleAttributesFromMapper(const rtl::OUString & rStr)95ddde725dSArmin Le Grand         void SvgDocument::removeSvgStyleAttributesFromMapper(const rtl::OUString& rStr)
96ddde725dSArmin Le Grand         {
97ddde725dSArmin Le Grand             if(rStr.getLength())
98ddde725dSArmin Le Grand             {
99ddde725dSArmin Le Grand                 maIdStyleTokenMapperList.erase(rStr);
100ddde725dSArmin Le Grand             }
101ddde725dSArmin Le Grand         }
102ddde725dSArmin Le Grand 
findGlobalCssStyleAttributes(const rtl::OUString & rStr) const103*eb82bfcdSArmin Le Grand         const SvgStyleAttributes* SvgDocument::findGlobalCssStyleAttributes(const rtl::OUString& rStr) const
104ddde725dSArmin Le Grand         {
105ddde725dSArmin Le Grand             const IdStyleTokenMapper::const_iterator aResult(maIdStyleTokenMapperList.find(rStr));
106ddde725dSArmin Le Grand 
107ddde725dSArmin Le Grand             if(aResult == maIdStyleTokenMapperList.end())
108ddde725dSArmin Le Grand             {
109ddde725dSArmin Le Grand                 return 0;
110ddde725dSArmin Le Grand             }
111ddde725dSArmin Le Grand             else
112ddde725dSArmin Le Grand             {
113ddde725dSArmin Le Grand                 return aResult->second;
114ddde725dSArmin Le Grand             }
115ddde725dSArmin Le Grand         }
116ddde725dSArmin Le Grand 
117ddde725dSArmin Le Grand     } // end of namespace svgreader
118ddde725dSArmin Le Grand } // end of namespace svgio
119ddde725dSArmin Le Grand 
120ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
121ddde725dSArmin Le Grand // eof
122