Ejemplo n.º 1
0
        public SVGText(ISVGElement parent, string text, int x, int y, int width, int height, string units)
        {
            System.Xml.XmlElement  parentElement = parent.Element;
            System.Xml.XmlDocument document      = parentElement.OwnerDocument;
            System.Xml.XmlElement  element       = document.CreateElement("text");
            parentElement.AppendChild(element);

            element.InnerText = text;

            System.Xml.XmlAttribute xAttr = document.CreateAttribute("x");
            xAttr.Value = System.String.Format("{0}{1}", x, units);
            element.Attributes.Append(xAttr);

            System.Xml.XmlAttribute yAttr = document.CreateAttribute("y");
            yAttr.Value = System.String.Format("{0}{1}", y, units);
            element.Attributes.Append(yAttr);

            System.Xml.XmlAttribute widthAttr = document.CreateAttribute("width");
            widthAttr.Value = System.String.Format("{0}{1}", width, units);
            element.Attributes.Append(widthAttr);

            System.Xml.XmlAttribute heightAttr = document.CreateAttribute("height");
            heightAttr.Value = System.String.Format("{0}{1}", height, units);
            element.Attributes.Append(heightAttr);

            (this as ISVGElement).Element = element;
        }
Ejemplo n.º 2
0
        public int GetShapeCenter(ISVGElement shape)
        {
            double centerX = 99999.0;
            double centerY = 99999.0;

            foreach (var contour in shape.GetContours())
            {
                foreach (PointF point in contour)
                {
                    if (point.X < centerX)
                    {
                        centerX = point.X;
                    }
                    if (point.Y < centerY)
                    {
                        centerY = point.Y;
                    }
                }
            }

            centerX = centerX * 10;
            centerY = centerY * 10;
            int x = (int)centerX / 1;
            int y = (int)centerY / 1;

            return(y * 10000 + x);
        }
Ejemplo n.º 3
0
        public SVGArrow(ISVGElement parent, int x1, int y1, int x2, int y2, string units)
        {
            System.Xml.XmlElement  parentElement = parent.Element;
            System.Xml.XmlDocument document      = parentElement.OwnerDocument;
            System.Xml.XmlElement  element       = document.CreateElement("line");
            parentElement.AppendChild(element);

            System.Xml.XmlAttribute x1Attr = document.CreateAttribute("x1");
            x1Attr.Value = System.String.Format("{0}{1}", x1, units);
            element.Attributes.Append(x1Attr);

            System.Xml.XmlAttribute y1Attr = document.CreateAttribute("y1");
            y1Attr.Value = System.String.Format("{0}{1}", y1, units);
            element.Attributes.Append(y1Attr);

            System.Xml.XmlAttribute x2Attr = document.CreateAttribute("x2");
            x2Attr.Value = System.String.Format("{0}{1}", x2, units);
            element.Attributes.Append(x2Attr);

            System.Xml.XmlAttribute y2Attr = document.CreateAttribute("y2");
            y2Attr.Value = System.String.Format("{0}{1}", y2, units);
            element.Attributes.Append(y2Attr);

            (this as ISVGElement).Element = element;
        }
Ejemplo n.º 4
0
        public SVGDefinitions(ISVGElement parent)
        {
            System.Xml.XmlElement parentElement = parent.Element;
            System.Xml.XmlElement element       = parentElement.OwnerDocument.CreateElement("defs");
            parentElement.AppendChild(element);

            (this as ISVGElement).Element = element;
        }
 private void CompleteShape(ISVGElement sVGElement)
 {
     if (SelectedShapes.Count == 1)
     {
         EditMode = EditMode.None;
         sVGElement.Complete();
         SelectedShapes.Clear();
     }
 }
Ejemplo n.º 6
0
        public SVGMarker(ISVGElement parent, string id)
        {
            System.Xml.XmlElement  parentElement = parent.Element;
            System.Xml.XmlDocument document      = parentElement.OwnerDocument;
            System.Xml.XmlElement  element       = document.CreateElement("marker");
            parentElement.AppendChild(element);

            System.Xml.XmlAttribute idAttr = document.CreateAttribute("id");
            idAttr.Value = id;
            element.Attributes.Append(idAttr);

            (this as ISVGElement).Element = element;
        }
Ejemplo n.º 7
0
        private static System.Xml.XmlAttribute GetAttribute(ISVGElement svgElement, string name)
        {
            System.Xml.XmlElement   element   = (svgElement as ISVGElement).Element;
            System.Xml.XmlDocument  document  = element.OwnerDocument;
            System.Xml.XmlAttribute attribute = element.Attributes[name];
            if (null == attribute)
            {
                attribute = document.CreateAttribute(name);
                element.Attributes.Append(attribute);
            }

            return(attribute);
        }
Ejemplo n.º 8
0
        public static List <ISVGElement> Sort(List <ISVGElement> aElements)
        {
            if (aElements.Count == 0)
            {
                return(new List <ISVGElement>());
            }

            List <ISVGElement> result = new List <ISVGElement>(aElements);
            Vector2            end    = Vector2.zero;

            for (int i = 0; i < result.Count; i++)
            {
                float minDist = float.MaxValue;
                bool  reverse = false;
                int   index   = i;

                // find path with an endpoint that is closes to the last path
                for (int e = i; e < result.Count; e++)
                {
                    float d = (end - result[e].Start).sqrMagnitude;
                    if (d < minDist)
                    {
                        minDist = d;
                        reverse = false;
                        index   = e;
                    }

                    d = (end - result[e].End).sqrMagnitude;
                    if (d < minDist)
                    {
                        minDist = d;
                        reverse = true;
                        index   = e;
                    }
                }

                ISVGElement t = result[i];
                result[i]     = result[index];
                result[index] = t;

                if (reverse)
                {
                    result[i] = result[i].Reverse();
                }
                end = result[i].End;
            }

            return(result);
        }
    public async Task PasteElementsAsync(ISVGElement SVGElement = null)
    {
        string clipboard = await JSRuntime.InvokeAsync <string>("navigator.clipboard.readText");

        List <string> elementsAsHtml = Elements.Select(e => e.StoredHtml).ToList();

        if (SVGElement != null)
        {
            int index = Elements.IndexOf(SVGElement);
            elementsAsHtml.Insert(index + 1, clipboard);
        }
        else
        {
            elementsAsHtml.Add(clipboard);
        }
        SelectedShapes.Clear();
        InputUpdated(string.Join("\n", elementsAsHtml));
    }
    public void Group(Shape shape)
    {
        List <string> elementsAsHtml = Elements.Select(e => e.StoredHtml).ToList();

        if (MarkedShapes.Count == 1)
        {
            int pos = Elements.IndexOf(shape);
            elementsAsHtml[pos] = "<g>" + shape.StoredHtml + "</g>";
        }
        else
        {
            ISVGElement frontElement = MarkedShapes.MaxBy(e => Elements.IndexOf(e));
            elementsAsHtml[Elements.IndexOf(frontElement)] = "<g>\n" + string.Join("\n", MarkedShapes.OrderBy(e => Elements.IndexOf(e)).Select(e => e.StoredHtml)) + "\n</g>";
            foreach (ISVGElement element in MarkedShapes.Where(e => e != frontElement))
            {
                int pos = Elements.IndexOf(element);
                Elements.RemoveAt(pos);
                elementsAsHtml.RemoveAt(pos);
            }
        }
        SelectedShapes.Clear();
        InputUpdated(string.Join("\n", elementsAsHtml));
    }
Ejemplo n.º 11
0
 public static System.Xml.XmlAttribute StrokeWidth(ISVGElement svgElement, int value)
 {
     System.Xml.XmlAttribute attribute = GetAttribute(svgElement, "stroke-width");
     attribute.Value = value.ToString();
     return(attribute);
 }
Ejemplo n.º 12
0
 public void AddShape(ISVGElement shape)
 {
     shapes.Add(shape);
 }
Ejemplo n.º 13
0
 public void AddShape(ISVGElement shape)
 {
     shapes.Add(shape);
 }
Ejemplo n.º 14
0
 private void UpdateInput(ISVGElement child)
 {
     child.UpdateHtml();
     Changed.Invoke(this);
 }
Ejemplo n.º 15
0
 public static System.Xml.XmlAttribute Stroke(ISVGElement svgElement, string value)
 {
     System.Xml.XmlAttribute attribute = GetAttribute(svgElement, "stroke");
     attribute.Value = value;
     return(attribute);
 }
 public ISVGBuilder AddElement(ISVGElement elem)
 {
     root.AddElement(elem);
     return(this);
 }
Ejemplo n.º 17
0
 public ISVGElement AddElement(ISVGElement Element)
 {
     Elements.Add(Element);
     return(this);
 }
Ejemplo n.º 18
0
        public static void Create(ISVGElement svgElement, string defaultName = null, ClosePathRule closePathRule = ClosePathRule.ALWAYS)
        {
            if (svgElement == null)
            {
                return;
            }
            if (svgElement.paintable.visibility != SVGVisibility.Visible || svgElement.paintable.display == SVGDisplay.None)
            {
                return;
            }

            List <SVGShape>        shapes     = new List <SVGShape>();
            List <List <Vector2> > inputPaths = svgElement.GetPath();

            if (inputPaths.Count == 1)
            {
                if (svgElement.paintable.IsFill())
                {
                    List <List <Vector2> > path = inputPaths;
                    if (svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
                    {
                        path = SVGGeom.ClipPolygon(new List <List <Vector2> >()
                        {
                            inputPaths[0]
                        }, svgElement.paintable.clipPathList);
                    }

                    SVGShape[] addShapes = SVGGraphics.GetShapes(path, svgElement.paintable, svgElement.transformMatrix);
                    if (addShapes != null && addShapes.Length > 0)
                    {
                        shapes.AddRange(addShapes);
                    }
                }
                if (svgElement.paintable.IsStroke())
                {
                    List <List <Vector2> > path = SVGSimplePath.CreateStroke(inputPaths[0], svgElement.paintable, closePathRule);
                    if (svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
                    {
                        path = SVGGeom.ClipPolygon(path, svgElement.paintable.clipPathList);
                    }

                    SVGShape[] addShapes = SVGGraphics.GetShapes(path, svgElement.paintable, svgElement.transformMatrix, true);
                    if (addShapes != null && addShapes.Length > 0)
                    {
                        shapes.AddRange(addShapes);
                    }
                }
            }
            else
            {
                if (svgElement.paintable.IsFill())
                {
                    List <List <Vector2> > fillPaths = inputPaths;
                    if (svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
                    {
                        fillPaths = SVGGeom.ClipPolygon(inputPaths, svgElement.paintable.clipPathList);
                    }

                    SVGShape[] addShapes = SVGGraphics.GetShapes(fillPaths, svgElement.paintable, svgElement.transformMatrix);
                    if (addShapes != null && addShapes.Length > 0)
                    {
                        shapes.AddRange(addShapes);
                    }
                }
                if (svgElement.paintable.IsStroke())
                {
                    List <List <Vector2> > strokePath = SVGSimplePath.CreateStroke(inputPaths, svgElement.paintable, closePathRule);
                    if (svgElement.paintable.clipPathList != null && svgElement.paintable.clipPathList.Count > 0)
                    {
                        strokePath = SVGGeom.ClipPolygon(strokePath, svgElement.paintable.clipPathList);
                    }

                    SVGShape[] addShapes = SVGGraphics.GetShapes(strokePath, svgElement.paintable, svgElement.transformMatrix, true);
                    if (addShapes != null && addShapes.Length > 0)
                    {
                        shapes.AddRange(addShapes);
                    }
                }
            }

            if (shapes.Count > 0)
            {
                string name = svgElement.attrList.GetValue("id");
                if (string.IsNullOrEmpty(name))
                {
                    name = defaultName;
                }
                SVGLayer layer = new SVGLayer();
                layer.shapes = shapes.ToArray();
                layer.name   = name;
                SVGGraphics.AddLayer(layer);
            }
        }
Ejemplo n.º 19
0
        public int GetShapeCenter(ISVGElement shape)
        {
            double centerX = 99999.0;
            double centerY = 99999.0;

            foreach (var contour in shape.GetContours())
            {
                foreach (PointF point in contour)
                {
                    if (point.X < centerX)
                    {
                        centerX = point.X;
                    }
                    if (point.Y < centerY)
                    {
                        centerY = point.Y;
                    }
                }
            }

            centerX = centerX * 10;
            centerY = centerY * 10;
            int x = (int)centerX / 1;
            int y = (int)centerY / 1;

            return y * 10000 + x;
        }