Outline of a text as single line vector path

落花浮王杯 提交于 2019-12-04 06:05:48
drankin2112

Single stroke fonts define themselves by the filled area of the font. TTF (outline) fonts define each character by the stroke surrounding the filled area. So, they necessarily form a closed shape. In other words, it's not possible to have a "true single stroke" outline font, because single stroke fonts only have a filled area. The .NET Framework only supports TTF fonts.

Luckily, there are some fonts that emulate single-stroke behavior by closing the outline strokes in on themselves. Mostly, they are used by CNC plotting software. Here is a link to the zip file containing the same fonts that @Simon Mourier suggested using.

I experimented with the first one and indeed I could not see a separate path for the enclosed areas. I did write some code that makes the strokes of a regular font close in on themselves, but the curved areas disappear in some spots. Whatever internal algorithm .NET uses to try to create a 1px path from a squashed outline just doesn't work as well as using a well designed font. So, this is as good as it's going to get using .NET.

You can use this code to see what each font produces after you install them. Or, I guess you could just try them in your software :) Either way, I hope this is useful for you.

This is the output of Graphics.DrawPath, NOT Graphics.FillPath.

    private void button1_Click(object sender, EventArgs e) {
        DrawText("single stroke ttf engraving fonts");
    }

    private void DrawText(string text) {
        using (Graphics g = panel.CreateGraphics())
        using (Font font = new System.Drawing.Font("1CamBam_Stick_1", 50, FontStyle.Regular))
        using (GraphicsPath gp = new GraphicsPath())
        using (StringFormat sf = new StringFormat()) {
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            gp.AddString(text, font.FontFamily, (int)font.Style, font.Size, panel.ClientRectangle, sf);
            g.Clear(Color.Black);
            g.DrawPath(Pens.Red, gp);
        }
    }

Also, Here is a very related article to read if you plan on doing alot of this. http://tipsandtricks.rolanddga.com/software/how-to-generate-single-line-fonts-for-use-with-dr-engrave/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!