Commit c94f649b authored by Brian C. Barnes's avatar Brian C. Barnes
Browse files

Finished aspect ratio parser

parent 0eb538ce
......@@ -22,6 +22,7 @@ namespace Svg
{
this.Align = align;
this.Slice = slice;
this.Defer = false;
}
public SvgPreserveAspectRatio Align
......@@ -36,6 +37,12 @@ namespace Svg
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
{
XMidYMid, //default
xMidYMid, //default
none,
XMinYMin,
XMidYMin,
XMaxYMin,
XMinYMid,
XMaxYMid,
XMinYMax,
XMidYMax,
XMaxYMax
xMinYMin,
xMidYMin,
xMaxYMin,
xMinYMid,
xMaxYMid,
xMinYMax,
xMidYMax,
xMaxYMax
}
}
......@@ -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);
}
......
......@@ -133,33 +133,33 @@ namespace Svg
switch (AspectRatio.Align)
{
case SvgPreserveAspectRatio.XMinYMin:
case SvgPreserveAspectRatio.xMinYMin:
break;
case SvgPreserveAspectRatio.XMidYMin:
case SvgPreserveAspectRatio.xMidYMin:
fMinX += (fMidX - fViewMidX) / fScaleX;
break;
case SvgPreserveAspectRatio.XMaxYMin:
case SvgPreserveAspectRatio.xMaxYMin:
fMinX += this.ViewBox.Width - this.Width.ToDeviceValue();
break;
case SvgPreserveAspectRatio.XMinYMid:
case SvgPreserveAspectRatio.xMinYMid:
fMinY += (fMidY - fViewMidY) / fScaleY;
break;
case SvgPreserveAspectRatio.XMidYMid:
case SvgPreserveAspectRatio.xMidYMid:
fMinX += (fMidX - fViewMidX) / fScaleX;
fMinY += (fMidY - fViewMidY) / fScaleY;
break;
case SvgPreserveAspectRatio.XMaxYMid:
case SvgPreserveAspectRatio.xMaxYMid:
fMinX += this.ViewBox.Width - this.Width.ToDeviceValue();
fMinY += (fMidY - fViewMidY) / fScaleY;
break;
case SvgPreserveAspectRatio.XMinYMax:
case SvgPreserveAspectRatio.xMinYMax:
fMinY += this.ViewBox.Height - this.Height.ToDeviceValue();
break;
case SvgPreserveAspectRatio.XMidYMax:
case SvgPreserveAspectRatio.xMidYMax:
fMinX += (fMidX - fViewMidX) / fScaleX;
fMinY += this.ViewBox.Height - this.Height.ToDeviceValue();
break;
case SvgPreserveAspectRatio.XMaxYMax:
case SvgPreserveAspectRatio.xMaxYMax:
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.XMidYMid);
this.AspectRatio = new SvgAspectRatio(SvgPreserveAspectRatio.xMidYMid);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment