summaryrefslogtreecommitdiffstats
path: root/svgio/source/svgreader/svgnode.cxx
blob: 0ae4e80363c88b93bc9b0dbe10e15de7f7b8a45e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <svgdocument.hxx>
#include <svgnode.hxx>
#include <svgstyleattributes.hxx>
#include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
#include <o3tl/string_view.hxx>
#include <osl/diagnose.h>
#include <tools/urlobj.hxx>


namespace svgio::svgreader
{
        /// #i125258#
        bool SvgNode::supportsParentStyle() const
        {
            return true;
        }

        const SvgStyleAttributes* SvgNode::getSvgStyleAttributes() const
        {
            return nullptr;
        }

        void SvgNode::addCssStyle(const SvgDocument& rDocument, const OUString& aConcatenated)
        {
            const SvgStyleAttributes* pNew = rDocument.findGlobalCssStyleAttributes(aConcatenated);

            if(pNew)
            {
                // add CssStyle if found
                maCssStyleVector.push_back(pNew);
            }
        }

namespace {
        std::vector< OUString > parseClass(const SvgNode& rNode)
        {
            std::vector< OUString > aParts;

            // check for 'class' references (a list of entries is allowed)
            if(rNode.getClass())
            {
                const OUString& rClassList = *rNode.getClass();
                const sal_Int32 nLen(rClassList.getLength());

                if(nLen)
                {
                    sal_Int32 nPos(0);
                    OUStringBuffer aToken;

                    while(nPos < nLen)
                    {
                        const sal_Int32 nInitPos(nPos);
                        copyToLimiter(rClassList, u' ', nPos, aToken, nLen);
                        skip_char(rClassList, u' ', nPos, nLen);
                        const OUString aPart(o3tl::trim(aToken));
                        aToken.setLength(0);

                        if(aPart.getLength())
                        {
                            aParts.push_back(aPart);
                        }

                        if(nInitPos == nPos)
                        {
                            OSL_ENSURE(false, "Could not interpret on current position (!)");
                            nPos++;
                        }
                    }
                }
            }

            return aParts;
        }
} //namespace

        void SvgNode::fillCssStyleVectorUsingHierarchyAndSelectors(
            const SvgNode& rCurrent,
            std::u16string_view aConcatenated)
        {
            const SvgDocument& rDocument = getDocument();

            if(!rDocument.hasGlobalCssStyleAttributes())
                return;

            const SvgNode* pParent = rCurrent.getParent();
            OUString sCurrentType(SVGTokenToStr(rCurrent.getType()));

            // check for ID (highest priority)
            if(rCurrent.getId())
            {
                const OUString& rId = *rCurrent.getId();

                if(rId.getLength())
                {
                    const OUString aNewConcatenated("#" + rId + aConcatenated);
                    addCssStyle(rDocument, aNewConcatenated);

                    if(!sCurrentType.isEmpty())
                        addCssStyle(rDocument, sCurrentType + aNewConcatenated);

                    if(pParent)
                    {
                        // check for combined selectors at parent first so that higher specificity will be in front
                        fillCssStyleVectorUsingHierarchyAndSelectors(*pParent, aNewConcatenated);
                    }
                }
            }

            std::vector <OUString> aClasses = parseClass(rCurrent);
            for(const auto &aClass : aClasses)
            {
                const OUString aNewConcatenated("." + aClass + aConcatenated);
                addCssStyle(rDocument, aNewConcatenated);

                if(!sCurrentType.isEmpty())
                    addCssStyle(rDocument, sCurrentType + aNewConcatenated);

                if(pParent)
                {
                    // check for combined selectors at parent first so that higher specificity will be in front
                    fillCssStyleVectorUsingHierarchyAndSelectors(*pParent, aNewConcatenated);
                }
            }

            if(!sCurrentType.isEmpty())
            {
                const OUString aNewConcatenated(sCurrentType + aConcatenated);
                addCssStyle(rDocument, aNewConcatenated);
            }

            OUString sType(SVGTokenToStr(getType()));

            // check for class-dependent references to CssStyles
            if(sType.isEmpty())
                return;

            if(pParent)
            {
                // check for combined selectors at parent first so that higher specificity will be in front
                fillCssStyleVectorUsingHierarchyAndSelectors(*pParent, sType);
            }
        }

        void SvgNode::fillCssStyleVectorUsingParent(const SvgNode& rCurrent)
        {
            const SvgDocument& rDocument = getDocument();

            if(!rDocument.hasGlobalCssStyleAttributes())
                return;

            const SvgNode* pParent = rCurrent.getParent();

            if (!pParent)
                return;

            OUString sParentId;
            if (pParent->getId().has_value())
            {
                sParentId = pParent->getId().value();
            }
            std::vector <OUString> aParentClasses = parseClass(*pParent);
            OUString sParentType(SVGTokenToStr(pParent->getType()));

            if(rCurrent.getId())
            {
                const OUString& rId = *rCurrent.getId();

                if(!rId.isEmpty())
                {
                    if (!sParentId.isEmpty())
                    {
                        const OUString aConcatenated("#" + sParentId + ">#" + rId);
                        addCssStyle(rDocument, aConcatenated);
                    }

                    for(const auto &aParentClass : aParentClasses)
                    {
                        const OUString aConcatenated("." + aParentClass + ">#" + rId);
                        addCssStyle(rDocument, aConcatenated);
                    }

                    if (!sParentType.isEmpty())
                    {
                        const OUString aConcatenated(sParentType + ">#" + rId);
                        addCssStyle(rDocument, aConcatenated);
                    }
                }

            }

            std::vector <OUString> aClasses = parseClass(rCurrent);
            for(const auto &aClass : aClasses)
            {

                if (!sParentId.isEmpty())
                {
                    const OUString aConcatenated("#" + sParentId + ">." + aClass);
                    addCssStyle(rDocument, aConcatenated);
                }

                for(const auto &aParentClass : aParentClasses)
                {
                    const OUString aConcatenated("." + aParentClass + ">." + aClass);
                    addCssStyle(rDocument, aConcatenated);
                }

                if (!sParentType.isEmpty())
                {
                    const OUString aConcatenated(sParentType + ">." + aClass);
                    addCssStyle(rDocument, aConcatenated);
                }
            }

            OUString sCurrentType(SVGTokenToStr(getType()));

            if(!sCurrentType.isEmpty())
            {
                if (!sParentId.isEmpty())
                {
                    const OUString aConcatenated("#" + sParentId + ">" + sCurrentType);
                    addCssStyle(rDocument, aConcatenated);
                }

                for(const auto &aParentClass : aParentClasses)
                {
                    const OUString aConcatenated("." + aParentClass + ">" + sCurrentType);
                    addCssStyle(rDocument, aConcatenated);
                }

                if (!sParentType.isEmpty())
                {
                    const OUString aConcatenated(sParentType + ">" + sCurrentType);
                    addCssStyle(rDocument, aConcatenated);
                }
            }
        }

        void SvgNode::fillCssStyleVector(const SvgStyleAttributes& rOriginal)
        {
            OSL_ENSURE(!mbCssStyleVectorBuilt, "OOps, fillCssStyleVector called double ?!?");
            mbCssStyleVectorBuilt = true;

            // #i125293# If we have CssStyles we need to build a linked list of SvgStyleAttributes
            // which represent this for the current object. There are various methods to
            // specify CssStyles which need to be taken into account in a given order:
            // - local CssStyle (independent from global CssStyles at SvgDocument)
            // - 'id' CssStyle
            // - 'class' CssStyle(s)
            // - type-dependent elements (e..g. 'rect' for all rect elements)
            // - Css selector '*'
            // - local attributes (rOriginal)
            // - inherited attributes (up the hierarchy)
            // The first four will be collected in maCssStyleVector for the current element
            // (once, this will not change) and be linked in the needed order using the
            // get/setCssStyleParent at the SvgStyleAttributes which will be used preferred in
            // member evaluation over the existing parent hierarchy

            // check for local CssStyle with highest priority
            if(mpLocalCssStyle)
            {
                // if we have one, use as first entry
                maCssStyleVector.push_back(mpLocalCssStyle.get());
            }

            // tdf#156038 check for child combinator
            fillCssStyleVectorUsingParent(*this);

            // check the hierarchy for concatenated patterns of Selectors
            fillCssStyleVectorUsingHierarchyAndSelectors(*this, std::u16string_view());


            // tdf#99115, Add css selector '*' style only if the element is on top of the hierarchy
            // meaning its parent is <svg>
            const SvgNode* pParent = this->getParent();

            if(pParent && pParent->getType() == SVGToken::Svg)
            {
                // #i125329# find Css selector '*', add as last element if found
                const SvgStyleAttributes* pNew = getDocument().findGlobalCssStyleAttributes("*");

                if(pNew)
                {
                    // add CssStyle for selector '*' if found
                    maCssStyleVector.push_back(pNew);
                }
            }

            //local attributes
            maCssStyleVector.push_back(&rOriginal);
        }

        const SvgStyleAttributes* SvgNode::checkForCssStyle(const SvgStyleAttributes& rOriginal) const
        {
            if(!mbCssStyleVectorBuilt)
            {
                // build needed CssStyleVector for local node
                const_cast< SvgNode* >(this)->fillCssStyleVector(rOriginal);
            }

            if(maCssStyleVector.empty())
            {
                // return given original if no CssStyles found
                return &rOriginal;
            }
            else
            {
                // #i125293# rOriginal will be the last element in the linked list; use no CssStyleParent
                // there (reset it) to ensure that the parent hierarchy will be used when it's base
                // is referenced. This new chaining inserts the CssStyles before the original style,
                // this makes the whole process much safer since the original style when used will
                // be not different to the situation without CssStyles; thus loops which may be caused
                // by trying to use the parent hierarchy of the owner of the style will be avoided
                // already in this mechanism. It's still good to keep the supportsParentStyle
                // from #i125258# in place, though.
                // This chain building using pointers will be done every time when checkForCssStyle
                // is used (not the search, only the chaining). This is needed since the CssStyles
                // themselves will be potentially used multiple times. It is not expensive since it's
                // only changing some pointers.
                // The alternative would be to create the style hierarchy for every element (or even
                // for the element containing the hierarchy) in a vector of pointers and to use that.
                // Resetting the CssStyleParent on rOriginal is probably not needed
                // but simply safer to do.

                // loop over the existing CssStyles and link them. There is a first one, take
                // as current
                SvgStyleAttributes* pCurrent = const_cast< SvgStyleAttributes* >(maCssStyleVector[0]);

                for(size_t a(1); a < maCssStyleVector.size(); a++)
                {
                    SvgStyleAttributes* pNext = const_cast< SvgStyleAttributes* >(maCssStyleVector[a]);

                    pCurrent->setCssStyleParent(pNext);
                    pCurrent = pNext;
                }

                // return 1st CssStyle as style chain start element (only for the
                // local element, still no hierarchy used here)
                return maCssStyleVector[0];
            }
        }

        SvgNode::SvgNode(
            SVGToken aType,
            SvgDocument& rDocument,
            SvgNode* pParent)
        :   maType(aType),
            mrDocument(rDocument),
            mpParent(pParent),
            mpAlternativeParent(nullptr),
            maXmlSpace(XmlSpace::NotSet),
            maDisplay(Display::Inline),
            mbDecomposing(false),
            mbCssStyleVectorBuilt(false)
        {
            if (pParent)
            {
                // tdf#150124 ignore when parent is unknown
                if (pParent->getType() != SVGToken::Unknown)
                    pParent->maChildren.emplace_back(this);
                else
                    mrDocument.addOrphanNode(this);
            }
        }

        SvgNode::~SvgNode()
        {
        }

        void SvgNode::readLocalCssStyle(std::u16string_view aContent)
        {
            if(!mpLocalCssStyle)
            {
                // create LocalCssStyle if needed but not yet added
                mpLocalCssStyle.reset(new SvgStyleAttributes(*this));
            }
            else
            {
                // 2nd fill would be an error
                OSL_ENSURE(false, "Svg node has two local CssStyles, this may lead to problems (!)");
            }

            if(mpLocalCssStyle)
            {
                // parse and set values to it
                mpLocalCssStyle->readCssStyle(aContent);
            }
            else
            {
                OSL_ENSURE(false, "Could not get/create a local CssStyle for a node (!)");
            }
        }

        void SvgNode::parseAttributes(const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs)
        {
            // no longer need to pre-sort moving 'style' entries to the back so that
            // values get overwritten - that was the previous, not complete solution for
            // handling the priorities between svg and Css properties
            const sal_uInt32 nAttributes(xAttribs->getLength());

            for(sal_uInt32 a(0); a < nAttributes; a++)
            {
                const OUString aTokenName(xAttribs->getNameByIndex(a));
                const SVGToken aSVGToken(StrToSVGToken(aTokenName, false));

                parseAttribute(aSVGToken, xAttribs->getValueByIndex(a));
            }
        }

        Display getDisplayFromContent(std::u16string_view aContent)
        {
            if(!aContent.empty())
            {
                if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"inline"))
                {
                    return Display::Inline;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"none"))
                {
                    return Display::None;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"inherit"))
                {
                    return Display::Inherit;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"block"))
                {
                    return Display::Block;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"list-item"))
                {
                    return Display::ListItem;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"run-in"))
                {
                    return Display::RunIn;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"compact"))
                {
                    return Display::Compact;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"marker"))
                {
                    return Display::Marker;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table"))
                {
                    return Display::Table;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"inline-table"))
                {
                    return Display::InlineTable;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table-row-group"))
                {
                    return Display::TableRowGroup;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table-header-group"))
                {
                    return Display::TableHeaderGroup;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table-footer-group"))
                {
                    return Display::TableFooterGroup;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table-row"))
                {
                    return Display::TableRow;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table-column-group"))
                {
                    return Display::TableColumnGroup;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table-column"))
                {
                    return Display::TableColumn;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table-cell"))
                {
                    return Display::TableCell;
                }
                else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"table-caption"))
                {
                    return Display::TableCaption;
                }
            }

            // return the default
            return Display::Inline;
        }

        void SvgNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent)
        {
            switch(aSVGToken)
            {
                case SVGToken::Id:
                {
                    if(!aContent.isEmpty())
                    {
                        setId(aContent);
                    }
                    break;
                }
                case SVGToken::Class:
                {
                    if(!aContent.isEmpty())
                    {
                        setClass(aContent);
                    }
                    break;
                }
                case SVGToken::XmlSpace:
                {
                    if(!aContent.isEmpty())
                    {
                        if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"default"))
                        {
                            setXmlSpace(XmlSpace::Default);
                        }
                        else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"preserve"))
                        {
                            setXmlSpace(XmlSpace::Preserve);
                        }
                    }
                    break;
                }
                case SVGToken::Display:
                {
                    if(!aContent.isEmpty())
                    {
                        setDisplay(getDisplayFromContent(aContent));
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
        }

        void SvgNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const
        {
            if (mbDecomposing) //guard against infinite recurse
                return;

            if(Display::None == getDisplay())
            {
                return;
            }

            if(!bReferenced)
            {
                if(SVGToken::Defs == getType() ||
                    SVGToken::Symbol == getType() ||
                    SVGToken::ClipPathNode == getType() ||
                    SVGToken::Mask == getType() ||
                    SVGToken::Marker == getType() ||
                    SVGToken::Pattern == getType())
                {
                    // do not decompose defs or symbol nodes (these hold only style-like
                    // objects which may be used by referencing them) except when doing
                    // so controlled referenced

                    // also do not decompose ClipPaths and Masks. These should be embedded
                    // in a defs node (which gets not decomposed by itself), but you never
                    // know

                    // also not directly used are Markers and Patterns, only indirectly used
                    // by reference

                    // #i121656# also do not decompose nodes which have display="none" set
                    // as property
                    return;
                }
            }

            const auto& rChildren = getChildren();

            if(rChildren.empty())
                return;

            mbDecomposing = true;

            const sal_uInt32 nCount(rChildren.size());

            for(sal_uInt32 a(0); a < nCount; a++)
            {
                SvgNode* pCandidate = rChildren[a].get();

                if(pCandidate && Display::None != pCandidate->getDisplay())
                {
                    const auto& rGrandChildren = pCandidate->getChildren();
                    const SvgStyleAttributes* pChildStyles = pCandidate->getSvgStyleAttributes();
                    // decompose:
                    // - visible terminal nodes
                    // - all non-terminal nodes (might contain visible nodes down the hierarchy)
                    if( !rGrandChildren.empty() || ( pChildStyles && (Visibility::visible == pChildStyles->getVisibility())) )
                    {
                        drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
                        pCandidate->decomposeSvgNode(aNewTarget, bReferenced);

                        if(!aNewTarget.empty())
                        {
                            rTarget.append(aNewTarget);
                        }
                    }
                }
                else if(!pCandidate)
                {
                    OSL_ENSURE(false, "Null-Pointer in child node list (!)");
                }
            }

            if(!rTarget.empty())
            {
                const SvgStyleAttributes* pStyles = getSvgStyleAttributes();
                if(pStyles)
                {
                    // check if we have Title or Desc
                    const OUString& rTitle = pStyles->getTitle();
                    const OUString& rDesc = pStyles->getDesc();

                    if(!rTitle.isEmpty() || !rDesc.isEmpty())
                    {
                        // default object name is empty
                        OUString aObjectName;

                        // use path as object name when outmost element
                        if (SVGToken::Svg == getType())
                        {
                            aObjectName = getDocument().getAbsolutePath();

                            if(!aObjectName.isEmpty())
                            {
                                INetURLObject aURL(aObjectName);

                                aObjectName = aURL.getName(
                                    INetURLObject::LAST_SEGMENT,
                                    true,
                                    INetURLObject::DecodeMechanism::WithCharset);
                            }
                        }

                        // pack in ObjectInfoPrimitive2D group
                        drawinglayer::primitive2d::Primitive2DReference xRef(
                            new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
                                std::move(rTarget),
                                aObjectName,
                                rTitle,
                                rDesc));

                        rTarget = drawinglayer::primitive2d::Primitive2DContainer { xRef };
                    }
                }
            }
            mbDecomposing = false;
        }

        basegfx::B2DRange SvgNode::getCurrentViewPort() const
        {
            if(getParent())
            {
                return getParent()->getCurrentViewPort();
            }
            else
            {
                return basegfx::B2DRange(); // return empty B2DRange
            }
        }

        double SvgNode::getCurrentFontSizeInherited() const
        {
            if(getParent())
            {
                return getParent()->getCurrentFontSize();
            }
            else
            {
                return 0.0;
            }
        }

        double SvgNode::getCurrentFontSize() const
        {
            if(getSvgStyleAttributes())
                return getSvgStyleAttributes()->getFontSizeNumber().solve(*this, NumberType::xcoordinate);

            return getCurrentFontSizeInherited();
        }

        double SvgNode::getCurrentXHeightInherited() const
        {
            if(getParent())
            {
                return getParent()->getCurrentXHeight();
            }
            else
            {
                return 0.0;
            }
        }

        double SvgNode::getCurrentXHeight() const
        {
            if(getSvgStyleAttributes())
                // for XHeight, use FontSize currently
                return getSvgStyleAttributes()->getFontSizeNumber().solve(*this, NumberType::ycoordinate);

            return getCurrentXHeightInherited();
        }

        void SvgNode::setId(OUString const & rId)
        {
            if(mpId)
            {
                mrDocument.removeSvgNodeFromMapper(*mpId);
                mpId.reset();
            }

            mpId = rId;
            mrDocument.addSvgNodeToMapper(*mpId, *this);
        }

        void SvgNode::setClass(OUString const & rClass)
        {
            if(mpClass)
            {
                mrDocument.removeSvgNodeFromMapper(*mpClass);
                mpClass.reset();
            }

            mpClass = rClass;
            mrDocument.addSvgNodeToMapper(*mpClass, *this);
        }

        XmlSpace SvgNode::getXmlSpace() const
        {
            if(maXmlSpace != XmlSpace::NotSet)
            {
                return maXmlSpace;
            }

            if(getParent())
            {
                return getParent()->getXmlSpace();
            }

            // default is XmlSpace::Default
            return XmlSpace::Default;
        }

        void SvgNode::accept(Visitor & rVisitor)
        {
            rVisitor.visit(*this);
        }
} // end of namespace svgio


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */