/// <summary> /// Applies the required transforms to <see cref="SvgRenderer"/>. /// </summary> /// <param name="renderer">The <see cref="SvgRenderer"/> to be transformed.</param> protected internal override void PushTransforms(SvgRenderer renderer) { base.PushTransforms(renderer); if (!this.ViewBox.Equals(SvgViewBox.Empty)) { renderer.TranslateTransform(-this.ViewBox.MinX, -this.ViewBox.MinY, MatrixOrder.Append); renderer.ScaleTransform(this.Width.ToDeviceValue() / this.ViewBox.Width, this.Height.ToDeviceValue() / this.ViewBox.Height, MatrixOrder.Append); } }
/// <summary> /// Applies the required transforms to <see cref="SvgRenderer"/>. /// </summary> /// <param name="renderer">The <see cref="SvgRenderer"/> to be transformed.</param> protected internal override void PushTransforms(SvgRenderer renderer) { base.PushTransforms(renderer); if (!this.ViewBox.Equals(SvgViewBox.Empty)) { if (this.ViewBox.MinX > 0 || this.ViewBox.MinY > 0) { renderer.TranslateTransform(this.ViewBox.MinX, this.ViewBox.MinY, MatrixOrder.Append); } renderer.ScaleTransform(this.Width.ToDeviceValue() / this.ViewBox.Width, this.Height.ToDeviceValue() / this.ViewBox.Height, MatrixOrder.Append); } }
/// <summary> /// Applies the required transforms to <see cref="SvgRenderer"/>. /// </summary> /// <param name="renderer">The <see cref="SvgRenderer"/> to be transformed.</param> protected internal override bool PushTransforms(SvgRenderer renderer) { if (!base.PushTransforms(renderer)) { return(false); } if (!this.ViewBox.Equals(SvgViewBox.Empty)) { var width = this.Width.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this); var height = this.Height.ToDeviceValue(renderer, UnitRenderingType.Vertical, this); var fScaleX = width / this.ViewBox.Width; var fScaleY = height / this.ViewBox.Height; var fMinX = -this.ViewBox.MinX; var fMinY = -this.ViewBox.MinY; if (AspectRatio.Align != SvgPreserveAspectRatio.none) { if (AspectRatio.Slice) { fScaleX = Math.Max(fScaleX, fScaleY); fScaleY = Math.Max(fScaleX, fScaleY); } else { fScaleX = Math.Min(fScaleX, fScaleY); fScaleY = Math.Min(fScaleX, fScaleY); } float fViewMidX = (this.ViewBox.Width / 2) * fScaleX; float fViewMidY = (this.ViewBox.Height / 2) * fScaleY; float fMidX = width / 2; float fMidY = height / 2; switch (AspectRatio.Align) { case SvgPreserveAspectRatio.xMinYMin: break; case SvgPreserveAspectRatio.xMidYMin: fMinX += fMidX - fViewMidX; break; case SvgPreserveAspectRatio.xMaxYMin: fMinX += width - this.ViewBox.Width * fScaleX; break; case SvgPreserveAspectRatio.xMinYMid: fMinY += fMidY - fViewMidY; break; case SvgPreserveAspectRatio.xMidYMid: fMinX += fMidX - fViewMidX; fMinY += fMidY - fViewMidY; break; case SvgPreserveAspectRatio.xMaxYMid: fMinX += width - this.ViewBox.Width * fScaleX; fMinY += fMidY - fViewMidY; break; case SvgPreserveAspectRatio.xMinYMax: fMinY += height - this.ViewBox.Height * fScaleY; break; case SvgPreserveAspectRatio.xMidYMax: fMinX += fMidX - fViewMidX; fMinY += height - this.ViewBox.Height * fScaleY; break; case SvgPreserveAspectRatio.xMaxYMax: fMinX += width - this.ViewBox.Width * fScaleX; fMinY += height - this.ViewBox.Height * fScaleY; break; default: break; } } var x = _x.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this); var y = _y.ToDeviceValue(renderer, UnitRenderingType.Vertical, this); renderer.AddClip(new Region(new RectangleF(x, y, width, height))); renderer.ScaleTransform(fScaleX, fScaleY, MatrixOrder.Prepend); renderer.TranslateTransform(x, y); renderer.TranslateTransform(fMinX, fMinY); } return(true); }
/// <summary> /// Applies the required transforms to <see cref="SvgRenderer"/>. /// </summary> /// <param name="renderer">The <see cref="SvgRenderer"/> to be transformed.</param> protected internal override void PushTransforms(SvgRenderer renderer) { base.PushTransforms(renderer); if (!this.ViewBox.Equals(SvgViewBox.Empty)) { float fScaleX = this.Width.ToDeviceValue(this, false) / this.ViewBox.Width; float fScaleY = this.Height.ToDeviceValue(this, true) / this.ViewBox.Height; float fMinX = -this.ViewBox.MinX; float fMinY = -this.ViewBox.MinY; if (AspectRatio.Align != SvgPreserveAspectRatio.none) { if (AspectRatio.Slice) { fScaleX = Math.Max(fScaleX, fScaleY); fScaleY = Math.Max(fScaleX, fScaleY); } else { fScaleX = Math.Min(fScaleX, fScaleY); fScaleY = Math.Min(fScaleX, fScaleY); } float fViewMidX = (this.ViewBox.Width / 2) * fScaleX; float fViewMidY = (this.ViewBox.Height / 2) * fScaleY; float fMidX = this.Width.ToDeviceValue(this, false) / 2; float fMidY = this.Height.ToDeviceValue(this, true) / 2; switch (AspectRatio.Align) { case SvgPreserveAspectRatio.xMinYMin: break; case SvgPreserveAspectRatio.xMidYMin: fMinX += (fMidX - fViewMidX) / fScaleX; break; case SvgPreserveAspectRatio.xMaxYMin: fMinX += (this.Width.ToDeviceValue(this, false) / fScaleX) - this.ViewBox.Width; break; case SvgPreserveAspectRatio.xMinYMid: fMinY += (fMidY - fViewMidY) / fScaleY; break; case SvgPreserveAspectRatio.xMidYMid: fMinX += (fMidX - fViewMidX) / fScaleX; fMinY += (fMidY - fViewMidY) / fScaleY; break; case SvgPreserveAspectRatio.xMaxYMid: fMinX += (this.Width.ToDeviceValue(this, false) / fScaleX) - this.ViewBox.Width; fMinY += (fMidY - fViewMidY) / fScaleY; break; case SvgPreserveAspectRatio.xMinYMax: fMinY += (this.Height.ToDeviceValue(this, true) / fScaleY) - this.ViewBox.Height; break; case SvgPreserveAspectRatio.xMidYMax: fMinX += (fMidX - fViewMidX) / fScaleX; fMinY += (this.Height.ToDeviceValue(this, true) / fScaleY) - this.ViewBox.Height; break; case SvgPreserveAspectRatio.xMaxYMax: fMinX += (this.Width.ToDeviceValue(this, false) / fScaleX) - this.ViewBox.Width; fMinY += (this.Height.ToDeviceValue(this, true) / fScaleY) - this.ViewBox.Height; break; default: break; } } renderer.TranslateTransform(_x, _y); renderer.TranslateTransform(fMinX, fMinY); renderer.ScaleTransform(fScaleX, fScaleY); } }