LibreOffice Module svgio (master) 1
svgellipsenode.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 <svgellipsenode.hxx>
24
25namespace svgio::svgreader
26{
28 SvgDocument& rDocument,
29 SvgNode* pParent)
30 : SvgNode(SVGToken::Ellipse, rDocument, pParent),
31 maSvgStyleAttributes(*this),
32 maCx(0),
33 maCy(0),
34 maRx(0),
35 maRy(0)
36 {
37 }
38
40 {
41 }
42
44 {
46 }
47
48 void SvgEllipseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
49 {
50 // call parent
51 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
52
53 // read style attributes
54 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
55
56 // parse own
57 switch(aSVGToken)
58 {
59 case SVGToken::Style:
60 {
61 readLocalCssStyle(aContent);
62 break;
63 }
64 case SVGToken::Cx:
65 {
66 SvgNumber aNum;
67
68 if(readSingleNumber(aContent, aNum))
69 {
70 maCx = aNum;
71 }
72 break;
73 }
74 case SVGToken::Cy:
75 {
76 SvgNumber aNum;
77
78 if(readSingleNumber(aContent, aNum))
79 {
80 maCy = aNum;
81 }
82 break;
83 }
84 case SVGToken::Rx:
85 {
86 SvgNumber aNum;
87
88 if(readSingleNumber(aContent, aNum))
89 {
90 if(aNum.isPositive())
91 {
92 maRx = aNum;
93 }
94 }
95 break;
96 }
97 case SVGToken::Ry:
98 {
99 SvgNumber aNum;
100
101 if(readSingleNumber(aContent, aNum))
102 {
103 if(aNum.isPositive())
104 {
105 maRy = aNum;
106 }
107 }
108 break;
109 }
111 {
112 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
113
114 if(!aMatrix.isIdentity())
115 {
116 setTransform(aMatrix);
117 }
118 break;
119 }
120 default:
121 {
122 break;
123 }
124 }
125 }
126
128 {
130
131 if(!(pStyle && getRx().isSet() && getRy().isSet()))
132 return;
133
134 const double fRx(getRx().solve(*this, NumberType::xcoordinate));
135 const double fRy(getRy().solve(*this, NumberType::ycoordinate));
136
137 if(fRx <= 0.0 || fRy <= 0.0)
138 return;
139
140 const basegfx::B2DPolygon aPath(
143 getCx().isSet() ? getCx().solve(*this, NumberType::xcoordinate) : 0.0,
144 getCy().isSet() ? getCy().solve(*this, NumberType::ycoordinate) : 0.0),
145 fRx, fRy));
146
148
149 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, nullptr);
150
151 if(!aNewTarget.empty())
152 {
153 pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
154 }
155 }
156} // end of namespace svgio::svgreader
157
158/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isIdentity() const
virtual const SvgStyleAttributes * getSvgStyleAttributes() const override
const SvgNumber & getRy() const
Ry content, set if found in current context.
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
const SvgNumber & getRx() const
Rx content, set if found in current context.
const SvgNumber & getCx() const
Cx content, set if found in current context.
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const override
SvgStyleAttributes maSvgStyleAttributes
use styles
void setTransform(const std::optional< basegfx::B2DHomMatrix > &pMatrix)
const std::optional< basegfx::B2DHomMatrix > & getTransform() const
transform content, set if found in current context
const SvgNumber & getCy() const
Cy content, set if found in current context.
SvgNumber maCx
variable scan values, dependent of given XAttributeList
SvgEllipseNode(SvgDocument &rDocument, SvgNode *pParent)
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 createPolygonFromEllipse(const B2DPoint &rCenter, double fRadiusX, double fRadiusY, sal_uInt32 nStartQuadrant=0)
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