AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=318&pId=-1
Loading a true type font with GDI+
page
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 18903/ 30

Loading a true type font with GDI+

Loading a true type font with GDI+
by Chris Garrett

In this article I will show you how to use a font that is not installed on the server by loading it at run time!

The obvious immediate use for this is where you are on shared hosting or any other occasion where you can't or don't want to bother your ISP/Server Admin.

This solution is administrator-free, you only need a font and FTP :O)

See it in action
http://authors.aspalliance.com/chrisg/tools/LoadFont.aspx

View Source
- http://authors.aspalliance.com/chrisg/tools/view-LoadFont.vb.aspx
- http://authors.aspalliance.com/chrisg/tools/view-LoadFont.aspx.aspx

The way it works is to create a PrivateFontCollection()  from the System.Drawing.Text namespace. This enables us to create a collection of font families outside of the main user fonts.

To this collection we add our font file by pointing to the filesystem path of the .ttf (True Type Font).

After this is loaded we need to from then on use an instance of a font family only from this collection - the effect otherwise is the system selects a match for you so the font displayed would not be the one we loaded.

The remainder of the script deals with displaying the various combinations of style depending on if the style is available using IsStyleAvailable.

If you like the Lazy Dog font I have used it is available from http://www.neave.com/

Download
- http://authors.aspalliance.com/chrisg/tools/download.asp?file=LoadFont.aspx
- http://authors.aspalliance.com/chrisg/tools/download.asp?file=LoadFont.vb


Product Spotlight
Product Spotlight 

©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-03-24 11:52:26 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search