xref: /aoo42x/main/svgio/source/svgreader/svgnode.cxx (revision 7b027e49)
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/svgnode.hxx>
26ddde725dSArmin Le Grand #include <basegfx/polygon/b2dpolypolygontools.hxx>
27ddde725dSArmin Le Grand #include <svgio/svgreader/svgdocument.hxx>
28ddde725dSArmin Le Grand #include <svgio/svgreader/svgnode.hxx>
29ddde725dSArmin Le Grand #include <svgio/svgreader/svgstyleattributes.hxx>
30025b0597SArmin Le Grand #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
31172c67b2SArmin Le Grand #include <tools/urlobj.hxx>
32ddde725dSArmin Le Grand 
33ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
34ddde725dSArmin Le Grand 
35ddde725dSArmin Le Grand namespace svgio
36ddde725dSArmin Le Grand {
37ddde725dSArmin Le Grand     namespace svgreader
38ddde725dSArmin Le Grand     {
39ddde725dSArmin Le Grand         const SvgStyleAttributes* SvgNode::getSvgStyleAttributes() const
40ddde725dSArmin Le Grand         {
41ddde725dSArmin Le Grand             return 0;
42ddde725dSArmin Le Grand         }
43ddde725dSArmin Le Grand 
4450b37974SArmin Le Grand         const SvgStyleAttributes* SvgNode::checkForCssStyle(const rtl::OUString& rClassStr, const SvgStyleAttributes& rOriginal) const
4550b37974SArmin Le Grand         {
460906e779SArmin Le Grand             if(maCssStyleVector.empty()) // #120435# Evaluate for CSS styles only once, this cannot change
4750b37974SArmin Le Grand             {
480906e779SArmin Le Grand                 const SvgDocument& rDocument = getDocument();
490906e779SArmin Le Grand 
500906e779SArmin Le Grand                 if(rDocument.hasSvgStyleAttributesById())
5150b37974SArmin Le Grand                 {
520906e779SArmin Le Grand                     if(getClass())
530906e779SArmin Le Grand                     {
540906e779SArmin Le Grand                         // find all referenced CSS styles, a list of entries is allowed
550906e779SArmin Le Grand                         const rtl::OUString* pClassList = getClass();
560906e779SArmin Le Grand                         const sal_Int32 nLen(pClassList->getLength());
570906e779SArmin Le Grand                         sal_Int32 nPos(0);
580906e779SArmin Le Grand                         const SvgStyleAttributes* pNew = 0;
5950b37974SArmin Le Grand 
600906e779SArmin Le Grand                         skip_char(*pClassList, sal_Unicode(' '), nPos, nLen);
6150b37974SArmin Le Grand 
620906e779SArmin Le Grand                         while(nPos < nLen)
630906e779SArmin Le Grand                         {
640906e779SArmin Le Grand                             rtl::OUStringBuffer aTokenValue;
6550b37974SArmin Le Grand 
660906e779SArmin Le Grand                             copyToLimiter(*pClassList, sal_Unicode(' '), nPos, aTokenValue, nLen);
670906e779SArmin Le Grand                             skip_char(*pClassList, sal_Unicode(' '), nPos, nLen);
6850b37974SArmin Le Grand 
690906e779SArmin Le Grand                             rtl::OUString aId(rtl::OUString::createFromAscii("."));
700906e779SArmin Le Grand                             const rtl::OUString aOUTokenValue(aTokenValue.makeStringAndClear());
7150b37974SArmin Le Grand 
720906e779SArmin Le Grand                             // look for CSS style common to token
730906e779SArmin Le Grand                             aId = aId + aOUTokenValue;
740906e779SArmin Le Grand                             pNew = rDocument.findSvgStyleAttributesById(aId);
7550b37974SArmin Le Grand 
760906e779SArmin Le Grand                             if(!pNew && rClassStr.getLength())
770906e779SArmin Le Grand                             {
780906e779SArmin Le Grand                                 // look for CSS style common to class.token
790906e779SArmin Le Grand                                 aId = rClassStr + aId;
8050b37974SArmin Le Grand 
810906e779SArmin Le Grand                                 pNew = rDocument.findSvgStyleAttributesById(aId);
820906e779SArmin Le Grand                             }
8350b37974SArmin Le Grand 
840906e779SArmin Le Grand                             if(pNew)
850906e779SArmin Le Grand                             {
860906e779SArmin Le Grand                                 const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
870906e779SArmin Le Grand                             }
880906e779SArmin Le Grand                         }
890906e779SArmin Le Grand                     }
900906e779SArmin Le Grand 
910906e779SArmin Le Grand                     if(maCssStyleVector.empty() && getId())
920906e779SArmin Le Grand                     {
930906e779SArmin Le Grand                         // if none found, search for CSS style equal to Id
940906e779SArmin Le Grand                         const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(*getId());
950906e779SArmin Le Grand 
9650b37974SArmin Le Grand                         if(pNew)
9750b37974SArmin Le Grand                         {
9850b37974SArmin Le Grand                             const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
9950b37974SArmin Le Grand                         }
10050b37974SArmin Le Grand                     }
10150b37974SArmin Le Grand 
1020906e779SArmin Le Grand                     if(maCssStyleVector.empty() && rClassStr.getLength())
10350b37974SArmin Le Grand                     {
1040906e779SArmin Le Grand                         // if none found, search for CSS style equal to class type
1050906e779SArmin Le Grand                         const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(rClassStr);
10650b37974SArmin Le Grand 
1070906e779SArmin Le Grand                         if(pNew)
1080906e779SArmin Le Grand                         {
1090906e779SArmin Le Grand                             const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
1100906e779SArmin Le Grand                         }
11150b37974SArmin Le Grand                     }
11250b37974SArmin Le Grand                 }
11350b37974SArmin Le Grand             }
11450b37974SArmin Le Grand 
115*7b027e49SArmin Le Grand             if(!maCssStyleVector.empty())
11650b37974SArmin Le Grand             {
117*7b027e49SArmin Le Grand                 // #123510# if CSS styles were found, create a linked list with rOriginal as parent
118*7b027e49SArmin Le Grand                 // and all CSS styles as linked children, so that the style attribute has
119*7b027e49SArmin Le Grand                 // priority over the CSS style. If there is no style attribute this means that
120*7b027e49SArmin Le Grand                 // no values are set at rOriginal, thus it is still correct to have that order.
1210906e779SArmin Le Grand                 // Repeated style requests should only be issued from sub-Text nodes and I'm not
1220906e779SArmin Le Grand                 // sure if in-between text nodes may build other chains (should not happen). But
1230906e779SArmin Le Grand                 // it's only a re-chaining with pointers (cheap), so allow to do it every time.
12450b37974SArmin Le Grand                 SvgStyleAttributes* pCurrent = const_cast< SvgStyleAttributes* >(&rOriginal);
1250906e779SArmin Le Grand                 pCurrent->setCssStyleParent(0);
12650b37974SArmin Le Grand 
12750b37974SArmin Le Grand                 for(sal_uInt32 a(0); a < maCssStyleVector.size(); a++)
12850b37974SArmin Le Grand                 {
129*7b027e49SArmin Le Grand                     SvgStyleAttributes* pNext = const_cast< SvgStyleAttributes* >(maCssStyleVector[a]);
13050b37974SArmin Le Grand 
131*7b027e49SArmin Le Grand                     pCurrent->setCssStyleParent(pNext);
132*7b027e49SArmin Le Grand                     pCurrent = pNext;
133*7b027e49SArmin Le Grand                     pCurrent->setCssStyleParent(0);
13450b37974SArmin Le Grand                 }
13550b37974SArmin Le Grand             }
136*7b027e49SArmin Le Grand 
137*7b027e49SArmin Le Grand             return &rOriginal;
13850b37974SArmin Le Grand         }
13950b37974SArmin Le Grand 
140ddde725dSArmin Le Grand         SvgNode::SvgNode(
141ddde725dSArmin Le Grand             SVGToken aType,
142ddde725dSArmin Le Grand             SvgDocument& rDocument,
143ddde725dSArmin Le Grand             SvgNode* pParent)
144ddde725dSArmin Le Grand         :   maType(aType),
145ddde725dSArmin Le Grand             mrDocument(rDocument),
146ddde725dSArmin Le Grand             mpParent(pParent),
147ddde725dSArmin Le Grand             mpAlternativeParent(0),
148ddde725dSArmin Le Grand             maChildren(),
149ddde725dSArmin Le Grand             mpId(0),
150ddde725dSArmin Le Grand             mpClass(0),
15150b37974SArmin Le Grand             maXmlSpace(XmlSpace_notset),
152a275c134SArmin Le Grand             maDisplay(Display_inline),
15350b37974SArmin Le Grand             maCssStyleVector()
154ddde725dSArmin Le Grand         {
155ddde725dSArmin Le Grand             OSL_ENSURE(SVGTokenUnknown != maType, "SvgNode with unknown type created (!)");
156ddde725dSArmin Le Grand 
157ddde725dSArmin Le Grand             if(pParent)
158ddde725dSArmin Le Grand             {
159ddde725dSArmin Le Grand                 pParent->maChildren.push_back(this);
160ddde725dSArmin Le Grand             }
161ddde725dSArmin Le Grand             else
162ddde725dSArmin Le Grand             {
163ddde725dSArmin Le Grand #ifdef DBG_UTIL
164ddde725dSArmin Le Grand                 if(SVGTokenSvg != getType())
165ddde725dSArmin Le Grand                 {
166ddde725dSArmin Le Grand                     OSL_ENSURE(false, "No parent for this node (!)");
167ddde725dSArmin Le Grand                 }
168ddde725dSArmin Le Grand #endif
169ddde725dSArmin Le Grand             }
170ddde725dSArmin Le Grand         }
171ddde725dSArmin Le Grand 
172ddde725dSArmin Le Grand         SvgNode::~SvgNode()
173ddde725dSArmin Le Grand         {
174ddde725dSArmin Le Grand             while(maChildren.size())
175ddde725dSArmin Le Grand             {
176ddde725dSArmin Le Grand                 delete maChildren[maChildren.size() - 1];
177ddde725dSArmin Le Grand                 maChildren.pop_back();
178ddde725dSArmin Le Grand             }
179ddde725dSArmin Le Grand 
180ddde725dSArmin Le Grand             if(mpId) delete mpId;
181ddde725dSArmin Le Grand             if(mpClass) delete mpClass;
182ddde725dSArmin Le Grand         }
183ddde725dSArmin Le Grand 
184ddde725dSArmin Le Grand         void SvgNode::parseAttributes(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs)
185ddde725dSArmin Le Grand         {
186ddde725dSArmin Le Grand             const sal_uInt32 nAttributes(xAttribs->getLength());
187175cd092SArmin Le Grand             // #122522# SVG defines that 'In general, this means that the presentation attributes have
188175cd092SArmin Le Grand             // lower priority than other CSS style rules specified in author style sheets or �style�
189175cd092SArmin Le Grand             // attributes.' in http://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes
190175cd092SArmin Le Grand             // (6.4 Specifying properties using the presentation attributes SVG 1.1). That means that
191175cd092SArmin Le Grand             // e.g. font-size will appear as presentation attribute and CSS style attribute. In these
192175cd092SArmin Le Grand             // cases, CSS style attributes need to have precedence. To do so it is possible to create
193175cd092SArmin Le Grand             // a proirity system for all properties of a shape, but it will also work to parse the
194175cd092SArmin Le Grand             // presentation attributes of type 'style' last, so they will overwrite the less-prioritized
195175cd092SArmin Le Grand             // already interpreted ones. Thus, remember SVGTokenStyle entries and parse them last.
196175cd092SArmin Le Grand             // To make this work it is required that parseAttribute is only called by parseAttributes
197175cd092SArmin Le Grand             // which is the case.
198175cd092SArmin Le Grand             std::vector< sal_uInt32 > aSVGTokenStyleIndexes;
199175cd092SArmin Le Grand 
200ddde725dSArmin Le Grand             for(sal_uInt32 a(0); a < nAttributes; a++)
201ddde725dSArmin Le Grand             {
202ddde725dSArmin Le Grand                 const ::rtl::OUString aTokenName(xAttribs->getNameByIndex(a));
203175cd092SArmin Le Grand                 const SVGToken aSVGToken(StrToSVGToken(aTokenName));
204175cd092SArmin Le Grand 
205175cd092SArmin Le Grand                 if(SVGTokenStyle == aSVGToken)
206175cd092SArmin Le Grand                 {
207175cd092SArmin Le Grand                     // #122522# remember SVGTokenStyle entry
208175cd092SArmin Le Grand                     aSVGTokenStyleIndexes.push_back(a);
209175cd092SArmin Le Grand                 }
210175cd092SArmin Le Grand                 else
211175cd092SArmin Le Grand                 {
21286d02030SArmin Le Grand                     parseAttribute(aTokenName, aSVGToken, xAttribs->getValueByIndex(a));
213175cd092SArmin Le Grand                 }
214175cd092SArmin Le Grand             }
215175cd092SArmin Le Grand 
216175cd092SArmin Le Grand             // #122522# parse SVGTokenStyle entries last to override already interpreted
217175cd092SArmin Le Grand             // 'presentation attributes' of potenially the same type
218175cd092SArmin Le Grand             for(sal_uInt32 b(0); b < aSVGTokenStyleIndexes.size(); b++)
219175cd092SArmin Le Grand             {
220175cd092SArmin Le Grand                 const sal_uInt32 nSVGTokenStyleIndex(aSVGTokenStyleIndexes[b]);
221175cd092SArmin Le Grand                 const ::rtl::OUString aTokenName(xAttribs->getNameByIndex(nSVGTokenStyleIndex));
222175cd092SArmin Le Grand 
223175cd092SArmin Le Grand                 parseAttribute(aTokenName, SVGTokenStyle, xAttribs->getValueByIndex(nSVGTokenStyleIndex));
224ddde725dSArmin Le Grand             }
225ddde725dSArmin Le Grand         }
226ddde725dSArmin Le Grand 
22701e92ad6SArmin Le Grand         Display getDisplayFromContent(const rtl::OUString& aContent)
22801e92ad6SArmin Le Grand         {
22901e92ad6SArmin Le Grand             if(aContent.getLength())
23001e92ad6SArmin Le Grand             {
231e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrInline(rtl::OUString::createFromAscii("inline"));
232e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrBlock(rtl::OUString::createFromAscii("block"));
233e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrList_item(rtl::OUString::createFromAscii("list-item"));
234e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrRun_in(rtl::OUString::createFromAscii("run-in"));
235e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrCompact(rtl::OUString::createFromAscii("compact"));
236e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrMarker(rtl::OUString::createFromAscii("marker"));
237e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrTable(rtl::OUString::createFromAscii("table"));
238e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrInline_table(rtl::OUString::createFromAscii("inline-table"));
239e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrTable_row_group(rtl::OUString::createFromAscii("table-row-group"));
240e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrTable_header_group(rtl::OUString::createFromAscii("table-header-group"));
241e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrTable_footer_group(rtl::OUString::createFromAscii("table-footer-group"));
242e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrTable_row(rtl::OUString::createFromAscii("table-row"));
243e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrTable_column_group(rtl::OUString::createFromAscii("table-column-group"));
244e92bb418SOliver-Rainer Wittmann                 static rtl::OUString aStrTable_column(rtl::OUString::createFromAscii("table-column"));
24501e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_cell(rtl::OUString::createFromAscii("table-cell"));
24601e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_caption(rtl::OUString::createFromAscii("table-caption"));
24701e92ad6SArmin Le Grand                 static rtl::OUString aStrNone(rtl::OUString::createFromAscii("none"));
24801e92ad6SArmin Le Grand                 static rtl::OUString aStrInherit(rtl::OUString::createFromAscii("inherit"));
24901e92ad6SArmin Le Grand 
25001e92ad6SArmin Le Grand                 if(aContent.match(aStrInline))
25101e92ad6SArmin Le Grand                 {
25201e92ad6SArmin Le Grand                     return Display_inline;
25301e92ad6SArmin Le Grand                 }
25401e92ad6SArmin Le Grand                 else if(aContent.match(aStrNone))
25501e92ad6SArmin Le Grand                 {
25601e92ad6SArmin Le Grand                     return Display_none;
25701e92ad6SArmin Le Grand                 }
25801e92ad6SArmin Le Grand                 else if(aContent.match(aStrInherit))
25901e92ad6SArmin Le Grand                 {
26001e92ad6SArmin Le Grand                     return Display_inherit;
26101e92ad6SArmin Le Grand                 }
262e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrBlock))
26301e92ad6SArmin Le Grand                 {
26401e92ad6SArmin Le Grand                     return Display_block;
26501e92ad6SArmin Le Grand                 }
266e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrList_item))
26701e92ad6SArmin Le Grand                 {
26801e92ad6SArmin Le Grand                     return Display_list_item;
26901e92ad6SArmin Le Grand                 }
270e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrRun_in))
27101e92ad6SArmin Le Grand                 {
27201e92ad6SArmin Le Grand                     return Display_run_in;
27301e92ad6SArmin Le Grand                 }
274e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrCompact))
27501e92ad6SArmin Le Grand                 {
27601e92ad6SArmin Le Grand                     return Display_compact;
27701e92ad6SArmin Le Grand                 }
278e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrMarker))
27901e92ad6SArmin Le Grand                 {
28001e92ad6SArmin Le Grand                     return Display_marker;
28101e92ad6SArmin Le Grand                 }
282e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrTable))
28301e92ad6SArmin Le Grand                 {
28401e92ad6SArmin Le Grand                     return Display_table;
28501e92ad6SArmin Le Grand                 }
286e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrInline_table))
28701e92ad6SArmin Le Grand                 {
28801e92ad6SArmin Le Grand                     return Display_inline_table;
28901e92ad6SArmin Le Grand                 }
290e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrTable_row_group))
29101e92ad6SArmin Le Grand                 {
29201e92ad6SArmin Le Grand                     return Display_table_row_group;
29301e92ad6SArmin Le Grand                 }
294e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrTable_header_group))
29501e92ad6SArmin Le Grand                 {
29601e92ad6SArmin Le Grand                     return Display_table_header_group;
29701e92ad6SArmin Le Grand                 }
298e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrTable_footer_group))
29901e92ad6SArmin Le Grand                 {
30001e92ad6SArmin Le Grand                     return Display_table_footer_group;
30101e92ad6SArmin Le Grand                 }
302e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrTable_row))
30301e92ad6SArmin Le Grand                 {
30401e92ad6SArmin Le Grand                     return Display_table_row;
30501e92ad6SArmin Le Grand                 }
306e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrTable_column_group))
30701e92ad6SArmin Le Grand                 {
30801e92ad6SArmin Le Grand                     return Display_table_column_group;
30901e92ad6SArmin Le Grand                 }
310e92bb418SOliver-Rainer Wittmann                 else if(aContent.match(aStrTable_column))
31101e92ad6SArmin Le Grand                 {
31201e92ad6SArmin Le Grand                     return Display_table_column;
31301e92ad6SArmin Le Grand                 }
31401e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_cell))
31501e92ad6SArmin Le Grand                 {
31601e92ad6SArmin Le Grand                     return Display_table_cell;
31701e92ad6SArmin Le Grand                 }
31801e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_caption))
31901e92ad6SArmin Le Grand                 {
32001e92ad6SArmin Le Grand                     return Display_table_caption;
32101e92ad6SArmin Le Grand                 }
32201e92ad6SArmin Le Grand             }
32301e92ad6SArmin Le Grand 
32401e92ad6SArmin Le Grand             // return the default
32501e92ad6SArmin Le Grand             return Display_inline;
32601e92ad6SArmin Le Grand         }
32701e92ad6SArmin Le Grand 
328e2bf1e9dSArmin Le Grand         void SvgNode::parseAttribute(const rtl::OUString& /*rTokenName*/, SVGToken aSVGToken, const rtl::OUString& aContent)
329ddde725dSArmin Le Grand         {
330ddde725dSArmin Le Grand             switch(aSVGToken)
331ddde725dSArmin Le Grand             {
332ddde725dSArmin Le Grand                 case SVGTokenId:
333ddde725dSArmin Le Grand                 {
334ddde725dSArmin Le Grand                     if(aContent.getLength())
335ddde725dSArmin Le Grand                     {
336ddde725dSArmin Le Grand                         setId(&aContent);
337ddde725dSArmin Le Grand                     }
338ddde725dSArmin Le Grand                     break;
339ddde725dSArmin Le Grand                 }
340ddde725dSArmin Le Grand                 case SVGTokenClass:
341ddde725dSArmin Le Grand                 {
342ddde725dSArmin Le Grand                     if(aContent.getLength())
343ddde725dSArmin Le Grand                     {
344ddde725dSArmin Le Grand                         setClass(&aContent);
345ddde725dSArmin Le Grand                     }
346ddde725dSArmin Le Grand                     break;
347ddde725dSArmin Le Grand                 }
348ddde725dSArmin Le Grand                 case SVGTokenXmlSpace:
349ddde725dSArmin Le Grand                 {
350ddde725dSArmin Le Grand                     if(aContent.getLength())
351ddde725dSArmin Le Grand                     {
352ddde725dSArmin Le Grand                         static rtl::OUString aStrDefault(rtl::OUString::createFromAscii("default"));
353ddde725dSArmin Le Grand                         static rtl::OUString aStrPreserve(rtl::OUString::createFromAscii("preserve"));
354ddde725dSArmin Le Grand 
355ddde725dSArmin Le Grand                         if(aContent.match(aStrDefault))
356ddde725dSArmin Le Grand                         {
357ddde725dSArmin Le Grand                             setXmlSpace(XmlSpace_default);
358ddde725dSArmin Le Grand                         }
359ddde725dSArmin Le Grand                         else if(aContent.match(aStrPreserve))
360ddde725dSArmin Le Grand                         {
361ddde725dSArmin Le Grand                             setXmlSpace(XmlSpace_preserve);
362ddde725dSArmin Le Grand                         }
363ddde725dSArmin Le Grand                     }
364ddde725dSArmin Le Grand                     break;
365ddde725dSArmin Le Grand                 }
366a275c134SArmin Le Grand                 case SVGTokenDisplay:
367a275c134SArmin Le Grand                 {
368a275c134SArmin Le Grand                     if(aContent.getLength())
369a275c134SArmin Le Grand                     {
37001e92ad6SArmin Le Grand                         setDisplay(getDisplayFromContent(aContent));
371a275c134SArmin Le Grand                     }
372a275c134SArmin Le Grand                     break;
373a275c134SArmin Le Grand                 }
374e2bf1e9dSArmin Le Grand                 default:
375e2bf1e9dSArmin Le Grand                 {
376e2bf1e9dSArmin Le Grand                     break;
377e2bf1e9dSArmin Le Grand                 }
378ddde725dSArmin Le Grand             }
379ddde725dSArmin Le Grand         }
380ddde725dSArmin Le Grand 
381ddde725dSArmin Le Grand         void SvgNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const
382ddde725dSArmin Le Grand         {
383a275c134SArmin Le Grand             if(Display_none == getDisplay())
384a275c134SArmin Le Grand             {
385a275c134SArmin Le Grand                 return;
386a275c134SArmin Le Grand             }
387a275c134SArmin Le Grand 
388ddde725dSArmin Le Grand             if(!bReferenced)
389ddde725dSArmin Le Grand             {
390ddde725dSArmin Le Grand                 if(SVGTokenDefs == getType() ||
391ddde725dSArmin Le Grand                     SVGTokenSymbol == getType() ||
392ddde725dSArmin Le Grand                     SVGTokenClipPathNode == getType() ||
393ddde725dSArmin Le Grand                     SVGTokenMask == getType() ||
394ddde725dSArmin Le Grand                     SVGTokenMarker == getType() ||
395ddde725dSArmin Le Grand                     SVGTokenPattern == getType())
396ddde725dSArmin Le Grand                 {
397ddde725dSArmin Le Grand                     // do not decompose defs or symbol nodes (these hold only style-like
398ddde725dSArmin Le Grand                     // objects which may be used by referencing them) except when doing
399ddde725dSArmin Le Grand                     // so controlled referenced
400ddde725dSArmin Le Grand 
401ddde725dSArmin Le Grand                     // also do not decompose ClipPaths and Masks. These should be embedded
402ddde725dSArmin Le Grand                     // in a defs node (which gets not decomposed by itself), but you never
403ddde725dSArmin Le Grand                     // know
404ddde725dSArmin Le Grand 
405ddde725dSArmin Le Grand                     // also not directly used are Markers and Patterns, only indirecty used
406ddde725dSArmin Le Grand                     // by reference
407a275c134SArmin Le Grand 
408a275c134SArmin Le Grand                     // #121656# also do not decompose nodes which have display="none" set
409a275c134SArmin Le Grand                     // as property
410ddde725dSArmin Le Grand                     return;
411ddde725dSArmin Le Grand                 }
412ddde725dSArmin Le Grand             }
413ddde725dSArmin Le Grand 
414ddde725dSArmin Le Grand             const SvgNodeVector& rChildren = getChildren();
415ddde725dSArmin Le Grand 
416ddde725dSArmin Le Grand             if(!rChildren.empty())
417ddde725dSArmin Le Grand             {
418ddde725dSArmin Le Grand                 const sal_uInt32 nCount(rChildren.size());
419ddde725dSArmin Le Grand 
420ddde725dSArmin Le Grand                 for(sal_uInt32 a(0); a < nCount; a++)
421ddde725dSArmin Le Grand                 {
422ddde725dSArmin Le Grand                     SvgNode* pCandidate = rChildren[a];
423ddde725dSArmin Le Grand 
424a275c134SArmin Le Grand                     if(pCandidate && Display_none != pCandidate->getDisplay())
425ddde725dSArmin Le Grand                     {
426ddde725dSArmin Le Grand                         drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
427ddde725dSArmin Le Grand 
428ddde725dSArmin Le Grand                         pCandidate->decomposeSvgNode(aNewTarget, bReferenced);
429ddde725dSArmin Le Grand 
430ddde725dSArmin Le Grand                         if(aNewTarget.hasElements())
431ddde725dSArmin Le Grand                         {
432ddde725dSArmin Le Grand                             drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aNewTarget);
433ddde725dSArmin Le Grand                         }
434ddde725dSArmin Le Grand                     }
435ddde725dSArmin Le Grand                     else
436ddde725dSArmin Le Grand                     {
437ddde725dSArmin Le Grand                         OSL_ENSURE(false, "Null-Pointer in child node list (!)");
438ddde725dSArmin Le Grand                     }
439ddde725dSArmin Le Grand                 }
440025b0597SArmin Le Grand 
441025b0597SArmin Le Grand                 if(rTarget.hasElements())
442025b0597SArmin Le Grand                 {
443025b0597SArmin Le Grand                     const SvgStyleAttributes* pStyles = getSvgStyleAttributes();
444025b0597SArmin Le Grand 
445025b0597SArmin Le Grand                     if(pStyles)
446025b0597SArmin Le Grand                     {
447025b0597SArmin Le Grand                         // check if we have Title or Desc
448025b0597SArmin Le Grand                         const rtl::OUString& rTitle = pStyles->getTitle();
449025b0597SArmin Le Grand                         const rtl::OUString& rDesc = pStyles->getDesc();
450025b0597SArmin Le Grand 
451025b0597SArmin Le Grand                         if(rTitle.getLength() || rDesc.getLength())
452025b0597SArmin Le Grand                         {
453025b0597SArmin Le Grand                             // default object name is empty
454025b0597SArmin Le Grand                             rtl::OUString aObjectName;
455025b0597SArmin Le Grand 
456025b0597SArmin Le Grand                             // use path as object name when outmost element
457025b0597SArmin Le Grand                             if(SVGTokenSvg == getType())
458025b0597SArmin Le Grand                             {
459025b0597SArmin Le Grand                                 aObjectName = getDocument().getAbsolutePath();
460172c67b2SArmin Le Grand 
461172c67b2SArmin Le Grand                                 if(aObjectName.getLength())
462172c67b2SArmin Le Grand                                 {
463172c67b2SArmin Le Grand                             		INetURLObject aURL(aObjectName);
464172c67b2SArmin Le Grand 
465172c67b2SArmin Le Grand                                     aObjectName = aURL.getName(
466172c67b2SArmin Le Grand                                         INetURLObject::LAST_SEGMENT,
467172c67b2SArmin Le Grand                                         true,
468172c67b2SArmin Le Grand                                         INetURLObject::DECODE_WITH_CHARSET);
469172c67b2SArmin Le Grand                                 }
470025b0597SArmin Le Grand                             }
471025b0597SArmin Le Grand 
472025b0597SArmin Le Grand                             // pack in ObjectInfoPrimitive2D group
473025b0597SArmin Le Grand                             const drawinglayer::primitive2d::Primitive2DReference xRef(
474025b0597SArmin Le Grand                                 new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
475025b0597SArmin Le Grand                                     rTarget,
476025b0597SArmin Le Grand                                     aObjectName,
477025b0597SArmin Le Grand                                     rTitle,
478025b0597SArmin Le Grand                                     rDesc));
479025b0597SArmin Le Grand 
480025b0597SArmin Le Grand                             rTarget = drawinglayer::primitive2d::Primitive2DSequence(&xRef, 1);
481025b0597SArmin Le Grand                         }
482025b0597SArmin Le Grand                     }
483025b0597SArmin Le Grand                 }
484ddde725dSArmin Le Grand             }
485ddde725dSArmin Le Grand         }
486ddde725dSArmin Le Grand 
487e92bb418SOliver-Rainer Wittmann         const basegfx::B2DRange SvgNode::getCurrentViewPort() const
488ddde725dSArmin Le Grand         {
489ddde725dSArmin Le Grand             if(getParent())
490ddde725dSArmin Le Grand             {
491ddde725dSArmin Le Grand                 return getParent()->getCurrentViewPort();
492ddde725dSArmin Le Grand             }
493ddde725dSArmin Le Grand             else
494ddde725dSArmin Le Grand             {
495e92bb418SOliver-Rainer Wittmann                 return basegfx::B2DRange(); // return empty B2DRange
496ddde725dSArmin Le Grand             }
497ddde725dSArmin Le Grand         }
498ddde725dSArmin Le Grand 
499ddde725dSArmin Le Grand         double SvgNode::getCurrentFontSize() const
500ddde725dSArmin Le Grand         {
501ddde725dSArmin Le Grand             if(getSvgStyleAttributes())
502ddde725dSArmin Le Grand             {
503ddde725dSArmin Le Grand                 return getSvgStyleAttributes()->getFontSize().solve(*this, xcoordinate);
504ddde725dSArmin Le Grand             }
505ddde725dSArmin Le Grand             else if(getParent())
506ddde725dSArmin Le Grand             {
507ddde725dSArmin Le Grand                 return getParent()->getCurrentFontSize();
508ddde725dSArmin Le Grand             }
509ddde725dSArmin Le Grand             else
510ddde725dSArmin Le Grand             {
511ddde725dSArmin Le Grand                 return 0.0;
512ddde725dSArmin Le Grand             }
513ddde725dSArmin Le Grand         }
514ddde725dSArmin Le Grand 
515ddde725dSArmin Le Grand         double SvgNode::getCurrentXHeight() const
516ddde725dSArmin Le Grand         {
517ddde725dSArmin Le Grand             if(getSvgStyleAttributes())
518ddde725dSArmin Le Grand             {
519ddde725dSArmin Le Grand                 // for XHeight, use FontSize currently
520ddde725dSArmin Le Grand                 return getSvgStyleAttributes()->getFontSize().solve(*this, ycoordinate);
521ddde725dSArmin Le Grand             }
522ddde725dSArmin Le Grand             else if(getParent())
523ddde725dSArmin Le Grand             {
524ddde725dSArmin Le Grand                 return getParent()->getCurrentXHeight();
525ddde725dSArmin Le Grand             }
526ddde725dSArmin Le Grand             else
527ddde725dSArmin Le Grand             {
528ddde725dSArmin Le Grand                 return 0.0;
529ddde725dSArmin Le Grand             }
530ddde725dSArmin Le Grand         }
531ddde725dSArmin Le Grand 
532ddde725dSArmin Le Grand         void SvgNode::setId(const rtl::OUString* pfId)
533ddde725dSArmin Le Grand         {
534ddde725dSArmin Le Grand             if(mpId)
535ddde725dSArmin Le Grand             {
536ddde725dSArmin Le Grand                 mrDocument.removeSvgNodeFromMapper(*mpId);
537ddde725dSArmin Le Grand                 delete mpId;
538ddde725dSArmin Le Grand                 mpId = 0;
539ddde725dSArmin Le Grand             }
540ddde725dSArmin Le Grand 
541ddde725dSArmin Le Grand             if(pfId)
542ddde725dSArmin Le Grand             {
543ddde725dSArmin Le Grand                 mpId = new rtl::OUString(*pfId);
544ddde725dSArmin Le Grand                 mrDocument.addSvgNodeToMapper(*mpId, *this);
545ddde725dSArmin Le Grand             }
546ddde725dSArmin Le Grand         }
547ddde725dSArmin Le Grand 
548ddde725dSArmin Le Grand         void SvgNode::setClass(const rtl::OUString* pfClass)
549ddde725dSArmin Le Grand         {
550ddde725dSArmin Le Grand             if(mpClass)
551ddde725dSArmin Le Grand             {
552ddde725dSArmin Le Grand                 mrDocument.removeSvgNodeFromMapper(*mpClass);
553ddde725dSArmin Le Grand                 delete mpClass;
554ddde725dSArmin Le Grand                 mpClass = 0;
555ddde725dSArmin Le Grand             }
556ddde725dSArmin Le Grand 
557ddde725dSArmin Le Grand             if(pfClass)
558ddde725dSArmin Le Grand             {
559ddde725dSArmin Le Grand                 mpClass = new rtl::OUString(*pfClass);
560ddde725dSArmin Le Grand                 mrDocument.addSvgNodeToMapper(*mpClass, *this);
561ddde725dSArmin Le Grand             }
562ddde725dSArmin Le Grand         }
563ddde725dSArmin Le Grand 
564ddde725dSArmin Le Grand         XmlSpace SvgNode::getXmlSpace() const
565ddde725dSArmin Le Grand         {
566ddde725dSArmin Le Grand             if(maXmlSpace != XmlSpace_notset)
567ddde725dSArmin Le Grand             {
568ddde725dSArmin Le Grand                 return maXmlSpace;
569ddde725dSArmin Le Grand             }
570ddde725dSArmin Le Grand 
571ddde725dSArmin Le Grand             if(getParent())
572ddde725dSArmin Le Grand             {
573ddde725dSArmin Le Grand                 return getParent()->getXmlSpace();
574ddde725dSArmin Le Grand             }
575ddde725dSArmin Le Grand 
576ddde725dSArmin Le Grand             // default is XmlSpace_default
577ddde725dSArmin Le Grand             return XmlSpace_default;
578ddde725dSArmin Le Grand         }
579ddde725dSArmin Le Grand 
580ddde725dSArmin Le Grand     } // end of namespace svgreader
581ddde725dSArmin Le Grand } // end of namespace svgio
582ddde725dSArmin Le Grand 
583ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
584ddde725dSArmin Le Grand // eof
585