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 ...@@ -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
{ {
XMidYMid, //default xMidYMid, //default
none, none,
XMinYMin, xMinYMin,
XMidYMin, xMidYMin,
XMaxYMin, xMaxYMin,
XMinYMid, xMinYMid,
XMaxYMid, xMaxYMid,
XMinYMax, xMinYMax,
XMidYMax, xMidYMax,
XMaxYMax xMaxYMax
} }
} }
...@@ -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);
} }
......
...@@ -133,33 +133,33 @@ namespace Svg ...@@ -133,33 +133,33 @@ namespace Svg
switch (AspectRatio.Align) switch (AspectRatio.Align)
{ {
case SvgPreserveAspectRatio.XMinYMin: case SvgPreserveAspectRatio.xMinYMin:
break; break;
case SvgPreserveAspectRatio.XMidYMin: case SvgPreserveAspectRatio.xMidYMin:
fMinX += (fMidX - fViewMidX) / fScaleX; fMinX += (fMidX - fViewMidX) / fScaleX;
break; break;
case SvgPreserveAspectRatio.XMaxYMin: case SvgPreserveAspectRatio.xMaxYMin:
fMinX += this.ViewBox.Width - this.Width.ToDeviceValue(); fMinX += this.ViewBox.Width - this.Width.ToDeviceValue();
break; break;
case SvgPreserveAspectRatio.XMinYMid: case SvgPreserveAspectRatio.xMinYMid:
fMinY += (fMidY - fViewMidY) / fScaleY; fMinY += (fMidY - fViewMidY) / fScaleY;
break; break;
case SvgPreserveAspectRatio.XMidYMid: case SvgPreserveAspectRatio.xMidYMid:
fMinX += (fMidX - fViewMidX) / fScaleX; fMinX += (fMidX - fViewMidX) / fScaleX;
fMinY += (fMidY - fViewMidY) / fScaleY; fMinY += (fMidY - fViewMidY) / fScaleY;
break; break;
case SvgPreserveAspectRatio.XMaxYMid: case SvgPreserveAspectRatio.xMaxYMid:
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.XMinYMax: case SvgPreserveAspectRatio.xMinYMax:
fMinY += this.ViewBox.Height - this.Height.ToDeviceValue(); fMinY += this.ViewBox.Height - this.Height.ToDeviceValue();
break; break;
case SvgPreserveAspectRatio.XMidYMax: case SvgPreserveAspectRatio.xMidYMax:
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.XMaxYMax: case SvgPreserveAspectRatio.xMaxYMax:
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.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