public MatrixTransform Multiply(MatrixTransform matrix) { if (matrix == null) return this; /* * "matrix("+(a1*a2+c1*b2)+","+ (b1*a2+d1*b2)+","+ (a1*c2+c1*d2)+","+ (b1*c2+d1*d2)+","+ (a1*e2+c1*g2+e1)+","+ (b1*e2+d1*g2+g1)+")" */ return new MatrixTransform { A = this.A * matrix.A + this.C * matrix.B, B = this.B * matrix.A + this.D * matrix.B, C = this.A * matrix.C + this.C * matrix.D, D = this.B * matrix.C + this.D * matrix.D, E = this.A * matrix.E + this.C * matrix.F + this.E, F = this.B * matrix.E + this.D * matrix.F + this.F }; }
static List<PathData> CreateTexts(XElement layer, MatrixTransform parentTransform) { var textElems = layer.Elements ("{" + layer.Name.NamespaceName + "}text"); if (textElems == null || !textElems.Any()) return new List<PathData> (); List<PathData> list = new List<PathData> (); foreach (var textElem in textElems) { List<PathData> pathData = CreateTextData(textElem, parentTransform); list.AddRange(pathData); } return list; }
static List<PathData> CreatePaths(XElement layer, MatrixTransform transform) { var pathElems = layer.Elements ("{" + layer.Name.NamespaceName + "}path"); if (pathElems == null || !pathElems.Any()) return new List<PathData> (); List<PathData> list = new List<PathData> (); foreach (var pathElem in pathElems) { PathData pathData = CreatePathData(pathElem, transform); list.Add(pathData); } return list; }
static List<PathData> CreateTextData(XElement textElem, MatrixTransform parentTransform) { if (textElem == null) return null; var globalData = new PathData(); XAttribute attr = textElem.Attribute ("style"); if (attr != null && !string.IsNullOrWhiteSpace(attr.Value)) { // парсим стили объекта string[] rawStyles = attr.Value.Split(';'); foreach (var rawStyle in rawStyles) { string name = rawStyle.Split(':')[0]; string val = rawStyle.Split(':')[1]; if (rawStyle.StartsWith("fill:")) globalData.color = val; if (rawStyle.StartsWith("fill-opacity:")) globalData.opacity = Convert.ToDouble(val, CultureInfo.InvariantCulture); if (rawStyle.StartsWith("font-size:")) globalData.fontSize = Convert.ToDouble(val.Replace("px",""), CultureInfo.InvariantCulture); if (rawStyle.StartsWith("font-family:")) globalData.fontFamily = val; if (rawStyle.StartsWith("font-weight:")) globalData.fontWeight = val; if (rawStyle.StartsWith("text-align:")) globalData.align = val; } } MatrixTransform transform = null; if (textElem.Attribute ("transform") != null) { transform = MatrixTransform.Parse (textElem.Attribute ("transform").Value); if (parentTransform != null) transform = parentTransform.Multiply (transform); } else { transform = parentTransform; } //if (transform != null) // globalData.matrix = transform.ToString (); List<PathData> list = new List<PathData>(); foreach (var spanElem in textElem.Elements ("{" + textElem.Name.NamespaceName + "}tspan")) { PathData pathData = globalData.Clone(); attr = spanElem.Attribute ("x"); pathData.x = Convert.ToDouble (attr.Value.Replace("px",""), CultureInfo.InvariantCulture); attr = spanElem.Attribute ("y"); pathData.y = Convert.ToDouble (attr.Value.Replace("px",""), CultureInfo.InvariantCulture); pathData.text = spanElem.Value; if (transform != null) transform.Apply(pathData); list.Add(pathData); } return list; }
static PathData CreatePathData(XElement pathElem, MatrixTransform parentTransform) { if (pathElem == null) return null; string objectPath = pathElem.Attribute ("d").Value; var transformAttr = pathElem.Attribute ("transform"); MatrixTransform transform = null; if (transformAttr != null) { transform = MatrixTransform.Parse (transformAttr.Value); if (parentTransform != null) transform = parentTransform.Multiply (transform); } else { transform = parentTransform; } PathData pathData = new PathData { path = objectPath }; var attr = pathElem.Attribute ("style"); if (attr != null && !string.IsNullOrWhiteSpace(attr.Value)) { // парсим стили объекта string[] rawStyles = attr.Value.Split(';'); foreach (var rawStyle in rawStyles) { string name = rawStyle.Split(':')[0]; string val = rawStyle.Split(':')[1]; switch (name) { case "fill": pathData.bgColor = val; break; case "fill-opacity": pathData.opacity = Convert.ToDouble (val, CultureInfo.InvariantCulture); break; case "stroke": pathData.borderColor = val; break; case "stroke-width": pathData.borderWidth = Convert.ToDouble (val.Replace ("px", ""), CultureInfo.InvariantCulture); break; case "stroke-linejoin": pathData.borderJoin = val; break; case "stroke-linecap": pathData.borderCap = val; break; } } } if (transform != null) { //pathData.matrix = transform.ToString (); transform.Apply(pathData); } return pathData; }