public static RectangleF ToRectangle(SvgRect rect) { if (rect == null) { return RectangleF.Empty; } return new RectangleF((float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height); }
private Transform FitToViewbox(SvgRect viewBox, Rect rectToFit) { SvgPreserveAspectRatioType alignment = SvgPreserveAspectRatioType.XMidYMid; double[] transformArray = FitToViewBox(alignment, viewBox, new SvgRect(rectToFit.X, rectToFit.Y, rectToFit.Width, rectToFit.Height)); double translateX = transformArray[0]; double translateY = transformArray[1]; double scaleX = transformArray[2]; double scaleY = transformArray[3]; Transform translateMatrix = null; Transform scaleMatrix = null; if (translateX != 0 || translateY != 0) { translateMatrix = new TranslateTransform(translateX, translateY); } if ((float)scaleX != 1.0f && (float)scaleY != 1.0f) { scaleMatrix = new ScaleTransform(scaleX, scaleY); } if (translateMatrix != null && scaleMatrix != null) { // Create a TransformGroup to contain the transforms // and add the transforms to it. TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(scaleMatrix); transformGroup.Children.Add(translateMatrix); return transformGroup; } else if (translateMatrix != null) { return translateMatrix; } else if (scaleMatrix != null) { return scaleMatrix; } return null; }
public SvgAnimatedRect(SvgRect rect) { _baseVal = rect; _animVal = _baseVal; }
public SvgAnimatedRect(string str) { _baseVal = new SvgRect(str); _animVal = _baseVal; }
public SvgAnimatedRect(SvgRect rect) { baseVal = rect; animVal = baseVal; }
public SvgAnimatedRect(string str) { baseVal = new SvgRect(str); animVal = baseVal; }
public double[] FitToViewBox(SvgRect viewBox, SvgRect rectToFit) { var localName = _ownerElement.LocalName; if (string.Equals(localName, "svg", StringComparison.Ordinal)) // (_ownerElement is SvgSvgElement) { ISvgMatrix mat = ((SvgSvgElement)_ownerElement).ViewBoxTransform; return(new double[] { mat.E, mat.F, mat.A, mat.D }); } if (string.Equals(localName, "pattern", StringComparison.Ordinal)) // (_ownerElement is SvgPatternElement) { ISvgMatrix mat = ((SvgPatternElement)_ownerElement).ViewBoxTransform; return(new double[] { mat.E, mat.F, mat.A, mat.D }); } double translateX = 0; double translateY = 0; double scaleX = 1; double scaleY = 1; if (!viewBox.IsEmpty && !rectToFit.IsEmpty) { // calculate scale values for non-uniform scaling scaleX = rectToFit.Width / viewBox.Width; scaleY = rectToFit.Height / viewBox.Height; if (_alignment != SvgPreserveAspectRatioType.None) { // uniform scaling if (_meetOrSlice == SvgMeetOrSlice.Meet) { scaleX = Math.Min(scaleX, scaleY); } else { scaleX = Math.Max(scaleX, scaleY); } scaleY = scaleX; if (_alignment == SvgPreserveAspectRatioType.XMidYMax || _alignment == SvgPreserveAspectRatioType.XMidYMid || _alignment == SvgPreserveAspectRatioType.XMidYMin) { // align to the Middle X translateX = (rectToFit.X + rectToFit.Width / 2) - scaleX * (viewBox.X + viewBox.Width / 2); } else if (_alignment == SvgPreserveAspectRatioType.XMaxYMax || _alignment == SvgPreserveAspectRatioType.XMaxYMid || _alignment == SvgPreserveAspectRatioType.XMaxYMin) { // align to the right X translateX = (rectToFit.Width - viewBox.Width * scaleX); } if (_alignment == SvgPreserveAspectRatioType.XMaxYMid || _alignment == SvgPreserveAspectRatioType.XMidYMid || _alignment == SvgPreserveAspectRatioType.XMinYMid) { // align to the Middle Y translateY = (rectToFit.Y + rectToFit.Height / 2) - scaleY * (viewBox.Y + viewBox.Height / 2); } else if (_alignment == SvgPreserveAspectRatioType.XMaxYMax || _alignment == SvgPreserveAspectRatioType.XMidYMax || _alignment == SvgPreserveAspectRatioType.XMinYMax) { // align to the bottom Y translateY = (rectToFit.Height - viewBox.Height * scaleY); } } else { translateX = -viewBox.X * scaleX; translateY = -viewBox.Y * scaleY; } } if (!SvgNumber.IsValid(translateX)) { translateX = 0; } if (!SvgNumber.IsValid(translateY)) { translateY = 0; } if (!SvgNumber.IsValid(scaleX)) { scaleX = 1; } if (!SvgNumber.IsValid(scaleY)) { scaleY = 1; } return(new double[] { translateX, translateY, scaleX, scaleY }); }
public SvgAnimatedRect(SvgRect rect) { baseVal = rect; animVal = baseVal; }
public SvgAnimatedRect(string str) { baseVal = new SvgRect(str); animVal = baseVal; }
private double[] FitToViewBox(SvgPreserveAspectRatioType alignment, SvgRect viewBox, SvgRect rectToFit) { double translateX = 0; double translateY = 0; double scaleX = 1; double scaleY = 1; if (!viewBox.IsEmpty) { // calculate scale values for non-uniform scaling scaleX = rectToFit.Width / viewBox.Width; scaleY = rectToFit.Height / viewBox.Height; if (alignment != SvgPreserveAspectRatioType.None) { // uniform scaling scaleX = Math.Max(scaleX, scaleY); scaleY = scaleX; if (alignment == SvgPreserveAspectRatioType.XMidYMax || alignment == SvgPreserveAspectRatioType.XMidYMid || alignment == SvgPreserveAspectRatioType.XMidYMin) { // align to the Middle X translateX = (rectToFit.X + rectToFit.Width / 2) - scaleX * (viewBox.X + viewBox.Width / 2); } else if (alignment == SvgPreserveAspectRatioType.XMaxYMax || alignment == SvgPreserveAspectRatioType.XMaxYMid || alignment == SvgPreserveAspectRatioType.XMaxYMin) { // align to the right X translateX = (rectToFit.Width - viewBox.Width * scaleX); } if (alignment == SvgPreserveAspectRatioType.XMaxYMid || alignment == SvgPreserveAspectRatioType.XMidYMid || alignment == SvgPreserveAspectRatioType.XMinYMid) { // align to the Middle Y translateY = (rectToFit.Y + rectToFit.Height / 2) - scaleY * (viewBox.Y + viewBox.Height / 2); } else if (alignment == SvgPreserveAspectRatioType.XMaxYMax || alignment == SvgPreserveAspectRatioType.XMidYMax || alignment == SvgPreserveAspectRatioType.XMinYMax) { // align to the bottom Y translateY = (rectToFit.Height - viewBox.Height * scaleY); } } else { translateX = -viewBox.X * scaleX; translateY = -viewBox.Y * scaleY; } } return new double[]{ translateX, translateY, scaleX, scaleY }; }
public float[] FitToViewBox(SvgRect viewBox, SvgRect rectToFit) { if (ownerElement is SvgSvgElement) { ISvgMatrix mat = ((SvgSvgElement)ownerElement).ViewBoxTransform; return new float[]{ (float) mat.E, (float) mat.F, (float) mat.A, (float) mat.D }; } double translateX = 0; double translateY = 0; double scaleX = 1; double scaleY = 1; if(!viewBox.IsEmpty) { // calculate scale values for non-uniform scaling scaleX = rectToFit.Width / viewBox.Width; scaleY = rectToFit.Height / viewBox.Height; if(Align != SvgPreserveAspectRatioType.None) { // uniform scaling if(MeetOrSlice == SvgMeetOrSlice.Meet) scaleX = Math.Min(scaleX, scaleY); else scaleX = Math.Max(scaleX, scaleY); scaleY = scaleX; if(Align == SvgPreserveAspectRatioType.XMidYMax || Align == SvgPreserveAspectRatioType.XMidYMid || Align == SvgPreserveAspectRatioType.XMidYMin) { // align to the Middle X translateX = (rectToFit.X + rectToFit.Width / 2) - scaleX * (viewBox.X + viewBox.Width / 2); } else if(Align == SvgPreserveAspectRatioType.XMaxYMax || Align == SvgPreserveAspectRatioType.XMaxYMid || Align == SvgPreserveAspectRatioType.XMaxYMin) { // align to the right X translateX = (rectToFit.Width - viewBox.Width * scaleX); } if(Align == SvgPreserveAspectRatioType.XMaxYMid || Align == SvgPreserveAspectRatioType.XMidYMid || Align == SvgPreserveAspectRatioType.XMinYMid) { // align to the Middle Y translateY = (rectToFit.Y + rectToFit.Height / 2) - scaleY * (viewBox.Y + viewBox.Height / 2); } else if(Align == SvgPreserveAspectRatioType.XMaxYMax || Align == SvgPreserveAspectRatioType.XMidYMax || Align == SvgPreserveAspectRatioType.XMinYMax) { // align to the bottom Y translateY = (rectToFit.Height - viewBox.Height * scaleY); } } else { translateX = -viewBox.X * scaleX; translateY = -viewBox.Y * scaleY; } } return new float[]{ (float) translateX, (float) translateY, (float) scaleX, (float) scaleY }; }
public double[] FitToViewBox(SvgRect viewBox, SvgRect rectToFit) { if (ownerElement is SvgSvgElement) { ISvgMatrix mat = ((SvgSvgElement)ownerElement).ViewBoxTransform; return(new double[] { mat.E, mat.F, mat.A, mat.D }); } double translateX = 0; double translateY = 0; double scaleX = 1; double scaleY = 1; if (!viewBox.IsEmpty) { // calculate scale values for non-uniform scaling scaleX = rectToFit.Width / viewBox.Width; scaleY = rectToFit.Height / viewBox.Height; if (_alignment != SvgPreserveAspectRatioType.None) { // uniform scaling if (_meetOrSlice == SvgMeetOrSlice.Meet) { scaleX = Math.Min(scaleX, scaleY); } else { scaleX = Math.Max(scaleX, scaleY); } scaleY = scaleX; if (_alignment == SvgPreserveAspectRatioType.XMidYMax || _alignment == SvgPreserveAspectRatioType.XMidYMid || _alignment == SvgPreserveAspectRatioType.XMidYMin) { // align to the Middle X translateX = (rectToFit.X + rectToFit.Width / 2) - scaleX * (viewBox.X + viewBox.Width / 2); } else if (_alignment == SvgPreserveAspectRatioType.XMaxYMax || _alignment == SvgPreserveAspectRatioType.XMaxYMid || _alignment == SvgPreserveAspectRatioType.XMaxYMin) { // align to the right X translateX = (rectToFit.Width - viewBox.Width * scaleX); } if (_alignment == SvgPreserveAspectRatioType.XMaxYMid || _alignment == SvgPreserveAspectRatioType.XMidYMid || _alignment == SvgPreserveAspectRatioType.XMinYMid) { // align to the Middle Y translateY = (rectToFit.Y + rectToFit.Height / 2) - scaleY * (viewBox.Y + viewBox.Height / 2); } else if (_alignment == SvgPreserveAspectRatioType.XMaxYMax || _alignment == SvgPreserveAspectRatioType.XMidYMax || _alignment == SvgPreserveAspectRatioType.XMinYMax) { // align to the bottom Y translateY = (rectToFit.Height - viewBox.Height * scaleY); } } else { translateX = -viewBox.X * scaleX; translateY = -viewBox.Y * scaleY; } } return(new double[] { translateX, translateY, scaleX, scaleY }); }
private Transform GetAspectRatioTransform(SvgPreserveAspectRatio spar, SvgRect sourceBounds, SvgRect elementBounds) { double[] transformArray = spar.FitToViewBox(sourceBounds, elementBounds); double translateX = transformArray[0]; double translateY = transformArray[1]; double scaleX = transformArray[2]; double scaleY = transformArray[3]; Transform translateMatrix = null; Transform scaleMatrix = null; if ((float)translateX >= 0 && (float)translateY >= 0) { translateMatrix = new TranslateTransform(translateX, translateY); } if ((float)scaleX != 1.0f && (float)scaleY != 1.0) { scaleMatrix = new ScaleTransform(scaleX, scaleY); } if (translateMatrix != null && scaleMatrix != null) { // Create a TransformGroup to contain the transforms // and add the transforms to it. TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(scaleMatrix); transformGroup.Children.Add(translateMatrix); return transformGroup; } else if (translateMatrix != null) { return translateMatrix; } else if (scaleMatrix != null) { return scaleMatrix; } return null; }