highcharts.js提供了导出的功能,可惜是要服务器连到官方的服务器上才能导出图片,有网友已经给出.net 的解决方案,见如下链接:
http://blog.csdn.net/lanwilliam/article/details/8251272
必须引用SVG和iTextSharp
svg的地址如下:
可惜由于SVG Render Engine 本身是不完善的Lib,而且作者在2008年后,已经停止更新,导致在导出图片时,很容易发生内存的溢出的问题。相关的网友已经给出一些修复的Patch,见如下链接:
http://svg.codeplex.com/SourceControl/list/patches?size=50
在实际应用过程中,主要发现如下的问题,并修复了问题,可以顺利导出图片:
1、SvgLinearGradientServer.cs 在实例化时LinearGradientBrush,由于Start等于End,导致内存溢出。
2、新增enum SvgVisibility解决了Visibility的属性问题。
3、SvgVisualElement方法修改解决了Visibility问题
主要的SVGPatch的见附件。
没地方上传附件,只有放到资源里面:
http://download.csdn.net/detail/fly_miss/5273050
Index: S:/qs/3rdparty/trunk/svg/Exceptions/SvgException.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Exceptions/SvgException.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Exceptions/SvgException.cs(revision 71)
@@ -1,13 +1,10 @@
?using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace Svg
{
public class SvgException : FormatException
{
- public SvgException(string message) : base(message)
+ public SvgException(String message) : base(message)
{
}
}
Index: S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgPolyline.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgPolyline.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgPolyline.cs(revision 71)
@@ -17,15 +17,16 @@
{
get
{
- if (this._path == null || this.IsPathDirty)
+ if (_path == null || IsPathDirty)
{
- this._path = new GraphicsPath();
+ _path = new GraphicsPath();
try
{
- for (int i = 0; i < this._points.Count; i += 2)
+ for (int i = 0; i < _points.Count; i += 2)
{
- PointF endPoint = new PointF(this._points[i].ToDeviceValue(this), this._points[i + 1].ToDeviceValue(this));
+ PointF endPoint = new PointF(_points[i].ToDeviceValue(this),
+ _points[i + 1].ToDeviceValue(this));
// TODO: Remove unrequired first line
if (_path.PointCount == 0)
@@ -42,9 +43,9 @@
{
Trace.TraceError("Error rendering points: " + exc.Message);
}
- this.IsPathDirty = false;
+ IsPathDirty = false;
}
- return this._path;
+ return _path;
}
}
}
Index: S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisualElement.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisualElement.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisualElement.cs(revision 71)
@@ -84,28 +84,28 @@
/// <param name="graphics">The <see cref="SvgRenderer"/> object to render to.</param>
protected override void Render(SvgRenderer renderer)
{
- if (this.Path != null && this.Visible)
+ if (Path != null && Visible == SvgVisibility.Visible)
{
- this.PushTransforms(renderer);
- this.SetClip(renderer);
+ PushTransforms(renderer);
+ SetClip(renderer);
// If this element needs smoothing enabled turn anti-aliasing on
- if (this.RequiresSmoothRendering)
+ if (RequiresSmoothRendering)
{
renderer.SmoothingMode = SmoothingMode.AntiAlias;
}
- this.RenderFill(renderer);
- this.RenderStroke(renderer);
+ RenderFill(renderer);
+ RenderStroke(renderer);
// Reset the smoothing mode
- if (this.RequiresSmoothRendering && renderer.SmoothingMode == SmoothingMode.AntiAlias)
+ if (RequiresSmoothRendering && renderer.SmoothingMode == SmoothingMode.AntiAlias)
{
renderer.SmoothingMode = SmoothingMode.Default;
}
- this.ResetClip(renderer);
- this.PopTransforms(renderer);
+ ResetClip(renderer);
+ PopTransforms(renderer);
}
}
@@ -115,13 +115,13 @@
/// <param name="renderer">The <see cref="SvgRenderer"/> object to render to.</param>
protected internal virtual void RenderFill(SvgRenderer renderer)
{
- if (this.Fill != null)
+ if (Fill != null)
{
- using (Brush brush = this.Fill.GetBrush(this, this.FillOpacity))
+ using (Brush brush = Fill.GetBrush(this, FillOpacity))
{
if (brush != null)
{
- renderer.FillPath(brush, this.Path);
+ renderer.FillPath(brush, Path);
}
}
}
@@ -135,18 +135,23 @@
{
if (this.Stroke != null)
{
- float strokeWidth = this.StrokeWidth.ToDeviceValue(this);
- using (Pen pen = new Pen(this.Stroke.GetBrush(this, this.StrokeOpacity), strokeWidth))
+ float strokeWidth = StrokeWidth.ToDeviceValue(this);
+ Brush brush = Stroke.GetBrush(this, StrokeOpacity);
+ if (brush != null)
{
- if (pen != null)
+ using (Pen pen = new Pen(brush, strokeWidth))
{
- if (this.StrokeDashArray != null)
+ if (pen != null)
{
- /* divide by stroke width - GDI behaviour that I don't quite understand yet.*/
- pen.DashPattern = this.StrokeDashArray.ConvertAll(u => u.Value / ((strokeWidth <= 0) ? 1 : strokeWidth)).ToArray();
+ if (this.StrokeDashArray != null)
+ {
+ /* divide by stroke width - GDI behaviour that I don't quite understand yet.*/
+ List<float> strokes = this.StrokeDashArray.ConvertAll(u => u.Value / ((strokeWidth <= 0) ? 1 : strokeWidth));
+ pen.DashPattern = strokes.ToArray();
+ }
+
+ renderer.DrawPath(pen, this.Path);
}
-
- renderer.DrawPath(pen, this.Path);
}
}
}
Index: S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisualElementStyle.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisualElementStyle.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisualElementStyle.cs(revision 71)
@@ -19,10 +19,10 @@
/// Gets or sets a value to determine whether the element will be rendered.
/// </summary>
[SvgAttribute("visibility")]
- public virtual bool Visible
+ public virtual SvgVisibility Visible
{
- get { return (this.Attributes["Visible"] == null) ? true : (bool)this.Attributes["Visible"]; }
- set { this.Attributes["Visible"] = value; }
+ get { return (Attributes["Visible"] == null) ? SvgVisibility.Visible : (SvgVisibility)Attributes["Visible"]; }
+ set { Attributes["Visible"] = value; }
}
/// <summary>
@@ -31,8 +31,8 @@
[SvgAttribute("fill")]
public virtual SvgPaintServer Fill
{
- get { return (this.Attributes["Fill"] == null) ? new SvgColourServer() : (SvgPaintServer)this.Attributes["Fill"]; }
- set { this.Attributes["Fill"] = value; }
+ get { return (SvgPaintServer)Attributes["Fill"] ?? new SvgColourServer(); }
+ set { Attributes["Fill"] = value; }
}
/// <summary>
@@ -41,8 +41,8 @@
[SvgAttribute("stroke")]
public virtual SvgPaintServer Stroke
{
- get { return (this.Attributes["Stroke"] == null) ? null : (SvgPaintServer)this.Attributes["Stroke"]; }
- set { this.Attributes["Stroke"] = value; }
+ get { return (Attributes["Stroke"] == null) ? null : (SvgPaintServer)Attributes["Stroke"]; }
+ set { Attributes["Stroke"] = value; }
}
[SvgAttribute("fill-rule")]
@@ -68,22 +68,22 @@
[SvgAttribute("stroke-width")]
public virtual SvgUnit StrokeWidth
{
- get { return (this.Attributes["StrokeWidth"] == null) ? new SvgUnit(1.0f) : (SvgUnit)this.Attributes["StrokeWidth"]; }
- set { this.Attributes["StrokeWidth"] = value; }
+ get { return (Attributes["StrokeWidth"] == null) ? new SvgUnit(1.0f) : (SvgUnit)this.Attributes["StrokeWidth"]; }
+ set { Attributes["StrokeWidth"] = value; }
}
[SvgAttribute("stroke-linecap")]
public virtual SvgStrokeLineCap StrokeLineCap
{
- get { return (this.Attributes["StrokeLineCap"] == null) ? SvgStrokeLineCap.Butt : (SvgStrokeLineCap)this.Attributes["StrokeLineCap"]; }
- set { this.Attributes["StrokeLineCap"] = value; }
+ get { return (Attributes["StrokeLineCap"] == null) ? SvgStrokeLineCap.Butt : (SvgStrokeLineCap)Attributes["StrokeLineCap"]; }
+ set { Attributes["StrokeLineCap"] = value; }
}
[SvgAttribute("stroke-linejoin")]
public virtual SvgStrokeLineJoin StrokeLineJoin
{
- get { return (this.Attributes["StrokeLineJoin"] == null) ? SvgStrokeLineJoin.Miter : (SvgStrokeLineJoin)this.Attributes["StrokeLineJoin"]; }
- set { this.Attributes["StrokeLineJoin"] = value; }
+ get { return (Attributes["StrokeLineJoin"] == null) ? SvgStrokeLineJoin.Miter : (SvgStrokeLineJoin)Attributes["StrokeLineJoin"]; }
+ set { Attributes["StrokeLineJoin"] = value; }
}
[SvgAttribute("stroke-miterlimit")]
Index: S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgCircle.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgCircle.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgCircle.cs(revision 71)
@@ -23,7 +23,7 @@
/// <value>The center.</value>
public SvgPoint Center
{
- get { return new SvgPoint(this.CenterX, this.CenterY); }
+ get { return new SvgPoint(CenterX, CenterY); }
}
/// <summary>
Index: S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisibility.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisibility.cs(revision 0)
+++ S:/qs/3rdparty/trunk/svg/Basic Shapes/SvgVisibility.cs(revision 71)
@@ -0,0 +1,14 @@
+?using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Svg
+{
+ public enum SvgVisibility
+ {
+ Visible,
+ Hidden,
+ Inherit
+ }
+}
Index: S:/qs/3rdparty/trunk/svg/Filter Effects/SvgFilterPrimitive.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Filter Effects/SvgFilterPrimitive.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Filter Effects/SvgFilterPrimitive.cs(revision 71)
@@ -18,20 +18,20 @@
[SvgAttribute("in")]
public string Input
{
- get { return this.Attributes.GetAttribute<string>("in"); }
- set { this.Attributes["in"] = value; }
+ get { return Attributes.GetAttribute<string>("in"); }
+ set { Attributes["in"] = value; }
}
[SvgAttribute("result")]
public string Result
{
- get { return this.Attributes.GetAttribute<string>("result"); }
- set { this.Attributes["result"] = value; }
+ get { return Attributes.GetAttribute<string>("result"); }
+ set { Attributes["result"] = value; }
}
protected SvgFilter Owner
{
- get { return (SvgFilter)this.Parent; }
+ get { return (SvgFilter)Parent; }
}
public abstract Bitmap Process();
Index: S:/qs/3rdparty/trunk/svg/Filter Effects/SvgFilter.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Filter Effects/SvgFilter.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Filter Effects/SvgFilter.cs(revision 71)
@@ -23,8 +23,8 @@
[SvgAttribute("width")]
public SvgUnit Width
{
- get { return this.Attributes.GetAttribute<SvgUnit>("width"); }
- set { this.Attributes["width"] = value; }
+ get { return Attributes.GetAttribute<SvgUnit>("width"); }
+ set { Attributes["width"] = value; }
}
/// <summary>
@@ -33,8 +33,8 @@
[SvgAttribute("height")]
public SvgUnit Height
{
- get { return this.Attributes.GetAttribute<SvgUnit>("height"); }
- set { this.Attributes["height"] = value; }
+ get { return Attributes.GetAttribute<SvgUnit>("height"); }
+ set { Attributes["height"] = value; }
}
internal Dictionary<string, Func<SvgVisualElement, SvgRenderer, Bitmap>> Buffer { get; private set; }
@@ -44,7 +44,7 @@
/// </summary>
public SvgFilter()
{
- this.Buffer = new Dictionary<string, Func<SvgVisualElement, SvgRenderer, Bitmap>>();
+ Buffer = new Dictionary<string, Func<SvgVisualElement, SvgRenderer, Bitmap>>();
}
/// <summary>
@@ -72,7 +72,7 @@
this.Buffer.Clear();
this.PopulateDefaults(element, renderer);
- IEnumerable<SvgFilterPrimitive> primitives = this.Children.OfType<SvgFilterPrimitive>();
+ IEnumerable<SvgFilterPrimitive> primitives = Children.OfType<SvgFilterPrimitive>();
if (primitives.Count() > 0)
{
@@ -82,43 +82,43 @@
}
// Render the final filtered image
- renderer.DrawImageUnscaled(this.Buffer.Last().Value(element, renderer), new Point(0, 0));
+ renderer.DrawImageUnscaled(Buffer.Last().Value(element, renderer), new Point(0, 0));
}
}
private void PopulateDefaults(SvgVisualElement element, SvgRenderer renderer)
{
- this.ResetDefaults();
+ ResetDefaults();
- this.Buffer.Add(SvgFilterPrimitive.SourceGraphic, this.CreateSourceGraphic);
- this.Buffer.Add(SvgFilterPrimitive.SourceAlpha, this.CreateSourceAlpha);
+ Buffer.Add(SvgFilterPrimitive.SourceGraphic, CreateSourceGraphic);
+ Buffer.Add(SvgFilterPrimitive.SourceAlpha, CreateSourceAlpha);
}
#region Defaults
private void ResetDefaults()
{
- if (this.sourceGraphic != null)
+ if (sourceGraphic != null)
{
- this.sourceGraphic.Dispose();
- this.sourceGraphic = null;
+ sourceGraphic.Dispose();
+ sourceGraphic = null;
}
- if (this.sourceAlpha != null)
+ if (sourceAlpha != null)
{
- this.sourceAlpha.Dispose();
- this.sourceAlpha = null;
+ sourceAlpha.Dispose();
+ sourceAlpha = null;
}
}
private Bitmap CreateSourceGraphic(SvgVisualElement element, SvgRenderer renderer)
{
- if (this.sourceGraphic == null)
+ if (sourceGraphic == null)
{
RectangleF bounds = element.Path.GetBounds();
- this.sourceGraphic = new Bitmap((int)bounds.Width, (int)bounds.Height);
+ sourceGraphic = new Bitmap((int)bounds.Width, (int)bounds.Height);
- using (var graphics = Graphics.FromImage(this.sourceGraphic))
+ using (Graphics graphics = Graphics.FromImage(sourceGraphic))
{
graphics.Clip = renderer.Clip;
graphics.Transform = renderer.Transform;
@@ -134,7 +134,7 @@
private Bitmap CreateSourceAlpha(SvgVisualElement element, SvgRenderer renderer)
{
- if (this.sourceAlpha == null)
+ if (sourceAlpha == null)
{
Bitmap source = this.Buffer[SvgFilterPrimitive.SourceGraphic](element, renderer);
@@ -145,23 +145,22 @@
new float[] {0, 0, 0, 1, 1}, // alpha
new float[] {0, 0, 0, 0, 0} }; // translations
- var matrix = new ColorMatrix(colorMatrixElements);
+ ColorMatrix matrix = new ColorMatrix(colorMatrixElements);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix);
- this.sourceAlpha = new Bitmap(source.Width, source.Height);
+ sourceAlpha = new Bitmap(source.Width, source.Height);
- using (var graphics = Graphics.FromImage(this.sourceAlpha))
+ using (Graphics graphics = Graphics.FromImage(sourceAlpha))
{
-
graphics.DrawImage(source, new Rectangle(0, 0, source.Width, source.Height), 0, 0,
source.Width, source.Height, GraphicsUnit.Pixel, attributes);
graphics.Save();
}
}
- return this.sourceAlpha;
+ return sourceAlpha;
}
#endregion
}
Index: S:/qs/3rdparty/trunk/svg/SvgElementCollection.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/SvgElementCollection.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/SvgElementCollection.cs(revision 71)
@@ -80,10 +80,10 @@
this._owner.OwnerDocument.IdManager.Add(item);
}
- item._parent = this._owner;
+ item.Parent = this._owner;
}
- item._parent.OnElementAdded(item, this.Count - 1);
+ item.Parent.OnElementAdded(item, this.Count - 1);
this._elements.Add(item);
}
@@ -127,7 +127,7 @@
if (!this._mock)
{
- item._parent = null;
+ item.Parent = null;
if (this._owner.OwnerDocument != null)
{
Index: S:/qs/3rdparty/trunk/svg/DataTypes/SvgUnitCollection.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/DataTypes/SvgUnitCollection.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/DataTypes/SvgUnitCollection.cs(revision 71)
@@ -34,6 +34,8 @@
{
if (value is string)
{
+ if ((value as String) == "none")
+ return null;
string[] points = ((string)value).Trim().Split(new char[] { ',', ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries);
SvgUnitCollection units = new SvgUnitCollection();
Index: S:/qs/3rdparty/trunk/svg/Svg.csproj
===================================================================
--- S:/qs/3rdparty/trunk/svg/Svg.csproj (revision 70)
+++ S:/qs/3rdparty/trunk/svg/Svg.csproj (revision 71)
@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
+ <ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{886A98C5-37C0-4E8B-885E-30C1D2F98B47}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -64,6 +64,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Basic Shapes\SvgVisibility.cs" />
<Compile Include="Basic Shapes\SvgVisualElement.cs" />
<Compile Include="Basic Shapes\SvgCircle.cs" />
<Compile Include="Basic Shapes\SvgEllipse.cs" />
Index: S:/qs/3rdparty/trunk/svg/Document Structure/SvgGroup.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Document Structure/SvgGroup.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Document Structure/SvgGroup.cs(revision 71)
@@ -51,11 +51,11 @@
/// <param name="graphics">The <see cref="Graphics"/> object to render to.</param>
protected override void Render(SvgRenderer renderer)
{
- this.PushTransforms(renderer);
- this.SetClip(renderer);
+ PushTransforms(renderer);
+ SetClip(renderer);
base.RenderChildren(renderer);
- this.ResetClip(renderer);
- this.PopTransforms(renderer);
+ ResetClip(renderer);
+ PopTransforms(renderer);
}
}
}
\ No newline at end of file
Index: S:/qs/3rdparty/trunk/svg/Document Structure/SvgUse.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Document Structure/SvgUse.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Document Structure/SvgUse.cs(revision 71)
@@ -11,14 +11,9 @@
[SvgElement("use")]
public class SvgUse : SvgVisualElement
{
- private Uri _referencedElement;
-
[SvgAttribute("href")]
public virtual Uri ReferencedElement
- {
- get { return this._referencedElement; }
- set { this._referencedElement = value; }
- }
+ { get; set; }
[SvgAttribute("x")]
public virtual SvgUnit X
@@ -83,10 +78,10 @@
SvgVisualElement element = (SvgVisualElement)this.OwnerDocument.IdManager.GetElementById(this.ReferencedElement);
// For the time of rendering we want the referenced element to inherit
// this elements transforms
- SvgElement parent = element._parent;
- element._parent = this;
+ SvgElement parent = element.Parent;
+ element.Parent = this;
element.RenderElement(renderer);
- element._parent = parent;
+ element.Parent = parent;
this.PopTransforms(renderer);
}
Index: S:/qs/3rdparty/trunk/svg/Document Structure/SvgDescription.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Document Structure/SvgDescription.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Document Structure/SvgDescription.cs(revision 71)
@@ -9,17 +9,12 @@
[SvgElement("desc")]
public class SvgDescription : SvgElement
{
- private string _text;
-
public string Text
- {
- get { return this._text; }
- set { this._text = value; }
- }
+ { get; set; }
public override string ToString()
{
- return this.Text;
+ return Text;
}
}
}
\ No newline at end of file
Index: S:/qs/3rdparty/trunk/svg/Document Structure/SvgFragment.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Document Structure/SvgFragment.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Document Structure/SvgFragment.cs(revision 71)
@@ -14,10 +14,6 @@
[SvgElement("svg")]
public class SvgFragment : SvgElement, ISvgViewPort
{
- private SvgUnit _width;
- private SvgUnit _height;
- private SvgViewBox _viewBox;
-
/// <summary>
/// Gets the SVG namespace string.
/// </summary>
@@ -29,10 +25,7 @@
/// <value>The width.</value>
[SvgAttribute("width")]
public SvgUnit Width
- {
- get { return this._width; }
- set { this._width = value; }
- }
+ { get; set; }
/// <summary>
/// Gets or sets the height of the fragment.
@@ -40,10 +33,7 @@
/// <value>The height.</value>
[SvgAttribute("height")]
public SvgUnit Height
- {
- get { return this._height; }
- set { this._height = value; }
- }
+ { get; set; }
/// <summary>
/// Gets or sets the viewport of the element.
@@ -51,10 +41,7 @@
/// <value></value>
[SvgAttribute("viewBox")]
public SvgViewBox ViewBox
- {
- get { return this._viewBox; }
- set { this._viewBox = value; }
- }
+ { get; set; }
/// <summary>
/// Applies the required transforms to <see cref="SvgRenderer"/>.
@@ -64,14 +51,14 @@
{
base.PushTransforms(renderer);
- if (!this.ViewBox.Equals(SvgViewBox.Empty))
+ if (!ViewBox.Equals(SvgViewBox.Empty))
{
- if (this.ViewBox.MinX > 0 || this.ViewBox.MinY > 0)
+ if (ViewBox.MinX > 0 || ViewBox.MinY > 0)
{
- renderer.TranslateTransform(this.ViewBox.MinX, this.ViewBox.MinY, MatrixOrder.Append);
+ renderer.TranslateTransform(ViewBox.MinX, ViewBox.MinY, MatrixOrder.Append);
}
- renderer.ScaleTransform(this.Width.ToDeviceValue() / this.ViewBox.Width, this.Height.ToDeviceValue() / this.ViewBox.Height, MatrixOrder.Append);
+ renderer.ScaleTransform(Width.ToDeviceValue() / ViewBox.Width, Height.ToDeviceValue() / this.ViewBox.Height, MatrixOrder.Append);
}
}
@@ -80,9 +67,9 @@
/// </summary>
public SvgFragment()
{
- this._height = new SvgUnit(SvgUnitType.Percentage, 100.0f);
- this._width = 1000.0f;
- this.ViewBox = SvgViewBox.Empty;
+ Height = new SvgUnit(SvgUnitType.Percentage, 100.0f);
+ Width = 1000.0f;
+ ViewBox = SvgViewBox.Empty;
}
}
}
\ No newline at end of file
Index: S:/qs/3rdparty/trunk/svg/SvgDocument.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/SvgDocument.cs (revision 70)
+++ S:/qs/3rdparty/trunk/svg/SvgDocument.cs (revision 71)
@@ -165,7 +165,7 @@
Trace.TraceInformation("Begin Read");
- using (var reader = new SvgTextReader(stream, entities))
+ using (XmlTextReader reader = new SvgTextReader(stream, entities))
{
var elementStack = new Stack<SvgElement>();
var value = new StringBuilder();
@@ -311,7 +311,12 @@
throw new ArgumentNullException("graphics");
}
- this.Render(SvgRenderer.FromGraphics(graphics));
+ try
+ {
+ Render(SvgRenderer.FromGraphics(graphics));
+ }
+ catch (Exception e)
+ { }
}
/// <summary>
@@ -323,11 +328,11 @@
Trace.TraceInformation("Begin Render");
var size = GetDimensions();
- var bitmap = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height));
+ Bitmap bitmap = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height));
try
{
- using (var renderer = SvgRenderer.FromImage(bitmap))
+ using (SvgRenderer renderer = SvgRenderer.FromImage(bitmap))
{
renderer.TextRenderingHint = TextRenderingHint.AntiAlias;
renderer.TextContrast = 1;
Index: S:/qs/3rdparty/trunk/svg/SvgElementFactory.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/SvgElementFactory.cs (revision 70)
+++ S:/qs/3rdparty/trunk/svg/SvgElementFactory.cs (revision 71)
@@ -164,7 +164,8 @@
try
{
- descriptor.SetValue(element, descriptor.Converter.ConvertFrom(document, CultureInfo.InvariantCulture, attributeValue));
+ object obj = descriptor.Converter.ConvertFrom(document, CultureInfo.InvariantCulture, attributeValue);
+ descriptor.SetValue(element, obj);
}
catch
{
Index: S:/qs/3rdparty/trunk/svg/Painting/SvgLinearGradientServer.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Painting/SvgLinearGradientServer.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Painting/SvgLinearGradientServer.cs(revision 71)
@@ -10,67 +10,38 @@
[SvgElement("linearGradient")]
public sealed class SvgLinearGradientServer : SvgGradientServer
{
- private SvgUnit _x1;
- private SvgUnit _y1;
- private SvgUnit _x2;
- private SvgUnit _y2;
-
[DefaultValue(typeof(SvgUnit), "0"), SvgAttribute("x1")]
public SvgUnit X1
- {
- get { return this._x1; }
- set
- {
- this._x1 = value;
- }
- }
+ { get; set; }
[DefaultValue(typeof(SvgUnit), "0"), SvgAttribute("y1")]
public SvgUnit Y1
- {
- get { return this._y1; }
- set
- {
- this._y1 = value;
- }
- }
+ { get; set; }
[DefaultValue(typeof(SvgUnit), "0"), SvgAttribute("x2")]
public SvgUnit X2
- {
- get { return this._x2; }
- set
- {
- this._x2 = value;
- }
- }
+ { get; set; }
[DefaultValue(typeof(SvgUnit), "0"), SvgAttribute("y2")]
public SvgUnit Y2
- {
- get { return this._y2; }
- set
- {
- this._y2 = value;
- }
- }
+ { get; set; }
public SvgLinearGradientServer()
{
- this._x1 = new SvgUnit(0.0f);
- this._y1 = new SvgUnit(0.0f);
- this._x2 = new SvgUnit(0.0f);
- this._y2 = new SvgUnit(0.0f);
+ X1 = new SvgUnit(0.0f);
+ Y1 = new SvgUnit(0.0f);
+ X2 = new SvgUnit(0.0f);
+ Y2 = new SvgUnit(0.0f);
}
public SvgPoint Start
{
- get { return new SvgPoint(this.X1, this.Y1); }
+ get { return new SvgPoint(X1, Y1); }
}
public SvgPoint End
{
- get { return new SvgPoint(this.X2, this.Y2); }
+ get { return new SvgPoint(X2, Y2); }
}
public override Brush GetBrush(SvgVisualElement owner, float opacity)
Index: S:/qs/3rdparty/trunk/svg/Painting/SvgRadialGradientServer.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Painting/SvgRadialGradientServer.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Painting/SvgRadialGradientServer.cs(revision 71)
@@ -64,7 +64,8 @@
PathGradientBrush brush = new PathGradientBrush(path);
ColorBlend blend = base.GetColourBlend(renderingElement, opacity);
- brush.InterpolationColors = blend;
+ if (blend != null)
+ brush.InterpolationColors = blend;
brush.CenterPoint = new PointF(this.FocalX.ToDeviceValue(renderingElement), this.FocalY.ToDeviceValue(renderingElement, true));
return brush;
Index: S:/qs/3rdparty/trunk/svg/Painting/SvgGradientStop.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Painting/SvgGradientStop.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Painting/SvgGradientStop.cs(revision 71)
@@ -13,8 +13,6 @@
public class SvgGradientStop : SvgElement
{
private SvgUnit _offset;
- private Color _colour;
- private float _opacity;
/// <summary>
/// Gets or sets the offset, i.e. where the stop begins from the beginning, of the gradient stop.
@@ -35,20 +33,14 @@
[SvgAttribute("stop-color")]
[TypeConverter(typeof(SvgColourConverter))]
public Color Colour
- {
- get { return this._colour; }
- set { this._colour = value; }
- }
+ { get; set; }
/// <summary>
/// Gets or sets the opacity of the gradient stop (0-1).
/// </summary>
[SvgAttribute("stop-opacity")]
public float Opacity
- {
- get { return this._opacity; }
- set { this._opacity = value; }
- }
+ { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="SvgGradientStop"/> class.
@@ -56,8 +48,8 @@
public SvgGradientStop()
{
this._offset = new SvgUnit(0.0f);
- this._colour = Color.Transparent;
- this._opacity = 1.0f;
+ Colour = Color.Transparent;
+ Opacity = 1.0f;
}
/// <summary>
@@ -68,8 +60,8 @@
public SvgGradientStop(SvgUnit offset, Color colour)
{
this._offset = offset;
- this._colour = colour;
- this._opacity = 1.0f;
+ Colour = colour;
+ Opacity = 1.0f;
}
}
}
\ No newline at end of file
Index: S:/qs/3rdparty/trunk/svg/Painting/SvgGradientServer.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Painting/SvgGradientServer.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Painting/SvgGradientServer.cs(revision 71)
@@ -12,9 +12,7 @@
/// </summary>
public abstract class SvgGradientServer : SvgPaintServer
{
- private SvgCoordinateUnits _gradientUnits;
private SvgGradientSpreadMethod _spreadMethod = SvgGradientSpreadMethod.Pad;
- private SvgGradientServer _inheritGradient;
private List<SvgGradientStop> _stops;
/// <summary>
@@ -62,7 +60,14 @@
/// </summary>
public List<SvgGradientStop> Stops
{
- get { return this._stops; }
+ get
+ {
+ if (_stops.Count == 0 && InheritGradient != null)
+ {
+ return InheritGradient.Stops;
+ }
+ return _stops;
+ }
}
/// <summary>
@@ -80,16 +85,11 @@
/// </summary>
[SvgAttribute("gradientUnits")]
public SvgCoordinateUnits GradientUnits
- {
- get { return this._gradientUnits; }
- set { this._gradientUnits = value; }
- }
+ { get; set; }
+ [SvgAttribute("href")]
public SvgGradientServer InheritGradient
- {
- get { return this._inheritGradient; }
- set { this._inheritGradient = value; }
- }
+ { get; set; }
/// <summary>
/// Gets a <see cref="ColourBlend"/> representing the <see cref="SvgGradientServer"/>'s gradient stops.
@@ -98,8 +98,12 @@
/// <param name="opacity">The opacity of the colour blend.</param>
protected ColorBlend GetColourBlend(SvgVisualElement owner, float opacity)
{
+ int colourBlends = this.Stops.Count;
+ if (colourBlends <= 0)
+ return null;
+
ColorBlend blend = new ColorBlend();
- int colourBlends = this.Stops.Count;
+
bool insertStart = false;
bool insertEnd = false;
Index: S:/qs/3rdparty/trunk/svg/Painting/SvgPaintServerFactory.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/Painting/SvgPaintServerFactory.cs(revision 70)
+++ S:/qs/3rdparty/trunk/svg/Painting/SvgPaintServerFactory.cs(revision 71)
@@ -34,7 +34,10 @@
}
else // Otherwise try and parse as colour
{
- SvgColourServer server = new SvgColourServer((Color)_colourConverter.ConvertFrom(value.Trim()));
+ String val = value.Trim();
+ SvgPaintServer server = (SvgPaintServer)document.IdManager.GetElementById(val);
+ if (server == null)
+ server = new SvgColourServer((Color)_colourConverter.ConvertFrom(val));
return server;
}
}
Index: S:/qs/3rdparty/trunk/svg/SvgElement.cs
===================================================================
--- S:/qs/3rdparty/trunk/svg/SvgElement.cs (revision 70)
+++ S:/qs/3rdparty/trunk/svg/SvgElement.cs (revision 71)
@@ -14,11 +14,8 @@
/// </summary>
public abstract class SvgElement : ISvgElement, ISvgTransformable, ICloneable
{
- internal SvgElement _parent;
- private string _elementName;
private SvgAttributeCollection _attributes;
private EventHandlerList _eventHandlers;
- private SvgElementCollection _children;
private static readonly object _loadEventKey = new object();
private Matrix _graphicsMatrix;
@@ -26,10 +23,7 @@
/// Gets the name of the element.
/// </summary>
protected internal string ElementName
- {
- get { return this._elementName; }
- internal set { this._elementName = value; }
- }
+ { get; internal set; }
/// <summary>
/// Gets or sets the content of the element.
@@ -61,9 +55,7 @@
/// Gets a collection of all child <see cref="SvgElements"/>.
/// </summary>
public virtual SvgElementCollection Children
- {
- get { return this._children; }
- }
+ { get; private set; }
/// <summary>
/// Gets a value to determine whether the element has children.
@@ -78,9 +70,7 @@
/// </summary>
/// <value>An <see cref="SvgElement"/> if one exists; otherwise null.</value>
public virtual SvgElement Parent
- {
- get { return this._parent; }
- }
+ { get; internal set; }
/// <summary>
/// Gets the owner <see cref="SvgDocument"/>.
@@ -114,12 +104,12 @@
{
get
{
- if (this._attributes == null)
+ if (_attributes == null)
{
- this._attributes = new SvgAttributeCollection(this);
+ _attributes = new SvgAttributeCollection(this);
}
- return this._attributes;
+ return _attributes;
}
}
@@ -132,7 +122,7 @@
_graphicsMatrix = renderer.Transform;
// Return if there are no transforms
- if (this.Transforms == null || this.Transforms.Count == 0)
+ if (Transforms == null || Transforms.Count == 0)
{
return;
}
@@ -182,8 +172,8 @@
[SvgAttribute("transform")]
public SvgTransformCollection Transforms
{
- get { return this.Attributes.GetAttribute<SvgTransformCollection>("Transforms"); }
- set { this.Attributes["Transforms"] = value; }
+ get { return Attributes.GetAttribute<SvgTransformCollection>("Transforms"); }
+ set { Attributes["Transforms"] = value; }
}
/// <summary>
@@ -233,7 +223,7 @@
/// <param name="index">An <see cref="int"/> representing the index where the element was added to the collection.</param>
internal void OnElementAdded(SvgElement child, int index)
{
- this.AddElement(child, index);
+ AddElement(child, index);
}
/// <summary>
@@ -251,7 +241,7 @@
/// <param name="child">The <see cref="SvgElement"/> that has been removed.</param>
internal void OnElementRemoved(SvgElement child)
{
- this.RemoveElement(child);
+ RemoveElement(child);
}
/// <summary>
@@ -259,9 +249,9 @@
/// </summary>
internal SvgElement()
{
- this._children = new SvgElementCollection(this);
+ Children = new SvgElementCollection(this);
this._eventHandlers = new EventHandlerList();
- this._elementName = string.Empty;
+ ElementName = string.Empty;
}
/// <summary>
@@ -324,9 +314,9 @@
/// <param name="renderer">The <see cref="SvgRenderer"/> object to render to.</param>
protected virtual void Render(SvgRenderer renderer)
{
- this.PushTransforms(renderer);
- this.RenderChildren(renderer);
- this.PopTransforms(renderer);
+ PushTransforms(renderer);
+ RenderChildren(renderer);
+ PopTransforms(renderer);
}
/// <summary>
@@ -335,7 +325,7 @@
/// <param name="renderer">The <see cref="SvgRenderer"/> to render the child <see cref="SvgElement"/>s to.</param>
protected virtual void RenderChildren(SvgRenderer renderer)
{
- foreach (SvgElement element in this.Children)
+ foreach (SvgElement element in Children)
{
element.Render(renderer);
}