Commit d5c84b66 authored by Axyonych's avatar Axyonych
Browse files

-Fixed SvgRectangle default fill color.

parent ab3a7c58
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Xml;
using System.ComponentModel;
namespace Svg namespace Svg
{ {
[Serializable()] [Serializable]
public class SvgRectangle : SvgGraphicsElement public class SvgRectangle : SvgGraphicsElement
{ {
private SvgUnit _width;
private SvgUnit _height;
private SvgUnit _x;
private SvgUnit _y;
private SvgUnit _cornerRadiusX; private SvgUnit _cornerRadiusX;
private SvgUnit _cornerRadiusY; private SvgUnit _cornerRadiusY;
private SvgUnit _height;
private GraphicsPath _path; private GraphicsPath _path;
private SvgUnit _width;
private SvgUnit _x;
private SvgUnit _y;
public SvgRectangle()
{
_width = new SvgUnit(0.0f);
_height = new SvgUnit(0.0f);
}
public SvgPoint Location public SvgPoint Location
{ {
get { return new SvgPoint(this.X, this.Y); } get { return new SvgPoint(X, Y); }
}
public override SvgPaintServer Fill
{
get { return (this.Attributes["Fill"] == null) ? new SvgColourServer(Color.Black) : (SvgPaintServer)this.Attributes["Fill"]; }
set { this.Attributes["Fill"] = value; }
} }
[SvgAttribute("x")] [SvgAttribute("x")]
public SvgUnit X public SvgUnit X
{ {
get { return this._x; } get { return _x; }
set { this._x = value; this.IsPathDirty = true; } set
{
_x = value;
IsPathDirty = true;
}
} }
[SvgAttribute("y")] [SvgAttribute("y")]
public SvgUnit Y public SvgUnit Y
{ {
get { return this._y; } get { return _y; }
set { this._y = value; this.IsPathDirty = true; } set
{
_y = value;
IsPathDirty = true;
}
} }
[SvgAttribute("width")] [SvgAttribute("width")]
public SvgUnit Width public SvgUnit Width
{ {
get { return this._width; } get { return _width; }
set { this._width = value; this.IsPathDirty = true; } set
{
_width = value;
IsPathDirty = true;
}
} }
[SvgAttribute("height")] [SvgAttribute("height")]
public SvgUnit Height public SvgUnit Height
{ {
get { return this._height; } get { return _height; }
set { this._height = value; this.IsPathDirty = true; } set
{
_height = value;
IsPathDirty = true;
}
} }
[SvgAttribute("rx")] [SvgAttribute("rx")]
...@@ -58,12 +82,16 @@ namespace Svg ...@@ -58,12 +82,16 @@ namespace Svg
get get
{ {
// If ry has been set and rx hasn't, use it's value // If ry has been set and rx hasn't, use it's value
if (this._cornerRadiusX.Value == 0.0f && this._cornerRadiusY.Value > 0.0f) if (_cornerRadiusX.Value == 0.0f && _cornerRadiusY.Value > 0.0f)
return this._cornerRadiusY; return _cornerRadiusY;
return this._cornerRadiusX; return _cornerRadiusX;
}
set
{
_cornerRadiusX = value;
IsPathDirty = true;
} }
set { this._cornerRadiusX = value; this.IsPathDirty = true; }
} }
[SvgAttribute("ry")] [SvgAttribute("ry")]
...@@ -72,38 +100,39 @@ namespace Svg ...@@ -72,38 +100,39 @@ namespace Svg
get get
{ {
// If rx has been set and ry hasn't, use it's value // If rx has been set and ry hasn't, use it's value
if (this._cornerRadiusY.Value == 0.0f && this._cornerRadiusX.Value > 0.0f) if (_cornerRadiusY.Value == 0.0f && _cornerRadiusX.Value > 0.0f)
return this._cornerRadiusX; return _cornerRadiusX;
return this._cornerRadiusY; return _cornerRadiusY;
} }
set set
{ {
this._cornerRadiusY = value; _cornerRadiusY = value;
this.IsPathDirty = true; IsPathDirty = true;
} }
} }
protected override bool RequiresSmoothRendering protected override bool RequiresSmoothRendering
{ {
get { return (this.CornerRadiusX.Value > 0 || this.CornerRadiusY.Value > 0); } get { return (CornerRadiusX.Value > 0 || CornerRadiusY.Value > 0); }
} }
public override RectangleF Bounds public override RectangleF Bounds
{ {
get { return this.Path.GetBounds(); } get { return Path.GetBounds(); }
} }
public override GraphicsPath Path public override GraphicsPath Path
{ {
get get
{ {
if (this._path == null || this.IsPathDirty) if (_path == null || IsPathDirty)
{ {
// If the corners aren't to be rounded just create a rectangle // If the corners aren't to be rounded just create a rectangle
if (this.CornerRadiusX.Value == 0.0f && this.CornerRadiusY.Value == 0.0f) if (CornerRadiusX.Value == 0.0f && CornerRadiusY.Value == 0.0f)
{ {
RectangleF rectangle = new RectangleF(this.Location.ToDeviceValue(), new SizeF(this.Width.ToDeviceValue(), this.Height.ToDeviceValue())); var rectangle = new RectangleF(Location.ToDeviceValue(),
new SizeF(Width.ToDeviceValue(), Height.ToDeviceValue()));
_path = new GraphicsPath(); _path = new GraphicsPath();
_path.StartFigure(); _path.StartFigure();
...@@ -113,14 +142,14 @@ namespace Svg ...@@ -113,14 +142,14 @@ namespace Svg
else else
{ {
_path = new GraphicsPath(); _path = new GraphicsPath();
RectangleF arcBounds = new RectangleF(); var arcBounds = new RectangleF();
PointF lineStart = new PointF(); var lineStart = new PointF();
PointF lineEnd = new PointF(); var lineEnd = new PointF();
float width = this.Width.ToDeviceValue(); var width = Width.ToDeviceValue();
float height = this.Height.ToDeviceValue(); var height = Height.ToDeviceValue();
float rx = this.CornerRadiusX.ToDeviceValue(); var rx = CornerRadiusX.ToDeviceValue();
float ry = this.CornerRadiusY.ToDeviceValue(); var ry = CornerRadiusY.ToDeviceValue();
PointF location = this.Location.ToDeviceValue(); var location = Location.ToDeviceValue();
// Start // Start
_path.StartFigure(); _path.StartFigure();
...@@ -132,7 +161,7 @@ namespace Svg ...@@ -132,7 +161,7 @@ namespace Svg
_path.AddArc(arcBounds, 180, 90); _path.AddArc(arcBounds, 180, 90);
// Add first line // Add first line
lineStart.X = location.X+rx; lineStart.X = location.X + rx;
lineStart.Y = location.Y; lineStart.Y = location.Y;
lineEnd.X = location.X + width - rx; lineEnd.X = location.X + width - rx;
lineEnd.Y = lineStart.Y; lineEnd.Y = lineStart.Y;
...@@ -174,7 +203,7 @@ namespace Svg ...@@ -174,7 +203,7 @@ namespace Svg
// Close // Close
_path.CloseFigure(); _path.CloseFigure();
} }
this.IsPathDirty = false; IsPathDirty = false;
} }
return _path; return _path;
} }
...@@ -182,14 +211,8 @@ namespace Svg ...@@ -182,14 +211,8 @@ namespace Svg
protected override void Render(Graphics graphics) protected override void Render(Graphics graphics)
{ {
if (this.Width.Value > 0.0f && this.Height.Value > 0.0f) if (Width.Value > 0.0f && Height.Value > 0.0f)
base.Render(graphics); base.Render(graphics);
} }
public SvgRectangle()
{
this._width = new SvgUnit(0.0f);
this._height = new SvgUnit(0.0f);
}
} }
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment