Commit 9521956d authored by Tebjan Halm's avatar Tebjan Halm Committed by Eric Domke
Browse files

Revert ".Net 3.5 Support and Rendering Improvements (Markers, TSpans, Paths, etc.)"

parent 2261cfdb
......@@ -22,14 +22,12 @@ namespace SVGViewer
private void open_Click(object sender, EventArgs e)
{
//if (openSvgFile.ShowDialog() == DialogResult.OK)
//{
//var path = openSvgFile.FileName;
var path = @"C:\Users\edomke\AppData\Local\Temp\map.svg";
SvgDocument svgDoc = SvgDocument.Open(path);
if (openSvgFile.ShowDialog() == DialogResult.OK)
{
SvgDocument svgDoc = SvgDocument.Open(openSvgFile.FileName);
RenderSvg(svgDoc);
//}
}
}
private string FXML = "";
......
......@@ -7,7 +7,6 @@ namespace Svg.DataTypes
{
public enum SvgFontWeight
{
inherit,
normal,
bold
}
......
......@@ -100,22 +100,6 @@ namespace Svg
{
return new SvgOrient(value);
}
public static implicit operator SvgOrient(string value)
{
float angle;
if (value == "auto")
{
return new SvgOrient();
}
else if (float.TryParse(value, out angle))
{
return new SvgOrient(angle);
}
else
{
throw new ArgumentException("The value '" + value + "' cannot be converted to an SVG value.");
}
}
}
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Globalization;
namespace Svg
namespace Svg.DataTypes
{
public sealed class SvgOrientConverter : TypeConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if (value == null || value.ToString() == string.Empty || value.ToString() == "auto")
if (value == null)
{
return new SvgOrient();
return new SvgUnit(SvgUnitType.User, 0.0f);
}
else if (value is float)
if (!(value is string))
{
return new SvgOrient((float)value);
throw new ArgumentOutOfRangeException("value must be a string.");
}
else if (value is int)
switch (value.ToString())
{
return new SvgOrient((float)value);
case "auto":
return (new SvgOrient());
default:
float fTmp = float.MinValue;
if(!float.TryParse(value.ToString(), out fTmp))
throw new ArgumentOutOfRangeException("value must be a valid float.");
return (new SvgOrient(fTmp));
}
throw new ArgumentException("The value '" + value.ToString() + "' cannot be converted to an SVG value.");
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string) || sourceType == typeof(float) || sourceType == typeof(int))
if (sourceType == typeof(string))
{
return true;
}
......@@ -48,11 +52,6 @@ namespace Svg
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
return ((SvgOrient)value).ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
......
......@@ -45,7 +45,6 @@ namespace Svg
{
if (value is string)
{
if (string.Compare(((string)value).Trim(), "none", StringComparison.InvariantCultureIgnoreCase) == 0) return null;
string[] points = ((string)value).Trim().Split(new char[] { ',', ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries);
SvgUnitCollection units = new SvgUnitCollection();
......
......@@ -5,14 +5,24 @@ using System.ComponentModel;
namespace Svg
{
[DefaultProperty("Text")]
[SvgElement("desc")]
public class SvgDescription : SvgElement
{
private string _text;
public string Text
{
get { return this._text; }
set { this._text = value; }
}
public override string ToString()
{
return this.Content;
return this.Text;
}
public override SvgElement DeepCopy()
{
return DeepCopy<SvgDescription>();
......@@ -21,6 +31,7 @@ namespace Svg
public override SvgElement DeepCopy<T>()
{
var newObj = base.DeepCopy<T>() as SvgDescription;
newObj.Text = this.Text;
return newObj;
}
......
......@@ -8,11 +8,6 @@ namespace Svg
[SvgElement("title")]
public class SvgTitle : SvgElement
{
public override string ToString()
{
return this.Content;
}
public override SvgElement DeepCopy()
{
return DeepCopy<SvgTitle>();
......
......@@ -13,7 +13,7 @@ namespace Svg
{
private Uri _referencedElement;
[SvgAttribute("href", SvgAttributeAttribute.XLinkNamespace)]
[SvgAttribute("xlink:href")]
public virtual Uri ReferencedElement
{
get { return this._referencedElement; }
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Svg
{
public static class Extensions
{
public static IEnumerable<SvgElement> Descendants<T>(this IEnumerable<T> source) where T : SvgElement
{
if (source == null) throw new ArgumentNullException("source");
return GetDescendants<T>(source, false);
}
private static IEnumerable<SvgElement> GetAncestors<T>(IEnumerable<T> source, bool self) where T : SvgElement
{
foreach (var start in source)
{
if (start != null)
{
for (var elem = (self ? start : start.Parent) as SvgElement; elem != null; elem = (elem.Parent as SvgElement))
{
yield return elem;
}
}
}
yield break;
}
private static IEnumerable<SvgElement> GetDescendants<T>(IEnumerable<T> source, bool self) where T : SvgElement
{
var positons = new Stack<int>();
int currPos;
SvgElement currParent;
foreach (var start in source)
{
if (start != null)
{
if (self) yield return start;
positons.Push(0);
currParent = start;
while (positons.Count > 0)
{
currPos = positons.Pop();
if (currPos < currParent.Children.Count)
{
yield return currParent.Children[currPos];
currParent = currParent.Children[currPos];
positons.Push(currPos + 1);
positons.Push(0);
}
else
{
currParent = currParent.Parent;
}
}
}
}
yield break;
}
}
}
......@@ -14,7 +14,7 @@ namespace Svg.FilterEffects
[SvgElement("feGaussianBlur")]
public class SvgGaussianBlur : SvgFilterPrimitive
{
private float _stdDeviation;
private int _stdDeviation;
private BlurType _blurType;
private int[] _kernel;
......@@ -26,13 +26,12 @@ namespace Svg.FilterEffects
{
}
public SvgGaussianBlur(float stdDeviation)
public SvgGaussianBlur(int stdDeviation)
: this(stdDeviation, BlurType.Both)
{
}
public SvgGaussianBlur(float stdDeviation, BlurType blurType)
: base()
public SvgGaussianBlur(int stdDeviation, BlurType blurType) : base()
{
_stdDeviation = stdDeviation;
_blurType = blurType;
......@@ -43,13 +42,13 @@ namespace Svg.FilterEffects
private void PreCalculate()
{
int sz = (int)(_stdDeviation * 2 + 1);
int sz = _stdDeviation * 2 + 1;
_kernel = new int[sz];
_multable = new int[sz, 256];
for (int i = 1; i <= _stdDeviation; i++)
{
int szi = (int)(_stdDeviation - i);
int szj = (int)(_stdDeviation + i);
int szi = _stdDeviation - i;
int szj = _stdDeviation + i;
_kernel[szj] = _kernel[szi] = (szi + 1) * (szi + 1);
_kernelSum += (_kernel[szj] + _kernel[szi]);
for (int j = 0; j < 256; j++)
......@@ -57,11 +56,11 @@ namespace Svg.FilterEffects
_multable[szj, j] = _multable[szi, j] = _kernel[szj] * j;
}
}
_kernel[(int)_stdDeviation] = (int)((_stdDeviation + 1) * (_stdDeviation + 1));
_kernelSum += _kernel[(int)_stdDeviation];
_kernel[_stdDeviation] = (_stdDeviation + 1) * (_stdDeviation + 1);
_kernelSum += _kernel[_stdDeviation];
for (int j = 0; j < 256; j++)
{
_multable[(int)_stdDeviation, j] = _kernel[(int)_stdDeviation] * j;
_multable[_stdDeviation, j] = _kernel[_stdDeviation] * j;
}
}
......@@ -105,7 +104,7 @@ namespace Svg.FilterEffects
for (int i = 0; i < pixelCount; i++)
{
bsum = gsum = rsum = asum = 0;
read = (int)(i - _stdDeviation);
read = i - _stdDeviation;
for (int z = 0; z < _kernel.Length; z++)
{
if (read < start)
......@@ -157,7 +156,7 @@ namespace Svg.FilterEffects
index = 0;
for (int i = 0; i < src.Height; i++)
{
int y = (int)(i - _stdDeviation);
int y = i - _stdDeviation;
start = y * src.Width;
for (int j = 0; j < src.Width; j++)
{
......@@ -224,12 +223,12 @@ namespace Svg.FilterEffects
/// Gets or sets the radius of the blur (only allows for one value - not the two specified in the SVG Spec)
/// </summary>
[SvgAttribute("stdDeviation")]
public float StdDeviation
public int StdDeviation
{
get { return _stdDeviation; }
set
{
if (value <= 0)
if (value < 1)
{
throw new InvalidOperationException("Radius must be greater then 0");
}
......
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="ad4d99d5-165f-493c-9b8f-937d51b9a02a" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment enabled="false" />
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
</TestSettings>
\ No newline at end of file
......@@ -50,18 +50,7 @@ namespace Svg
//so we have to determine the corosponding byte value
alphaValue = (int)(decimal.Parse(values[3]) * 255);
}
Color colorpart;
if (values[0].Trim().EndsWith("%"))
{
colorpart = System.Drawing.Color.FromArgb(alphaValue, (int)(255 * float.Parse(values[0].Trim().TrimEnd('%')) / 100f),
(int)(255 * float.Parse(values[1].Trim().TrimEnd('%')) / 100f),
(int)(255 * float.Parse(values[2].Trim().TrimEnd('%')) / 100f));
}
else
{
colorpart = System.Drawing.Color.FromArgb(alphaValue, int.Parse(values[0]), int.Parse(values[1]), int.Parse(values[2]));
}
Color colorpart = System.Drawing.Color.FromArgb(alphaValue, int.Parse(values[0]), int.Parse(values[1]), int.Parse(values[2]));
return colorpart;
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Svg
{
/// <summary>
/// A wrapper for a paint server which isn't defined currently in the parse process, but
/// should be defined by the time the image needs to render.
/// </summary>
public class SvgDeferredPaintServer : SvgPaintServer
{
private bool _serverLoaded = false;
private SvgPaintServer _concreteServer;
public SvgDocument Document { get; set; }
public string DeferredId { get; set; }
public SvgDeferredPaintServer() {}
public SvgDeferredPaintServer(SvgDocument document, string id)
{
this.Document = document;
this.DeferredId = id;
}
private void EnsureServer()
{
if (!_serverLoaded)
{
_concreteServer = this.Document.IdManager.GetElementById(this.DeferredId) as SvgPaintServer;
_serverLoaded = true;
}
}
public override System.Drawing.Brush GetBrush(SvgVisualElement styleOwner, float opacity)
{
EnsureServer();
return _concreteServer.GetBrush(styleOwner, opacity);
}
public override SvgElement DeepCopy()
{
return DeepCopy<SvgDeferredPaintServer>();
}
public override SvgElement DeepCopy<T>()
{
var newObj = base.DeepCopy<T>() as SvgDeferredPaintServer;
newObj.Document = this.Document;
newObj.DeferredId = this.DeferredId;
return newObj;
}
public override bool Equals(object obj)
{
var other = obj as SvgDeferredPaintServer;
if (other == null)
return false;
return this.Document == other.Document && this.DeferredId == other.DeferredId;
}
public override int GetHashCode()
{
if (this.Document == null || this.DeferredId == null) return 0;
return this.Document.GetHashCode() ^ this.DeferredId.GetHashCode();
}
public override string ToString()
{
return (_serverLoaded ? _serverLoaded.ToString() : string.Format("deferred: {0}", this.DeferredId));
}
public static T TryGet<T>(SvgPaintServer server) where T : SvgPaintServer
{
var deferred = server as SvgDeferredPaintServer;
if (deferred == null)
{
return server as T;
}
else
{
return deferred._concreteServer as T;
}
}
}
}
......@@ -11,7 +11,7 @@ namespace Svg
{
private SvgCoordinateUnits _gradientUnits;
private SvgGradientSpreadMethod _spreadMethod = SvgGradientSpreadMethod.Pad;
private SvgPaintServer _inheritGradient;
private SvgGradientServer _inheritGradient;
private List<SvgGradientStop> _stops;
/// <summary>
......@@ -86,12 +86,13 @@ namespace Svg
/// Gets or sets another gradient fill from which to inherit the stops from.
/// </summary>
[SvgAttribute("href")]
public SvgPaintServer InheritGradient
public SvgGradientServer InheritGradient
{
get { return this._inheritGradient; }
set
{
this._inheritGradient = value;
this.InheritStops();
}
}
......@@ -189,15 +190,18 @@ namespace Svg
return blend;
}
protected void LoadStops()
/// <summary>
// If this gradient contains no stops then it will search any inherited gradients for stops.
/// </summary>
protected virtual void InheritStops()
{
var core = SvgDeferredPaintServer.TryGet<SvgGradientServer>(_inheritGradient);
if (this.Stops.Count == 0 && core != null)
if (this.Stops.Count == 0 && this.InheritGradient != null)
{
_stops.AddRange(core.Stops);
_stops.AddRange(this.InheritGradient.Stops);
}
}
public override SvgElement DeepCopy<T>()
{
var newObj = base.DeepCopy<T>() as SvgGradientServer;
......
......@@ -75,7 +75,6 @@ namespace Svg
public override Brush GetBrush(SvgVisualElement owner, float opacity)
{
LoadStops();
// Need at least 2 colours to do the gradient fill
if (this.Stops.Count < 2)
{
......
......@@ -14,16 +14,8 @@ namespace Svg
[SvgElement("marker")]
public class SvgMarker : SvgVisualElement, ISvgViewPort
{
private SvgMarkerUnits _svgMarkerUnits = SvgMarkerUnits.strokeWidth;
private SvgOrient _svgOrient = new SvgOrient();
[SvgAttribute("markerUnits")]
public virtual SvgMarkerUnits MarkerUnits
{
get { return _svgMarkerUnits; }
set { _svgMarkerUnits = value; }
}
[SvgAttribute("refX")]
public virtual SvgUnit RefX
{
......
......@@ -38,18 +38,7 @@ namespace Svg
{
return (SvgPaintServer)document.IdManager.GetElementById(value);
}
else if (value.StartsWith("#")) // Otherwise try and parse as colour
{
try
{
return new SvgColourServer((Color)_colourConverter.ConvertFrom(value.Trim()));
}
catch
{
return new SvgDeferredPaintServer(document, value);
}
}
else
else // Otherwise try and parse as colour
{
return new SvgColourServer((Color)_colourConverter.ConvertFrom(value.Trim()));
}
......@@ -60,7 +49,7 @@ namespace Svg
if (value is string)
{
var s = (string) value;
if(String.Equals( s.Trim(), "none", StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(s) || s.Trim().Length < 1)
if(String.Equals( s.Trim(), "none", StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(s))
return SvgPaintServer.None;
else
return SvgPaintServerFactory.Create(s, (SvgDocument)context);
......
......@@ -76,7 +76,6 @@ namespace Svg
public override Brush GetBrush(SvgVisualElement renderingElement, float opacity)
{
LoadStops();
float radius = this.Radius.ToDeviceValue(renderingElement);
if (radius <= 0)
......
......@@ -8,14 +8,6 @@ namespace Svg.Pathing
{
public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
{
// Important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
if (graphicsPath.PathPoints.Length > 1 && !graphicsPath.PathPoints[0].Equals(graphicsPath.PathPoints[graphicsPath.PathPoints.Length - 1]))
{
int i = graphicsPath.PathTypes.Length - 1;
while (i >= 0 && graphicsPath.PathTypes[i] > 0) i--;
if (i < 0) i = 0;
graphicsPath.AddLine(graphicsPath.PathPoints[graphicsPath.PathPoints.Length - 1], graphicsPath.PathPoints[i]);
}
graphicsPath.CloseFigure();
}
......
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
......@@ -193,6 +192,7 @@ namespace Svg
newObj.MarkerStart = this.MarkerStart;
newObj.MarkerEnd = this.MarkerEnd;
return newObj;
}
}
}
\ 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