LibreOffice Module svgio (master) 1
svglinenode.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 <svglinenode.hxx>
23
24namespace svgio::svgreader
25{
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)
35 {
36 }
37
39 {
40 }
41
43 {
45 }
46
47 void SvgLineNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
48 {
49 // call parent
50 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
51
52 // read style attributes
53 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
54
55 // parse own
56 switch(aSVGToken)
57 {
58 case SVGToken::Style:
59 {
60 readLocalCssStyle(aContent);
61 break;
62 }
63 case SVGToken::X1:
64 {
65 SvgNumber aNum;
66
67 if(readSingleNumber(aContent, aNum))
68 {
69 maX1 = aNum;
70 }
71 break;
72 }
73 case SVGToken::Y1:
74 {
75 SvgNumber aNum;
76
77 if(readSingleNumber(aContent, aNum))
78 {
79 maY1 = aNum;
80 }
81 break;
82 }
83 case SVGToken::X2:
84 {
85 SvgNumber aNum;
86
87 if(readSingleNumber(aContent, aNum))
88 {
89 maX2 = aNum;
90 }
91 break;
92 }
93 case SVGToken::Y2:
94 {
95 SvgNumber aNum;
96
97 if(readSingleNumber(aContent, aNum))
98 {
99 maY2 = aNum;
100 }
101 break;
102 }
104 {
105 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
106
107 if(!aMatrix.isIdentity())
108 {
109 setTransform(aMatrix);
110 }
111 break;
112 }
113 default:
114 {
115 break;
116 }
117 }
118 }
119
121 {
123
124 if(!pStyle)
125 return;
126
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);
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
138
139 aPath.append(X);
140 aPath.append(Y);
141
143
144 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, nullptr);
145
146 if(!aNewTarget.empty())
147 {
148 pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
149 }
150 }
151} // end of namespace svgio::svgreader
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isIdentity() const
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
SvgNumber maX1
variable scan values, dependent of given XAttributeList
Definition: svglinenode.hxx:35
const SvgNumber & getX2() const
X2 content, set if found in current context.
Definition: svglinenode.hxx:58
const SvgNumber & getY2() const
Y2 content, set if found in current context.
Definition: svglinenode.hxx:61
virtual const SvgStyleAttributes * getSvgStyleAttributes() const override
Definition: svglinenode.cxx:42
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const override
const std::optional< basegfx::B2DHomMatrix > & getTransform() const
transform content, set if found in current context
Definition: svglinenode.hxx:64
SvgLineNode(SvgDocument &rDocument, SvgNode *pParent)
Definition: svglinenode.cxx:26
void setTransform(const std::optional< basegfx::B2DHomMatrix > &pMatrix)
Definition: svglinenode.hxx:65
SvgStyleAttributes maSvgStyleAttributes
use styles
Definition: svglinenode.hxx:32
virtual ~SvgLineNode() override
Definition: svglinenode.cxx:38
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
Definition: svglinenode.cxx:47
const SvgNumber & getY1() const
Y1 content, set if found in current context.
Definition: svglinenode.hxx:55
const SvgNumber & getX1() const
X1 content, set if found in current context.
Definition: svglinenode.hxx:52
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
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 solve(Matrix &matrix, int rows, int cols, Vector &result, BaseType minPivot)
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
#define Y