从ttf文件中提取字体字符图像
有谁知道如何从字体(ttf)文件中提取字符图像?
Does anyone knows how to extract the characters image from a font(ttf) file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有谁知道如何从字体(ttf)文件中提取字符图像?
Does anyone knows how to extract the characters image from a font(ttf) file?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
TTF 是一种矢量格式,因此实际上没有字符形状。加载字体,将其选择到设备上下文(内存上下文)中,渲染字符,抓取位图。
相关 API:AddFontResource、CreateFont、CreateDC、CreateBitmap、SelectObject、TextOut(或 DrawText)。
TTF is a vector format, so there are no characters shapes, really. Load the font, select it into a device context (a memory one), render a character, grab a bitmap.
Relevant APIs: AddFontResource, CreateFont, CreateDC, CreateBitmap, SelectObject, TextOut (or DrawText).
您可以将 GetGlyphOutline 与
GGO_BEZIER 结合使用
获取单个字符的形状。You can use GetGlyphOutline with
GGO_BEZIER
to get the shape of a single character.为了完整起见,我想向这个相当古老的线程添加 GUI 和 Python 方式。
如果目标是从 .ttf 文件中提取图像(例如 png),我发现了两种非常直接的方法,它们都涉及开源程序 fontforge (链接到他们的网站):
链接1:https://fontforge.org/en-US/
链接2:https://superuser.com /questions/1337567/how-do-i-convert-a-ttf-into-individual-png-character-images
For the sake of completeness I'd like to add a GUI and Python way to this pretty old thread.
If the goal is to extract images (as e.g. png) from a .ttf file I found two pretty straight forward ways which both involve the open-source program fontforge (Link to their website):
Link 1: https://fontforge.org/en-US/
Link 2: https://superuser.com/questions/1337567/how-do-i-convert-a-ttf-into-individual-png-character-images
要获取图像,首要任务是处理 glyf 表。您需要找到一种方法来解析该表。
假设您可以从 ttf 完全解析它,有几种情况:
以下讨论将重点关注
简单字形
。对于每个简单字形,您可以总结以下信息:
有了这些信息,您就可以开始绘图了。参考如下方法进行绘制:
当你有了点和 onCurve 信息后,你实际上可以通过观察和实验来推断它。您可以修改以下信息来自由绘制一些形状。
To obtain the image, the primary task is to process the glyf table. You need to find a way to parse this table.
Assuming you can fully parse it form ttf, there are a few scenarios:
The following discussion will focus on
Simple Glyph
.For each Simple Glyph, you can summarize the following information:
With this information, you can start drawing. Refer to the following method for drawing:
When you have the point and the onCurve information, you can actually deduce it through observation and experimentation. You can modify the following information to draw some shapes freely.