Exemple #1
0
 public void Restore()
 {
     _transform    = states.Pop();
     _currClipPath = clipPaths.Pop();
     currentPath   = new SVGPathObject();
     currentFigure = new SVGFigure();
 }
Exemple #2
0
        public void Close()
        {
            if (currentFigure.PointCount > 0)
            {
                currentFigure.Data += "Z ";
                currentPath.Figures.Add(currentFigure);

                currentFigure = new SVGFigure();
            }
        }
Exemple #3
0
        public void MoveTo(double x, double y)
        {
            if (currentFigure.PointCount > 0)
            {
                currentPath.Figures.Add(currentFigure);
            }

            currentFigure = new SVGFigure();
            currentFigure.CurrentPoint = new Point(x, y);
            currentFigure.StartPoint   = new Point(x, y);
            currentFigure.Data        += "M " + x.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + y.ToString(System.Globalization.CultureInfo.InvariantCulture) + " ";
            currentFigure.PointCount   = 1;
        }
Exemple #4
0
        public SVGContext(double width, double height, bool textToPaths, Dictionary <string, string> linkDestinations)
        {
            this.linkDestinations = linkDestinations;

            this.Width  = width;
            this.Height = height;

            currentPath   = new SVGPathObject();
            currentFigure = new SVGFigure();

            StrokeStyle = Colour.FromRgba(0, 0, 0, 0);
            FillStyle   = Colour.FromRgb(0, 0, 0);
            LineWidth   = 1;

            LineCap   = LineCaps.Butt;
            LineJoin  = LineJoins.Miter;
            _lineDash = new LineDash(0, 0, 0);

            Font = new Font(new FontFamily(FontFamily.StandardFontFamilies.Helvetica), 12);

            TextBaseline = TextBaselines.Top;

            _transform = new double[3, 3];

            _transform[0, 0] = 1;
            _transform[1, 1] = 1;
            _transform[2, 2] = 1;

            states = new Stack <double[, ]>();

            clipPaths = new Stack <string>();
            clipPaths.Push(null);
            _currClipPath = null;

            UsedFontFamilies = new Dictionary <string, FontFamily>();
            UsedChars        = new Dictionary <string, HashSet <char> >();

            Document = new XmlDocument();

            Document.InsertBefore(Document.CreateXmlDeclaration("1.0", "UTF-8", null), Document.DocumentElement);

            currentElement = Document.CreateElement(null, "svg", SVGNamespace);
            currentElement.SetAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
            currentElement.SetAttribute("viewBox", "0 0 " + width.ToString(System.Globalization.CultureInfo.InvariantCulture) + " " + height.ToString(System.Globalization.CultureInfo.InvariantCulture));
            currentElement.SetAttribute("version", "1.1");
            Document.AppendChild(currentElement);

            this.TextToPaths = textToPaths;
        }
Exemple #5
0
        public void Fill()
        {
            if (currentFigure.PointCount > 0)
            {
                currentPath.Figures.Add(currentFigure);
            }

            XmlElement currElement = currentElement;

            if (!string.IsNullOrEmpty(_currClipPath))
            {
                currentElement = Document.CreateElement("g", SVGNamespace);
                currentElement.SetAttribute("clip-path", _currClipPath);
                currElement.AppendChild(currentElement);
            }

            XmlElement path = Document.CreateElement("path", SVGNamespace);

            path.SetAttribute("d", currentPath.Figures.Aggregate("", (a, b) => a + b.Data));
            path.SetAttribute("stroke", "none");
            path.SetAttribute("fill", FillStyle.ToCSSString(false));
            path.SetAttribute("fill-opacity", FillStyle.A.ToString(System.Globalization.CultureInfo.InvariantCulture));
            path.SetAttribute("transform", "matrix(" + _transform[0, 0].ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + _transform[1, 0].ToString(System.Globalization.CultureInfo.InvariantCulture) +
                              "," + _transform[0, 1].ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + _transform[1, 1].ToString(System.Globalization.CultureInfo.InvariantCulture) +
                              "," + _transform[0, 2].ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + _transform[1, 2].ToString(System.Globalization.CultureInfo.InvariantCulture) + ")");

            if (!string.IsNullOrEmpty(Tag))
            {
                path.SetAttribute("id", Tag);
            }

            if (!string.IsNullOrEmpty(this.Tag) && this.linkDestinations.TryGetValue(this.Tag, out string destination) && !string.IsNullOrEmpty(destination))
            {
                XmlElement aElement = Document.CreateElement("a", SVGNamespace);
                aElement.SetAttribute("href", destination);
                currentElement.AppendChild(aElement);
                currentElement = aElement;
            }

            currentElement.AppendChild(path);

            currentElement = currElement;

            currentPath   = new SVGPathObject();
            currentFigure = new SVGFigure();
        }
Exemple #6
0
 public void Scale(double scaleX, double scaleY)
 {
     _transform    = MatrixUtils.Scale(_transform, scaleX, scaleY);
     currentPath   = new SVGPathObject();
     currentFigure = new SVGFigure();
 }
Exemple #7
0
 public void Rotate(double angle)
 {
     _transform    = MatrixUtils.Rotate(_transform, angle);
     currentPath   = new SVGPathObject(); currentPath = new SVGPathObject();
     currentFigure = new SVGFigure();
 }