简体   繁体   English

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

[英]Use different weights of a custom font?

I have an asp.net application, and I am using a custom font, however I need to use both the bold version and the light version of the font. 我有一个asp.net应用程序,并且我使用的是自定义字体,但是我需要同时使用该字体的粗体和浅色版本。 They are both from the same font family. 它们都来自相同的字体系列。 I am adding them like this: 我要这样添加他们:

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);

Although I am adding two font files, there is only one item in the Families array of pfc, therefore everything gets printed bold no matter what FontStyle I specify. 尽管我要添加两个字体文件,但pfc的Families数组中只有一个项目,因此无论我指定哪种FontStyle,所有内容都会以粗体显示。 How can I use both of the files I have added, and how can I make some things bold and some things light? 如何使用添加的两个文件,如何使某些内容变粗,使某些内容变浅?

There should be no need to add the same font twice with different styles. 不必使用相同的样式两次添加相同的字体。 Most fonts support multiple styles. 大多数字体支持多种样式。 The below works fine when adding only something like Arial.ttf . 当仅添加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