public void Build(Selection selection) { // check visibility Visible = selection.ForAll(f => RendererDecorator.ContainsType(f.Renderer, typeof(ShadowRendererDecorator))); if (!Visible) { return; // do not build anything } // remember editing object _selection = selection; // get list of objects var shadowStyles = _selection.Select(f => (ShadowRendererDecorator)RendererDecorator.GetDecorator(f.Renderer, typeof(ShadowRendererDecorator))).ToList(); // copy properties of object to GUI _updating++; nudOpacity.Value = shadowStyles.GetProperty(f => (decimal)f.Opacity); nudOffsetX.Value = shadowStyles.GetProperty(f => (decimal)f.Offset.X); nudOffsetY.Value = shadowStyles.GetProperty(f => (decimal)f.Offset.Y); lbColor.BackColor = shadowStyles.GetProperty(f => f.Color, Color.Black); _updating--; }
private void UpdateObject() { if (_updating > 0) { return; // we are in updating mode } // fire event StartChanging(this, new ChangingEventArgs("Image Fill Style")); // get list of objects foreach (var fig in _selection.Where(f => RendererDecorator.GetBaseRenderer(f.Renderer) is ImageRenderer)) { var renderer = (ImageRenderer)RendererDecorator.GetBaseRenderer(fig.Renderer); var firstIsEmpty = renderer.Image.Bitmap == null; renderer.Image = (Bitmap)_image; if (firstIsEmpty) { var bounds = fig.GetTransformedPath().Path.GetBounds(); var x = bounds.X; var y = bounds.Y; var width = renderer.Image.Bitmap.Width; var height = renderer.Image.Bitmap.Height; var m = new Matrix(); m.Translate(x + width / 2f, y + height / 2f); m.Scale(width, height); fig.Transform.Matrix = m; } } // fire event Changed(this, EventArgs.Empty); }
public static bool ContainsAnyDecorator(Figure figure) { var result = false; result |= RendererDecorator.ContainsAnyDecorator(figure.Renderer); result |= FillDecorator.ContainsAnyDecorator(figure.Style.FillStyle); return(result); }
/// <summary> /// Перемещение точки искажения /// </summary> /// <param name="owner">Фигура</param> /// <param name="index">Индекс точки искажения</param> /// <param name="newPosition">Смещение</param> public void MoveWarpNode(Figure owner, int index, PointF newPosition) { var warped = (WarpRendererDecorator)RendererDecorator.GetDecorator(owner.Renderer, typeof(WarpRendererDecorator)); if (warped == null) { return; // работаем только с градиентами } //get points in world coordinates var points = warped.GetWarpPoints(owner); //move point points[index] = newPosition; //push warped.SetWarpPoints(owner, points); }
private void UpdateObject() { if (_updating > 0) { return; // we are in updating mode } // fire event StartChanging(this, new ChangingEventArgs("Glow Fill Style")); // get list of objects var glowStyles = _selection.Select(f => (GlowRenderer)RendererDecorator.GetDecorator(f.Renderer, typeof(GlowRenderer))).ToList(); // send values back from GUI to object glowStyles.SetProperty(f => f.Color = lbColor.BackColor); // fire event Changed(this, EventArgs.Empty); }
public void Build(Selection selection) { // check visibility Visible = selection.ForAll(f => RendererDecorator.GetBaseRenderer(f.Renderer) is ITextBlock || RendererDecorator.GetDecorator(f.Renderer, typeof(TextBlockDecorator)) is ITextBlock); if (!Visible) { return; // do not build anything } // remember editing object _selection = selection; var textBlockStyles = from figure in _selection where RendererDecorator.GetBaseRenderer(figure.Renderer) is ITextBlock || RendererDecorator.GetDecorator(figure.Renderer, typeof(TextBlockDecorator)) is ITextBlock let decorator = RendererDecorator.GetBaseRenderer(figure.Renderer) is ITextBlock? RendererDecorator.GetBaseRenderer(figure.Renderer) as ITextBlock: RendererDecorator.GetDecorator(figure.Renderer, typeof(TextBlockDecorator)) as ITextBlock select decorator; var isBezierText = selection.ForAll(f => RendererDecorator.GetBaseRenderer(f.Renderer) is BezierTextRenderer); _updating++; cbFontName.Text = textBlockStyles.GetProperty(f => f.FontName); cbFontSize.Text = textBlockStyles.GetProperty(f => f.FontSize.ToString("0")); _fontStyle = textBlockStyles.GetProperty(f => f.FontStyle); lbText.Text = textBlockStyles.GetProperty(f => f.Text); lbText.TextAlign = textBlockStyles.GetProperty(f => f.Alignment); nudLeft.Value = textBlockStyles.GetProperty(f => f.Padding.Left); nudTop.Value = textBlockStyles.GetProperty(f => f.Padding.Top); nudRight.Value = textBlockStyles.GetProperty(f => f.Padding.Right); nudBottom.Value = textBlockStyles.GetProperty(f => f.Padding.Bottom); cbWrap.Checked = textBlockStyles.GetProperty(f => f.WordWrap); cbWrap.Enabled = nudLeft.Enabled = nudTop.Enabled = nudRight.Enabled = nudBottom.Enabled = btnTopLeftAllign.Enabled = btnMiddleLeftAllign.Enabled = btnBottomLeftAllign.Enabled = btnTopRightAllign.Enabled = btnMiddleRightAllign.Enabled = btnBottomRightAllign.Enabled = !isBezierText; _updating--; }
public void Build(Selection selection) { // check visibility Visible = selection.ForAll(f => RendererDecorator.ContainsType(f.Renderer, typeof(GlowRenderer))); if (!Visible) { return; // do not build anything } // remember editing object _selection = selection; // get list of objects var glowStyles = _selection.Select(f => (GlowRenderer)RendererDecorator.GetDecorator(f.Renderer, typeof(GlowRenderer))).ToList(); // copy properties of object to GUI _updating++; lbColor.BackColor = glowStyles.GetProperty(f => f.Color); _updating--; }
private void UpdateObject() { if (_updating > 0) { return; // we are in updating mode } // fire event StartChanging(this, new ChangingEventArgs("Shadow Fill Style")); // get list of objects var shadowStyles = _selection.Select(f => (ShadowRendererDecorator)RendererDecorator.GetDecorator(f.Renderer, typeof(ShadowRendererDecorator))).ToList(); // send values back from GUI to object shadowStyles.SetProperty(f => f.Opacity = (int)nudOpacity.Value); shadowStyles.SetProperty(f => f.Offset = new PointF((float)nudOffsetX.Value, f.Offset.Y)); shadowStyles.SetProperty(f => f.Offset = new PointF(f.Offset.X, (float)nudOffsetY.Value)); shadowStyles.SetProperty(f => f.Color = lbColor.BackColor); // fire event Changed(this, EventArgs.Empty); }
private static void AddDecorators(Figure fig, FigureTreeNode fignode) { if (Helper.ContainsAnyDecorator(fig)) { if (FillDecorator.ContainsAnyDecorator(fig.Style.FillStyle)) { var list = FillDecorator.GetDecorators(fig.Style.FillStyle); foreach (var item in list) { fignode.Nodes.Add(string.Format("{0}FillStyleDecorator", item)); } } if (RendererDecorator.ContainsAnyDecorator(fig.Renderer)) { var list = RendererDecorator.GetDecorators(fig.Renderer); foreach (var item in list) { fignode.Nodes.Add(string.Format("{0}RendererDecorator", item)); } } } }
private void UpdateObject() { if (_updating > 0) { return; // we are in updating mode } // fire event StartChanging(this, new ChangingEventArgs("Arrow Style")); // get list of objects var arrowStyles = _selection.Select(f => (ArrowRendererDecorator)RendererDecorator.GetDecorator(f.Renderer, typeof(ArrowRendererDecorator))).ToList(); // send values back from GUI to object arrowStyles.SetProperty(f => f.OtherColor = lbColor.BackColor); arrowStyles.SetProperty(f => f.IsOtherColorFilled = cbColor.Checked); _arrowPosition = (ArrowPosition)cbPosition.SelectedIndex; arrowStyles.SetProperty(f => f.ArrowPosition = _arrowPosition); // fire event Changed(this, EventArgs.Empty); }
public void Build(Selection selection) { // check visibility Visible = selection.ForAll(f => RendererDecorator.GetBaseRenderer(f.Renderer) is ImageRenderer); if (!Visible) { return; // do not build anything } // remember editing object _selection = selection; // get list of objects var imageFillStyles = _selection.Select(f => (ImageRenderer)RendererDecorator.GetBaseRenderer(f.Renderer)).ToList(); // copy properties of object to GUI _updating++; _image = imageFillStyles.GetProperty(f => f.Image); _updating--; }
private void UpdateObject() { if (_updating > 0) { return; // we are in updating mode } // fire event StartChanging(this, new ChangingEventArgs("Text Block Style")); // get list of objects var textBlockStyles = from figure in _selection where RendererDecorator.GetBaseRenderer(figure.Renderer) is ITextBlock || RendererDecorator.GetDecorator(figure.Renderer, typeof(TextBlockDecorator)) is ITextBlock let decorator = RendererDecorator.GetBaseRenderer(figure.Renderer) is ITextBlock? RendererDecorator.GetBaseRenderer(figure.Renderer) as ITextBlock: RendererDecorator.GetDecorator(figure.Renderer, typeof(TextBlockDecorator)) as ITextBlock select decorator; // send values back from GUI to object textBlockStyles.SetProperty(f => f.FontName = cbFontName.Text); float fontSize; if (float.TryParse(cbFontSize.Text, out fontSize)) { textBlockStyles.SetProperty(f => f.FontSize = fontSize); } textBlockStyles.SetProperty(f => f.FontStyle = _fontStyle); textBlockStyles.SetProperty(f => f.Text = lbText.Text); textBlockStyles.SetProperty(f => f.Alignment = lbText.TextAlign); var padding = new Padding((int)nudLeft.Value, (int)nudTop.Value, (int)nudRight.Value, (int)nudBottom.Value); textBlockStyles.SetProperty(f => f.Padding = padding); textBlockStyles.SetProperty(f => f.WordWrap = cbWrap.Checked); // fire event Changed(this, EventArgs.Empty); }
public void Build(Selection selection) { // check visibility Visible = selection.ForAll(f => RendererDecorator.ContainsType(f.Renderer, typeof(ArrowRendererDecorator))); if (!Visible) { return; // do not build anything } // remember editing object _selection = selection; // get list of objects var arrowStyles = _selection.Select(f => (ArrowRendererDecorator)RendererDecorator.GetDecorator(f.Renderer, typeof(ArrowRendererDecorator))).ToList(); // copy properties of object to GUI _updating++; cbColor.Checked = arrowStyles.GetProperty(f => f.IsOtherColorFilled); lbColor.BackColor = arrowStyles.GetProperty(f => f.OtherColor, Color.White); cbPosition.SelectedIndex = (int)arrowStyles.GetProperty(f => f.ArrowPosition, _arrowPosition); _updating--; }
/// <summary> /// Метод строит маркеры у объекта Selection /// </summary> private void BuildMarkers() { // стираем предыдущие маркеры Markers.Clear(); // если ничего не выбрано, выходим if (Selection.Count == 0) { return; } switch (_editorMode) { case EditorMode.Warp: //создаём маркеры искажения по горизонтали и по вертикали if (_selection.Geometry.AllowedOperations.HasFlag(AllowedOperations.Warp)) //если разрешёно искажение { // создаём маркеры искажения foreach (var fig in RendererDecorator.WhereContainsDecorator(_selection, typeof(WarpRendererDecorator))) { var warped = fig.Renderer as WarpRendererDecorator; //get transformed points if (warped == null) { continue; } var points = warped.GetWarpPoints(fig); for (var i = 0; i < points.Length; i++) { Markers.Add(CreateMarker(MarkerType.Warp, points[i], i, fig)); } } } break; case EditorMode.Skew: //создаём маркеры скоса по горизонтали и по вертикали if (_selection.Geometry.AllowedOperations.HasFlag(AllowedOperations.Skew)) //если разрешён скос { Markers.Add(CreateMarker(MarkerType.SkewX, 0.5f, 0, UserCursor.SkewHorizontal, 1, 1)); Markers.Add(CreateMarker(MarkerType.SkewY, 0, 0.5f, UserCursor.SkewVertical, 1, 1)); Markers.Add(CreateMarker(MarkerType.SkewY, 1, 0.5f, UserCursor.SkewVertical, 0, 0)); Markers.Add(CreateMarker(MarkerType.SkewX, 0.5f, 1, UserCursor.SkewHorizontal, 0, 0)); } break; case EditorMode.Verticies: // создаём маркеры на вершинах фигур if (_selection.Geometry.AllowedOperations.HasFlag(AllowedOperations.Vertex)) //если разрешено редактирование вершин { foreach (var fig in _selection.Where(figure => figure.Geometry is ITransformedGeometry)) { var transformed = fig.Geometry as ITransformedGeometry; //get transformed points if (transformed == null) { continue; } var points = transformed.GetTransformedPoints(fig); var types = transformed.GetTransformedPointTypes(fig); Markers.Add(CreateMarker(MarkerType.Vertex, points[0], 0, fig)); var nt = 0; MarkerType mt; for (var i = 1; i < points.Length; i++) { var typ = types[i]; if ((typ & 0x07) == 3) { mt = nt % 3 == 2 ? MarkerType.Vertex : MarkerType.ControlBezier; nt++; } else { mt = MarkerType.Vertex; nt = 0; } Markers.Add(CreateMarker(mt, points[i], i, fig)); } } } // создаём маркеры градиента foreach (var fig in _selection.Where(figure => figure.Style.FillStyle is IGradientFill)) { var gradient = fig.Style.FillStyle as IGradientFill; //get transformed points if (gradient == null) { continue; } var points = gradient.GetGradientPoints(fig); for (var i = 0; i < points.Length; i++) { Markers.Add(CreateMarker(MarkerType.Gradient, points[i], i, fig)); } } break; case EditorMode.Select: // создаём маркеры масштаба if (Selection.Geometry.AllowedOperations.HasFlag(AllowedOperations.Scale)) //если разрешено масштабирование { Markers.Add(CreateMarker(MarkerType.Scale, 0, 0, UserCursor.SizeNWSE, 1, 1)); Markers.Add(CreateMarker(MarkerType.Scale, 1, 0, UserCursor.SizeNESW, 0, 1)); Markers.Add(CreateMarker(MarkerType.Scale, 1, 1, UserCursor.SizeNWSE, 0, 0)); Markers.Add(CreateMarker(MarkerType.Scale, 0, 1, UserCursor.SizeNESW, 1, 0)); } // создаём маркеры ресайза по вертикали и горизонтали if (Selection.Geometry.AllowedOperations.HasFlag(AllowedOperations.Size)) //если разрешено изменение размера { Markers.Add(CreateMarker(MarkerType.SizeY, 0.5f, 0, UserCursor.SizeNS, 0.5f, 1)); Markers.Add(CreateMarker(MarkerType.SizeX, 1, 0.5f, UserCursor.SizeWE, 0, 0.5f)); Markers.Add(CreateMarker(MarkerType.SizeY, 0.5f, 1, UserCursor.SizeNS, 0.5f, 0)); Markers.Add(CreateMarker(MarkerType.SizeX, 0, 0.5f, UserCursor.SizeWE, 1, 0.5f)); } // создаём маркер вращения if (Selection.Geometry.AllowedOperations.HasFlag(AllowedOperations.Rotate)) //если разрешено вращение { var sf = ScaleFactor; var rotateMarker = CreateMarker(MarkerType.Rotate, 1, 0, UserCursor.Rotate, 0.5f, 0.5f, 15 / sf, -15 / sf); Markers.Add(rotateMarker); } break; } // задаём геометрию маркеров по умолчанию foreach (var marker in Markers) { FigureBuilder.BuildMarkerGeometry(marker); } }
public static void ExportToSvg(string fileName, Layer layer) { var fp = System.Globalization.CultureInfo.GetCultureInfo("en-US"); var list = new List <string> { "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>", "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"", " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" }; list.Add("<svg width=\"1000\" height=\"1000\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">"); foreach (var fig in layer.Figures) { var stroke = fig.Style.BorderStyle != null && fig.Style.BorderStyle.IsVisible ? string.Format(fp, "stroke:{0};stroke-width:{1};", ColorToStr(fig.Style.BorderStyle.Color), fig.Style.BorderStyle.Width) : ""; var fill = fig.Style.FillStyle != null && fig.Style.FillStyle.IsVisible ? string.Format("fill:{0};", ColorToStr(fig.Style.FillStyle.Color)) : "fill:none;"; var style = string.Format("style=\"{0}{1}\"", fill, stroke); if (RendererDecorator.GetBaseRenderer(fig.Renderer) is DefaultRenderer) { var pathPoints = fig.Geometry.Path.Path.PathPoints; var pathTypes = fig.Geometry.Path.Path.PathTypes; var hasMarkers = pathTypes.Any(item => (item & (byte)PathPointType.PathMarker) > 0); fig.Transform.Matrix.TransformPoints(pathPoints); var sb = new StringBuilder(); sb.AppendFormat(fp, "M{0} {1}", pathPoints[0].X, pathPoints[0].Y); var nt = 0; for (var i = 1; i < pathPoints.Length; i++) { var pt = pathPoints[i]; var typ = pathTypes[i]; if ((typ & (byte)PathPointType.PathTypeMask) == (byte)PathPointType.Bezier) { sb.AppendFormat(fp, "{0} {1} {2}", (nt % 3 == 0 ? " C" : ","), pt.X, pt.Y); nt++; } else if ((typ & (byte)PathPointType.PathTypeMask) == (byte)PathPointType.Line) { sb.AppendFormat(fp, " L {0} {1}", pt.X, pt.Y); nt = 0; } var combine = (byte)(PathPointType.CloseSubpath | PathPointType.PathMarker); if (hasMarkers && (typ & combine) == combine || !hasMarkers && ((typ & (byte)PathPointType.CloseSubpath) == (byte)PathPointType.CloseSubpath || i == pathPoints.Length - 1)) { if ((typ & (byte)PathPointType.CloseSubpath) == (byte)PathPointType.CloseSubpath) { sb.Append(" Z"); } if (hasMarkers && (typ & combine) == combine) { list.Add(string.Format("<path fill-rule=\"evenodd\" d=\"{0}\" {1}/>", sb, style)); } else { list.Add(string.Format("<path d=\"{0}\" {1}/>", sb, style)); } sb.Clear(); } else if (typ == (byte)PathPointType.Start) { sb.AppendFormat(fp, "M{0} {1}", pathPoints[i].X, pathPoints[i].Y); nt = 0; } } } } list.Add("</svg>"); File.WriteAllLines(fileName, list, Encoding.UTF8); }