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
c94f649b
Commit
c94f649b
authored
Jun 28, 2014
by
Brian C. Barnes
Browse files
Finished aspect ratio parser
parent
0eb538ce
Changes
3
Show whitespace changes
Inline
Side-by-side
Source/DataTypes/SvgAspectRatio.cs
View file @
c94f649b
...
@@ -22,6 +22,7 @@ namespace Svg
...
@@ -22,6 +22,7 @@ namespace Svg
{
{
this
.
Align
=
align
;
this
.
Align
=
align
;
this
.
Slice
=
slice
;
this
.
Slice
=
slice
;
this
.
Defer
=
false
;
}
}
public
SvgPreserveAspectRatio
Align
public
SvgPreserveAspectRatio
Align
...
@@ -36,6 +37,12 @@ namespace Svg
...
@@ -36,6 +37,12 @@ namespace Svg
set
;
set
;
}
}
public
bool
Defer
{
get
;
set
;
}
public
override
string
ToString
()
public
override
string
ToString
()
{
{
return
TypeDescriptor
.
GetConverter
(
typeof
(
SvgPreserveAspectRatio
)).
ConvertToString
(
this
.
Align
)
+
(
Slice
?
" slice"
:
""
);
return
TypeDescriptor
.
GetConverter
(
typeof
(
SvgPreserveAspectRatio
)).
ConvertToString
(
this
.
Align
)
+
(
Slice
?
" slice"
:
""
);
...
@@ -45,15 +52,15 @@ namespace Svg
...
@@ -45,15 +52,15 @@ namespace Svg
public
enum
SvgPreserveAspectRatio
public
enum
SvgPreserveAspectRatio
{
{
X
MidYMid
,
//default
x
MidYMid
,
//default
none
,
none
,
X
MinYMin
,
x
MinYMin
,
X
MidYMin
,
x
MidYMin
,
X
MaxYMin
,
x
MaxYMin
,
X
MinYMid
,
x
MinYMid
,
X
MaxYMid
,
x
MaxYMid
,
X
MinYMax
,
x
MinYMax
,
X
MidYMax
,
x
MidYMax
,
X
MaxYMax
x
MaxYMax
}
}
}
}
Source/DataTypes/SvgAspectRatioConverter.cs
View file @
c94f649b
...
@@ -25,10 +25,43 @@ namespace Svg.DataTypes
...
@@ -25,10 +25,43 @@ namespace Svg.DataTypes
}
}
SvgPreserveAspectRatio
eAlign
=
SvgPreserveAspectRatio
.
none
;
SvgPreserveAspectRatio
eAlign
=
SvgPreserveAspectRatio
.
none
;
if
(!
Enum
.
TryParse
<
SvgPreserveAspectRatio
>(
value
as
string
,
out
eAlign
))
bool
bDefer
=
false
;
bool
bSlice
=
false
;
string
[]
sParts
=
(
value
as
string
).
Split
(
new
char
[]
{
' '
},
StringSplitOptions
.
RemoveEmptyEntries
);
int
nAlignIndex
=
0
;
if
(
sParts
[
0
].
Equals
(
"defer"
))
{
bDefer
=
true
;
nAlignIndex
++;
if
(
sParts
.
Length
<
2
)
throw
new
ArgumentOutOfRangeException
(
"value is not a member of SvgPreserveAspectRatio"
);
}
if
(!
Enum
.
TryParse
<
SvgPreserveAspectRatio
>(
sParts
[
nAlignIndex
],
out
eAlign
))
throw
new
ArgumentOutOfRangeException
(
"value is not a member of SvgPreserveAspectRatio"
);
nAlignIndex
++;
if
(
sParts
.
Length
>
nAlignIndex
)
{
switch
(
sParts
[
nAlignIndex
])
{
case
"meet"
:
break
;
case
"slice"
:
bSlice
=
true
;
break
;
default
:
throw
new
ArgumentOutOfRangeException
(
"value is not a member of SvgPreserveAspectRatio"
);
}
}
nAlignIndex
++;
if
(
sParts
.
Length
>
nAlignIndex
)
throw
new
ArgumentOutOfRangeException
(
"value is not a member of SvgPreserveAspectRatio"
);
throw
new
ArgumentOutOfRangeException
(
"value is not a member of SvgPreserveAspectRatio"
);
SvgAspectRatio
pRet
=
new
SvgAspectRatio
(
eAlign
);
SvgAspectRatio
pRet
=
new
SvgAspectRatio
(
eAlign
);
pRet
.
Slice
=
bSlice
;
pRet
.
Defer
=
bDefer
;
return
(
pRet
);
return
(
pRet
);
}
}
...
...
Source/Document Structure/SvgFragment.cs
View file @
c94f649b
...
@@ -133,33 +133,33 @@ namespace Svg
...
@@ -133,33 +133,33 @@ namespace Svg
switch
(
AspectRatio
.
Align
)
switch
(
AspectRatio
.
Align
)
{
{
case
SvgPreserveAspectRatio
.
X
MinYMin
:
case
SvgPreserveAspectRatio
.
x
MinYMin
:
break
;
break
;
case
SvgPreserveAspectRatio
.
X
MidYMin
:
case
SvgPreserveAspectRatio
.
x
MidYMin
:
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
break
;
break
;
case
SvgPreserveAspectRatio
.
X
MaxYMin
:
case
SvgPreserveAspectRatio
.
x
MaxYMin
:
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
break
;
break
;
case
SvgPreserveAspectRatio
.
X
MinYMid
:
case
SvgPreserveAspectRatio
.
x
MinYMid
:
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
break
;
break
;
case
SvgPreserveAspectRatio
.
X
MidYMid
:
case
SvgPreserveAspectRatio
.
x
MidYMid
:
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
break
;
break
;
case
SvgPreserveAspectRatio
.
X
MaxYMid
:
case
SvgPreserveAspectRatio
.
x
MaxYMid
:
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
break
;
break
;
case
SvgPreserveAspectRatio
.
X
MinYMax
:
case
SvgPreserveAspectRatio
.
x
MinYMax
:
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
break
;
break
;
case
SvgPreserveAspectRatio
.
X
MidYMax
:
case
SvgPreserveAspectRatio
.
x
MidYMax
:
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
break
;
break
;
case
SvgPreserveAspectRatio
.
X
MaxYMax
:
case
SvgPreserveAspectRatio
.
x
MaxYMax
:
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
break
;
break
;
...
@@ -212,7 +212,7 @@ namespace Svg
...
@@ -212,7 +212,7 @@ namespace Svg
this
.
Height
=
new
SvgUnit
(
SvgUnitType
.
Percentage
,
100.0f
);
this
.
Height
=
new
SvgUnit
(
SvgUnitType
.
Percentage
,
100.0f
);
this
.
Width
=
new
SvgUnit
(
SvgUnitType
.
Percentage
,
100.0f
);
this
.
Width
=
new
SvgUnit
(
SvgUnitType
.
Percentage
,
100.0f
);
this
.
ViewBox
=
SvgViewBox
.
Empty
;
this
.
ViewBox
=
SvgViewBox
.
Empty
;
this
.
AspectRatio
=
new
SvgAspectRatio
(
SvgPreserveAspectRatio
.
X
MidYMid
);
this
.
AspectRatio
=
new
SvgAspectRatio
(
SvgPreserveAspectRatio
.
x
MidYMid
);
}
}
...
...
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