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
1fcb5709
Commit
1fcb5709
authored
Jun 04, 2013
by
Tebjan Halm
Browse files
added custom attributes to svg elements, svg writing to XML is non verbose
parent
5d3b01aa
Changes
10
Show whitespace changes
Inline
Side-by-side
Source/DataTypes/SvgUnit.cs
View file @
1fcb5709
...
@@ -21,12 +21,12 @@ namespace Svg
...
@@ -21,12 +21,12 @@ namespace Svg
/// <summary>
/// <summary>
/// Gets and empty <see cref="SvgUnit"/>.
/// Gets and empty <see cref="SvgUnit"/>.
/// </summary>
/// </summary>
public
static
readonly
SvgUnit
Empty
=
new
SvgUnit
();
public
static
readonly
SvgUnit
Empty
=
new
SvgUnit
(
SvgUnitType
.
User
,
0
);
/// <summary>
/// <summary>
/// Gets an <see cref="SvgUnit"/> with a value of none.
/// Gets an <see cref="SvgUnit"/> with a value of none.
/// </summary>
/// </summary>
public
static
readonly
SvgUnit
None
=
new
SvgUnit
(
SvgUnitType
.
None
,
0f
);
public
static
readonly
SvgUnit
None
=
new
SvgUnit
(
SvgUnitType
.
None
,
0f
);
/// <summary>
/// <summary>
/// Gets a value to determine whether the unit is empty.
/// Gets a value to determine whether the unit is empty.
...
...
Source/Painting/EnumConverters.cs
View file @
1fcb5709
...
@@ -107,4 +107,12 @@ namespace Svg
...
@@ -107,4 +107,12 @@ namespace Svg
{
{
}
}
public
sealed
class
SvgStrokeLineCapConverter
:
EnumBaseConverter
<
SvgStrokeLineCap
>
{
}
public
sealed
class
SvgStrokeLineJoinConverter
:
EnumBaseConverter
<
SvgStrokeLineJoin
>
{
}
}
}
Source/Painting/SvgStrokeLineCap.cs
View file @
1fcb5709
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Text
;
using
System.ComponentModel
;
namespace
Svg
namespace
Svg
{
{
[
TypeConverter
(
typeof
(
SvgStrokeLineCapConverter
))]
public
enum
SvgStrokeLineCap
public
enum
SvgStrokeLineCap
{
{
Butt
,
Butt
,
...
...
Source/Painting/SvgStrokeLineJoin.cs
View file @
1fcb5709
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Text
;
using
System.ComponentModel
;
namespace
Svg
namespace
Svg
{
{
[
TypeConverter
(
typeof
(
SvgStrokeLineJoinConverter
))]
public
enum
SvgStrokeLineJoin
public
enum
SvgStrokeLineJoin
{
{
Miter
,
Miter
,
...
...
Source/Paths/SvgPathBuilder.cs
View file @
1fcb5709
...
@@ -18,7 +18,7 @@ namespace Svg
...
@@ -18,7 +18,7 @@ namespace Svg
}
}
}
}
internal
class
SvgPathBuilder
:
TypeConverter
public
class
SvgPathBuilder
:
TypeConverter
{
{
/// <summary>
/// <summary>
/// Parses the specified string into a collection of path segments.
/// Parses the specified string into a collection of path segments.
...
@@ -46,6 +46,20 @@ namespace Svg
...
@@ -46,6 +46,20 @@ namespace Svg
isRelative
=
char
.
IsLower
(
command
);
isRelative
=
char
.
IsLower
(
command
);
// http://www.w3.org/TR/SVG11/paths.html#PathDataGeneralInformation
// http://www.w3.org/TR/SVG11/paths.html#PathDataGeneralInformation
CreatePathSegment
(
command
,
segments
,
coords
,
isRelative
);
}
}
catch
(
Exception
exc
)
{
Trace
.
TraceError
(
"Error parsing path \"{0}\": {1}"
,
path
,
exc
.
Message
);
}
return
segments
;
}
public
static
void
CreatePathSegment
(
char
command
,
SvgPathSegmentList
segments
,
List
<
float
>
coords
,
bool
isRelative
)
{
switch
(
command
)
switch
(
command
)
{
{
case
'm'
:
// relative moveto
case
'm'
:
// relative moveto
...
@@ -149,14 +163,6 @@ namespace Svg
...
@@ -149,14 +163,6 @@ namespace Svg
break
;
break
;
}
}
}
}
}
catch
(
Exception
exc
)
{
Trace
.
TraceError
(
"Error parsing path \"{0}\": {1}"
,
path
,
exc
.
Message
);
}
return
segments
;
}
private
static
PointF
Reflect
(
PointF
point
,
PointF
mirror
)
private
static
PointF
Reflect
(
PointF
point
,
PointF
mirror
)
{
{
...
...
Source/Svg.csproj
View file @
1fcb5709
...
@@ -121,6 +121,7 @@
...
@@ -121,6 +121,7 @@
<Compile
Include=
"Filter Effects\feGaussianBlur\SvgGaussianBlur.cs"
/>
<Compile
Include=
"Filter Effects\feGaussianBlur\SvgGaussianBlur.cs"
/>
<Compile
Include=
"Filter Effects\feMerge\SvgMerge.cs"
/>
<Compile
Include=
"Filter Effects\feMerge\SvgMerge.cs"
/>
<Compile
Include=
"Painting\EnumConverters.cs"
/>
<Compile
Include=
"Painting\EnumConverters.cs"
/>
<Compile
Include=
"SvgDefinitionDefaults.cs"
/>
<Compile
Include=
"SvgElementAttribute.cs"
/>
<Compile
Include=
"SvgElementAttribute.cs"
/>
<Compile
Include=
"SvgRenderer.cs"
/>
<Compile
Include=
"SvgRenderer.cs"
/>
<Compile
Include=
"Painting\SvgColourConverter.cs"
/>
<Compile
Include=
"Painting\SvgColourConverter.cs"
/>
...
...
Source/SvgDefinitionDefaults.cs
0 → 100644
View file @
1fcb5709
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
Svg
{
/// <summary>
/// Holds a dictionary of the default values of the SVG specification
/// </summary>
public
static
class
SvgDefaults
{
//internal dictionary for the defaults
private
static
readonly
Dictionary
<
string
,
string
>
_defaults
=
new
Dictionary
<
string
,
string
>();
static
SvgDefaults
()
{
_defaults
[
"viewBox"
]
=
"0, 0, 0, 0"
;
_defaults
[
"visibility"
]
=
"visible"
;
_defaults
[
"opacity"
]
=
"1"
;
_defaults
[
"clip-rule"
]
=
"nonzero"
;
_defaults
[
"transform"
]
=
""
;
_defaults
[
"fill"
]
=
"Black"
;
_defaults
[
"fill-opacity"
]
=
"1"
;
_defaults
[
"fill-rule"
]
=
"nonzero"
;
_defaults
[
"stroke"
]
=
"none"
;
_defaults
[
"stroke-opacity"
]
=
"1"
;
_defaults
[
"stroke-width"
]
=
"1"
;
_defaults
[
"stroke-miterlimit"
]
=
"4"
;
_defaults
[
"stroke-linecap"
]
=
"butt"
;
_defaults
[
"stroke-linejoin"
]
=
"miter"
;
_defaults
[
"stroke-dasharray"
]
=
"none"
;
_defaults
[
"stroke-dashoffset"
]
=
"0"
;
}
/// <summary>
/// Checks whether the property value is the default value of the svg definition.
/// </summary>
/// <param name="attributeName">Name of the svg attribute</param>
/// <param name="propertyValue">.NET value of the attribute</param>
public
static
bool
IsDefault
(
string
attributeName
,
string
value
)
{
if
(
_defaults
.
ContainsKey
(
attributeName
))
{
if
(
_defaults
[
attributeName
]
==
value
)
return
true
;
else
if
(
attributeName
==
"fill"
)
return
value
==
"#000000"
;
}
return
false
;
}
}
}
Source/SvgElement.cs
View file @
1fcb5709
...
@@ -22,6 +22,7 @@ namespace Svg
...
@@ -22,6 +22,7 @@ namespace Svg
private
SvgElementCollection
_children
;
private
SvgElementCollection
_children
;
private
static
readonly
object
_loadEventKey
=
new
object
();
private
static
readonly
object
_loadEventKey
=
new
object
();
private
Matrix
_graphicsMatrix
;
private
Matrix
_graphicsMatrix
;
private
Dictionary
<
string
,
string
>
_customAttributes
;
/// <summary>
/// <summary>
/// Gets the name of the element.
/// Gets the name of the element.
...
@@ -137,6 +138,11 @@ namespace Svg
...
@@ -137,6 +138,11 @@ namespace Svg
}
}
}
}
public
Dictionary
<
string
,
string
>
CustomAttributes
{
get
{
return
this
.
_customAttributes
;
}
}
/// <summary>
/// <summary>
/// Applies the required transforms to <see cref="SvgRenderer"/>.
/// Applies the required transforms to <see cref="SvgRenderer"/>.
/// </summary>
/// </summary>
...
@@ -276,12 +282,13 @@ namespace Svg
...
@@ -276,12 +282,13 @@ namespace Svg
this
.
_children
=
new
SvgElementCollection
(
this
);
this
.
_children
=
new
SvgElementCollection
(
this
);
this
.
_eventHandlers
=
new
EventHandlerList
();
this
.
_eventHandlers
=
new
EventHandlerList
();
this
.
_elementName
=
string
.
Empty
;
this
.
_elementName
=
string
.
Empty
;
this
.
_customAttributes
=
new
Dictionary
<
string
,
string
>();
}
}
public
virtual
void
InitialiseFromXML
(
XmlTextReader
reader
,
SvgDocument
document
)
public
virtual
void
InitialiseFromXML
(
XmlTextReader
reader
,
SvgDocument
document
)
{
{
throw
new
NotImplementedException
();
}
}
...
@@ -343,15 +350,10 @@ namespace Svg
...
@@ -343,15 +350,10 @@ namespace Svg
if
(
propertyValue
!=
null
)
if
(
propertyValue
!=
null
)
{
{
var
type
=
propertyValue
.
GetType
();
var
type
=
propertyValue
.
GetType
();
object
defaultValue
=
null
;
if
(
type
.
IsValueType
)
defaultValue
=
Activator
.
CreateInstance
(
type
);
if
(!
propertyValue
.
Equals
(
defaultValue
)
||
type
==
typeof
(
float
)
||
type
==
typeof
(
bool
)
||
type
==
typeof
(
SvgColourServer
))
{
string
value
=
(
string
)
attr
.
Property
.
Converter
.
ConvertTo
(
propertyValue
,
typeof
(
string
));
string
value
=
(
string
)
attr
.
Property
.
Converter
.
ConvertTo
(
propertyValue
,
typeof
(
string
));
if
(!
SvgDefaults
.
IsDefault
(
attr
.
Attribute
.
Name
,
value
))
{
writer
.
WriteAttributeString
(
attr
.
Attribute
.
NamespaceAndName
,
value
);
writer
.
WriteAttributeString
(
attr
.
Attribute
.
NamespaceAndName
,
value
);
}
}
}
}
...
@@ -362,6 +364,13 @@ namespace Svg
...
@@ -362,6 +364,13 @@ namespace Svg
}
}
}
}
}
}
//add the custom attributes
foreach
(
var
item
in
this
.
_customAttributes
)
{
writer
.
WriteAttributeString
(
item
.
Key
,
item
.
Value
);
}
}
}
protected
virtual
void
Write
(
XmlTextWriter
writer
)
protected
virtual
void
Write
(
XmlTextWriter
writer
)
...
...
Source/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
View file @
1fcb5709
No preview for this file type
Source/obj/Release/ResolveAssemblyReference.cache
deleted
100644 → 0
View file @
5d3b01aa
File deleted
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