1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svglinenode.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolypolygon.hxx>
24 namespace svgio::svgreader
26 SvgLineNode::SvgLineNode(
27 SvgDocument
& rDocument
,
29 : SvgNode(SVGToken::Line
, rDocument
, pParent
),
30 maSvgStyleAttributes(*this),
38 SvgLineNode::~SvgLineNode()
42 const SvgStyleAttributes
* SvgLineNode::getSvgStyleAttributes() const
44 return checkForCssStyle("line", maSvgStyleAttributes
);
47 void SvgLineNode::parseAttribute(const OUString
& rTokenName
, SVGToken aSVGToken
, const OUString
& aContent
)
50 SvgNode::parseAttribute(rTokenName
, aSVGToken
, aContent
);
52 // read style attributes
53 maSvgStyleAttributes
.parseStyleAttribute(aSVGToken
, aContent
, false);
60 readLocalCssStyle(aContent
);
67 if(readSingleNumber(aContent
, aNum
))
77 if(readSingleNumber(aContent
, aNum
))
87 if(readSingleNumber(aContent
, aNum
))
97 if(readSingleNumber(aContent
, aNum
))
103 case SVGToken::Transform
:
105 const basegfx::B2DHomMatrix
aMatrix(readTransform(aContent
, *this));
107 if(!aMatrix
.isIdentity())
109 setTransform(&aMatrix
);
120 void SvgLineNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer
& rTarget
, bool /*bReferenced*/) const
122 const SvgStyleAttributes
* pStyle
= getSvgStyleAttributes();
127 const basegfx::B2DPoint
X(
128 getX1().isSet() ? getX1().solve(*this, NumberType::xcoordinate
) : 0.0,
129 getY1().isSet() ? getY1().solve(*this, NumberType::ycoordinate
) : 0.0);
130 const basegfx::B2DPoint
Y(
131 getX2().isSet() ? getX2().solve(*this, NumberType::xcoordinate
) : 0.0,
132 getY2().isSet() ? getY2().solve(*this, NumberType::ycoordinate
) : 0.0);
134 // X and Y may be equal, do not drop them. Markers or linecaps 'round' and 'square'
135 // need to be drawn for zero-length lines too.
137 basegfx::B2DPolygon aPath
;
142 drawinglayer::primitive2d::Primitive2DContainer aNewTarget
;
144 pStyle
->add_path(basegfx::B2DPolyPolygon(aPath
), aNewTarget
, nullptr);
146 if(!aNewTarget
.empty())
148 pStyle
->add_postProcess(rTarget
, aNewTarget
, getTransform());
151 } // end of namespace svgio::svgreader
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */