繁体   English   中英

使用自定义字体的不同粗细?

[英]Use different weights of a custom font?

我有一个asp.net应用程序,并且我使用的是自定义字体,但是我需要同时使用该字体的粗体和浅色版本。 它们都来自相同的字体系列。 我要这样添加他们:

protected PrivateFontCollection pfc = new PrivateFontCollection();

pfc.AddFontFile(HttpContext.Current.Server.MapPath(@"~\Content\Fonts\Exo-Bold.ttf"));
pfc.AddFontFile(HttpContext.Current.Server.MapPath(@"~\Content\Fonts\Exo-Light.ttf"));

Font questionFont = new Font(pfc.Families[0], 32, FontStyle.Regular, GraphicsUnit.World);

尽管我要添加两个字体文件,但pfc的Families数组中只有一个项目,因此无论我指定哪种FontStyle,所有内容都会以粗体显示。 如何使用添加的两个文件,如何使某些内容变粗,使某些内容变浅?

不必使用相同的样式两次添加相同的字体。 大多数字体支持多种样式。 当仅添加Arial.ttf类的内容时,下面的方法可以正常工作。

Font regularFont = new Font(pfc.Families[0], 32, FontStyle.Regular, GraphicsUnit.World);
Font boldFont = new Font(pfc.Families[0], 32, FontStyle.Bold, GraphicsUnit.World);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM