예제 #1
0
        private void RenderTSpanPath(SvgTSpanElement element, WpfPathTextBuilder pathBuilder, ref Point ctp)
        {
            WpfTextPlacement placement = WpfTextPlacement.Create(element, ctp, true);

            ctp = placement.Location;
            double rotate = placement.Rotation;

            if (!placement.HasPositions)
            {
                placement = null; // Render it useless.
            }

            string sBaselineShift = element.GetPropertyValue("baseline-shift").Trim();
            double shiftBy        = 0;

            var comparer = StringComparison.OrdinalIgnoreCase;

            if (sBaselineShift.Length > 0)
            {
                SvgTextBaseElement textElement = (SvgTextBaseElement)element.SelectSingleNode("ancestor::svg:text",
                                                                                              element.OwnerDocument.NamespaceManager);

                double textFontSize = GetComputedFontSize(textElement);
                if (sBaselineShift.EndsWith("%", comparer))
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0,
                                                                             sBaselineShift.Length - 1)) / 100f * textFontSize;
                }
                else if (string.Equals(sBaselineShift, "sub", comparer))
                {
                    shiftBy = -0.6F * textFontSize;
                }
                else if (string.Equals(sBaselineShift, "super", comparer))
                {
                    shiftBy = 0.6F * textFontSize;
                }
                else if (string.Equals(sBaselineShift, "baseline", comparer))
                {
                    shiftBy = 0;
                }
                else
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift);
                }
            }

            foreach (XmlNode child in element.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Text)
                {
                    ctp.Y -= shiftBy;
                    RenderTextPath(element, pathBuilder, GetText(element, child),
                                   new Point(ctp.X, ctp.Y), rotate, placement);
                    ctp.Y += shiftBy;
                }
            }
        }
예제 #2
0
        private void RenderTSpanPath(SvgTSpanElement element, WpfTextOnPathDrawing pathDrawing,
                                     ref Point ctp)
        {
            WpfTextPlacement placement = GetCurrentTextPosition(element, ctp);

            ctp = placement.Location;
            double rotate = placement.Rotation;

            if (!placement.HasPositions)
            {
                placement = null; // Render it useless.
            }

            string sBaselineShift = element.GetPropertyValue("baseline-shift").Trim();
            double shiftBy        = 0;

            if (sBaselineShift.Length > 0)
            {
                SvgTextElement textElement = (SvgTextElement)element.SelectSingleNode("ancestor::svg:text",
                                                                                      element.OwnerDocument.NamespaceManager);

                double textFontSize = GetComputedFontSize(textElement);
                if (sBaselineShift.EndsWith("%"))
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0,
                                                                             sBaselineShift.Length - 1)) / 100f * textFontSize;
                }
                else if (sBaselineShift == "sub")
                {
                    shiftBy = -0.6F * textFontSize;
                }
                else if (sBaselineShift == "super")
                {
                    shiftBy = 0.6F * textFontSize;
                }
                else if (sBaselineShift == "baseline")
                {
                    shiftBy = 0;
                }
                else
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift);
                }
            }

            foreach (XmlNode child in element.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Text)
                {
                    ctp.Y -= shiftBy;
                    RenderTextPath(element, pathDrawing, GetText(element, child),
                                   new Point(ctp.X, ctp.Y), rotate, placement);
                    ctp.Y += shiftBy;
                }
            }
        }
예제 #3
0
        private void AddTSpanElementPath(SvgTSpanElement element, ref PointF ctp)
        {
            ctp = GetCurrentTextPosition(element, ctp);
            string sBaselineShift = element.GetPropertyValue("baseline-shift").Trim();
            double shiftBy        = 0;

            if (sBaselineShift.Length > 0)
            {
                SvgTextBaseElement textElement = (SvgTextBaseElement)element.SelectSingleNode("ancestor::svg:text",
                                                                                              element.OwnerDocument.NamespaceManager);

                float textFontSize = GetComputedFontSize(textElement);
                if (sBaselineShift.EndsWith("%", StringComparison.OrdinalIgnoreCase))
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0,
                                                                             sBaselineShift.Length - 1)) / 100 * textFontSize;
                }
                else if (sBaselineShift == "sub")
                {
                    shiftBy = -0.6F * textFontSize;
                }
                else if (sBaselineShift == "super")
                {
                    shiftBy = 0.6F * textFontSize;
                }
                else if (sBaselineShift == "baseline")
                {
                    shiftBy = 0;
                }
                else
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift);
                }
            }

            foreach (XmlNode child in element.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Text)
                {
                    ctp.Y -= (float)shiftBy;
                    AddGraphicsPath(element, ref ctp, GetText(element, child));
                    ctp.Y += (float)shiftBy;
                }
            }
        }
        private void AddTSpanElementRun(SvgTSpanElement element, ref Point ctp,
                                        bool isVertical, bool isSingleLine)
        {
            WpfTextPlacement placement = WpfTextRenderer.GetCurrentTextPosition(element, ctp);

            ctp = placement.Location;
            double rotate = placement.Rotation;

            if (!placement.HasPositions)
            {
                placement = null; // render it useless
            }

            string sBaselineShift = element.GetPropertyValue("baseline-shift").Trim();
            double shiftBy        = 0;

            if (sBaselineShift.Length > 0)
            {
                double textFontSize = WpfTextRenderer.GetComputedFontSize(_textElement);
                if (sBaselineShift.EndsWith("%", StringComparison.OrdinalIgnoreCase))
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0,
                                                                             sBaselineShift.Length - 1)) / 100f * textFontSize;
                }
                else if (sBaselineShift == "sub")
                {
                    shiftBy = -0.6F * textFontSize;
                }
                else if (sBaselineShift == "super")
                {
                    shiftBy = 0.6F * textFontSize;
                }
                else if (sBaselineShift == "baseline")
                {
                    shiftBy = 0;
                }
                else
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift);
                }
            }

            foreach (XmlNode child in element.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Text)
                {
                    if (isVertical)
                    {
                        ctp.X += shiftBy;
                        if (isSingleLine)
                        {
                            RenderSingleLineTextV(element, ref ctp,
                                                  WpfTextRenderer.GetText(element, child), rotate, placement);
                        }
                        else
                        {
                            RenderTextRunV(element, ref ctp,
                                           WpfTextRenderer.GetText(element, child), rotate, placement);
                        }
                        ctp.X -= shiftBy;
                    }
                    else
                    {
                        ctp.Y -= shiftBy;
                        if (isSingleLine)
                        {
                            RenderSingleLineTextH(element, ref ctp,
                                                  WpfTextRenderer.GetText(element, child), rotate, placement);
                        }
                        else
                        {
                            RenderTextRunH(element, ref ctp,
                                           WpfTextRenderer.GetText(element, child), rotate, placement);
                        }
                        ctp.Y += shiftBy;
                    }
                }
            }
        }
예제 #5
0
        private void AddTSpanElementRun(SvgTSpanElement element, ref Point ctp,
                                        bool isVertical, bool isSingleLine, XmlNode spaceNode = null)
        {
            var nodeList  = element.ChildNodes;
            int nodeCount = nodeList.Count;

            if (nodeCount == 0)
            {
                return;
            }

            _textContext.PositioningElement = element;
            _textContext.PositioningStart   = new Point(ctp.X, ctp.Y);

            WpfTextPlacement placement = WpfTextPlacement.Create(element, ctp);

            ctp = placement.Location;
            double rotate = placement.Rotation;

            if (!placement.HasPositions)
            {
                placement = null; // render it useless
            }

            _textContext.PositioningEnd = new Point(ctp.X, ctp.Y);

            var comparer = StringComparison.OrdinalIgnoreCase;

            string sBaselineShift = element.GetPropertyValue("baseline-shift").Trim();
            double shiftBy        = 0;

            if (sBaselineShift.Length > 0)
            {
                double textFontSize = WpfTextRenderer.GetComputedFontSize(_textElement);
                if (sBaselineShift.EndsWith("%", comparer))
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0,
                                                                             sBaselineShift.Length - 1)) / 100f * textFontSize;
                }
                else if (string.Equals(sBaselineShift, "sub", comparer))
                {
                    shiftBy = -0.6F * textFontSize;
                }
                else if (string.Equals(sBaselineShift, "super", comparer))
                {
                    shiftBy = 0.6F * textFontSize;
                }
                else if (string.Equals(sBaselineShift, "baseline", comparer))
                {
                    shiftBy = 0;
                }
                else
                {
                    shiftBy = SvgNumber.ParseNumber(sBaselineShift);
                }
            }

            for (int i = 0; i < nodeCount; i++)
            {
                XmlNode child = nodeList[i];
                if (child.NodeType == XmlNodeType.Text)
                {
                    if (isVertical)
                    {
                        ctp.X += shiftBy;
                        if (isSingleLine)
                        {
                            if (i == (nodeCount - 1) && spaceNode != null)
                            {
                                RenderSingleLineTextV(element, ref ctp,
                                                      WpfTextRenderer.GetText(element, child, spaceNode), rotate, placement);
                            }
                            else
                            {
                                RenderSingleLineTextV(element, ref ctp,
                                                      WpfTextRenderer.GetText(element, child), rotate, placement);
                            }
                        }
                        else
                        {
                            if (i == (nodeCount - 1) && spaceNode != null)
                            {
                                RenderTextRunV(element, ref ctp,
                                               WpfTextRenderer.GetText(element, child, spaceNode), rotate, placement);
                            }
                            else
                            {
                                RenderTextRunV(element, ref ctp,
                                               WpfTextRenderer.GetText(element, child), rotate, placement);
                            }
                        }
                        ctp.X -= shiftBy;
                    }
                    else
                    {
                        ctp.Y -= shiftBy;
                        if (isSingleLine)
                        {
                            if (i == (nodeCount - 1) && spaceNode != null)
                            {
                                RenderSingleLineTextH(element, ref ctp,
                                                      WpfTextRenderer.GetText(element, child, spaceNode), rotate, placement);
                            }
                            else
                            {
                                RenderSingleLineTextH(element, ref ctp,
                                                      WpfTextRenderer.GetText(element, child), rotate, placement);
                            }
                        }
                        else
                        {
                            if (i == (nodeCount - 1) && spaceNode != null)
                            {
                                RenderTextRunH(element, ref ctp,
                                               WpfTextRenderer.GetText(element, child, spaceNode), rotate, placement);
                            }
                            else
                            {
                                RenderTextRunH(element, ref ctp,
                                               WpfTextRenderer.GetText(element, child), rotate, placement);
                            }
                        }
                        ctp.Y += shiftBy;
                    }
                }
            }
        }