LibreOffice Module svgio (master) 1
svgpathnode.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <svgpathnode.hxx>
22
23namespace svgio::svgreader
24{
26 SvgDocument& rDocument,
27 SvgNode* pParent)
28 : SvgNode(SVGToken::Path, rDocument, pParent),
29 maSvgStyleAttributes(*this)
30 {
31 }
32
34 {
35 }
36
38 {
40 }
41
42 void SvgPathNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
43 {
44 // call parent
45 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
46
47 // read style attributes
48 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
49
50 // parse own
51 switch(aSVGToken)
52 {
53 case SVGToken::Style:
54 {
55 readLocalCssStyle(aContent);
56 break;
57 }
58 case SVGToken::D:
59 {
61
62 if(basegfx::utils::importFromSvgD(aPath, aContent, false, &maHelpPointIndices))
63 {
64 if(aPath.count())
65 {
66 setPath(aPath);
67 }
68 }
69 break;
70 }
72 {
73 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
74
75 if(!aMatrix.isIdentity())
76 {
77 setTransform(aMatrix);
78 }
79 break;
80 }
82 {
83 SvgNumber aNum;
84
85 if(readSingleNumber(aContent, aNum))
86 {
87 maPathLength = aNum;
88 }
89 break;
90 }
91 default:
92 {
93 break;
94 }
95 }
96 }
97
99 {
100 // fill and/or stroke needed, also a path
102
103 if(pStyle && getPath())
104 {
106
107 pStyle->add_path(*getPath(), aNewTarget, &maHelpPointIndices);
108
109 if(!aNewTarget.empty())
110 {
111 pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
112 }
113 }
114 }
115} // end of namespace svgio::svgreader
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isIdentity() const
sal_uInt32 count() const
const SvgStyleAttributes * checkForCssStyle(const SvgStyleAttributes &rOriginal) const
helper to evtl. link to css style
Definition: svgnode.cxx:335
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent)
Definition: svgnode.cxx:534
void readLocalCssStyle(std::u16string_view aContent)
scan helper to read and interpret a local CssStyle to mpLocalCssStyle
Definition: svgnode.cxx:412
const std::optional< basegfx::B2DPolyPolygon > & getPath() const
path content, set if found in current context
Definition: svgpathnode.hxx:54
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
Definition: svgpathnode.cxx:42
SvgStyleAttributes maSvgStyleAttributes
use styles
Definition: svgpathnode.hxx:35
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const override
Definition: svgpathnode.cxx:98
virtual const SvgStyleAttributes * getSvgStyleAttributes() const override
Definition: svgpathnode.cxx:37
void setTransform(const std::optional< basegfx::B2DHomMatrix > &pMatrix)
Definition: svgpathnode.hxx:59
const std::optional< basegfx::B2DHomMatrix > & getTransform() const
transform content, set if found in current context
Definition: svgpathnode.hxx:58
basegfx::utils::PointIndexSet maHelpPointIndices
Definition: svgpathnode.hxx:41
void setPath(const std::optional< basegfx::B2DPolyPolygon > &pPath)
Definition: svgpathnode.hxx:55
SvgPathNode(SvgDocument &rDocument, SvgNode *pParent)
Definition: svgpathnode.cxx:25
virtual ~SvgPathNode() override
Definition: svgpathnode.cxx:33
void add_postProcess(drawinglayer::primitive2d::Primitive2DContainer &rTarget, drawinglayer::primitive2d::Primitive2DContainer &&rSource, const std::optional< basegfx::B2DHomMatrix > &pTransform) const
void add_path(const basegfx::B2DPolyPolygon &rPath, drawinglayer::primitive2d::Primitive2DContainer &rTarget, const basegfx::utils::PointIndexSet *pHelpPointIndices) const
void parseStyleAttribute(SVGToken aSVGToken, const OUString &rContent)
local attribute scanner
FilterGroup & rTarget
bool importFromSvgD(B2DPolyPolygon &o_rPolyPoly, std::u16string_view rSvgDAttribute, bool bHandleRelativeNextPointCompatible, PointIndexSet *pHelpPointIndexSet)
bool readSingleNumber(std::u16string_view rCandidate, SvgNumber &aNum)
Definition: svgtools.cxx:1076
basegfx::B2DHomMatrix readTransform(std::u16string_view rCandidate, InfoProvider const &rInfoProvider)
Definition: svgtools.cxx:871