Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
32319fd1
Commit
32319fd1
authored
9 years ago
by
tebjan
Browse files
Options
Download
Email Patches
Plain Diff
normalized line endings
parent
2a58f88d
master
netstandard2
nuget2.4.2
nuget2.4.1
nuget2.4
nuget2.3
nuget2.2.2
nuget2.2.1
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tests/SvgW3CTestRunner/View.Designer.cs
+256
-259
Tests/SvgW3CTestRunner/View.Designer.cs
Tests/SvgW3CTestRunner/View.cs
+242
-242
Tests/SvgW3CTestRunner/View.cs
with
498 additions
and
501 deletions
+498
-501
Tests/SvgW3CTestRunner/View.Designer.cs
+
256
-
259
View file @
32319fd1
This diff is collapsed.
Click to expand it.
Tests/SvgW3CTestRunner/View.cs
+
242
-
242
View file @
32319fd1
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Drawing.Imaging
;
using
System.Drawing.Imaging
;
using
System.Linq
;
using
System.Linq
;
using
System.Windows.Forms
;
using
System.Windows.Forms
;
using
System.Drawing
;
using
System.Drawing
;
using
System.IO
;
using
System.IO
;
using
Svg
;
using
Svg
;
using
System.Diagnostics
;
using
System.Diagnostics
;
namespace
SvgW3CTestRunner
namespace
SvgW3CTestRunner
{
{
public
partial
class
View
:
Form
public
partial
class
View
:
Form
{
{
//DIRECTORY SEPARATOR: The value of this field is a slash ("/") on UNIX and on Mac OSX, and a backslash ("\") on the Windows operating systems.
//DIRECTORY SEPARATOR: The value of this field is a slash ("/") on UNIX and on Mac OSX, and a backslash ("\") on the Windows operating systems.
static
private
string
sprt
=
Path
.
DirectorySeparatorChar
.
ToString
();
static
private
string
sprt
=
Path
.
DirectorySeparatorChar
.
ToString
();
//Data folders
//Data folders
private
string
_svgBasePath
=
@".."
+
sprt
+
".."
+
sprt
+
".."
+
sprt
+
"W3CTestSuite"
+
sprt
+
"svg"
+
sprt
;
private
string
_svgBasePath
=
@".."
+
sprt
+
".."
+
sprt
+
".."
+
sprt
+
"W3CTestSuite"
+
sprt
+
"svg"
+
sprt
;
private
string
_pngBasePath
=
@".."
+
sprt
+
".."
+
sprt
+
".."
+
sprt
+
"W3CTestSuite"
+
sprt
+
"png"
+
sprt
;
private
string
_pngBasePath
=
@".."
+
sprt
+
".."
+
sprt
+
".."
+
sprt
+
"W3CTestSuite"
+
sprt
+
"png"
+
sprt
;
public
View
()
public
View
()
{
{
InitializeComponent
();
InitializeComponent
();
// ignore tests pertaining to javascript or xml reading
// ignore tests pertaining to javascript or xml reading
var
passes
=
File
.
ReadAllLines
(
_svgBasePath
+
@".."
+
sprt
+
"PassingTests.txt"
).
ToDictionary
((
f
)
=>
f
,
(
f
)
=>
true
);
var
passes
=
File
.
ReadAllLines
(
_svgBasePath
+
@".."
+
sprt
+
"PassingTests.txt"
).
ToDictionary
((
f
)
=>
f
,
(
f
)
=>
true
);
var
files
=
(
from
f
in
var
files
=
(
from
f
in
(
from
g
in
Directory
.
GetFiles
(
_svgBasePath
)
(
from
g
in
Directory
.
GetFiles
(
_svgBasePath
)
select
Path
.
GetFileName
(
g
))
select
Path
.
GetFileName
(
g
))
where
!
f
.
StartsWith
(
"animate-"
)
&&
!
f
.
StartsWith
(
"conform-viewer"
)
&&
where
!
f
.
StartsWith
(
"animate-"
)
&&
!
f
.
StartsWith
(
"conform-viewer"
)
&&
!
f
.
Contains
(
"-dom-"
)
&&
!
f
.
StartsWith
(
"linking-"
)
&&
!
f
.
StartsWith
(
"interact-"
)
&&
!
f
.
Contains
(
"-dom-"
)
&&
!
f
.
StartsWith
(
"linking-"
)
&&
!
f
.
StartsWith
(
"interact-"
)
&&
!
f
.
StartsWith
(
"script-"
)
!
f
.
StartsWith
(
"script-"
)
orderby
f
orderby
f
select
(
object
)
f
);
select
(
object
)
f
);
files
=
files
.
Where
((
f
)
=>
!
passes
.
ContainsKey
((
string
)
f
)).
Union
(
Enumerable
.
Repeat
((
object
)
"## PASSING ##"
,
1
)).
Union
(
files
.
Where
((
f
)
=>
passes
.
ContainsKey
((
string
)
f
)));
files
=
files
.
Where
((
f
)
=>
!
passes
.
ContainsKey
((
string
)
f
)).
Union
(
Enumerable
.
Repeat
((
object
)
"## PASSING ##"
,
1
)).
Union
(
files
.
Where
((
f
)
=>
passes
.
ContainsKey
((
string
)
f
)));
lstFiles
.
Items
.
AddRange
(
files
.
ToArray
());
lstFiles
.
Items
.
AddRange
(
files
.
ToArray
());
}
}
private
void
boxConsoleLog_MouseDown
(
object
sender
,
MouseEventArgs
e
)
private
void
boxConsoleLog_MouseDown
(
object
sender
,
MouseEventArgs
e
)
{
{
if
(
e
.
Button
==
System
.
Windows
.
Forms
.
MouseButtons
.
Right
)
if
(
e
.
Button
==
System
.
Windows
.
Forms
.
MouseButtons
.
Right
)
{
//click event
{
//click event
ContextMenu
contextMenu
=
new
System
.
Windows
.
Forms
.
ContextMenu
();
ContextMenu
contextMenu
=
new
System
.
Windows
.
Forms
.
ContextMenu
();
MenuItem
menuItem
=
new
MenuItem
(
"Copy"
);
MenuItem
menuItem
=
new
MenuItem
(
"Copy"
);
menuItem
.
Click
+=
new
EventHandler
(
CopyAction
);
menuItem
.
Click
+=
new
EventHandler
(
CopyAction
);
contextMenu
.
MenuItems
.
Add
(
menuItem
);
contextMenu
.
MenuItems
.
Add
(
menuItem
);
boxConsoleLog
.
ContextMenu
=
contextMenu
;
boxConsoleLog
.
ContextMenu
=
contextMenu
;
}
}
}
}
void
CopyAction
(
object
sender
,
EventArgs
e
)
void
CopyAction
(
object
sender
,
EventArgs
e
)
{
{
if
(
boxConsoleLog
.
SelectedText
!=
null
&&
boxConsoleLog
.
SelectedText
!=
""
)
if
(
boxConsoleLog
.
SelectedText
!=
null
&&
boxConsoleLog
.
SelectedText
!=
""
)
{
{
//Clipboard.SetText(boxConsoleLog.SelectedText.Replace("\n", "\r\n"));
//Clipboard.SetText(boxConsoleLog.SelectedText.Replace("\n", "\r\n"));
boxConsoleLog
.
Copy
();
boxConsoleLog
.
Copy
();
}
}
}
}
private
void
lstFiles_SelectedIndexChanged
(
object
sender
,
EventArgs
e
)
private
void
lstFiles_SelectedIndexChanged
(
object
sender
,
EventArgs
e
)
{
{
//render svg
//render svg
var
fileName
=
lstFiles
.
SelectedItem
.
ToString
();
var
fileName
=
lstFiles
.
SelectedItem
.
ToString
();
if
(
fileName
.
StartsWith
(
"#"
))
return
;
if
(
fileName
.
StartsWith
(
"#"
))
return
;
//display png
//display png
var
png
=
Image
.
FromFile
(
_pngBasePath
+
Path
.
GetFileNameWithoutExtension
(
fileName
)
+
".png"
);
var
png
=
Image
.
FromFile
(
_pngBasePath
+
Path
.
GetFileNameWithoutExtension
(
fileName
)
+
".png"
);
picPng
.
Image
=
png
;
picPng
.
Image
=
png
;
var
doc
=
new
SvgDocument
();
var
doc
=
new
SvgDocument
();
try
try
{
{
Debug
.
Print
(
fileName
);
Debug
.
Print
(
fileName
);
doc
=
SvgDocument
.
Open
(
_svgBasePath
+
fileName
);
doc
=
SvgDocument
.
Open
(
_svgBasePath
+
fileName
);
if
(
fileName
.
StartsWith
(
"__"
))
if
(
fileName
.
StartsWith
(
"__"
))
{
{
picSvg
.
Image
=
doc
.
Draw
();
picSvg
.
Image
=
doc
.
Draw
();
}
}
else
else
{
{
var
img
=
new
Bitmap
(
480
,
360
);
var
img
=
new
Bitmap
(
480
,
360
);
doc
.
Draw
(
img
);
doc
.
Draw
(
img
);
picSvg
.
Image
=
img
;
picSvg
.
Image
=
img
;
}
}
this
.
boxConsoleLog
.
AppendText
(
"\n\nWC3 TEST "
+
fileName
+
"\n"
);
this
.
boxConsoleLog
.
AppendText
(
"\n\nWC3 TEST "
+
fileName
+
"\n"
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
this
.
boxConsoleLog
.
AppendText
(
"Result: TEST FAILED\n"
);
this
.
boxConsoleLog
.
AppendText
(
"Result: TEST FAILED\n"
);
this
.
boxConsoleLog
.
AppendText
(
"SVG RENDERING ERROR for "
+
fileName
+
"\n"
);
this
.
boxConsoleLog
.
AppendText
(
"SVG RENDERING ERROR for "
+
fileName
+
"\n"
);
this
.
boxConsoleLog
.
AppendText
(
ex
.
ToString
());
this
.
boxConsoleLog
.
AppendText
(
ex
.
ToString
());
//MessageBox.Show(ex.ToString(), "SVG Rendering");
//MessageBox.Show(ex.ToString(), "SVG Rendering");
picSvg
.
Image
=
null
;
picSvg
.
Image
=
null
;
}
}
//save load
//save load
try
try
{
{
using
(
var
memStream
=
new
MemoryStream
())
using
(
var
memStream
=
new
MemoryStream
())
{
{
doc
.
Write
(
memStream
);
doc
.
Write
(
memStream
);
memStream
.
Position
=
0
;
memStream
.
Position
=
0
;
var
reader
=
new
StreamReader
(
memStream
);
var
reader
=
new
StreamReader
(
memStream
);
var
tempFilePath
=
Path
.
Combine
(
Path
.
GetTempPath
(),
"test.svg"
);
var
tempFilePath
=
Path
.
Combine
(
Path
.
GetTempPath
(),
"test.svg"
);
System
.
IO
.
File
.
WriteAllText
(
tempFilePath
,
reader
.
ReadToEnd
());
System
.
IO
.
File
.
WriteAllText
(
tempFilePath
,
reader
.
ReadToEnd
());
memStream
.
Position
=
0
;
memStream
.
Position
=
0
;
var
baseUri
=
doc
.
BaseUri
;
var
baseUri
=
doc
.
BaseUri
;
doc
=
SvgDocument
.
Open
(
tempFilePath
);
doc
=
SvgDocument
.
Open
(
tempFilePath
);
doc
.
BaseUri
=
baseUri
;
doc
.
BaseUri
=
baseUri
;
if
(
fileName
.
StartsWith
(
"__"
))
if
(
fileName
.
StartsWith
(
"__"
))
{
{
picSaveLoad
.
Image
=
doc
.
Draw
();
picSaveLoad
.
Image
=
doc
.
Draw
();
}
}
else
else
{
{
var
img
=
new
Bitmap
(
480
,
360
);
var
img
=
new
Bitmap
(
480
,
360
);
doc
.
Draw
(
img
);
doc
.
Draw
(
img
);
picSaveLoad
.
Image
=
img
;
picSaveLoad
.
Image
=
img
;
}
}
}
}
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
this
.
boxConsoleLog
.
AppendText
(
"Result: TEST FAILED\n"
);
this
.
boxConsoleLog
.
AppendText
(
"Result: TEST FAILED\n"
);
this
.
boxConsoleLog
.
AppendText
(
"SVG SERIALIZATION ERROR for "
+
fileName
+
"\n"
);
this
.
boxConsoleLog
.
AppendText
(
"SVG SERIALIZATION ERROR for "
+
fileName
+
"\n"
);
this
.
boxConsoleLog
.
AppendText
(
ex
.
ToString
());
this
.
boxConsoleLog
.
AppendText
(
ex
.
ToString
());
//MessageBox.Show(ex.ToString(), "SVG Serialization");
//MessageBox.Show(ex.ToString(), "SVG Serialization");
picSaveLoad
.
Image
=
null
;
picSaveLoad
.
Image
=
null
;
}
}
//compare svg to png
//compare svg to png
try
try
{
{
picSVGPNG
.
Image
=
PixelDiff
((
Bitmap
)
picPng
.
Image
,
(
Bitmap
)
picSvg
.
Image
);
picSVGPNG
.
Image
=
PixelDiff
((
Bitmap
)
picPng
.
Image
,
(
Bitmap
)
picSvg
.
Image
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
this
.
boxConsoleLog
.
AppendText
(
"Result: TEST FAILED\n"
);
this
.
boxConsoleLog
.
AppendText
(
"Result: TEST FAILED\n"
);
this
.
boxConsoleLog
.
AppendText
(
"SVG TO PNG COMPARISON ERROR for "
+
fileName
+
"\n"
);
this
.
boxConsoleLog
.
AppendText
(
"SVG TO PNG COMPARISON ERROR for "
+
fileName
+
"\n"
);
this
.
boxConsoleLog
.
AppendText
(
ex
.
ToString
());
this
.
boxConsoleLog
.
AppendText
(
ex
.
ToString
());
//MessageBox.Show(ex.ToString(), "SVG Comparison");
//MessageBox.Show(ex.ToString(), "SVG Comparison");
picSVGPNG
.
Image
=
null
;
picSVGPNG
.
Image
=
null
;
}
}
}
}
unsafe
Bitmap
PixelDiff
(
Bitmap
a
,
Bitmap
b
)
unsafe
Bitmap
PixelDiff
(
Bitmap
a
,
Bitmap
b
)
{
{
Bitmap
output
=
new
Bitmap
(
a
.
Width
,
a
.
Height
,
PixelFormat
.
Format32bppArgb
);
Bitmap
output
=
new
Bitmap
(
a
.
Width
,
a
.
Height
,
PixelFormat
.
Format32bppArgb
);
Rectangle
rect
=
new
Rectangle
(
Point
.
Empty
,
a
.
Size
);
Rectangle
rect
=
new
Rectangle
(
Point
.
Empty
,
a
.
Size
);
using
(
var
aData
=
a
.
LockBitsDisposable
(
rect
,
ImageLockMode
.
ReadOnly
,
PixelFormat
.
Format32bppArgb
))
using
(
var
aData
=
a
.
LockBitsDisposable
(
rect
,
ImageLockMode
.
ReadOnly
,
PixelFormat
.
Format32bppArgb
))
using
(
var
bData
=
b
.
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
))
using
(
var
outputData
=
output
.
LockBitsDisposable
(
rect
,
ImageLockMode
.
ReadWrite
,
PixelFormat
.
Format32bppArgb
))
{
{
byte
*
aPtr
=
(
byte
*)
aData
.
Scan0
;
byte
*
aPtr
=
(
byte
*)
aData
.
Scan0
;
byte
*
bPtr
=
(
byte
*)
bData
.
Scan0
;
byte
*
bPtr
=
(
byte
*)
bData
.
Scan0
;
byte
*
outputPtr
=
(
byte
*)
outputData
.
Scan0
;
byte
*
outputPtr
=
(
byte
*)
outputData
.
Scan0
;
int
len
=
aData
.
Stride
*
aData
.
Height
;
int
len
=
aData
.
Stride
*
aData
.
Height
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
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)
// For alpha use the average of both images (otherwise pixels with the same alpha won't be visible)
if
((
i
+
1
)
%
4
==
0
)
if
((
i
+
1
)
%
4
==
0
)
*
outputPtr
=
(
byte
)((*
aPtr
+
*
bPtr
)
/
2
);
*
outputPtr
=
(
byte
)((*
aPtr
+
*
bPtr
)
/
2
);
else
else
*
outputPtr
=
(
byte
)~(*
aPtr
^
*
bPtr
);
*
outputPtr
=
(
byte
)~(*
aPtr
^
*
bPtr
);
outputPtr
++;
outputPtr
++;
aPtr
++;
aPtr
++;
bPtr
++;
bPtr
++;
}
}
}
}
return
output
;
return
output
;
}
}
...
@@ -198,63 +198,63 @@ namespace SvgW3CTestRunner
...
@@ -198,63 +198,63 @@ namespace SvgW3CTestRunner
}
}
}
}
}
}
static
class
BitmapExtensions
static
class
BitmapExtensions
{
{
public
static
DisposableImageData
LockBitsDisposable
(
this
Bitmap
bitmap
,
Rectangle
rect
,
ImageLockMode
flags
,
PixelFormat
format
)
public
static
DisposableImageData
LockBitsDisposable
(
this
Bitmap
bitmap
,
Rectangle
rect
,
ImageLockMode
flags
,
PixelFormat
format
)
{
{
return
new
DisposableImageData
(
bitmap
,
rect
,
flags
,
format
);
return
new
DisposableImageData
(
bitmap
,
rect
,
flags
,
format
);
}
}
public
class
DisposableImageData
:
IDisposable
public
class
DisposableImageData
:
IDisposable
{
{
private
readonly
Bitmap
_bitmap
;
private
readonly
Bitmap
_bitmap
;
private
readonly
BitmapData
_data
;
private
readonly
BitmapData
_data
;
internal
DisposableImageData
(
Bitmap
bitmap
,
Rectangle
rect
,
ImageLockMode
flags
,
PixelFormat
format
)
internal
DisposableImageData
(
Bitmap
bitmap
,
Rectangle
rect
,
ImageLockMode
flags
,
PixelFormat
format
)
{
{
_bitmap
=
bitmap
;
_bitmap
=
bitmap
;
_data
=
bitmap
.
LockBits
(
rect
,
flags
,
format
);
_data
=
bitmap
.
LockBits
(
rect
,
flags
,
format
);
}
}
public
void
Dispose
()
public
void
Dispose
()
{
{
_bitmap
.
UnlockBits
(
_data
);
_bitmap
.
UnlockBits
(
_data
);
}
}
public
IntPtr
Scan0
public
IntPtr
Scan0
{
{
get
{
return
_data
.
Scan0
;
}
get
{
return
_data
.
Scan0
;
}
}
}
public
int
Stride
public
int
Stride
{
{
get
{
return
_data
.
Stride
;}
get
{
return
_data
.
Stride
;}
}
}
public
int
Width
public
int
Width
{
{
get
{
return
_data
.
Width
;}
get
{
return
_data
.
Width
;}
}
}
public
int
Height
public
int
Height
{
{
get
{
return
_data
.
Height
;}
get
{
return
_data
.
Height
;}
}
}
public
PixelFormat
PixelFormat
public
PixelFormat
PixelFormat
{
{
get
{
return
_data
.
PixelFormat
;}
get
{
return
_data
.
PixelFormat
;}
}
}
public
int
Reserved
public
int
Reserved
{
{
get
{
return
_data
.
Reserved
;}
get
{
return
_data
.
Reserved
;}
}
}
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help