1

我有一個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的家庭數組中的項目,因此一切都被印刷大膽不管我指定哪些FontStyle。如何使用我已添加的兩個文件,以及如何使某些內容大膽且有些東西亮起來?

+0

正在使用css @ font-face規則的一個選項嗎? http://stackoverflow.com/questions/2436749/how-to-define-bold-italic-using-font-face – KHeaney 2014-09-03 17:15:07

+0

不,我需要使用DrawString方法在Graphics對象上...... – KateMak 2014-09-03 17:43:16

回答

0

應該不需要使用不同樣式添加相同的字體兩次。大多數字體支持多種樣式。以下工作正常時,只添加像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); 
+0

我怎樣才能得到字體的「光」版本?不幸的是,我已經嘗試了上述方法,並且無法獲得我想要的結果。 – KateMak 2014-09-03 18:24:29

+0

我不確定您使用的是什麼字體,但是如果您查看系統中安裝的常用字體,則沒有單獨的「粗體」或「斜體」版本。如果這是你的字體問題,我只是不會使用'PrivateFontCollection'。 – Zer0 2014-09-03 18:28:47