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
0eb538ce
Commit
0eb538ce
authored
Jun 28, 2014
by
Brian C. Barnes
Browse files
New types/converters for markers and aspect ratio
parent
4b19ecb4
Changes
3
Show whitespace changes
Inline
Side-by-side
Source/DataTypes/SvgAspectRatioConverter.cs
0 → 100644
View file @
0eb538ce
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Globalization
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Svg.DataTypes
{
//implementaton for preserve aspect ratio
public
sealed
class
SvgPreserveAspectRatioConverter
:
TypeConverter
{
public
override
object
ConvertFrom
(
ITypeDescriptorContext
context
,
System
.
Globalization
.
CultureInfo
culture
,
object
value
)
{
if
(
value
==
null
)
{
return
new
SvgAspectRatio
();
}
if
(!(
value
is
string
))
{
throw
new
ArgumentOutOfRangeException
(
"value must be a string."
);
}
SvgPreserveAspectRatio
eAlign
=
SvgPreserveAspectRatio
.
none
;
if
(!
Enum
.
TryParse
<
SvgPreserveAspectRatio
>(
value
as
string
,
out
eAlign
))
throw
new
ArgumentOutOfRangeException
(
"value is not a member of SvgPreserveAspectRatio"
);
SvgAspectRatio
pRet
=
new
SvgAspectRatio
(
eAlign
);
return
(
pRet
);
}
public
override
bool
CanConvertFrom
(
ITypeDescriptorContext
context
,
Type
sourceType
)
{
if
(
sourceType
==
typeof
(
string
))
{
return
true
;
}
return
base
.
CanConvertFrom
(
context
,
sourceType
);
}
public
override
bool
CanConvertTo
(
ITypeDescriptorContext
context
,
Type
destinationType
)
{
if
(
destinationType
==
typeof
(
string
))
{
return
true
;
}
return
base
.
CanConvertTo
(
context
,
destinationType
);
}
public
override
object
ConvertTo
(
ITypeDescriptorContext
context
,
CultureInfo
culture
,
object
value
,
Type
destinationType
)
{
if
(
destinationType
==
typeof
(
string
))
{
return
((
SvgUnit
)
value
).
ToString
();
}
return
base
.
ConvertTo
(
context
,
culture
,
value
,
destinationType
);
}
}
}
Source/DataTypes/SvgMarkerUnits.cs
0 → 100644
View file @
0eb538ce
using
System.ComponentModel
;
namespace
Svg.DataTypes
{
[
TypeConverter
(
typeof
(
SvgMarkerUnitsConverter
))]
public
enum
SvgMarkerUnits
{
strokeWidth
,
userSpaceOnUse
}
}
Source/DataTypes/SvgOrientConverter.cs
0 → 100644
View file @
0eb538ce
using
System
;
using
System.ComponentModel
;
using
System.Globalization
;
namespace
Svg.DataTypes
{
public
sealed
class
SvgOrientConverter
:
TypeConverter
{
public
override
object
ConvertFrom
(
ITypeDescriptorContext
context
,
System
.
Globalization
.
CultureInfo
culture
,
object
value
)
{
if
(
value
==
null
)
{
return
new
SvgUnit
(
SvgUnitType
.
User
,
0.0f
);
}
if
(!(
value
is
string
))
{
throw
new
ArgumentOutOfRangeException
(
"value must be a string."
);
}
switch
(
value
.
ToString
())
{
case
"auto"
:
return
(
new
SvgOrient
());
default
:
float
fTmp
=
float
.
MinValue
;
if
(!
float
.
TryParse
(
value
.
ToString
(),
out
fTmp
))
throw
new
ArgumentOutOfRangeException
(
"value must be a valid float."
);
return
(
new
SvgOrient
(
fTmp
));
}
}
public
override
bool
CanConvertFrom
(
ITypeDescriptorContext
context
,
Type
sourceType
)
{
if
(
sourceType
==
typeof
(
string
))
{
return
true
;
}
return
base
.
CanConvertFrom
(
context
,
sourceType
);
}
public
override
bool
CanConvertTo
(
ITypeDescriptorContext
context
,
Type
destinationType
)
{
if
(
destinationType
==
typeof
(
string
))
{
return
true
;
}
return
base
.
CanConvertTo
(
context
,
destinationType
);
}
public
override
object
ConvertTo
(
ITypeDescriptorContext
context
,
CultureInfo
culture
,
object
value
,
Type
destinationType
)
{
if
(
destinationType
==
typeof
(
string
))
{
return
((
SvgUnit
)
value
).
ToString
();
}
return
base
.
ConvertTo
(
context
,
culture
,
value
,
destinationType
);
}
}
}
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