The SvgTextPositioningElement interface is inherited by text-related interfaces: SvgTextElement, SvgTSpanElement, SvgTRefElement and SvgAltGlyphElement.
Inheritance: SvgTextContentElement, ISvgTextPositioningElement
Exemplo n.º 1
0
        private StringFormat _getGDIStringFormat()
        {
            StringFormat sf = new StringFormat();

            bool doAlign = true;

            if (this is SvgTSpanElement || this is SvgTRefElement)
            {
                SvgTextPositioningElement posElement = (SvgTextPositioningElement)this;
                if (posElement.X.AnimVal.NumberOfItems == 0)
                {
                    doAlign = false;
                }
            }

            if (doAlign)
            {
                string anchor = GetPropertyValue("text-anchor");
                if (anchor == "middle")
                {
                    sf.Alignment = StringAlignment.Center;
                }
                if (anchor == "end")
                {
                    sf.Alignment = StringAlignment.Far;
                }
            }

            string dir = GetPropertyValue("direction");

            if (dir == "rtl")
            {
                if (sf.Alignment == StringAlignment.Far)
                {
                    sf.Alignment = StringAlignment.Near;
                }
                else if (sf.Alignment == StringAlignment.Near)
                {
                    sf.Alignment = StringAlignment.Far;
                }
                sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
            }

            dir = GetPropertyValue("writing-mode");
            if (dir == "tb")
            {
                sf.FormatFlags = sf.FormatFlags | StringFormatFlags.DirectionVertical;
            }

            sf.FormatFlags = sf.FormatFlags | StringFormatFlags.MeasureTrailingSpaces;


            return(sf);
        }
Exemplo n.º 2
0
 protected PointF GetCurrentTextPosition(SvgTextPositioningElement posElement, PointF p)
 {
     if (posElement.X.AnimVal.NumberOfItems > 0)
     {
         p.X = (float)posElement.X.AnimVal.GetItem(0).Value;
     }
     if (posElement.Y.AnimVal.NumberOfItems > 0)
     {
         p.Y = (float)posElement.Y.AnimVal.GetItem(0).Value;
     }
     if (posElement.Dx.AnimVal.NumberOfItems > 0)
     {
         p.X += (float)posElement.Dx.AnimVal.GetItem(0).Value;
     }
     if (posElement.Dy.AnimVal.NumberOfItems > 0)
     {
         p.Y += (float)posElement.Dy.AnimVal.GetItem(0).Value;
     }
     return(p);
 }
Exemplo n.º 3
0
 private PointF GetCurrentTextPosition(SvgTextPositioningElement posElement, PointF p)
 {
     if (posElement.X.AnimVal.NumberOfItems > 0)
     {
         p.X = (float)posElement.X.AnimVal.GetItem(0).Value;
     }
     if (posElement.Y.AnimVal.NumberOfItems > 0)
     {
         p.Y = (float)posElement.Y.AnimVal.GetItem(0).Value;
     }
     if (posElement.Dx.AnimVal.NumberOfItems > 0)
     {
         p.X += (float)posElement.Dx.AnimVal.GetItem(0).Value;
     }
     if (posElement.Dy.AnimVal.NumberOfItems > 0)
     {
         p.Y += (float)posElement.Dy.AnimVal.GetItem(0).Value;
     }
     return p;
 }
Exemplo n.º 4
0
        public static WpfTextPlacement GetCurrentTextPosition(SvgTextPositioningElement posElement, Point p)
        {
            ISvgLengthList xValues  = posElement.X.AnimVal;
            ISvgLengthList yValues  = posElement.Y.AnimVal;
            ISvgLengthList dxValues = posElement.Dx.AnimVal;
            ISvgLengthList dyValues = posElement.Dy.AnimVal;
            ISvgNumberList rValues  = posElement.Rotate.AnimVal;

            bool requiresGlyphPositioning = false;
            bool isXYGlyphPositioning     = false;
            bool isDxyGlyphPositioning    = false;
            bool isRotateGlyphPositioning = false;

            double xValue  = p.X;
            double yValue  = p.Y;
            double rValue  = 0;
            double dxValue = 0;
            double dyValue = 0;

            WpfTextPlacement textPlacement = null;

            if (xValues.NumberOfItems > 0)
            {
                if (xValues.NumberOfItems > 1)
                {
                    isXYGlyphPositioning     = true;
                    requiresGlyphPositioning = true;
                }

                xValue = xValues.GetItem(0).Value;
                p.X = xValue;
            }
            if (yValues.NumberOfItems > 0)
            {
                if (yValues.NumberOfItems > 1)
                {
                    isXYGlyphPositioning     = true;
                    requiresGlyphPositioning = true;
                }

                yValue = yValues.GetItem(0).Value;
                p.Y = yValue;
            }
            if (dxValues.NumberOfItems > 0)
            {
                if (dxValues.NumberOfItems > 1)
                {
                    isDxyGlyphPositioning    = true;
                    requiresGlyphPositioning = true;
                }

                dxValue = dxValues.GetItem(0).Value;
                p.X += dxValue;
            }
            if (dyValues.NumberOfItems > 0)
            {
                if (dyValues.NumberOfItems > 1)
                {
                    isDxyGlyphPositioning    = true;
                    requiresGlyphPositioning = true;
                }

                dyValue = dyValues.GetItem(0).Value;
                p.Y += dyValue;
            }
            if (rValues.NumberOfItems > 0)
            {
                if (rValues.NumberOfItems > 1)
                {
                    isRotateGlyphPositioning = true;
                    requiresGlyphPositioning = true;
                }

                rValue = rValues.GetItem(0).Value;
            }

            if (requiresGlyphPositioning)
            {
                uint xCount  = xValues.NumberOfItems;
                uint yCount  = yValues.NumberOfItems;
                uint dxCount = dxValues.NumberOfItems;
                uint dyCount = dyValues.NumberOfItems;
                uint rCount  = rValues.NumberOfItems;

                List<WpfTextPosition> textPositions = null;

                bool isRotateOnly = false;

                if (isXYGlyphPositioning)
                {
                    uint itemCount = Math.Max(Math.Max(xCount, yCount), Math.Max(dxCount, dyCount));
                    itemCount      = Math.Max(itemCount, rCount);
                    textPositions  = new List<WpfTextPosition>((int)itemCount);

                    double xLast = 0;
                    double yLast = 0;

                    for (uint i = 0; i < itemCount; i++)
                    {
                        double xNext  = i < xCount  ? xValues.GetItem(i).Value  : xValue;
                        double yNext  = i < yCount  ? yValues.GetItem(i).Value  : yValue;
                        double rNext  = i < rCount  ? rValues.GetItem(i).Value  : rValue;
                        double dxNext = i < dxCount ? dxValues.GetItem(i).Value : dxValue;
                        double dyNext = i < dyCount ? dyValues.GetItem(i).Value : dyValue;

                        if (i < xCount)
                        {
                            xLast = xNext;
                        }
                        else
                        {
                            xNext = xLast;
                        }
                        if (i < yCount)
                        {
                            yLast = yNext;
                        }
                        else
                        {
                            yNext = yLast;
                        }

                        WpfTextPosition textPosition = new WpfTextPosition(
                            new Point(xNext + dxNext, yNext + dyNext), rNext);

                        textPositions.Add(textPosition);
                    }
                }
                else if (isDxyGlyphPositioning)
                {
                }
                else if (isRotateGlyphPositioning)
                {
                    isRotateOnly   = true;
                    uint itemCount = Math.Max(Math.Max(xCount, yCount), Math.Max(dxCount, dyCount));
                    itemCount      = Math.Max(itemCount, rCount);
                    textPositions  = new List<WpfTextPosition>((int)itemCount);

                    for (uint i = 0; i < itemCount; i++)
                    {
                        double rNext  = i < rCount  ? rValues.GetItem(i).Value  : rValue;

                        WpfTextPosition textPosition = new WpfTextPosition(p, rNext);

                        textPositions.Add(textPosition);
                    }
                }

                if (textPositions != null && textPositions.Count != 0)
                {
                    textPlacement = new WpfTextPlacement(p, rValue, textPositions, isRotateOnly);
                }
                else
                {
                    textPlacement = new WpfTextPlacement(p, rValue);
                }
            }
            else
            {
                textPlacement = new WpfTextPlacement(p, rValue);
            }

            return textPlacement;
        }
Exemplo n.º 5
0
        protected virtual void GetGraphicsPath(ref PointF ctp)
        {
            gp = new GraphicsPath();

            if (this is SvgTextPositioningElement)
            {
                SvgTextPositioningElement tpElm = (SvgTextPositioningElement)this;
                ctp = this.GetCurrentTextPosition(tpElm, ctp);
            }
            string sBaselineShift = GetPropertyValue("baseline-shift").Trim();
            double shiftBy        = 0;

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

                float textFontSize = textElement._getComputedFontSize();
                if (sBaselineShift.EndsWith("%"))
                {
                    shiftBy = SvgNumber.ParseToFloat(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.ParseToFloat(sBaselineShift);
                }
            }


            foreach (XmlNode child in this.ChildNodes)
            {
                gp.StartFigure();
                if (child.NodeType == XmlNodeType.Text)
                {
                    ctp.Y -= (float)shiftBy;
                    this.AddGraphicsPath(ref ctp, GetText(child));
                    ctp.Y += (float)shiftBy;
                }
                else if (child is SvgTRefElement)
                {
                    SvgTRefElement trChild = (SvgTRefElement)child;
                    trChild.GetGraphicsPath(ref ctp);
                }
                else if (child is SvgTextContentElement)
                {
                    SvgTextContentElement tcChild = (SvgTextContentElement)child;
                    tcChild.GetGraphicsPath(ref ctp);
                }
            }
        }