Пример #1
0
    /// <summary>
    /// Serialize the shape to an XML writer.
    /// </summary>
    public override void WriteToXML(XmlWriter writer, Vector2 origin, float scale)
    {
        Vector2 svgPosition = (position - origin) * new Vector2(scale, -scale);

        writer.WriteStartElement("circle");

        writer.WriteStartAttribute("cx");
        writer.WriteValue(svgPosition.x);
        writer.WriteEndAttribute();

        writer.WriteStartAttribute("cy");
        writer.WriteValue(svgPosition.y);
        writer.WriteEndAttribute();

        writer.WriteStartAttribute("r");
        writer.WriteValue(radius * scale);
        writer.WriteEndAttribute();

        writer.WriteStartAttribute("stroke");
        writer.WriteValue(VectorShapeFilesSVG.ConvertColor(colorOutline));
        writer.WriteEndAttribute();

        writer.WriteStartAttribute("stroke-width");
        writer.WriteValue("0.01");
        writer.WriteEndAttribute();

        writer.WriteStartAttribute("fill");
        writer.WriteValue(VectorShapeFilesSVG.ConvertColor(colorFill));
        writer.WriteEndAttribute();

        writer.WriteEndElement();
    }
Пример #2
0
    /// <summary>
    /// Serialize the shape to an XML writer.
    /// </summary>
    public override void WriteToXML(XmlWriter writer, Vector2 origin, float scale)
    {
        writer.WriteStartElement("path");

        writer.WriteStartAttribute("stroke");
        writer.WriteValue(VectorShapeFilesSVG.ConvertColor(colorOutline));
        writer.WriteEndAttribute();

        writer.WriteStartAttribute("stroke-width");
        writer.WriteValue("1mm");
        writer.WriteEndAttribute();

        writer.WriteStartAttribute("fill");
        writer.WriteValue(VectorShapeFilesSVG.ConvertColor(colorFill));
        writer.WriteEndAttribute();

        writer.WriteStartAttribute("d");
        if (vertices.Length > 1)
        {
            Vertex vert = vertices[0];
            writer.WriteValue("M ");
            writer.WriteValue(vert.position.x);
            writer.WriteValue(" ");
            writer.WriteValue(-vert.position.y);

            for (int i = 1; i < vertices.Length; i++)
            {
                Vertex vertNext = vertices[i];

                if (vert.segmentCurves)
                {
                    writer.WriteValue(" C ");
                    writer.WriteValue(vert.exitCP.x);
                    writer.WriteValue(" ");
                    writer.WriteValue(-vert.exitCP.y);
                    writer.WriteValue(" ");
                    writer.WriteValue(vertNext.enterCP.x);
                    writer.WriteValue(" ");
                    writer.WriteValue(-vertNext.enterCP.y);
                    writer.WriteValue(" ");
                    writer.WriteValue(vertNext.position.x);
                    writer.WriteValue(" ");
                    writer.WriteValue(-vertNext.position.y);
                }
                else
                {
                    writer.WriteValue(" L ");
                    writer.WriteValue(vertNext.position.x);
                    writer.WriteValue(" ");
                    writer.WriteValue(-vertNext.position.y);
                }

                vert = vertNext;
            }

            if (closed)
            {
                if (vert.segmentCurves)
                {
                    Vertex vertNext = vertices[0];
                    writer.WriteValue(" C ");
                    writer.WriteValue(vert.exitCP.x);
                    writer.WriteValue(" ");
                    writer.WriteValue(-vert.exitCP.y);
                    writer.WriteValue(" ");
                    writer.WriteValue(vertNext.enterCP.x);
                    writer.WriteValue(" ");
                    writer.WriteValue(-vertNext.enterCP.y);
                    writer.WriteValue(" ");
                    writer.WriteValue(vertNext.position.x);
                    writer.WriteValue(" ");
                    writer.WriteValue(-vertNext.position.y);
                }
                writer.WriteValue(" Z");
            }
        }
        writer.WriteEndAttribute();

        writer.WriteEndElement();
    }