private void ParseSkewY(StringPtr ptr) { if (ptr.String.StartsWith("skewY")) { ptr += 5; ptr.AdvanceWhiteSpace(); if (ptr.Char == '(') { ++ptr; ptr.AdvanceWhiteSpace(); var angle = ParseNumber(ptr).Value; this.ParseCommaOrWhitespace(ptr); ptr.AdvanceWhiteSpace(); if (ptr.Char == ')') { ++ptr; this.Transforms.Add(SvgTransform.CreateSkewY(angle)); return; } } throw new ArgumentException("transformData"); } }
public SelectionRectangleHandler(List <SvgRectangle> quads, List <SvgRectangle> selected, SvgTransform rectTransform, SvgText label, SvgRectangle selectionRect, string sessionID) : base(selectionRect, sessionID) { FQuads = quads; FSelectedQuads = selected; FRectTransform = rectTransform; FLabel = label; }
public SvgEllipse() { X = 0; Y = 0; RadiusX = 0; RadiusY = 0; Style = null; Transform = null; }
public SvgEllipse(float x, float y, float radiusX, float radiusY, SvgStyle style) { X = x; Y = y; RadiusX = radiusX; RadiusY = radiusY; Style = style; Transform = null; }
private void ParseRotate(StringPtr ptr) { if (ptr.String.StartsWith("rotate")) { ptr += 6; ptr.AdvanceWhiteSpace(); if (ptr.Char == '(') { ++ptr; ptr.AdvanceWhiteSpace(); var r = ParseNumber(ptr).Value; var current = ptr.Index; this.ParseCommaOrWhitespace(ptr); var cx = ParseNumber(ptr); if (cx.HasValue) { this.ParseCommaOrWhitespace(ptr); var cy = ParseNumber(ptr).Value; this.ParseCommaOrWhitespace(ptr); ptr.AdvanceWhiteSpace(); if (ptr.Char == ')') { ++ptr; this.Transforms.Add(SvgTransform.CreateRotate(r, cx.Value, cy)); return; } } else { ptr.Index = current; ptr.AdvanceWhiteSpace(); if (ptr.Char == ')') { ++ptr; this.Transforms.Add(SvgTransform.CreateRotate(r)); return; } } } throw new ArgumentException("transformData"); } }
public static Matrix GetTransformMatrix(SvgElement element) { ISvgTransformable transElm = element as ISvgTransformable; if (transElm == null) { return(Matrix.Identity); } SvgTransformList svgTList = (SvgTransformList)transElm.Transform.AnimVal; SvgTransform svgTransform = (SvgTransform)svgTList.Consolidate(); SvgMatrix svgMatrix = ((SvgTransformList)transElm.Transform.AnimVal).TotalMatrix; return(new Matrix(svgMatrix.A, svgMatrix.B, svgMatrix.C, svgMatrix.D, svgMatrix.E, svgMatrix.F)); }
private void ParseTranslate(StringPtr ptr) { if (ptr.String.StartsWith("translate")) { ptr += 9; ptr.AdvanceWhiteSpace(); if (ptr.Char == '(') { ++ptr; ptr.AdvanceWhiteSpace(); var tx = ParseNumber(ptr).Value; var current = ptr.Index; this.ParseCommaOrWhitespace(ptr); var ty = ParseNumber(ptr); if (ty.HasValue) { this.ParseCommaOrWhitespace(ptr); ptr.AdvanceWhiteSpace(); if (ptr.Char == ')') { ++ptr; this.Transforms.Add(SvgTransform.CreateTranslate(tx, ty.Value)); return; } } else { ptr.Index = current; ptr.AdvanceWhiteSpace(); if (ptr.Char == ')') { ++ptr; this.Transforms.Add(SvgTransform.CreateTranslate(tx, 0.0F)); return; } } } throw new ArgumentException("transformData"); } }
private void ParseMatrix(StringPtr ptr) { if (ptr.String.StartsWith("matrix")) { ptr += 6; ptr.AdvanceWhiteSpace(); if (ptr.Char == '(') { ++ptr; ptr.AdvanceWhiteSpace(); var a = ParseNumber(ptr).Value; this.ParseCommaOrWhitespace(ptr); var b = ParseNumber(ptr).Value; this.ParseCommaOrWhitespace(ptr); var c = ParseNumber(ptr).Value; this.ParseCommaOrWhitespace(ptr); var d = ParseNumber(ptr).Value; this.ParseCommaOrWhitespace(ptr); var e = ParseNumber(ptr).Value; this.ParseCommaOrWhitespace(ptr); var f = ParseNumber(ptr).Value; this.ParseCommaOrWhitespace(ptr); ptr.AdvanceWhiteSpace(); if (ptr.Char == ')') { ++ptr; this.Transforms.Add(SvgTransform.CreateMatrix(new SvgMatrix(a, b, c, d, e, f))); return; } } throw new ArgumentException("transformData"); } }
internal SvgUseElement(INode parent, XmlElement element) : base(parent, element) { this._stylableHelper = new SvgStylableHelper(this, element); this._transformableHelper = new SvgTransformableHelper(element); var nan = new SvgLength(SvgLength.SvgLengthType.Unknown, float.NaN); this.X = element.ParseCoordinate("x", nan); this.Y = element.ParseCoordinate("y", nan); this.Width = element.ParseLength("width", nan); this.Height = element.ParseLength("height", nan); this.Href = element.GetAttribute("xlink:href").Substring(1); var child = (SvgElement)this.OwnerDocument.GetElementById(this.Href).CloneNode(true); if (child.GetType() == typeof(SvgSymbolElement)) { throw new NotImplementedException(); } else if (child.GetType() == typeof(SvgRectElement)) { var casted = (SvgRectElement)child; if (this.Width.UnitType != SvgLength.SvgLengthType.Unknown) { casted.Width = this.Width; } if (this.Height.UnitType != SvgLength.SvgLengthType.Unknown) { casted.Height = this.Height; } } this.InstanceRoot = child; if (this.X.UnitType != SvgLength.SvgLengthType.Unknown && this.Y.UnitType != SvgLength.SvgLengthType.Unknown) { this.Transform.Add(SvgTransform.CreateTranslate( this.X.UnitType != SvgLength.SvgLengthType.Unknown ? this.X.ValueAsPixel : 0.0F, this.Y.UnitType != SvgLength.SvgLengthType.Unknown ? this.Y.ValueAsPixel : 0.0F)); } }
internal SvgUseElement(INode parent, XmlElement element) : base(parent, element) { this._stylableHelper = new SvgStylableHelper(this, element); this._transformableHelper = new SvgTransformableHelper(element); var nan = new SvgLength(SvgLength.SvgLengthType.Unknown, float.NaN); this.X = element.ParseCoordinate("x", nan); this.Y = element.ParseCoordinate("y", nan); this.Width = element.ParseLength("width", nan); this.Height = element.ParseLength("height", nan); this.Href = element.GetAttributeNS("http://www.w3.org/1999/xlink", "href").Substring(1); this._instanceRoot = new Lazy <SvgElement>(this.CreateInstanceRoot, true); if (this.X.UnitType != SvgLength.SvgLengthType.Unknown && this.Y.UnitType != SvgLength.SvgLengthType.Unknown) { this.Transform.Add(SvgTransform.CreateTranslate( this.X.UnitType != SvgLength.SvgLengthType.Unknown ? this.X.ValueAsPixel : 0.0F, this.Y.UnitType != SvgLength.SvgLengthType.Unknown ? this.Y.ValueAsPixel : 0.0F)); } }
public static Matrix GetTransformMatrix(SvgElement element, TransformGroup transform) { ISvgTransformable transElm = element as ISvgTransformable; if (transElm == null) { return(Matrix.Identity); } SvgTransformList svgTList = (SvgTransformList)transElm.Transform.AnimVal; SvgTransform svgTransform = (SvgTransform)svgTList.Consolidate(); SvgMatrix svgMatrix = ((SvgTransformList)transElm.Transform.AnimVal).TotalMatrix; var matrix = new Matrix(svgMatrix.A, svgMatrix.B, svgMatrix.C, svgMatrix.D, svgMatrix.E, svgMatrix.F); if (!matrix.IsIdentity) { transform.Children.Add(new MatrixTransform(matrix)); } return(matrix); }
private void RenderTextPath(SvgTextPathElement textPath, ref Point ctp, double rotate, WpfTextPlacement placement) { if (textPath.ChildNodes == null || textPath.ChildNodes.Count == 0) { return; } SvgElement targetPath = textPath.ReferencedElement as SvgElement; if (targetPath == null) { return; } Geometry textGeometry = CreateGeometry(targetPath, true); if (textGeometry == null) { return; } PathGeometry pathGeometry = textGeometry as PathGeometry; if (pathGeometry == null) { pathGeometry = textGeometry.GetFlattenedPathGeometry(); } // If the path has a transform, apply it to get a transformed path... if (targetPath.HasAttribute("transform")) { var svgTransform = new SvgTransform(targetPath.GetAttribute("transform")); var svgMatrix = svgTransform.Matrix; if (!svgMatrix.IsIdentity) { pathGeometry.Transform = new MatrixTransform(svgMatrix.A, svgMatrix.B, svgMatrix.C, svgMatrix.D, svgMatrix.E, svgMatrix.F); var transformPath = new PathGeometry(); transformPath.AddGeometry(pathGeometry); pathGeometry = transformPath; } } WpfPathTextBuilder pathBuilder = new WpfPathTextBuilder(_textElement); pathBuilder.BeginTextPath(textPath); var comparer = StringComparison.OrdinalIgnoreCase; XmlNodeType nodeType = XmlNodeType.None; int nodeCount = textPath.ChildNodes.Count; for (int i = 0; i < nodeCount; i++) { XmlNode child = textPath.ChildNodes[i]; nodeType = child.NodeType; if (nodeType == XmlNodeType.Text) { var nodeText = GetText(textPath, child); if (i == (nodeCount - 1)) { // No need to render the last white space... if (nodeCount == 1) { if (nodeText.StartsWith(NonBreaking, StringComparison.OrdinalIgnoreCase)) { if (!nodeText.EndsWith(NonBreaking, StringComparison.OrdinalIgnoreCase)) { nodeText = nodeText.TrimEnd(); } } else if (nodeText.EndsWith(NonBreaking, StringComparison.OrdinalIgnoreCase)) { nodeText = nodeText.TrimStart(); } else { nodeText = nodeText.Trim(); } } else { if (!nodeText.EndsWith(NonBreaking, StringComparison.OrdinalIgnoreCase)) { nodeText = nodeText.TrimEnd(); } } } else if (i == 0) { nodeText = nodeText.Trim(); } RenderTextPath(textPath, pathBuilder, nodeText, new Point(ctp.X, ctp.Y), rotate, placement); } else if (nodeType == XmlNodeType.Element) { string nodeName = child.Name; if (string.Equals(nodeName, "tref", comparer)) { RenderTRefPath((SvgTRefElement)child, pathBuilder, ref ctp); } else if (string.Equals(nodeName, "tspan", comparer)) { RenderTSpanPath((SvgTSpanElement)child, pathBuilder, ref ctp); } } } WpfTextStringFormat stringFormat = GetTextStringFormat(textPath); //ISvgAnimatedLength pathOffset = textPath.StartOffset; //SvgTextPathMethod pathMethod = (SvgTextPathMethod)textPath.Method.BaseVal; //SvgTextPathSpacing pathSpacing = (SvgTextPathSpacing)textPath.Spacing.BaseVal; pathBuilder.RenderTextPath(_drawContext, pathGeometry, stringFormat.Alignment); pathBuilder.EndTextPath(); }