public ISvgMatrix GetTransformToElement(ISvgElement element) { ISvgLocatable loc = element as ISvgLocatable; ISvgMatrix ctm = loc.GetCTM(); ISvgMatrix vctm; XmlNode node = element.ParentNode; while (node != null && node != OwnerDocument) { if (string.Equals(node.Name, "svg", StringComparison.Ordinal)) { vctm = ((SvgSvgElement)node).ViewBoxTransform; ctm = vctm.Multiply(ctm); } else { loc = node as ISvgLocatable; ctm = loc.GetCTM().Multiply(ctm); } node = node.ParentNode; } return(ctm); }
public ISvgMatrix GetTransformToElement(ISvgElement element) { ISvgLocatable loc = element as ISvgLocatable; ISvgMatrix ctm = loc.GetCTM(); ISvgMatrix vctm; XmlNode node = element.ParentNode; while (node != null && node != OwnerDocument) { if (node.Name == "svg") { vctm = (node as SvgSvgElement).ViewBoxTransform; ctm = vctm.Multiply(ctm); } else { loc = node as ISvgLocatable; ctm = loc.GetCTM().Multiply(ctm); } node = node.ParentNode; } return(ctm); }
public static bool TryGetTransform(ISvgTransformable element, out Transform transform) { transform = null; if (element == null) { return(false); } ISvgTransformList svgTList = element.Transform.AnimVal; ISvgMatrix svgMatrix = ((SvgTransformList)element.Transform.AnimVal).TotalMatrix; ISvgElement nVE = element.NearestViewportElement; if (nVE != null) { SvgTransformableElement par = (element as SvgElement).ParentNode as SvgTransformableElement; while (par != null && par != nVE) { svgTList = par.Transform.AnimVal; svgMatrix = svgTList.Consolidate().Matrix.Multiply(svgMatrix); par = par.ParentNode as SvgTransformableElement; } } if (svgMatrix.IsIdentity) { transform = Transform.Identity; return(false); } transform = new MatrixTransform(ToWpfMatrix(svgMatrix)); return(true); }
public ISvgPoint MatrixTransform(ISvgMatrix matrix) { return(new SvgPoint( matrix.A * x + matrix.C * y + matrix.E, matrix.B * x + matrix.D * y + matrix.F )); }
public void TestScale() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.Scale(10); Assert.AreEqual(10, m2.A); Assert.AreEqual(20, m2.B); Assert.AreEqual(30, m2.C); Assert.AreEqual(40, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestRotate() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.Rotate(30); Assert.AreEqual(2.36602540378444f, m2.A); Assert.AreEqual(3.73205080756888f, m2.B); Assert.AreEqual(2.09807621135332f, m2.C); Assert.AreEqual(2.46410161513775f, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestScaleNonUniform() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.ScaleNonUniform(10, 20); Assert.AreEqual(10, m2.A); Assert.AreEqual(20, m2.B); Assert.AreEqual(60, m2.C); Assert.AreEqual(80, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestFlipY() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.FlipY(); Assert.AreEqual(1, m2.A); Assert.AreEqual(2, m2.B); Assert.AreEqual(-3, m2.C); Assert.AreEqual(-4, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestSkewY() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.SkewY(30); Assert.AreEqual(2.73205080756888f, m2.A); Assert.AreEqual(4.3094010767585f, m2.B); Assert.AreEqual(3, m2.C); Assert.AreEqual(4, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestSkewX() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.SkewX(30); Assert.AreEqual(1, m2.A); Assert.AreEqual(2, m2.B); Assert.AreEqual(3.57735026918963f, m2.C); Assert.AreEqual(5.15470053837925f, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestInverse() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.Inverse(); Assert.AreEqual(-2, m2.A); Assert.AreEqual(1, m2.B); Assert.AreEqual(1.5, m2.C); Assert.AreEqual(-0.5, m2.D); Assert.AreEqual(1, m2.E); Assert.AreEqual(-2, m2.F); }
public void TestTranslate() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.Translate(10, 20); Assert.AreEqual(1, m2.A); Assert.AreEqual(2, m2.B); Assert.AreEqual(3, m2.C); Assert.AreEqual(4, m2.D); Assert.AreEqual(75, m2.E); Assert.AreEqual(106, m2.F); }
public void TestMultiply() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = new SvgMatrix(7, 8, 9, 10, 11, 12); ISvgMatrix m3 = m1.Multiply(m2); Assert.AreEqual(31, m3.A); Assert.AreEqual(46, m3.B); Assert.AreEqual(39, m3.C); Assert.AreEqual(58, m3.D); Assert.AreEqual(52, m3.E); Assert.AreEqual(76, m3.F); }
public ISvgMatrix Multiply(ISvgMatrix secondMatrix) { SvgMatrix matrix = (SvgMatrix)secondMatrix; return(new SvgMatrix( this.a * matrix.a + this.c * matrix.b, this.b * matrix.a + this.d * matrix.b, this.a * matrix.c + this.c * matrix.d, this.b * matrix.c + this.d * matrix.d, this.a * matrix.e + this.c * matrix.f + this.e, this.b * matrix.e + this.d * matrix.f + this.f )); }
public ISvgMatrix Multiply(ISvgMatrix secondMatrix) { if (secondMatrix == null) { secondMatrix = new SvgMatrix(); } SvgMatrix matrix = (SvgMatrix)secondMatrix; return(new SvgMatrix(_a * matrix._a + _c * matrix._b, _b * matrix._a + _d * matrix._b, _a * matrix._c + _c * matrix._d, _b * matrix._c + _d * matrix._d, _a * matrix._e + _c * matrix._f + _e, _b * matrix._e + _d * matrix._f + _f)); }
public void TestRotateFromVector() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.RotateFromVector(1.73205080756888f, 1); Assert.AreEqual(2.36602540378444f, m2.A); Assert.AreEqual(3.73205080756888f, m2.B); Assert.AreEqual(2.09807621135332f, m2.C); //D property incorrect when using doubles, probably due to rounding //Assert.AreEqual(2.46410161513775, m2.D); Assert.AreEqual(2.46410161513776f, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void Resize() { // TODO: Invalidate! Fire SVGResize _x = null; _y = null; _width = null; _height = null; _currentView = null; _cachedViewBoxTransform = null; _viewport = null; _svgFitToViewBox = null; _svgFitToViewBox = new SvgFitToViewBox(this); if (this != OwnerDocument.RootElement) { (OwnerDocument.RootElement as SvgSvgElement).Resize(); } }
public void Resize() { // TODO: Invalidate! Fire SVGResize width = null; height = null; x = null; y = null; currentView = null; cachedViewBoxTransform = null; viewport = null; svgFitToViewBox = null; svgFitToViewBox = new SvgFitToViewBox(this); if (this == OwnerDocument.RootElement) { // TODO } else { (OwnerDocument.RootElement as SvgSvgElement).Resize(); } }
public void SetTranslate(double tx, double ty) { _type = SvgTransformType.Translate; _matrix = new SvgMatrix().Translate(tx, ty); }
public void SetScale(double sx, double sy) { _type = SvgTransformType.Scale; _matrix = new SvgMatrix().ScaleNonUniform(sx, sy); }
public void SetRotate(double angle) { _type = SvgTransformType.Rotate; _angle = angle; _matrix = new SvgMatrix().Rotate(angle); }
public void SetRotate(double angle, double cx, double cy) { _type = SvgTransformType.Rotate; _angle = angle; _matrix = new SvgMatrix().Translate(cx, cy).Rotate(angle).Translate(-cx, -cy); }
public void TestRotateFromVectorZeroY() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 6, 0, 0); ISvgMatrix m2 = m1.RotateFromVector(1, 0); }
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 void SetTranslate(float tx, float ty) { type = (short) SvgTransform.SvgTransformType.Translate; matrix = new SvgMatrix().Translate(tx, ty); }
public void SetRotate(float angle, float cx, float cy) { type = (short) SvgTransform.SvgTransformType.Rotate; this.angle = angle; matrix = new SvgMatrix().Translate(cx, cy).Rotate(angle).Translate(-cx,-cy); }
public void SetMatrix(ISvgMatrix matrix) { type = (short) SvgTransform.SvgTransformType.Matrix; this.matrix = matrix; }
public ISvgPoint MatrixTransform(ISvgMatrix matrix) { return new SvgPoint(matrix.A*x + matrix.C*y + matrix.E, matrix.B*x + matrix.D*y + matrix.F); }
public void SetSkewY(float angle) { type = (short) SvgTransform.SvgTransformType.SkewY; this.angle = angle; matrix = new SvgMatrix().SkewY(angle); }
/// <summary> /// Creates an SVGTransform object outside of any document trees. The object is /// initialized to the given matrix transform (i.e., SVG_TRANSFORM_MATRIX). /// </summary> /// <param name="matrix">The transform matrix.</param> /// <returns>An SVGTransform object.</returns> public ISvgTransform CreateSvgTransformFromMatrix(ISvgMatrix matrix) { return new SvgTransform(matrix); }
public SvgTransform(ISvgMatrix matrix) { this.type = (short) SvgTransformType.Matrix; this.matrix = matrix; }
public SvgTransform(ISvgMatrix matrix) { _type = SvgTransformType.Matrix; _matrix = matrix; }
public void TestNoInverse() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 6, 0, 0); ISvgMatrix m2 = m1.Inverse(); }
public void SetSkewY(double angle) { _type = SvgTransformType.SkewY; _angle = angle; _matrix = new SvgMatrix().SkewY(angle); }
public void SetScale(float sx, float sy) { type = (short) SvgTransform.SvgTransformType.Scale; matrix = new SvgMatrix().ScaleNonUniform(sx, sy); }
public void SetRotate(float angle) { type = (short) SvgTransform.SvgTransformType.Rotate; this.angle = angle; matrix = new SvgMatrix().Rotate(angle); }
private SvgRectF GetElementBounds(SvgTransformableElement element, float margin) { SvgRenderingHint hint = element.RenderingHint; if (hint == SvgRenderingHint.Shape || hint == SvgRenderingHint.Text) { GraphicsPath gp = GdiRendering.CreatePath(element); ISvgMatrix svgMatrix = element.GetScreenCTM(); Matrix matrix = new Matrix((float)svgMatrix.A, (float)svgMatrix.B, (float)svgMatrix.C, (float)svgMatrix.D, (float)svgMatrix.E, (float)svgMatrix.F); SvgRectF bounds = SvgConverter.ToRect(gp.GetBounds(matrix)); bounds = SvgRectF.Inflate(bounds, margin, margin); return(bounds); } SvgUseElement useElement = element as SvgUseElement; if (useElement != null) { SvgTransformableElement refEl = useElement.ReferencedElement as SvgTransformableElement; if (refEl == null) { return(SvgRectF.Empty); } XmlElement refElParent = (XmlElement)refEl.ParentNode; element.OwnerDocument.Static = true; useElement.CopyToReferencedElement(refEl); element.AppendChild(refEl); SvgRectF bbox = this.GetElementBounds(refEl, margin); element.RemoveChild(refEl); useElement.RestoreReferencedElement(refEl); refElParent.AppendChild(refEl); element.OwnerDocument.Static = false; return(bbox); } SvgRectF union = SvgRectF.Empty; SvgTransformableElement transformChild; foreach (XmlNode childNode in element.ChildNodes) { if (childNode is SvgDefsElement) { continue; } if (childNode is ISvgTransformable) { transformChild = (SvgTransformableElement)childNode; SvgRectF bbox = this.GetElementBounds(transformChild, margin); if (bbox != SvgRectF.Empty) { if (union == SvgRectF.Empty) { union = bbox; } else { union = SvgRectF.Union(union, bbox); } } } } return(union); }
public ISvgMatrix Multiply(ISvgMatrix secondMatrix) { if (secondMatrix == null) { secondMatrix = new SvgMatrix(); } SvgMatrix matrix = (SvgMatrix)secondMatrix; return new SvgMatrix( this.a * matrix.a + this.c * matrix.b, this.b * matrix.a + this.d * matrix.b, this.a * matrix.c + this.c * matrix.d, this.b * matrix.c + this.d * matrix.d, this.a * matrix.e + this.c * matrix.f + this.e, this.b * matrix.e + this.d * matrix.f + this.f ); }
public void Resize() { // TODO: Invalidate! Fire SVGResize x = null; y = null; width = null; height = null; currentView = null; cachedViewBoxTransform = null; viewport = null; svgFitToViewBox = null; svgFitToViewBox = new SvgFitToViewBox(this); if (this == OwnerDocument.RootElement) { // TODO } else { (OwnerDocument.RootElement as SvgSvgElement).Resize(); } }
public static Matrix ToWpfMatrix(ISvgMatrix svgMatrix) { return(new Matrix(svgMatrix.A, svgMatrix.B, svgMatrix.C, svgMatrix.D, svgMatrix.E, svgMatrix.F)); }
/// <summary> /// Creates an SVGTransform object outside of any document trees. The object is /// initialized to the given matrix transform (i.e., SVG_TRANSFORM_MATRIX). /// </summary> /// <param name="matrix">The transform matrix.</param> /// <returns>An SVGTransform object.</returns> public ISvgTransform CreateSvgTransformFromMatrix(ISvgMatrix matrix) { return(new SvgTransform(matrix)); }
public void SetSkewX(double angle) { type = (short) SvgTransform.SvgTransformType.SkewX; this.angle = angle; matrix = new SvgMatrix().SkewX(angle); }