-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSvgRect.cs
More file actions
85 lines (78 loc) · 2.84 KB
/
Copy pathSvgRect.cs
File metadata and controls
85 lines (78 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing;
namespace ST.Library.Drawing.SvgRender
{
[SvgElement("rect")]
public class SvgRect : SvgElement
{
public override string TargetName {
get { return "rect"; }
}
public override bool AllowElementDraw {
get { return true; }
}
public float X { get; private set; }
public float Y { get; private set; }
public float Width { get; private set; }
public float Height { get; private set; }
public float RX { get; private set; }
public float RY { get; private set; }
protected internal override void OnInitAttribute(string strName, string strValue) {
switch (strName) {
case "x":
this.X = SvgAttributes.GetSize(this, "x");
break;
case "y":
this.Y = SvgAttributes.GetSize(this, "y");
break;
case "width":
this.Width = SvgAttributes.GetSize(this, "width");
break;
case "height":
this.Height = SvgAttributes.GetSize(this, "height");
break;
case "rx":
this.RX = SvgAttributes.GetSize(this, "rx");
break;
case "ry":
this.RY = SvgAttributes.GetSize(this, "ry");
break;
}
}
public override GraphicsPath GetPath() {
return this.GetRoundRectPath(
SvgAttributes.GetSize(this.CurrentParent, "x") + this.X,
SvgAttributes.GetSize(this.CurrentParent, "y") + this.Y,
this.Width,
this.Height,
this.RX,
this.RY);
}
protected internal override void Dispose() { }
private GraphicsPath GetRoundRectPath(float nX, float nY, float nWidth, float nHeight, float nRX, float nRY) {
GraphicsPath gp = new GraphicsPath();
if (nRX == 0 || nRY == 0) {
gp.AddRectangle(new RectangleF(nX, nY, nWidth, nHeight));
} else {
nRX *= 2;
nRY *= 2;
if (nRX > nWidth) {
nRX = nWidth;
}
if (nRY > nHeight) {
nRY = nHeight;
}
gp.AddArc(nX, nY, nRX, nRY, 180, 90);
gp.AddArc(nX + nWidth - nRX, nY, nRX, nRY, 270, 90);
gp.AddArc(nX + nWidth - nRX, nY + nHeight - nRY, nRX, nRY, 0, 90);
gp.AddArc(nX, nY + nHeight - nRY, nRX, nRY, 90, 90);
gp.CloseFigure();
}
return gp;
}
}
}