Text outline as a single line vector path

For the application, I need to draw text / glyphs as a vector path. Using GDI + GraphicsPath and Graphics.DrawPath or WPF FormattedText and Geometry work fine and I get the output as shown in the first shot. But is it possible to get the letters as one line path, as shown in the second figure (shows L).

I am glad if anyone has an idea.

Text outlineSingle line glyph path

See this example. Using the built-in function will always give you a path to a letter containing its inner and outer border. Only the first of them consists of single strokes, which leads to a much shorter path.

enter image description here

+7
source share
1 answer

Fonts with one stroke are determined by the filled area of ​​the font. TTF (outline) fonts define each character with a stroke surrounding the filled area. Thus, they necessarily form a closed form. In other words, it is not possible to have an outline font with a β€œtrue single stroke” because single-stroke fonts have only a filled area .. The .NET Framework only supports TTF fonts.

Fortunately, there are some fonts that mimic the behavior of a single hit, closing the contours of strokes on themselves. They are mainly used by CNC software. Here is a link to the zip file containing the same fonts that @Simon Mourier suggested using.

I experimented with the first, and indeed I could not see a separate path for closed areas. I wrote some code that makes the strokes of a regular font close to me, but curved areas disappear in some places. Whatever the internal .NET algorithm tries to create a 1-pixel path from a compressed path, it does not work as well as using a well-designed font. So, this is as good as using .NET.

You can use this code to see what each font produces after they are installed. Or, I think, you could just try them in your software :) Anyway, I hope this is useful to you.

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

enter image description here

  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 a lot of this. http://tipsandtricks.rolanddga.com/software/how-to-generate-single-line-fonts-for-use-with-dr-engrave/

+5
source

All Articles