文本作为单行矢量路径纲要 [英] Outline of a text as single line vector path

查看:183
本文介绍了文本作为单行矢量路径纲要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关的应用程序,我需要绘制文本/字形作为基于矢量的路径。使用 GDI + 的GraphicsPath和Graphics.DrawPath或的 WPF FormattedText与几何工作正常,我得到的输出,如图第一张照片。但是它在某种程度上可能得到的字母作为一行通路中所示的第二画面(示出一个L)。

For an application I need to draw text/glyphs as a vector based path. Using GDI+ GraphicsPath and Graphics.DrawPath or WPF FormattedText and Geometry works fine and I get the output as shown in the first picture. But is it somehow possible to get letters as a single line path as shown in the second picture (shows an L).

我很高兴,如果任何人有一个想法

I'm glad if anyone has an idea.

请参阅此示例。使用内置的功能将永远给你包含它的内部和外部边界的一封信的路径。只有第一个是由单一的笔划,这导致在更短的路径的

See this example. Using built-in function will always give you the path of a letter containing it's inner and outer borderline. Only the first one is made of single strokes which results in a much shorter path.

推荐答案

@Matthias单笔划字体用的填充区域定义自己字体。 TTF(大纲)字体由周围填充区域的笔触定义每个字符。因此,他们的不一定形成一个封闭的形状。换句话说,这是不可能有一个真正的单招的轮廓字体,因为单笔划字体只能有一个填充区域。 .NET框架只支持TTF字体。

@Matthias 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.

幸运的是,有一些字体,通过关闭轮廓招在对自己的模仿单行程的行为。大多数情况下,它们是由数控绘图软件的使用。下面是一个包含相同字体,@Simon一个链接的zip文件Mourier使用建议。

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.

我试验了第一个,事实上我看不出在封闭区域的独立路径。我也写一些代码,使一个常规字体的笔划关闭自己,但弯曲部位在某些点消失。无论内部算法.NET使用,试图创建一个压扁的轮廓1px的道路是行不通的,以及使用一个精心设计的字体。所以,这是一样好,它会使用.NET就搞定了。

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.

这是输出 Graphics.DrawPath ,而不是 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);
        }
    }



此外,这里是一个非常相关的文章来读,如果你打算做很多这一点。
http://tipsandtricks.rolanddga.com/software/how-to-generate-single-line-fonts-for-use-with-dr-engrave/

这篇关于文本作为单行矢量路径纲要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆