Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
4898799d
Commit
4898799d
authored
Oct 02, 2014
by
tebjan
Browse files
added save/load routine to W3C tester, fixed a bug in attribute writing
parent
0d2b50e7
Changes
5
Show whitespace changes
Inline
Side-by-side
Source/SvgAttributeAttribute.cs
View file @
4898799d
...
...
@@ -23,7 +23,8 @@ namespace Svg
public
static
readonly
List
<
KeyValuePair
<
string
,
string
>>
Namespaces
=
new
List
<
KeyValuePair
<
string
,
string
>>()
{
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
_namespace
;
...
...
Tests/SvgW3CTestRunner/SvgW3CTestRunner.csproj
View file @
4898799d
...
...
@@ -12,12 +12,16 @@
<AssemblyName>
SvgW3CTestRunner
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<AllowUnsafeBlocks>
True
</AllowUnsafeBlocks>
<NoStdLib>
False
</NoStdLib>
<TreatWarningsAsErrors>
False
</TreatWarningsAsErrors>
<IntermediateOutputPath>
obj\$(Configuration)\
</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|x86' "
>
<PlatformTarget>
x86
</PlatformTarget>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
f
ull
</DebugType>
<Optimize>
f
alse
</Optimize>
<DebugType>
F
ull
</DebugType>
<Optimize>
F
alse
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
...
...
@@ -32,6 +36,15 @@
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</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>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
...
...
Tests/SvgW3CTestRunner/View.Designer.cs
View file @
4898799d
...
...
@@ -32,18 +32,24 @@
this
.
tableLayoutPanel1
=
new
System
.
Windows
.
Forms
.
TableLayoutPanel
();
this
.
splitContainer1
=
new
System
.
Windows
.
Forms
.
SplitContainer
();
this
.
tableLayoutPanel2
=
new
System
.
Windows
.
Forms
.
TableLayoutPanel
();
this
.
picLoadSave
=
new
System
.
Windows
.
Forms
.
PictureBox
();
this
.
label1
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
picSvg
=
new
System
.
Windows
.
Forms
.
PictureBox
();
this
.
label3
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
tableLayoutPanel3
=
new
System
.
Windows
.
Forms
.
TableLayoutPanel
();
this
.
picSVGPNG
=
new
System
.
Windows
.
Forms
.
PictureBox
();
this
.
picPng
=
new
System
.
Windows
.
Forms
.
PictureBox
();
this
.
label2
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
label4
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
tableLayoutPanel1
.
SuspendLayout
();
this
.
splitContainer1
.
Panel1
.
SuspendLayout
();
this
.
splitContainer1
.
Panel2
.
SuspendLayout
();
this
.
splitContainer1
.
SuspendLayout
();
this
.
tableLayoutPanel2
.
SuspendLayout
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
picLoadSave
)).
BeginInit
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
picSvg
)).
BeginInit
();
this
.
tableLayoutPanel3
.
SuspendLayout
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
picSVGPNG
)).
BeginInit
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
picPng
)).
BeginInit
();
this
.
SuspendLayout
();
//
...
...
@@ -92,18 +98,33 @@
// tableLayoutPanel2
//
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
.
picSvg
,
0
,
1
);
this
.
tableLayoutPanel2
.
Controls
.
Add
(
this
.
label3
,
0
,
2
);
this
.
tableLayoutPanel2
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
tableLayoutPanel2
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
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
(
System
.
Windows
.
Forms
.
SizeType
.
Percent
,
50F
));
this
.
tableLayoutPanel2
.
Size
=
new
System
.
Drawing
.
Size
(
541
,
670
);
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
//
this
.
label1
.
AutoSize
=
true
;
...
...
@@ -120,25 +141,49 @@
this
.
picSvg
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
13
);
this
.
picSvg
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
0
);
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
.
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
//
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
.
label2
,
0
,
0
);
this
.
tableLayoutPanel3
.
Controls
.
Add
(
this
.
label4
,
0
,
2
);
this
.
tableLayoutPanel3
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Fill
;
this
.
tableLayoutPanel3
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
0
);
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
(
System
.
Windows
.
Forms
.
SizeType
.
Percent
,
50F
));
this
.
tableLayoutPanel3
.
Size
=
new
System
.
Drawing
.
Size
(
504
,
670
);
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
//
this
.
picPng
.
BackColor
=
System
.
Drawing
.
Color
.
White
;
...
...
@@ -146,7 +191,7 @@
this
.
picPng
.
Location
=
new
System
.
Drawing
.
Point
(
0
,
13
);
this
.
picPng
.
Margin
=
new
System
.
Windows
.
Forms
.
Padding
(
0
);
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
.
TabStop
=
false
;
//
...
...
@@ -159,6 +204,15 @@
this
.
label2
.
TabIndex
=
0
;
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
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
13F
);
...
...
@@ -173,14 +227,17 @@
this
.
splitContainer1
.
ResumeLayout
(
false
);
this
.
tableLayoutPanel2
.
ResumeLayout
(
false
);
this
.
tableLayoutPanel2
.
PerformLayout
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
picLoadSave
)).
EndInit
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
picSvg
)).
EndInit
();
this
.
tableLayoutPanel3
.
ResumeLayout
(
false
);
this
.
tableLayoutPanel3
.
PerformLayout
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
picSVGPNG
)).
EndInit
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
picPng
)).
EndInit
();
this
.
ResumeLayout
(
false
);
}
#
endregion
private
System
.
Windows
.
Forms
.
ListBox
lstFiles
;
...
...
@@ -192,6 +249,10 @@
private
System
.
Windows
.
Forms
.
TableLayoutPanel
tableLayoutPanel3
;
private
System
.
Windows
.
Forms
.
PictureBox
picPng
;
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
;
}
}
Tests/SvgW3CTestRunner/View.cs
View file @
4898799d
using
System
;
using
System.Collections.Generic
;
using
System.Drawing.Imaging
;
using
System.Linq
;
using
System.Windows.Forms
;
using
System.Drawing
;
...
...
@@ -36,6 +37,7 @@ namespace SvgW3CTestRunner
{
var
fileName
=
lstFiles
.
SelectedItem
.
ToString
();
if
(
fileName
.
StartsWith
(
"#"
))
return
;
try
{
Debug
.
Print
(
fileName
);
...
...
@@ -50,6 +52,26 @@ namespace SvgW3CTestRunner
doc
.
Draw
(
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
)
{
...
...
@@ -60,5 +82,90 @@ namespace SvgW3CTestRunner
var
png
=
Image
.
FromFile
(
_pngBasePath
+
Path
.
GetFileNameWithoutExtension
(
fileName
)
+
".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
;}
}
}
}
}
Tests/SvgW3CTestRunner/View.resx
View file @
4898799d
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment