LibreOffice Module svgio (master) 1
svgcirclenode.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 <svgcirclenode.hxx>
24
25namespace svgio::svgreader
26{
28 SvgDocument& rDocument,
29 SvgNode* pParent)
30 : SvgNode(SVGToken::Circle, rDocument, pParent),
31 maSvgStyleAttributes(*this),
32 maCx(0),
33 maCy(0),
34 maR(0)
35 {
36 }
37
39 {
40 }
41
43 {
45 }
46
47 void SvgCircleNode::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::Cx:
64 {
65 SvgNumber aNum;
66
67 if(readSingleNumber(aContent, aNum))
68 {
69 maCx = aNum;
70 }
71 break;
72 }
73 case SVGToken::Cy:
74 {
75 SvgNumber aNum;
76
77 if(readSingleNumber(aContent, aNum))
78 {
79 maCy = aNum;
80 }
81 break;
82 }
83 case SVGToken::R:
84 {
85 SvgNumber aNum;
86
87 if(readSingleNumber(aContent, aNum))
88 {
89 if(aNum.isPositive())
90 {
91 maR = aNum;
92 }
93 }
94 break;
95 }
97 {
98 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
99
100 if(!aMatrix.isIdentity())
101 {
102 setTransform(aMatrix);
103 }
104 break;
105 }
106 default:
107 {
108 break;
109 }
110 }
111 }
112
114 {
116
117 if(!(pStyle && getR().isSet()))
118 return;
119
120 const double fR(getR().solve(*this));
121
122 if(fR <= 0.0)
123 return;
124
125 const basegfx::B2DPolygon aPath(
128 getCx().isSet() ? getCx().solve(*this, NumberType::xcoordinate) : 0.0,
129 getCy().isSet() ? getCy().solve(*this, NumberType::ycoordinate) : 0.0),
130 fR));
131
133
134 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, nullptr);
135
136 if(!aNewTarget.empty())
137 {
138 pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
139 }
140 }
141} // end of namespace svgio::svgreader
142
143/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isIdentity() const
SvgCircleNode(SvgDocument &rDocument, SvgNode *pParent)
const std::optional< basegfx::B2DHomMatrix > & getTransform() const
transform content, set if found in current context
void setTransform(const std::optional< basegfx::B2DHomMatrix > &pMatrix)
SvgStyleAttributes maSvgStyleAttributes
use styles
SvgNumber maCx
variable scan values, dependent of given XAttributeList
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const override
virtual ~SvgCircleNode() override
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
virtual const SvgStyleAttributes * getSvgStyleAttributes() const override
const SvgNumber & getCx() const
Cx content, set if found in current context.
const SvgNumber & getR() const
R content, set if found in current context.
const SvgNumber & getCy() const
Cy content, set if found in current context.
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)
B2DPolygon createPolygonFromCircle(const B2DPoint &rCenter, double fRadius)
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