/src/libreoffice/svgio/source/svgreader/svglinenode.cxx
Line | Count | Source |
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 <svglinenode.hxx> |
21 | | #include <basegfx/polygon/b2dpolygon.hxx> |
22 | | #include <basegfx/polygon/b2dpolypolygon.hxx> |
23 | | |
24 | | namespace svgio::svgreader |
25 | | { |
26 | | SvgLineNode::SvgLineNode( |
27 | | SvgDocument& rDocument, |
28 | | SvgNode* pParent) |
29 | 0 | : SvgNode(SVGToken::Line, rDocument, pParent), |
30 | 0 | maSvgStyleAttributes(*this), |
31 | 0 | maX1(0), |
32 | 0 | maY1(0), |
33 | 0 | maX2(0), |
34 | 0 | maY2(0) |
35 | 0 | { |
36 | 0 | } |
37 | | |
38 | | SvgLineNode::~SvgLineNode() |
39 | 0 | { |
40 | 0 | } |
41 | | |
42 | | const SvgStyleAttributes* SvgLineNode::getSvgStyleAttributes() const |
43 | 0 | { |
44 | 0 | return checkForCssStyle(maSvgStyleAttributes); |
45 | 0 | } |
46 | | |
47 | | void SvgLineNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent) |
48 | 0 | { |
49 | | // call parent |
50 | 0 | SvgNode::parseAttribute(aSVGToken, aContent); |
51 | | |
52 | | // read style attributes |
53 | 0 | maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent); |
54 | | |
55 | | // parse own |
56 | 0 | switch(aSVGToken) |
57 | 0 | { |
58 | 0 | case SVGToken::Style: |
59 | 0 | { |
60 | 0 | readLocalCssStyle(aContent); |
61 | 0 | break; |
62 | 0 | } |
63 | 0 | case SVGToken::X1: |
64 | 0 | { |
65 | 0 | SvgNumber aNum; |
66 | |
|
67 | 0 | if(readSingleNumber(aContent, aNum)) |
68 | 0 | { |
69 | 0 | maX1 = aNum; |
70 | 0 | } |
71 | 0 | break; |
72 | 0 | } |
73 | 0 | case SVGToken::Y1: |
74 | 0 | { |
75 | 0 | SvgNumber aNum; |
76 | |
|
77 | 0 | if(readSingleNumber(aContent, aNum)) |
78 | 0 | { |
79 | 0 | maY1 = aNum; |
80 | 0 | } |
81 | 0 | break; |
82 | 0 | } |
83 | 0 | case SVGToken::X2: |
84 | 0 | { |
85 | 0 | SvgNumber aNum; |
86 | |
|
87 | 0 | if(readSingleNumber(aContent, aNum)) |
88 | 0 | { |
89 | 0 | maX2 = aNum; |
90 | 0 | } |
91 | 0 | break; |
92 | 0 | } |
93 | 0 | case SVGToken::Y2: |
94 | 0 | { |
95 | 0 | SvgNumber aNum; |
96 | |
|
97 | 0 | if(readSingleNumber(aContent, aNum)) |
98 | 0 | { |
99 | 0 | maY2 = aNum; |
100 | 0 | } |
101 | 0 | break; |
102 | 0 | } |
103 | 0 | case SVGToken::Transform: |
104 | 0 | { |
105 | 0 | const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this)); |
106 | |
|
107 | 0 | if(!aMatrix.isIdentity()) |
108 | 0 | { |
109 | 0 | setTransform(aMatrix); |
110 | 0 | } |
111 | 0 | break; |
112 | 0 | } |
113 | 0 | default: |
114 | 0 | { |
115 | 0 | break; |
116 | 0 | } |
117 | 0 | } |
118 | 0 | } |
119 | | |
120 | | void SvgLineNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const |
121 | 0 | { |
122 | 0 | const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); |
123 | |
|
124 | 0 | if(!pStyle) |
125 | 0 | return; |
126 | | |
127 | 0 | const basegfx::B2DPoint X( |
128 | 0 | getX1().isSet() ? getX1().solve(*this, NumberType::xcoordinate) : 0.0, |
129 | 0 | getY1().isSet() ? getY1().solve(*this, NumberType::ycoordinate) : 0.0); |
130 | 0 | const basegfx::B2DPoint Y( |
131 | 0 | getX2().isSet() ? getX2().solve(*this, NumberType::xcoordinate) : 0.0, |
132 | 0 | getY2().isSet() ? getY2().solve(*this, NumberType::ycoordinate) : 0.0); |
133 | | |
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. |
136 | |
|
137 | 0 | basegfx::B2DPolygon aPath; |
138 | |
|
139 | 0 | aPath.append(X); |
140 | 0 | aPath.append(Y); |
141 | |
|
142 | 0 | drawinglayer::primitive2d::Primitive2DContainer aNewTarget; |
143 | |
|
144 | 0 | pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, nullptr); |
145 | |
|
146 | 0 | if(!aNewTarget.empty()) |
147 | 0 | { |
148 | 0 | pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform()); |
149 | 0 | } |
150 | 0 | } |
151 | | } // end of namespace svgio::svgreader |
152 | | |
153 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |