Commit 4898799d authored by tebjan's avatar tebjan
Browse files

added save/load routine to W3C tester, fixed a bug in attribute writing

parent 0d2b50e7
...@@ -23,7 +23,8 @@ namespace Svg ...@@ -23,7 +23,8 @@ namespace Svg
public static readonly List<KeyValuePair<string, string>> Namespaces = new List<KeyValuePair<string, string>>() public static readonly List<KeyValuePair<string, string>> Namespaces = new List<KeyValuePair<string, string>>()
{ {
new KeyValuePair<string, string>("", SvgNamespace), new KeyValuePair<string, string>("", SvgNamespace),
new KeyValuePair<string, string>(XLinkPrefix, XLinkNamespace) new KeyValuePair<string, string>(XLinkPrefix, XLinkNamespace),
new KeyValuePair<string, string>("xml", XmlNamespace)
}; };
private string _name; private string _name;
private string _namespace; private string _namespace;
......
...@@ -12,12 +12,16 @@ ...@@ -12,12 +12,16 @@
<AssemblyName>SvgW3CTestRunner</AssemblyName> <AssemblyName>SvgW3CTestRunner</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>Full</DebugType>
<Optimize>false</Optimize> <Optimize>False</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
...@@ -32,6 +36,15 @@ ...@@ -32,6 +36,15 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<BaseAddress>4194304</BaseAddress>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
......
...@@ -32,18 +32,24 @@ ...@@ -32,18 +32,24 @@
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.picLoadSave = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.picSvg = new System.Windows.Forms.PictureBox(); this.picSvg = new System.Windows.Forms.PictureBox();
this.label3 = new System.Windows.Forms.Label();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.picSVGPNG = new System.Windows.Forms.PictureBox();
this.picPng = new System.Windows.Forms.PictureBox(); this.picPng = new System.Windows.Forms.PictureBox();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout(); this.splitContainer1.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picLoadSave)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picSvg)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picSvg)).BeginInit();
this.tableLayoutPanel3.SuspendLayout(); this.tableLayoutPanel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picSVGPNG)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.picPng)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picPng)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
...@@ -92,18 +98,33 @@ ...@@ -92,18 +98,33 @@
// tableLayoutPanel2 // tableLayoutPanel2
// //
this.tableLayoutPanel2.ColumnCount = 1; this.tableLayoutPanel2.ColumnCount = 1;
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.Controls.Add(this.picLoadSave, 0, 3);
this.tableLayoutPanel2.Controls.Add(this.label1, 0, 0); this.tableLayoutPanel2.Controls.Add(this.label1, 0, 0);
this.tableLayoutPanel2.Controls.Add(this.picSvg, 0, 1); this.tableLayoutPanel2.Controls.Add(this.picSvg, 0, 1);
this.tableLayoutPanel2.Controls.Add(this.label3, 0, 2);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel2.Name = "tableLayoutPanel2"; this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 2; this.tableLayoutPanel2.RowCount = 4;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(541, 670); this.tableLayoutPanel2.Size = new System.Drawing.Size(541, 670);
this.tableLayoutPanel2.TabIndex = 0; this.tableLayoutPanel2.TabIndex = 0;
// //
// picLoadSave
//
this.picLoadSave.BackColor = System.Drawing.Color.White;
this.picLoadSave.Dock = System.Windows.Forms.DockStyle.Fill;
this.picLoadSave.Location = new System.Drawing.Point(0, 348);
this.picLoadSave.Margin = new System.Windows.Forms.Padding(0);
this.picLoadSave.Name = "picLoadSave";
this.picLoadSave.Size = new System.Drawing.Size(541, 322);
this.picLoadSave.TabIndex = 2;
this.picLoadSave.TabStop = false;
//
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
...@@ -120,25 +141,49 @@ ...@@ -120,25 +141,49 @@
this.picSvg.Location = new System.Drawing.Point(0, 13); this.picSvg.Location = new System.Drawing.Point(0, 13);
this.picSvg.Margin = new System.Windows.Forms.Padding(0); this.picSvg.Margin = new System.Windows.Forms.Padding(0);
this.picSvg.Name = "picSvg"; this.picSvg.Name = "picSvg";
this.picSvg.Size = new System.Drawing.Size(541, 657); this.picSvg.Size = new System.Drawing.Size(541, 322);
this.picSvg.TabIndex = 1; this.picSvg.TabIndex = 1;
this.picSvg.TabStop = false; this.picSvg.TabStop = false;
// //
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(3, 335);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 13);
this.label3.TabIndex = 3;
this.label3.Text = "Save and Load";
//
// tableLayoutPanel3 // tableLayoutPanel3
// //
this.tableLayoutPanel3.ColumnCount = 1; this.tableLayoutPanel3.ColumnCount = 1;
this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel3.Controls.Add(this.picSVGPNG, 0, 3);
this.tableLayoutPanel3.Controls.Add(this.picPng, 0, 1); this.tableLayoutPanel3.Controls.Add(this.picPng, 0, 1);
this.tableLayoutPanel3.Controls.Add(this.label2, 0, 0); this.tableLayoutPanel3.Controls.Add(this.label2, 0, 0);
this.tableLayoutPanel3.Controls.Add(this.label4, 0, 2);
this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel3.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel3.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel3.Name = "tableLayoutPanel3"; this.tableLayoutPanel3.Name = "tableLayoutPanel3";
this.tableLayoutPanel3.RowCount = 2; this.tableLayoutPanel3.RowCount = 4;
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel3.Size = new System.Drawing.Size(504, 670); this.tableLayoutPanel3.Size = new System.Drawing.Size(504, 670);
this.tableLayoutPanel3.TabIndex = 0; this.tableLayoutPanel3.TabIndex = 0;
// //
// picSVGPNG
//
this.picSVGPNG.BackColor = System.Drawing.Color.White;
this.picSVGPNG.Dock = System.Windows.Forms.DockStyle.Fill;
this.picSVGPNG.Location = new System.Drawing.Point(0, 348);
this.picSVGPNG.Margin = new System.Windows.Forms.Padding(0);
this.picSVGPNG.Name = "picSVGPNG";
this.picSVGPNG.Size = new System.Drawing.Size(504, 322);
this.picSVGPNG.TabIndex = 3;
this.picSVGPNG.TabStop = false;
//
// picPng // picPng
// //
this.picPng.BackColor = System.Drawing.Color.White; this.picPng.BackColor = System.Drawing.Color.White;
...@@ -146,7 +191,7 @@ ...@@ -146,7 +191,7 @@
this.picPng.Location = new System.Drawing.Point(0, 13); this.picPng.Location = new System.Drawing.Point(0, 13);
this.picPng.Margin = new System.Windows.Forms.Padding(0); this.picPng.Margin = new System.Windows.Forms.Padding(0);
this.picPng.Name = "picPng"; this.picPng.Name = "picPng";
this.picPng.Size = new System.Drawing.Size(504, 657); this.picPng.Size = new System.Drawing.Size(504, 322);
this.picPng.TabIndex = 2; this.picPng.TabIndex = 2;
this.picPng.TabStop = false; this.picPng.TabStop = false;
// //
...@@ -159,6 +204,15 @@ ...@@ -159,6 +204,15 @@
this.label2.TabIndex = 0; this.label2.TabIndex = 0;
this.label2.Text = "PNG Render"; this.label2.Text = "PNG Render";
// //
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(3, 335);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(69, 13);
this.label4.TabIndex = 4;
this.label4.Text = "SVG vs PNG";
//
// View // View
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
...@@ -173,14 +227,17 @@ ...@@ -173,14 +227,17 @@
this.splitContainer1.ResumeLayout(false); this.splitContainer1.ResumeLayout(false);
this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout(); this.tableLayoutPanel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.picLoadSave)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picSvg)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picSvg)).EndInit();
this.tableLayoutPanel3.ResumeLayout(false); this.tableLayoutPanel3.ResumeLayout(false);
this.tableLayoutPanel3.PerformLayout(); this.tableLayoutPanel3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.picSVGPNG)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picPng)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picPng)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
private System.Windows.Forms.ListBox lstFiles; private System.Windows.Forms.ListBox lstFiles;
...@@ -192,6 +249,10 @@ ...@@ -192,6 +249,10 @@
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3;
private System.Windows.Forms.PictureBox picPng; private System.Windows.Forms.PictureBox picPng;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox picLoadSave;
private System.Windows.Forms.PictureBox picSVGPNG;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
} }
} }
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using System.Drawing; using System.Drawing;
...@@ -36,6 +37,7 @@ namespace SvgW3CTestRunner ...@@ -36,6 +37,7 @@ namespace SvgW3CTestRunner
{ {
var fileName = lstFiles.SelectedItem.ToString(); var fileName = lstFiles.SelectedItem.ToString();
if (fileName.StartsWith("#")) return; if (fileName.StartsWith("#")) return;
try try
{ {
Debug.Print(fileName); Debug.Print(fileName);
...@@ -50,6 +52,26 @@ namespace SvgW3CTestRunner ...@@ -50,6 +52,26 @@ namespace SvgW3CTestRunner
doc.Draw(img); doc.Draw(img);
picSvg.Image = img; picSvg.Image = img;
} }
//save load
using(var memStream = new MemoryStream())
{
doc.Write(memStream);
memStream.Position = 0;
doc = SvgDocument.Open<SvgDocument>(memStream);
if (fileName.StartsWith("__"))
{
picSvg.Image = doc.Draw();
}
else
{
var img = new Bitmap(480, 360);
doc.Draw(img);
picSvg.Image = img;
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -60,5 +82,90 @@ namespace SvgW3CTestRunner ...@@ -60,5 +82,90 @@ namespace SvgW3CTestRunner
var png = Image.FromFile(_pngBasePath + Path.GetFileNameWithoutExtension(fileName) + ".png"); var png = Image.FromFile(_pngBasePath + Path.GetFileNameWithoutExtension(fileName) + ".png");
picPng.Image = png; picPng.Image = png;
} }
unsafe Bitmap PixelDiff(Bitmap a, Bitmap b)
{
Bitmap output = new Bitmap(a.Width, a.Height, PixelFormat.Format32bppArgb);
Rectangle rect = new Rectangle(Point.Empty, a.Size);
using (var aData = a.LockBitsDisposable(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb))
using (var bData = b.LockBitsDisposable(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb))
using (var outputData = output.LockBitsDisposable(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb))
{
byte* aPtr = (byte*)aData.Scan0;
byte* bPtr = (byte*)bData.Scan0;
byte* outputPtr = (byte*)outputData.Scan0;
int len = aData.Stride * aData.Height;
for (int i = 0; i < len; i++)
{
// For alpha use the average of both images (otherwise pixels with the same alpha won't be visible)
if ((i + 1) % 4 == 0)
*outputPtr = (byte)((*aPtr + *bPtr) / 2);
else
*outputPtr = (byte)~(*aPtr ^ *bPtr);
outputPtr++;
aPtr++;
bPtr++;
}
}
return output;
}
}
static class BitmapExtensions
{
public static DisposableImageData LockBitsDisposable(this Bitmap bitmap, Rectangle rect, ImageLockMode flags, PixelFormat format)
{
return new DisposableImageData(bitmap, rect, flags, format);
}
public class DisposableImageData : IDisposable
{
private readonly Bitmap _bitmap;
private readonly BitmapData _data;
internal DisposableImageData(Bitmap bitmap, Rectangle rect, ImageLockMode flags, PixelFormat format)
{
_bitmap = bitmap;
_data = bitmap.LockBits(rect, flags, format);
}
public void Dispose()
{
_bitmap.UnlockBits(_data);
}
public IntPtr Scan0
{
get { return _data.Scan0; }
}
public int Stride
{
get { return _data.Stride;}
}
public int Width
{
get { return _data.Width;}
}
public int Height
{
get { return _data.Height;}
}
public PixelFormat PixelFormat
{
get { return _data.PixelFormat;}
}
public int Reserved
{
get { return _data.Reserved;}
}
}
} }
} }
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