/// <summary> /// Write out the image associated with the symbol. /// </summary> /// <param name="ms"> /// The symbol for which to write out the image. /// </param> /// <param name="rootName"> /// The name associated with the symbol. /// </param> private void WriteImage(MilSymbol ms, string rootName) { const double Scale = 0.333333; var ct = new CompositeTransform(); ct.ScaleX = ct.ScaleY = Scale; ct.TranslateX = -ms.Bounds.Left * Scale; ct.TranslateY = -ms.Bounds.Top * Scale; ms.RenderTransform = ct; target.Width = Scale * ms.Bounds.Width; target.Height = Scale * ms.Bounds.Height; var path = new System.Windows.Shapes.Path { Fill = new SolidColorBrush(Colors.White), Stroke = new SolidColorBrush(Colors.White), StrokeThickness = 3.0, Data = new RectangleGeometry { Rect = new Rect(0, 0, target.Width - 1, target.Height - 1) } }; target.Children.Add(path); target.Children.Add(ms); #if DO_WRITES this.SaveImage(rootName); #endif target.Children.Clear(); }
private UIElement ConvertPathToEllipse(XElement path) { System.Windows.Shapes.Path ellipsePath = new System.Windows.Shapes.Path(); var geometryData = new EllipseGeometry(); if ((path.Attribute("cx") != null) && (path.Attribute("cy") != null)) { geometryData.Center = new Point(double.Parse(path.Attribute("cx").Value), double.Parse(path.Attribute("cy").Value)); } if (path.Attribute("rx") != null) { geometryData.RadiusX = double.Parse(path.Attribute("rx").Value); } if (path.Attribute("ry") != null) { geometryData.RadiusY = double.Parse(path.Attribute("ry").Value); } if (path.Attribute("transform") != null) { var matrixTransformationValues = Helper.GetMatrixValuesFromXml(path, Helper.MatrixType.PathMatrix); MatrixTransform matrixTransform = new MatrixTransform(double.Parse(matrixTransformationValues[0]), double.Parse(matrixTransformationValues[1]), double.Parse(matrixTransformationValues[2]), double.Parse(matrixTransformationValues[3]), double.Parse(matrixTransformationValues[4]), double.Parse(matrixTransformationValues[5])); geometryData.Transform = matrixTransform; } ellipsePath.Data = geometryData; if (path.Attribute("fill") != null) { ellipsePath.Fill = GetBrushFromXElement(path, "fill"); } else { ellipsePath.Fill = Brushes.Black; } if (path.Attribute("stroke") != null) { ellipsePath.Stroke = GetBrushFromXElement(path, "stroke"); } if (path.Attribute("stroke-width") != null) { ellipsePath.StrokeThickness = double.Parse(path.Attribute("stroke-width").Value); } ellipsePath.Opacity = GetOpacityFromXElement(path); return ellipsePath; }
private UIElement ConvertPathToRectangle(XElement path) { var rectanglePath = new System.Windows.Shapes.Path(); var geometryData = new RectangleGeometry(); if ((path.Attribute("x") != null) && (path.Attribute("y") != null) && (path.Attribute("width") != null) && (path.Attribute("height") != null)) { geometryData.Rect = new Rect { Location = new Point(double.Parse(path.Attribute("x").Value), double.Parse(path.Attribute("y").Value)), Width = double.Parse(path.Attribute("width").Value), Height = double.Parse(path.Attribute("height").Value) }; } if (path.Attribute("transform") != null) { var matrixTransformationValues = Helper.GetMatrixValuesFromXml(path, Helper.MatrixType.PathMatrix); MatrixTransform matrixTransform = new MatrixTransform(double.Parse(matrixTransformationValues[0]), double.Parse(matrixTransformationValues[1]), double.Parse(matrixTransformationValues[2]), double.Parse(matrixTransformationValues[3]), double.Parse(matrixTransformationValues[4]), double.Parse(matrixTransformationValues[5])); geometryData.Transform = matrixTransform; } rectanglePath.Data = geometryData; if (path.Attribute("fill") != null) { rectanglePath.Fill = GetBrushFromXElement(path, "fill"); } else { rectanglePath.Fill = Brushes.Black; } if (path.Attribute("stroke") != null) { rectanglePath.Stroke = GetBrushFromXElement(path, "stroke"); } if (path.Attribute("stroke-width") != null) { rectanglePath.StrokeThickness = double.Parse(path.Attribute("stroke-width").Value); } rectanglePath.Opacity = GetOpacityFromXElement(path); return rectanglePath; }
private UIElement ConvertCustomPathToPath(XElement path) { System.Windows.Shapes.Path customPath = new System.Windows.Shapes.Path(); var geometryData = new PathGeometry(); if (path.Attribute("transform") != null) { var matrixTransformationValues = Helper.GetMatrixValuesFromXml(path, Helper.MatrixType.PathMatrix); MatrixTransform matrixTransform = new MatrixTransform(double.Parse(matrixTransformationValues[0]), double.Parse(matrixTransformationValues[1]), double.Parse(matrixTransformationValues[2]), double.Parse(matrixTransformationValues[3]), double.Parse(matrixTransformationValues[4]), double.Parse(matrixTransformationValues[5])); geometryData.Transform = matrixTransform; } if (path.Attribute("d") != null) { geometryData.AddGeometry(Geometry.Parse(path.Attribute("d").Value)); } if (path.Attribute("fill") != null) { customPath.Fill = GetBrushFromXElement(path, "fill"); } else { customPath.Fill = Brushes.Black; } if (path.Attribute("stroke") != null) { customPath.Stroke = GetBrushFromXElement(path, "stroke"); } if (path.Attribute("stroke-width") != null) { customPath.StrokeThickness = double.Parse(path.Attribute("stroke-width").Value); } customPath.Opacity = GetOpacityFromXElement(path); customPath.Data = geometryData; string fillData = string.Empty; Brush brush = customPath.Fill; if (brush is LinearGradientBrush || brush is RadialGradientBrush) { GradientBrush linearBrush = brush as GradientBrush; foreach (var gradientStop in linearBrush.GradientStops) { fillData += "Stop: " + gradientStop.Offset + " Colour: " + gradientStop.Color + Environment.NewLine; } } else { fillData = brush.ToString(); } customPath.Tag = "Data: " + customPath.Data + Environment.NewLine + "Stroke: " + customPath.Stroke + Environment.NewLine + "Fill: " + fillData + Environment.NewLine; customPath.PreviewMouseUp += customPath_MouseUp; return customPath; }