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
"vscode:/vscode.git/clone" did not exist on "9521956d99e23140337493f3d8e363cb19786a70"
Commit
c94f649b
authored
Jun 28, 2014
by
Brian C. Barnes
Browse files
Finished aspect ratio parser
parent
0eb538ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Source/DataTypes/SvgAspectRatio.cs
View file @
c94f649b
...
...
@@ -22,6 +22,7 @@ namespace Svg
{
this
.
Align
=
align
;
this
.
Slice
=
slice
;
this
.
Defer
=
false
;
}
public
SvgPreserveAspectRatio
Align
...
...
@@ -35,7 +36,13 @@ namespace Svg
get
;
set
;
}
public
bool
Defer
{
get
;
set
;
}
public
override
string
ToString
()
{
return
TypeDescriptor
.
GetConverter
(
typeof
(
SvgPreserveAspectRatio
)).
ConvertToString
(
this
.
Align
)
+
(
Slice
?
" slice"
:
""
);
...
...
@@ -45,15 +52,15 @@ namespace Svg
public
enum
SvgPreserveAspectRatio
{
X
MidYMid
,
//default
x
MidYMid
,
//default
none
,
X
MinYMin
,
X
MidYMin
,
X
MaxYMin
,
X
MinYMid
,
X
MaxYMid
,
X
MinYMax
,
X
MidYMax
,
X
MaxYMax
x
MinYMin
,
x
MidYMin
,
x
MaxYMin
,
x
MinYMid
,
x
MaxYMid
,
x
MinYMax
,
x
MidYMax
,
x
MaxYMax
}
}
Source/DataTypes/SvgAspectRatioConverter.cs
View file @
c94f649b
...
...
@@ -25,10 +25,43 @@ namespace Svg.DataTypes
}
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"
);
SvgAspectRatio
pRet
=
new
SvgAspectRatio
(
eAlign
);
pRet
.
Slice
=
bSlice
;
pRet
.
Defer
=
bDefer
;
return
(
pRet
);
}
...
...
Source/Document Structure/SvgFragment.cs
View file @
c94f649b
...
...
@@ -133,33 +133,33 @@ namespace Svg
switch
(
AspectRatio
.
Align
)
{
case
SvgPreserveAspectRatio
.
X
MinYMin
:
case
SvgPreserveAspectRatio
.
x
MinYMin
:
break
;
case
SvgPreserveAspectRatio
.
X
MidYMin
:
case
SvgPreserveAspectRatio
.
x
MidYMin
:
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
break
;
case
SvgPreserveAspectRatio
.
X
MaxYMin
:
case
SvgPreserveAspectRatio
.
x
MaxYMin
:
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
break
;
case
SvgPreserveAspectRatio
.
X
MinYMid
:
case
SvgPreserveAspectRatio
.
x
MinYMid
:
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
break
;
case
SvgPreserveAspectRatio
.
X
MidYMid
:
case
SvgPreserveAspectRatio
.
x
MidYMid
:
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
break
;
case
SvgPreserveAspectRatio
.
X
MaxYMid
:
case
SvgPreserveAspectRatio
.
x
MaxYMid
:
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
fMinY
+=
(
fMidY
-
fViewMidY
)
/
fScaleY
;
break
;
case
SvgPreserveAspectRatio
.
X
MinYMax
:
case
SvgPreserveAspectRatio
.
x
MinYMax
:
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
break
;
case
SvgPreserveAspectRatio
.
X
MidYMax
:
case
SvgPreserveAspectRatio
.
x
MidYMax
:
fMinX
+=
(
fMidX
-
fViewMidX
)
/
fScaleX
;
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
break
;
case
SvgPreserveAspectRatio
.
X
MaxYMax
:
case
SvgPreserveAspectRatio
.
x
MaxYMax
:
fMinX
+=
this
.
ViewBox
.
Width
-
this
.
Width
.
ToDeviceValue
();
fMinY
+=
this
.
ViewBox
.
Height
-
this
.
Height
.
ToDeviceValue
();
break
;
...
...
@@ -212,7 +212,7 @@ namespace Svg
this
.
Height
=
new
SvgUnit
(
SvgUnitType
.
Percentage
,
100.0f
);
this
.
Width
=
new
SvgUnit
(
SvgUnitType
.
Percentage
,
100.0f
);
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