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 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--;
        }
Example #3
0
        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 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);
        }