Skip to content

Commit e676baa

Browse files
committed
v2.2.2 - Obsoleting some imprecise constructors, providing better overrides
1 parent b83c49b commit e676baa

File tree

10 files changed

+251
-196
lines changed

10 files changed

+251
-196
lines changed

SvgDocTest/DocForm.Designer.cs

Lines changed: 25 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SvgDocTest/DocForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private void Button2_Click(object sender, EventArgs e) {
5050
},
5151

5252
new SvgAElement("https://github.com/managed-commons/SvgNet").AddChildren(
53-
new SvgTextElement("Textastic!", 30, 20) {
53+
new SvgTextElement("Textastic!", "30px", "20px") {
5454
Style = "fill:midnightblue;stroke:navy;stroke-width:1px;font-size:30px;font-family:Calibri"
5555
})
5656
);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright © 2003 RiskCare Ltd. All rights reserved.
3+
Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4+
Copyright © 2015-2019 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5+
6+
Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7+
*/
8+
9+
using SvgNet.SvgTypes;
10+
11+
namespace SvgNet.SvgElements {
12+
public abstract class SvgBaseTextElement : SvgStyledTransformedElement {
13+
public SvgLength DX {
14+
get => (SvgLength)_atts["dx"];
15+
set => _atts["dx"] = value;
16+
}
17+
18+
public SvgLength DY {
19+
get => (SvgLength)_atts["dy"];
20+
set => _atts["dy"] = value;
21+
}
22+
23+
public string LengthAdjust {
24+
get => (string)_atts["lengthAdjust"];
25+
set => _atts["lengthAdjust"] = value;
26+
}
27+
28+
public SvgNumList Rotate {
29+
get => (SvgNumList)_atts["rotate"];
30+
set => _atts["rotate"] = value;
31+
}
32+
33+
public SvgLength X {
34+
get => (SvgLength)_atts["x"];
35+
set => _atts["x"] = value;
36+
}
37+
38+
public SvgLength Y {
39+
get => (SvgLength)_atts["y"];
40+
set => _atts["y"] = value;
41+
}
42+
}
43+
}

SvgNet/Elements/SvgTextElement.cs

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,10 @@
77
*/
88

99
using System;
10+
1011
using SvgNet.SvgTypes;
1112

1213
namespace SvgNet.SvgElements {
13-
public abstract class SvgBaseTextElement : SvgStyledTransformedElement {
14-
public SvgLength DX {
15-
get => (SvgLength)_atts["dx"];
16-
set => _atts["dx"] = value;
17-
}
18-
19-
public SvgLength DY {
20-
get => (SvgLength)_atts["dy"];
21-
set => _atts["dy"] = value;
22-
}
23-
24-
public string LengthAdjust {
25-
get => (string)_atts["lengthAdjust"];
26-
set => _atts["lengthAdjust"] = value;
27-
}
28-
29-
public SvgNumList Rotate {
30-
get => (SvgNumList)_atts["rotate"];
31-
set => _atts["rotate"] = value;
32-
}
33-
34-
public SvgLength X {
35-
get => (SvgLength)_atts["x"];
36-
set => _atts["x"] = value;
37-
}
38-
39-
public SvgLength Y {
40-
get => (SvgLength)_atts["y"];
41-
set => _atts["y"] = value;
42-
}
43-
}
4414

4515
/// <summary>
4616
/// Represents a <c>text</c> element. The SVG text element is unusual in that it expects actual XML text nodes below
@@ -49,6 +19,7 @@ public SvgLength Y {
4919
/// to XML slightly differently.
5020
/// </summary>
5121
public class SvgTextElement : SvgBaseTextElement, IElementWithText {
22+
5223
public SvgTextElement() {
5324
}
5425

@@ -57,7 +28,7 @@ public SvgTextElement(string s) {
5728
AddChild(tn);
5829
}
5930

60-
[Obsolete()]
31+
[Obsolete("Must pass SvgLength, for x and y, which specifies a unit. Use the new constructor override")]
6132
public SvgTextElement(string s, float x, float y) {
6233
var tn = new TextNode(s);
6334
AddChild(tn);
@@ -84,51 +55,4 @@ public SvgLength TextLength {
8455
set => _atts["textLength"] = value;
8556
}
8657
}
87-
88-
/// <summary>
89-
/// Represents a <c>tref</c> element.
90-
/// </summary>
91-
[Obsolete("Don't use it anymore")]
92-
public class SvgTrefElement : SvgBaseTextElement, IElementWithXRef {
93-
public SvgTrefElement() {
94-
}
95-
96-
public SvgTrefElement(string href) => Href = href;
97-
98-
public SvgTrefElement(string href, float x, float y) {
99-
Href = href;
100-
X = x;
101-
Y = y;
102-
}
103-
104-
public string Href {
105-
get => (string)_atts["xlink:href"];
106-
set => _atts["xlink:href"] = value;
107-
}
108-
109-
public override string Name => "tref";
110-
111-
public SvgXRef XRef {
112-
get => new(this);
113-
set => value.WriteToElement(this);
114-
}
115-
}
116-
117-
/// <summary>
118-
/// Represents a <c>tspan</c> element. The tspan element is unique in that it expects actual XML text nodes below
119-
/// it, rather than consisting only of attributes and child elements. <c>SvgTextElement</c> therefore has to be serialized
120-
/// to XML slightly differently.
121-
/// </summary>
122-
public class SvgTspanElement : SvgTextElement {
123-
public SvgTspanElement() {
124-
}
125-
126-
public SvgTspanElement(string s) : base(s) {
127-
}
128-
129-
public SvgTspanElement(string s, float x, float y) : base(s, x, y) {
130-
}
131-
132-
public override string Name => "tspan";
133-
}
134-
}
58+
}

SvgNet/Elements/SvgTrefElement.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright © 2003 RiskCare Ltd. All rights reserved.
3+
Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4+
Copyright © 2015-2019 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5+
6+
Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7+
*/
8+
9+
using System;
10+
11+
using SvgNet.SvgTypes;
12+
13+
namespace SvgNet.SvgElements {
14+
/// <summary>
15+
/// Represents a <c>tref</c> element.
16+
/// </summary>
17+
[Obsolete("Don't use it anymore")]
18+
public class SvgTrefElement : SvgBaseTextElement, IElementWithXRef {
19+
20+
public SvgTrefElement() {
21+
}
22+
23+
public SvgTrefElement(string href) => Href = href;
24+
25+
public SvgTrefElement(string href, float x, float y) {
26+
Href = href;
27+
X = x;
28+
Y = y;
29+
}
30+
31+
public string Href {
32+
get => (string)_atts["xlink:href"];
33+
set => _atts["xlink:href"] = value;
34+
}
35+
36+
public override string Name => "tref";
37+
38+
public SvgXRef XRef {
39+
get => new(this);
40+
set => value.WriteToElement(this);
41+
}
42+
}
43+
}

SvgNet/Elements/SvgTspanElement.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright © 2003 RiskCare Ltd. All rights reserved.
3+
Copyright © 2010 SvgNet & SvgGdi Bridge Project. All rights reserved.
4+
Copyright © 2015-2019 Rafael Teixeira, Mojmír Němeček, Benjamin Peterson and Other Contributors
5+
6+
Original source code licensed with BSD-2-Clause spirit, treat it thus, see accompanied LICENSE for more
7+
*/
8+
9+
using System;
10+
11+
using SvgNet.SvgTypes;
12+
13+
namespace SvgNet.SvgElements {
14+
/// <summary>
15+
/// Represents a <c>tspan</c> element. The tspan element is unique in that it expects actual XML text nodes below
16+
/// it, rather than consisting only of attributes and child elements. <c>SvgTextElement</c> therefore has to be serialized
17+
/// to XML slightly differently.
18+
/// </summary>
19+
public class SvgTspanElement : SvgTextElement {
20+
21+
public SvgTspanElement() {
22+
}
23+
24+
public SvgTspanElement(string s) : base(s) {
25+
}
26+
27+
[Obsolete("Use constructor override that receives SvgLength for x and y")]
28+
public SvgTspanElement(string s, float x, float y) : base(s, x, y) {
29+
}
30+
31+
public SvgTspanElement(string s, SvgLength x, SvgLength y) : base(s, x, y) {
32+
}
33+
34+
public override string Name => "tspan";
35+
}
36+
}

SvgNet/Graphics/SVGGraphics.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Globalization;
1616
using System.IO;
1717
using System.Text;
18+
1819
using SvgNet.SvgElements;
1920
using SvgNet.SvgTypes;
2021

@@ -2021,7 +2022,7 @@ private void DrawText(string s, Font font, Brush brush, RectangleF rect, StringF
20212022
if (s?.Contains('\n') == true)
20222023
throw new SvgGdiNotImplementedException("DrawText multiline text");
20232024

2024-
var txt = new SvgTextElement(s, rect.X, rect.Y) {
2025+
var txt = new SvgTextElement(s, new SvgLength(rect.X, SvgLengthType.SVG_LENGTHTYPE_PX), new SvgLength(rect.Y, SvgLengthType.SVG_LENGTHTYPE_PX)) {
20252026
//GDI takes x and y as the upper left corner; svg takes them as the lower left.
20262027
//We must therefore move the text one line down, but SVG does not understand about lines,
20272028
//so we do as best we can, applying a downward translation before the current GDI translation.

0 commit comments

Comments
 (0)