SharpVectors.Dom.Svg.SvgTextContentElement.AddGraphicsPath C# (CSharp) Method

AddGraphicsPath() protected method

protected AddGraphicsPath ( PointF &ctp, string text ) : void
ctp System.Drawing.PointF
text string
return void
        protected void AddGraphicsPath(ref PointF ctp, string text)
        {
            if(text.Length == 0)
            return;

              float emSize = _getComputedFontSize();
            FontFamily family = _getGDIFontFamily(emSize);
            int style = _getGDIStyle();
            StringFormat sf = _getGDIStringFormat();

            GraphicsPath gp2 = new GraphicsPath();
            gp2.StartFigure();

            float xCorrection = 0;
            if(sf.Alignment == StringAlignment.Near) xCorrection = emSize * 1 /6;
            else if(sf.Alignment == StringAlignment.Far) xCorrection = -emSize * 1 /6;

            float yCorrection = (float)(family.GetCellAscent(FontStyle.Regular)) / (float)(family.GetEmHeight(FontStyle.Regular)) * emSize;

            // TODO: font property

            PointF p = new PointF(ctp.X-xCorrection, ctp.Y - yCorrection);

            gp2.AddString(text, family, style, emSize, p, sf);
            if(!gp2.GetBounds().IsEmpty)
            {
                float bboxWidth = gp2.GetBounds().Width;
                if(sf.Alignment == StringAlignment.Center) bboxWidth /= 2;
                else if(sf.Alignment == StringAlignment.Far) bboxWidth = 0;

                ctp.X += bboxWidth + emSize/4;
            }

            gp.AddPath(gp2, false);
            gp2.Dispose();
        }