System.Drawing.FontFamily-> IsStyleAvailable始终返回true [英] System.Drawing.FontFamily->IsStyleAvailable always returns true

查看:91
本文介绍了System.Drawing.FontFamily-> IsStyleAvailable始终返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PrivateFontCollection通过AddMemoryFont加载字体.我检索FontFamily,然后使用IsStyleAvailable查询它以确定字体支持的样式.但是,使用多种字体,每次对IsStyleAvailable的调用都会返回true.

Im using a PrivateFontCollection to load a font via the AddMemoryFont. I retrieve the FontFamily, and then I query it using IsStyleAvailable to determine what the font supports as styles. However, with myriad fonts every single call to IsStyleAvailable returns true.

PrivateFontCollection pfc = new PrivateFontCollection();
var fontBuffer = Marshal.AllocCoTaskMem(dta.Length);
Marshal.Copy(dta, 0, fontBuffer, dta.Length);
pfc.AddMemoryFont(fontBuffer, dta.Length);

System.Drawing.FontFamily fam = pfc.Families[0];
if (fam.IsStyleAvailable(d.FontStyle.Bold)) //do something

有人知道如何从FontFamily获取实际的样式信息吗?如果查看C:\ Windows \ Fonts文件夹,则可以看到支持的样式.例如:代理商FB支持粗体.常规,但是当我以这种方式查询它时,会得到下划线,删除线和斜体以及粗体和常规的样式.

Does anyone know how to get the actual style information from the FontFamily? If you look at the C:\Windows\Fonts folder you can see the supported styles. For example: Agency FB supports Bold; Regular, but when I query it in this fashion I get styles for Underline, Strikeout, and Italic, as well as Bold and Regular.

有更好的方法吗?

推荐答案

Windows中的字体引擎知道如何合成未样式化基础字体中的样式.在纸上做起来并不是特别困难,只要使茎变胖以使其变粗,倾斜以使其斜体,画一条线以划线或删除即可.它并不完全像一个好的设计师将要创建的专用轮廓那么漂亮,但是它确实可以完成工作.所以当你问你能做到吗?"那么您将得到响亮的确定的东西!"

The font engine in Windows knows how to synthesize a style from the unstyled base font. It isn't particularly difficult to do on paper, just makes the stems fatter to get bold, tilt them to get italic, draw a line to get underline or strike-out. It isn't exactly as pretty as the dedicated outlines that a good designer will create but it certainly gets the job done. So when you ask "can you do that?" then you'll get a resounding "sure thing!"

由于您显式添加了TTF文件,因此您已经知道无需合成即可直接支持哪些样式,因此无需询问.通过pinvoke和/或在TTF表中进行挖掘可能仍然可以找到答案,但这将是很丑陋的,而且.NET肯定不会直接支持它.我所知道的没有winapi函数可以直接告诉您.

Since you explicitly added the TTF files, you already know what styles are directly supported without synthesis and should not need to ask. Finding out anyway is perhaps possible with pinvoke and/or digging through the TTF tables but it is going to be ugly and certainly not directly supported by .NET. There's no winapi function I know of that tells you directly.

这篇关于System.Drawing.FontFamily-> IsStyleAvailable始终返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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