簡體   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