C# - 读取和读取 预览字体
我可以在C#中读取和预览字体(主要是ttf和otf)吗? 我可以/应该使用哪些其他语言?
阅读:
- 字体系列、字体名称等信息
预览:
- 使用字体显示某些文本
- 有办法显示所有支持的字体字符吗?
Can I read and preview fonts (mainly ttf and otf) in C#? What other languages can/should I use?
Read:
- Info like font family, font name
Preview:
- Use the font to display some text
- Any way to display all supported font characters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
警告:如果您想预览 OTF 字体,请不要使用 System.Drawing / System.Windows.Forms。 除非它们是伪装的 TTF,否则您不会让它们出现。 System.Drawing,基于GDI+,仅支持TTF字体!
但是,如果您可以使用.NET 3.0,则可以使用
System.Windows.Media命名空间(只需引用PresentationCore.dll)。
从 FontFamily 中,您可以获得单独的 Typeface(.ttc 文件包含多个“字体”,但 FontFamily 还结合了各种重量和变体)。 从 Typeface 中,您可以调用 TryGetGlyphTypeface 来获取 GlyphTypeface,它具有 CharacterToGlyphMap 属性,该属性应该告诉您物理支持哪些 unicode 代码点。
似乎也可以直接使用 GlyphTypeface ,但我认为您无法处理 .ttc 文件。 但是,如果这不相关,只需为每个文件创建一个 GlyphTypeface 即可。
不过,我建议不要按顺序尝试所有 Unicode 代码点。
Caution: don't use System.Drawing / System.Windows.Forms if you want to preview OTF fonts. Unless they're TTF's in disguise, you won't get them to show. System.Drawing, based on GDI+, only supports TTF fonts!
However, if you can use .NET 3.0, you could use
from System.Windows.Media namespace (just reference PresentationCore.dll).
From a FontFamily, you can get the individual Typefaces (.ttc files contain more than one 'font', but a FontFamily also combines the various weights and variants). And from a Typeface, you can call TryGetGlyphTypeface to get the GlyphTypeface, which has a CharacterToGlyphMap property, which should tell you which unicode codepoints are physically supported.
It also seems possible to use GlyphTypeface directly, but I see no way that you can handle .ttc files. However, if that's not relevant, just create a GlyphTypeface per file.
I'd advice against trying all Unicode codepoints sequentially though.
要预览字体,您可以将其呈现为如下形式:
To preview a font you can render it out to a form like this: