xref: /aoo42x/main/svgio/source/svgreader/svgnode.cxx (revision 175cd092)
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 
11550b37974SArmin Le Grand             if(maCssStyleVector.empty())
11650b37974SArmin Le Grand             {
11750b37974SArmin Le Grand                 return &rOriginal;
11850b37974SArmin Le Grand             }
11950b37974SArmin Le Grand             else
12050b37974SArmin Le Grand             {
12150b37974SArmin Le Grand                 // set CssStyleParent at maCssStyleVector members to hang them in front of
1220906e779SArmin Le Grand                 // the existing style. Build a style chain, reset parent of original for security.
1230906e779SArmin Le Grand                 // Repeated style requests should only be issued from sub-Text nodes and I'm not
1240906e779SArmin Le Grand                 // sure if in-between text nodes may build other chains (should not happen). But
1250906e779SArmin Le Grand                 // it's only a re-chaining with pointers (cheap), so allow to do it every time.
12650b37974SArmin Le Grand                 SvgStyleAttributes* pCurrent = const_cast< SvgStyleAttributes* >(&rOriginal);
1270906e779SArmin Le Grand                 pCurrent->setCssStyleParent(0);
12850b37974SArmin Le Grand 
12950b37974SArmin Le Grand                 for(sal_uInt32 a(0); a < maCssStyleVector.size(); a++)
13050b37974SArmin Le Grand                 {
13150b37974SArmin Le Grand                     SvgStyleAttributes* pCandidate = const_cast< SvgStyleAttributes* >(maCssStyleVector[maCssStyleVector.size() - a - 1]);
13250b37974SArmin Le Grand 
13350b37974SArmin Le Grand                     pCandidate->setCssStyleParent(pCurrent);
13450b37974SArmin Le Grand                     pCurrent = pCandidate;
13550b37974SArmin Le Grand                 }
13650b37974SArmin Le Grand 
13750b37974SArmin Le Grand                 return pCurrent;
13850b37974SArmin Le Grand             }
13950b37974SArmin Le Grand         }
14050b37974SArmin Le Grand 
141ddde725dSArmin Le Grand         SvgNode::SvgNode(
142ddde725dSArmin Le Grand             SVGToken aType,
143ddde725dSArmin Le Grand             SvgDocument& rDocument,
144ddde725dSArmin Le Grand             SvgNode* pParent)
145ddde725dSArmin Le Grand         :   maType(aType),
146ddde725dSArmin Le Grand             mrDocument(rDocument),
147ddde725dSArmin Le Grand             mpParent(pParent),
148ddde725dSArmin Le Grand             mpAlternativeParent(0),
149ddde725dSArmin Le Grand             maChildren(),
150ddde725dSArmin Le Grand             mpId(0),
151ddde725dSArmin Le Grand             mpClass(0),
15250b37974SArmin Le Grand             maXmlSpace(XmlSpace_notset),
153a275c134SArmin Le Grand             maDisplay(Display_inline),
15450b37974SArmin Le Grand             maCssStyleVector()
155ddde725dSArmin Le Grand         {
156ddde725dSArmin Le Grand             OSL_ENSURE(SVGTokenUnknown != maType, "SvgNode with unknown type created (!)");
157ddde725dSArmin Le Grand 
158ddde725dSArmin Le Grand             if(pParent)
159ddde725dSArmin Le Grand             {
160ddde725dSArmin Le Grand                 pParent->maChildren.push_back(this);
161ddde725dSArmin Le Grand             }
162ddde725dSArmin Le Grand             else
163ddde725dSArmin Le Grand             {
164ddde725dSArmin Le Grand #ifdef DBG_UTIL
165ddde725dSArmin Le Grand                 if(SVGTokenSvg != getType())
166ddde725dSArmin Le Grand                 {
167ddde725dSArmin Le Grand                     OSL_ENSURE(false, "No parent for this node (!)");
168ddde725dSArmin Le Grand                 }
169ddde725dSArmin Le Grand #endif
170ddde725dSArmin Le Grand             }
171ddde725dSArmin Le Grand         }
172ddde725dSArmin Le Grand 
173ddde725dSArmin Le Grand         SvgNode::~SvgNode()
174ddde725dSArmin Le Grand         {
175ddde725dSArmin Le Grand             while(maChildren.size())
176ddde725dSArmin Le Grand             {
177ddde725dSArmin Le Grand                 delete maChildren[maChildren.size() - 1];
178ddde725dSArmin Le Grand                 maChildren.pop_back();
179ddde725dSArmin Le Grand             }
180ddde725dSArmin Le Grand 
181ddde725dSArmin Le Grand             if(mpId) delete mpId;
182ddde725dSArmin Le Grand             if(mpClass) delete mpClass;
183ddde725dSArmin Le Grand         }
184ddde725dSArmin Le Grand 
185ddde725dSArmin Le Grand         void SvgNode::parseAttributes(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs)
186ddde725dSArmin Le Grand         {
187ddde725dSArmin Le Grand             const sal_uInt32 nAttributes(xAttribs->getLength());
188*175cd092SArmin Le Grand             // #122522# SVG defines that 'In general, this means that the presentation attributes have
189*175cd092SArmin Le Grand             // lower priority than other CSS style rules specified in author style sheets or �style�
190*175cd092SArmin Le Grand             // attributes.' in http://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes
191*175cd092SArmin Le Grand             // (6.4 Specifying properties using the presentation attributes SVG 1.1). That means that
192*175cd092SArmin Le Grand             // e.g. font-size will appear as presentation attribute and CSS style attribute. In these
193*175cd092SArmin Le Grand             // cases, CSS style attributes need to have precedence. To do so it is possible to create
194*175cd092SArmin Le Grand             // a proirity system for all properties of a shape, but it will also work to parse the
195*175cd092SArmin Le Grand             // presentation attributes of type 'style' last, so they will overwrite the less-prioritized
196*175cd092SArmin Le Grand             // already interpreted ones. Thus, remember SVGTokenStyle entries and parse them last.
197*175cd092SArmin Le Grand             // To make this work it is required that parseAttribute is only called by parseAttributes
198*175cd092SArmin Le Grand             // which is the case.
199*175cd092SArmin Le Grand             std::vector< sal_uInt32 > aSVGTokenStyleIndexes;
200*175cd092SArmin Le Grand 
201ddde725dSArmin Le Grand             for(sal_uInt32 a(0); a < nAttributes; a++)
202ddde725dSArmin Le Grand             {
203ddde725dSArmin Le Grand                 const ::rtl::OUString aTokenName(xAttribs->getNameByIndex(a));
204*175cd092SArmin Le Grand                 const SVGToken aSVGToken(StrToSVGToken(aTokenName));
205*175cd092SArmin Le Grand 
206*175cd092SArmin Le Grand                 if(SVGTokenStyle == aSVGToken)
207*175cd092SArmin Le Grand                 {
208*175cd092SArmin Le Grand                     // #122522# remember SVGTokenStyle entry
209*175cd092SArmin Le Grand                     aSVGTokenStyleIndexes.push_back(a);
210*175cd092SArmin Le Grand                 }
211*175cd092SArmin Le Grand                 else
212*175cd092SArmin Le Grand                 {
213*175cd092SArmin Le Grand                     parseAttribute(aTokenName, StrToSVGToken(aTokenName), xAttribs->getValueByIndex(a));
214*175cd092SArmin Le Grand                 }
215*175cd092SArmin Le Grand             }
216*175cd092SArmin Le Grand 
217*175cd092SArmin Le Grand             // #122522# parse SVGTokenStyle entries last to override already interpreted
218*175cd092SArmin Le Grand             // 'presentation attributes' of potenially the same type
219*175cd092SArmin Le Grand             for(sal_uInt32 b(0); b < aSVGTokenStyleIndexes.size(); b++)
220*175cd092SArmin Le Grand             {
221*175cd092SArmin Le Grand                 const sal_uInt32 nSVGTokenStyleIndex(aSVGTokenStyleIndexes[b]);
222*175cd092SArmin Le Grand                 const ::rtl::OUString aTokenName(xAttribs->getNameByIndex(nSVGTokenStyleIndex));
223*175cd092SArmin Le Grand 
224*175cd092SArmin Le Grand                 parseAttribute(aTokenName, SVGTokenStyle, xAttribs->getValueByIndex(nSVGTokenStyleIndex));
225ddde725dSArmin Le Grand             }
226ddde725dSArmin Le Grand         }
227ddde725dSArmin Le Grand 
22801e92ad6SArmin Le Grand         Display getDisplayFromContent(const rtl::OUString& aContent)
22901e92ad6SArmin Le Grand         {
23001e92ad6SArmin Le Grand             if(aContent.getLength())
23101e92ad6SArmin Le Grand             {
23201e92ad6SArmin Le Grand                 static rtl::OUString aStrInline(rtl::OUString::createFromAscii("inline"));
23301e92ad6SArmin Le Grand                 static rtl::OUString aStrBlock(rtl::OUString::createFromAscii("block"));
23401e92ad6SArmin Le Grand                 static rtl::OUString aStrList_item(rtl::OUString::createFromAscii("list-item"));
23501e92ad6SArmin Le Grand                 static rtl::OUString aStrRun_in(rtl::OUString::createFromAscii("run-in"));
23601e92ad6SArmin Le Grand                 static rtl::OUString aStrCompact(rtl::OUString::createFromAscii("compact"));
23701e92ad6SArmin Le Grand                 static rtl::OUString aStrMarker(rtl::OUString::createFromAscii("marker"));
23801e92ad6SArmin Le Grand                 static rtl::OUString aStrTable(rtl::OUString::createFromAscii("table"));
23901e92ad6SArmin Le Grand                 static rtl::OUString aStrInline_table(rtl::OUString::createFromAscii("inline-table"));
24001e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_row_group(rtl::OUString::createFromAscii("table-row-group"));
24101e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_header_group(rtl::OUString::createFromAscii("table-header-group"));
24201e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_footer_group(rtl::OUString::createFromAscii("table-footer-group"));
24301e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_row(rtl::OUString::createFromAscii("table-row"));
24401e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_column_group(rtl::OUString::createFromAscii("table-column-group"));
24501e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_column(rtl::OUString::createFromAscii("table-column"));
24601e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_cell(rtl::OUString::createFromAscii("table-cell"));
24701e92ad6SArmin Le Grand                 static rtl::OUString aStrTable_caption(rtl::OUString::createFromAscii("table-caption"));
24801e92ad6SArmin Le Grand                 static rtl::OUString aStrNone(rtl::OUString::createFromAscii("none"));
24901e92ad6SArmin Le Grand                 static rtl::OUString aStrInherit(rtl::OUString::createFromAscii("inherit"));
25001e92ad6SArmin Le Grand 
25101e92ad6SArmin Le Grand                 if(aContent.match(aStrInline))
25201e92ad6SArmin Le Grand                 {
25301e92ad6SArmin Le Grand                     return Display_inline;
25401e92ad6SArmin Le Grand                 }
25501e92ad6SArmin Le Grand                 else if(aContent.match(aStrNone))
25601e92ad6SArmin Le Grand                 {
25701e92ad6SArmin Le Grand                     return Display_none;
25801e92ad6SArmin Le Grand                 }
25901e92ad6SArmin Le Grand                 else if(aContent.match(aStrInherit))
26001e92ad6SArmin Le Grand                 {
26101e92ad6SArmin Le Grand                     return Display_inherit;
26201e92ad6SArmin Le Grand                 }
26301e92ad6SArmin Le Grand                 else if(aContent.match(aStrBlock))
26401e92ad6SArmin Le Grand                 {
26501e92ad6SArmin Le Grand                     return Display_block;
26601e92ad6SArmin Le Grand                 }
26701e92ad6SArmin Le Grand                 else if(aContent.match(aStrList_item))
26801e92ad6SArmin Le Grand                 {
26901e92ad6SArmin Le Grand                     return Display_list_item;
27001e92ad6SArmin Le Grand                 }
27101e92ad6SArmin Le Grand                 else if(aContent.match(aStrRun_in))
27201e92ad6SArmin Le Grand                 {
27301e92ad6SArmin Le Grand                     return Display_run_in;
27401e92ad6SArmin Le Grand                 }
27501e92ad6SArmin Le Grand                 else if(aContent.match(aStrCompact))
27601e92ad6SArmin Le Grand                 {
27701e92ad6SArmin Le Grand                     return Display_compact;
27801e92ad6SArmin Le Grand                 }
27901e92ad6SArmin Le Grand                 else if(aContent.match(aStrMarker))
28001e92ad6SArmin Le Grand                 {
28101e92ad6SArmin Le Grand                     return Display_marker;
28201e92ad6SArmin Le Grand                 }
28301e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable))
28401e92ad6SArmin Le Grand                 {
28501e92ad6SArmin Le Grand                     return Display_table;
28601e92ad6SArmin Le Grand                 }
28701e92ad6SArmin Le Grand                 else if(aContent.match(aStrInline_table))
28801e92ad6SArmin Le Grand                 {
28901e92ad6SArmin Le Grand                     return Display_inline_table;
29001e92ad6SArmin Le Grand                 }
29101e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_row_group))
29201e92ad6SArmin Le Grand                 {
29301e92ad6SArmin Le Grand                     return Display_table_row_group;
29401e92ad6SArmin Le Grand                 }
29501e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_header_group))
29601e92ad6SArmin Le Grand                 {
29701e92ad6SArmin Le Grand                     return Display_table_header_group;
29801e92ad6SArmin Le Grand                 }
29901e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_footer_group))
30001e92ad6SArmin Le Grand                 {
30101e92ad6SArmin Le Grand                     return Display_table_footer_group;
30201e92ad6SArmin Le Grand                 }
30301e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_row))
30401e92ad6SArmin Le Grand                 {
30501e92ad6SArmin Le Grand                     return Display_table_row;
30601e92ad6SArmin Le Grand                 }
30701e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_column_group))
30801e92ad6SArmin Le Grand                 {
30901e92ad6SArmin Le Grand                     return Display_table_column_group;
31001e92ad6SArmin Le Grand                 }
31101e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_column))
31201e92ad6SArmin Le Grand                 {
31301e92ad6SArmin Le Grand                     return Display_table_column;
31401e92ad6SArmin Le Grand                 }
31501e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_cell))
31601e92ad6SArmin Le Grand                 {
31701e92ad6SArmin Le Grand                     return Display_table_cell;
31801e92ad6SArmin Le Grand                 }
31901e92ad6SArmin Le Grand                 else if(aContent.match(aStrTable_caption))
32001e92ad6SArmin Le Grand                 {
32101e92ad6SArmin Le Grand                     return Display_table_caption;
32201e92ad6SArmin Le Grand                 }
32301e92ad6SArmin Le Grand             }
32401e92ad6SArmin Le Grand 
32501e92ad6SArmin Le Grand             // return the default
32601e92ad6SArmin Le Grand             return Display_inline;
32701e92ad6SArmin Le Grand         }
32801e92ad6SArmin Le Grand 
329e2bf1e9dSArmin Le Grand         void SvgNode::parseAttribute(const rtl::OUString& /*rTokenName*/, SVGToken aSVGToken, const rtl::OUString& aContent)
330ddde725dSArmin Le Grand         {
331ddde725dSArmin Le Grand             switch(aSVGToken)
332ddde725dSArmin Le Grand             {
333ddde725dSArmin Le Grand                 case SVGTokenId:
334ddde725dSArmin Le Grand                 {
335ddde725dSArmin Le Grand                     if(aContent.getLength())
336ddde725dSArmin Le Grand                     {
337ddde725dSArmin Le Grand                         setId(&aContent);
338ddde725dSArmin Le Grand                     }
339ddde725dSArmin Le Grand                     break;
340ddde725dSArmin Le Grand                 }
341ddde725dSArmin Le Grand                 case SVGTokenClass:
342ddde725dSArmin Le Grand                 {
343ddde725dSArmin Le Grand                     if(aContent.getLength())
344ddde725dSArmin Le Grand                     {
345ddde725dSArmin Le Grand                         setClass(&aContent);
346ddde725dSArmin Le Grand                     }
347ddde725dSArmin Le Grand                     break;
348ddde725dSArmin Le Grand                 }
349ddde725dSArmin Le Grand                 case SVGTokenXmlSpace:
350ddde725dSArmin Le Grand                 {
351ddde725dSArmin Le Grand                     if(aContent.getLength())
352ddde725dSArmin Le Grand                     {
353ddde725dSArmin Le Grand                         static rtl::OUString aStrDefault(rtl::OUString::createFromAscii("default"));
354ddde725dSArmin Le Grand                         static rtl::OUString aStrPreserve(rtl::OUString::createFromAscii("preserve"));
355ddde725dSArmin Le Grand 
356ddde725dSArmin Le Grand                         if(aContent.match(aStrDefault))
357ddde725dSArmin Le Grand                         {
358ddde725dSArmin Le Grand                             setXmlSpace(XmlSpace_default);
359ddde725dSArmin Le Grand                         }
360ddde725dSArmin Le Grand                         else if(aContent.match(aStrPreserve))
361ddde725dSArmin Le Grand                         {
362ddde725dSArmin Le Grand                             setXmlSpace(XmlSpace_preserve);
363ddde725dSArmin Le Grand                         }
364ddde725dSArmin Le Grand                     }
365ddde725dSArmin Le Grand                     break;
366ddde725dSArmin Le Grand                 }
367a275c134SArmin Le Grand                 case SVGTokenDisplay:
368a275c134SArmin Le Grand                 {
369a275c134SArmin Le Grand                     if(aContent.getLength())
370a275c134SArmin Le Grand                     {
37101e92ad6SArmin Le Grand                         setDisplay(getDisplayFromContent(aContent));
372a275c134SArmin Le Grand                     }
373a275c134SArmin Le Grand                     break;
374a275c134SArmin Le Grand                 }
375e2bf1e9dSArmin Le Grand                 default:
376e2bf1e9dSArmin Le Grand                 {
377e2bf1e9dSArmin Le Grand                     break;
378e2bf1e9dSArmin Le Grand                 }
379ddde725dSArmin Le Grand             }
380ddde725dSArmin Le Grand         }
381ddde725dSArmin Le Grand 
382ddde725dSArmin Le Grand         void SvgNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const
383ddde725dSArmin Le Grand         {
384a275c134SArmin Le Grand             if(Display_none == getDisplay())
385a275c134SArmin Le Grand             {
386a275c134SArmin Le Grand                 return;
387a275c134SArmin Le Grand             }
388a275c134SArmin Le Grand 
389ddde725dSArmin Le Grand             if(!bReferenced)
390ddde725dSArmin Le Grand             {
391ddde725dSArmin Le Grand                 if(SVGTokenDefs == getType() ||
392ddde725dSArmin Le Grand                     SVGTokenSymbol == getType() ||
393ddde725dSArmin Le Grand                     SVGTokenClipPathNode == getType() ||
394ddde725dSArmin Le Grand                     SVGTokenMask == getType() ||
395ddde725dSArmin Le Grand                     SVGTokenMarker == getType() ||
396ddde725dSArmin Le Grand                     SVGTokenPattern == getType())
397ddde725dSArmin Le Grand                 {
398ddde725dSArmin Le Grand                     // do not decompose defs or symbol nodes (these hold only style-like
399ddde725dSArmin Le Grand                     // objects which may be used by referencing them) except when doing
400ddde725dSArmin Le Grand                     // so controlled referenced
401ddde725dSArmin Le Grand 
402ddde725dSArmin Le Grand                     // also do not decompose ClipPaths and Masks. These should be embedded
403ddde725dSArmin Le Grand                     // in a defs node (which gets not decomposed by itself), but you never
404ddde725dSArmin Le Grand                     // know
405ddde725dSArmin Le Grand 
406ddde725dSArmin Le Grand                     // also not directly used are Markers and Patterns, only indirecty used
407ddde725dSArmin Le Grand                     // by reference
408a275c134SArmin Le Grand 
409a275c134SArmin Le Grand                     // #121656# also do not decompose nodes which have display="none" set
410a275c134SArmin Le Grand                     // as property
411ddde725dSArmin Le Grand                     return;
412ddde725dSArmin Le Grand                 }
413ddde725dSArmin Le Grand             }
414ddde725dSArmin Le Grand 
415ddde725dSArmin Le Grand             const SvgNodeVector& rChildren = getChildren();
416ddde725dSArmin Le Grand 
417ddde725dSArmin Le Grand             if(!rChildren.empty())
418ddde725dSArmin Le Grand             {
419ddde725dSArmin Le Grand                 const sal_uInt32 nCount(rChildren.size());
420ddde725dSArmin Le Grand 
421ddde725dSArmin Le Grand                 for(sal_uInt32 a(0); a < nCount; a++)
422ddde725dSArmin Le Grand                 {
423ddde725dSArmin Le Grand                     SvgNode* pCandidate = rChildren[a];
424ddde725dSArmin Le Grand 
425a275c134SArmin Le Grand                     if(pCandidate && Display_none != pCandidate->getDisplay())
426ddde725dSArmin Le Grand                     {
427ddde725dSArmin Le Grand                         drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
428ddde725dSArmin Le Grand 
429ddde725dSArmin Le Grand                         pCandidate->decomposeSvgNode(aNewTarget, bReferenced);
430ddde725dSArmin Le Grand 
431ddde725dSArmin Le Grand                         if(aNewTarget.hasElements())
432ddde725dSArmin Le Grand                         {
433ddde725dSArmin Le Grand                             drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aNewTarget);
434ddde725dSArmin Le Grand                         }
435ddde725dSArmin Le Grand                     }
436ddde725dSArmin Le Grand                     else
437ddde725dSArmin Le Grand                     {
438ddde725dSArmin Le Grand                         OSL_ENSURE(false, "Null-Pointer in child node list (!)");
439ddde725dSArmin Le Grand                     }
440ddde725dSArmin Le Grand                 }
441025b0597SArmin Le Grand 
442025b0597SArmin Le Grand                 if(rTarget.hasElements())
443025b0597SArmin Le Grand                 {
444025b0597SArmin Le Grand                     const SvgStyleAttributes* pStyles = getSvgStyleAttributes();
445025b0597SArmin Le Grand 
446025b0597SArmin Le Grand                     if(pStyles)
447025b0597SArmin Le Grand                     {
448025b0597SArmin Le Grand                         // check if we have Title or Desc
449025b0597SArmin Le Grand                         const rtl::OUString& rTitle = pStyles->getTitle();
450025b0597SArmin Le Grand                         const rtl::OUString& rDesc = pStyles->getDesc();
451025b0597SArmin Le Grand 
452025b0597SArmin Le Grand                         if(rTitle.getLength() || rDesc.getLength())
453025b0597SArmin Le Grand                         {
454025b0597SArmin Le Grand                             // default object name is empty
455025b0597SArmin Le Grand                             rtl::OUString aObjectName;
456025b0597SArmin Le Grand 
457025b0597SArmin Le Grand                             // use path as object name when outmost element
458025b0597SArmin Le Grand                             if(SVGTokenSvg == getType())
459025b0597SArmin Le Grand                             {
460025b0597SArmin Le Grand                                 aObjectName = getDocument().getAbsolutePath();
461172c67b2SArmin Le Grand 
462172c67b2SArmin Le Grand                                 if(aObjectName.getLength())
463172c67b2SArmin Le Grand                                 {
464172c67b2SArmin Le Grand                             		INetURLObject aURL(aObjectName);
465172c67b2SArmin Le Grand 
466172c67b2SArmin Le Grand                                     aObjectName = aURL.getName(
467172c67b2SArmin Le Grand                                         INetURLObject::LAST_SEGMENT,
468172c67b2SArmin Le Grand                                         true,
469172c67b2SArmin Le Grand                                         INetURLObject::DECODE_WITH_CHARSET);
470172c67b2SArmin Le Grand                                 }
471025b0597SArmin Le Grand                             }
472025b0597SArmin Le Grand 
473025b0597SArmin Le Grand                             // pack in ObjectInfoPrimitive2D group
474025b0597SArmin Le Grand                             const drawinglayer::primitive2d::Primitive2DReference xRef(
475025b0597SArmin Le Grand                                 new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
476025b0597SArmin Le Grand                                     rTarget,
477025b0597SArmin Le Grand                                     aObjectName,
478025b0597SArmin Le Grand                                     rTitle,
479025b0597SArmin Le Grand                                     rDesc));
480025b0597SArmin Le Grand 
481025b0597SArmin Le Grand                             rTarget = drawinglayer::primitive2d::Primitive2DSequence(&xRef, 1);
482025b0597SArmin Le Grand                         }
483025b0597SArmin Le Grand                     }
484025b0597SArmin Le Grand                 }
485ddde725dSArmin Le Grand             }
486ddde725dSArmin Le Grand         }
487ddde725dSArmin Le Grand 
488ddde725dSArmin Le Grand         const basegfx::B2DRange* SvgNode::getCurrentViewPort() const
489ddde725dSArmin Le Grand         {
490ddde725dSArmin Le Grand             if(getParent())
491ddde725dSArmin Le Grand             {
492ddde725dSArmin Le Grand                 return getParent()->getCurrentViewPort();
493ddde725dSArmin Le Grand             }
494ddde725dSArmin Le Grand             else
495ddde725dSArmin Le Grand             {
496ddde725dSArmin Le Grand                 return 0;
497ddde725dSArmin Le Grand             }
498ddde725dSArmin Le Grand         }
499ddde725dSArmin Le Grand 
500ddde725dSArmin Le Grand         double SvgNode::getCurrentFontSize() const
501ddde725dSArmin Le Grand         {
502ddde725dSArmin Le Grand             if(getSvgStyleAttributes())
503ddde725dSArmin Le Grand             {
504ddde725dSArmin Le Grand                 return getSvgStyleAttributes()->getFontSize().solve(*this, xcoordinate);
505ddde725dSArmin Le Grand             }
506ddde725dSArmin Le Grand             else if(getParent())
507ddde725dSArmin Le Grand             {
508ddde725dSArmin Le Grand                 return getParent()->getCurrentFontSize();
509ddde725dSArmin Le Grand             }
510ddde725dSArmin Le Grand             else
511ddde725dSArmin Le Grand             {
512ddde725dSArmin Le Grand                 return 0.0;
513ddde725dSArmin Le Grand             }
514ddde725dSArmin Le Grand         }
515ddde725dSArmin Le Grand 
516ddde725dSArmin Le Grand         double SvgNode::getCurrentXHeight() const
517ddde725dSArmin Le Grand         {
518ddde725dSArmin Le Grand             if(getSvgStyleAttributes())
519ddde725dSArmin Le Grand             {
520ddde725dSArmin Le Grand                 // for XHeight, use FontSize currently
521ddde725dSArmin Le Grand                 return getSvgStyleAttributes()->getFontSize().solve(*this, ycoordinate);
522ddde725dSArmin Le Grand             }
523ddde725dSArmin Le Grand             else if(getParent())
524ddde725dSArmin Le Grand             {
525ddde725dSArmin Le Grand                 return getParent()->getCurrentXHeight();
526ddde725dSArmin Le Grand             }
527ddde725dSArmin Le Grand             else
528ddde725dSArmin Le Grand             {
529ddde725dSArmin Le Grand                 return 0.0;
530ddde725dSArmin Le Grand             }
531ddde725dSArmin Le Grand         }
532ddde725dSArmin Le Grand 
533ddde725dSArmin Le Grand         void SvgNode::setId(const rtl::OUString* pfId)
534ddde725dSArmin Le Grand         {
535ddde725dSArmin Le Grand             if(mpId)
536ddde725dSArmin Le Grand             {
537ddde725dSArmin Le Grand                 mrDocument.removeSvgNodeFromMapper(*mpId);
538ddde725dSArmin Le Grand                 delete mpId;
539ddde725dSArmin Le Grand                 mpId = 0;
540ddde725dSArmin Le Grand             }
541ddde725dSArmin Le Grand 
542ddde725dSArmin Le Grand             if(pfId)
543ddde725dSArmin Le Grand             {
544ddde725dSArmin Le Grand                 mpId = new rtl::OUString(*pfId);
545ddde725dSArmin Le Grand                 mrDocument.addSvgNodeToMapper(*mpId, *this);
546ddde725dSArmin Le Grand             }
547ddde725dSArmin Le Grand         }
548ddde725dSArmin Le Grand 
549ddde725dSArmin Le Grand         void SvgNode::setClass(const rtl::OUString* pfClass)
550ddde725dSArmin Le Grand         {
551ddde725dSArmin Le Grand             if(mpClass)
552ddde725dSArmin Le Grand             {
553ddde725dSArmin Le Grand                 mrDocument.removeSvgNodeFromMapper(*mpClass);
554ddde725dSArmin Le Grand                 delete mpClass;
555ddde725dSArmin Le Grand                 mpClass = 0;
556ddde725dSArmin Le Grand             }
557ddde725dSArmin Le Grand 
558ddde725dSArmin Le Grand             if(pfClass)
559ddde725dSArmin Le Grand             {
560ddde725dSArmin Le Grand                 mpClass = new rtl::OUString(*pfClass);
561ddde725dSArmin Le Grand                 mrDocument.addSvgNodeToMapper(*mpClass, *this);
562ddde725dSArmin Le Grand             }
563ddde725dSArmin Le Grand         }
564ddde725dSArmin Le Grand 
565ddde725dSArmin Le Grand         XmlSpace SvgNode::getXmlSpace() const
566ddde725dSArmin Le Grand         {
567ddde725dSArmin Le Grand             if(maXmlSpace != XmlSpace_notset)
568ddde725dSArmin Le Grand             {
569ddde725dSArmin Le Grand                 return maXmlSpace;
570ddde725dSArmin Le Grand             }
571ddde725dSArmin Le Grand 
572ddde725dSArmin Le Grand             if(getParent())
573ddde725dSArmin Le Grand             {
574ddde725dSArmin Le Grand                 return getParent()->getXmlSpace();
575ddde725dSArmin Le Grand             }
576ddde725dSArmin Le Grand 
577ddde725dSArmin Le Grand             // default is XmlSpace_default
578ddde725dSArmin Le Grand             return XmlSpace_default;
579ddde725dSArmin Le Grand         }
580ddde725dSArmin Le Grand 
581ddde725dSArmin Le Grand     } // end of namespace svgreader
582ddde725dSArmin Le Grand } // end of namespace svgio
583ddde725dSArmin Le Grand 
584ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
585ddde725dSArmin Le Grand // eof
586