Example #1
0
 public void Rotate(double angle)
 {
     _transform    = MatrixUtils.Rotate(_transform, angle);
     currentPath   = new SVGPathObject(); currentPath = new SVGPathObject();
     currentFigure = new SVGFigure();
 }
Example #2
0
 public void Scale(double scaleX, double scaleY)
 {
     _transform    = MatrixUtils.Scale(_transform, scaleX, scaleY);
     currentPath   = new SVGPathObject();
     currentFigure = new SVGFigure();
 }
Example #3
0
        public void FillText(string text, double x, double y)
        {
            if (!TextToPaths)
            {
                if (!UsedFontFamilies.ContainsKey(Font.FontFamily.FileName))
                {
                    UsedFontFamilies.Add(Font.FontFamily.FileName, Font.FontFamily);
                    UsedChars.Add(Font.FontFamily.FileName, new HashSet <char>());
                }

                UsedChars[Font.FontFamily.FileName].UnionWith(text);

                Font.DetailedFontMetrics metrics = Font.MeasureTextAdvanced(text);

                double[,] currTransform = null;

                switch (TextBaseline)
                {
                case TextBaselines.Baseline:
                    currTransform = MatrixUtils.Translate(_transform, x - metrics.LeftSideBearing, y);
                    break;

                case TextBaselines.Top:
                    currTransform = MatrixUtils.Translate(_transform, x - metrics.LeftSideBearing, y + metrics.Top);
                    break;

                case TextBaselines.Bottom:
                    currTransform = MatrixUtils.Translate(_transform, x - metrics.LeftSideBearing, y + metrics.Bottom);
                    break;

                case TextBaselines.Middle:
                    currTransform = MatrixUtils.Translate(_transform, x - metrics.LeftSideBearing, y + (metrics.Top + metrics.Bottom) * 0.5);
                    break;

                default:
                    currTransform = MatrixUtils.Translate(_transform, x - metrics.LeftSideBearing, y);
                    break;
                }

                XmlElement currElement = currentElement;

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

                XmlElement textElement = Document.CreateElement("text", SVGNamespace);

                textElement.SetAttribute("stroke", "none");
                textElement.SetAttribute("fill", FillStyle.ToCSSString(false));
                textElement.SetAttribute("fill-opacity", FillStyle.A.ToString(System.Globalization.CultureInfo.InvariantCulture));
                textElement.SetAttribute("transform", "matrix(" + currTransform[0, 0].ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + currTransform[1, 0].ToString(System.Globalization.CultureInfo.InvariantCulture) +
                                         "," + currTransform[0, 1].ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + currTransform[1, 1].ToString(System.Globalization.CultureInfo.InvariantCulture) +
                                         "," + currTransform[0, 2].ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + currTransform[1, 2].ToString(System.Globalization.CultureInfo.InvariantCulture) + ")");

                textElement.SetAttribute("x", "0");
                textElement.SetAttribute("y", "0");
                textElement.SetAttribute("font-size", Font.FontSize.ToString(System.Globalization.CultureInfo.InvariantCulture));
                textElement.SetAttribute("font-family", Font.FontFamily.FileName);

                if (Font.FontFamily.IsBold)
                {
                    textElement.SetAttribute("font-weight", "bold");
                }
                else
                {
                    textElement.SetAttribute("font-weight", "regular");
                }

                if (Font.FontFamily.IsItalic)
                {
                    textElement.SetAttribute("font-style", "italic");
                }
                else
                {
                    textElement.SetAttribute("font-style", "normal");
                }

                if (Font.FontFamily.IsOblique)
                {
                    textElement.SetAttribute("font-style", "oblique");
                }

                textElement.InnerText = text;

                if (!string.IsNullOrEmpty(Tag))
                {
                    textElement.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(textElement);

                currentElement = currElement;
            }
            else
            {
                PathText(text, x, y);
                Fill();
            }
        }