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

Support for 'slice' and fixed '...Max' in aspect ratio

parent 765f8f22
...@@ -123,9 +123,17 @@ namespace Svg ...@@ -123,9 +123,17 @@ namespace Svg
float fMinY = -this.ViewBox.MinY; float fMinY = -this.ViewBox.MinY;
if (AspectRatio.Align != SvgPreserveAspectRatio.none) if (AspectRatio.Align != SvgPreserveAspectRatio.none)
{
if (AspectRatio.Slice)
{
fScaleX = Math.Max(fScaleX, fScaleY);
fScaleY = Math.Max(fScaleX, fScaleY);
}
else
{ {
fScaleX = Math.Min(fScaleX, fScaleY); fScaleX = Math.Min(fScaleX, fScaleY);
fScaleY = Math.Min(fScaleX, fScaleY); fScaleY = Math.Min(fScaleX, fScaleY);
}
float fViewMidX = (this.ViewBox.Width / 2) * fScaleX; float fViewMidX = (this.ViewBox.Width / 2) * fScaleX;
float fViewMidY = (this.ViewBox.Height / 2) * fScaleY; float fViewMidY = (this.ViewBox.Height / 2) * fScaleY;
float fMidX = this.Width.ToDeviceValue() / 2; float fMidX = this.Width.ToDeviceValue() / 2;
...@@ -139,7 +147,7 @@ namespace Svg ...@@ -139,7 +147,7 @@ namespace Svg
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.Width.ToDeviceValue() / fScaleX) - this.ViewBox.Width;
break; break;
case SvgPreserveAspectRatio.xMinYMid: case SvgPreserveAspectRatio.xMinYMid:
fMinY += (fMidY - fViewMidY) / fScaleY; fMinY += (fMidY - fViewMidY) / fScaleY;
...@@ -149,28 +157,28 @@ namespace Svg ...@@ -149,28 +157,28 @@ namespace Svg
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.Width.ToDeviceValue() / fScaleX) - this.ViewBox.Width;
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.Height.ToDeviceValue() / fScaleY) - this.ViewBox.Height;
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.Height.ToDeviceValue() / fScaleY) - this.ViewBox.Height;
break; break;
case SvgPreserveAspectRatio.xMaxYMax: case SvgPreserveAspectRatio.xMaxYMax:
fMinX += this.ViewBox.Width - this.Width.ToDeviceValue(); fMinX += (this.Width.ToDeviceValue() / fScaleX) - this.ViewBox.Width;
fMinY += this.ViewBox.Height - this.Height.ToDeviceValue(); fMinY += (this.Height.ToDeviceValue() / fScaleY) - this.ViewBox.Height;
break; break;
default: default:
break; break;
} }
} }
renderer.TranslateTransform(_x, _y, MatrixOrder.Append); renderer.TranslateTransform(_x, _y);
renderer.TranslateTransform(fMinX, fMinY, MatrixOrder.Append); renderer.TranslateTransform(fMinX, fMinY);
renderer.ScaleTransform(fScaleX, fScaleY, MatrixOrder.Append); renderer.ScaleTransform(fScaleX, fScaleY);
} }
} }
......
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