开发者

How to manage char spacing in GraphicsPath.AddString?

I need to change distance betw开发者_StackOverflow社区een characters when adding string in GraphicsPath. What is the best way to do this?


You could draw each character individually and adjust the distance between characters, something like.

public void DrawText(string text, Point at, float distanceBetweenChars, FontFamily fontFamily, float fontSize, Graphics graphics)
{
    float currentX = at.X;
    for (int i = 0; i < text.Length; i++)
    {
        using (var path = new GraphicsPath())
        {
            path.AddString(text.Substring(i, 1), fontFamily, (int)FontStyle.Regular, fontSize,
                               new Point((int)currentX, at.Y),
                               StringFormat.GenericDefault);
                RectangleF bounds = path.GetBounds();
                currentX += bounds.Width + distanceBetweenChars;
                graphics.FillPath(new SolidBrush(Color.Black), path);
            }
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜