bump product version to 7.2.5.1
[LibreOffice.git] / svgio / source / svgreader / svglinenode.cxx
blob1f4ef9bbd60dee3f2829c2f32309f829d557f621
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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,
28 SvgNode* pParent)
29 : SvgNode(SVGToken::Line, rDocument, pParent),
30 maSvgStyleAttributes(*this),
31 maX1(0),
32 maY1(0),
33 maX2(0),
34 maY2(0)
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)
49 // call parent
50 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
52 // read style attributes
53 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent, false);
55 // parse own
56 switch(aSVGToken)
58 case SVGToken::Style:
60 readLocalCssStyle(aContent);
61 break;
63 case SVGToken::X1:
65 SvgNumber aNum;
67 if(readSingleNumber(aContent, aNum))
69 maX1 = aNum;
71 break;
73 case SVGToken::Y1:
75 SvgNumber aNum;
77 if(readSingleNumber(aContent, aNum))
79 maY1 = aNum;
81 break;
83 case SVGToken::X2:
85 SvgNumber aNum;
87 if(readSingleNumber(aContent, aNum))
89 maX2 = aNum;
91 break;
93 case SVGToken::Y2:
95 SvgNumber aNum;
97 if(readSingleNumber(aContent, aNum))
99 maY2 = aNum;
101 break;
103 case SVGToken::Transform:
105 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
107 if(!aMatrix.isIdentity())
109 setTransform(&aMatrix);
111 break;
113 default:
115 break;
120 void SvgLineNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const
122 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
124 if(!pStyle)
125 return;
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;
139 aPath.append(X);
140 aPath.append(Y);
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: */