Fonts and Font Families


A font describes exactly how each letter should be displayed. Selection of the appropriate font and providing a reasonable variety of fonts within a document are important factors in improving readability.

Most people, if asked to name a font, might mention Arial or Times New Roman (if they are Windows users) or Times or Helvetica (if they are Mac OS users). In fact, these are not fonts at all - they are font families. The font family tells you in generic terms the visual style of the text and is a key factor in the overall appearance of your application. Most of us will have become used to recognizing the styles of the most common font families, even if we’re not consciously aware of it.

An actual font would be something like Arial 9-point italic. In other words, the size and other modifications to the text are specified as well as the font family. These modifications might include whether it is bold, italic, underlined, or displayed in SMALL CAPS or as asubscript; this is technically referred to as the style, though in some ways the term is misleading, because the visual appearance is determined as much by the font family.

The way the size of the text is measured is by specifying its height. The height is measured in points -a traditional unit that represents 1/72 of an inch (0.351 mm). So letters in a 10-point font are roughly 1/7” or 3.5 mm high. However, you won’t get seven lines of 10-point text into one inch of vertical screen or paper space, because you need to allow for the spacing between the lines as well.

Tip 

Strictly speaking, measuring the height isn’t quite as simple as that, because there are several different heights that you must consider. For example, there is the height of tall letters like the A or F (this is the measurement that we are referring to when we talk about the height), the additional height occupied by any accents on letters like Å or Ñ (the internal leading), and the extra height below the baseline needed for the tails of letters like y and g (the descent). However, for this chapter we won’t worry about that. Once you specify the font family and the main height, these subsidiary heights are determined automatically.

When you’re dealing with fonts, you might also encounter some other terms commonly used to describe certain font families:

  • Serif font families have little tick marks at the ends of many of the lines that make up the characters (these ticks are known as serifs). Times New Roman is a classic example of this.

  • Sans serif font families, by contrast, don’t have these ticks. Good examples of sans serif fonts are Arial and Verdana. The lack of tick marks often gives text a blunt, in-your-face appearance, so sans serif fonts are often used for important text.

  • A True Type font family is one that is defined by expressing the shapes of the curves that make up the characters in a precise mathematical manner. This means that that the same definition can be used to calculate how to draw fonts of any size within the family. These days, virtually all the fonts you might use are true type fonts. Some older font families from the days of Windows 3.1 were defined by individually specifying the bitmap for each character separately for each font size, but the use of these fonts is now discouraged.

Microsoft has provided two main classes that you need to deal with when selecting or manipulating fonts:

  • System.Drawing.Font

  • System.Drawing.FontFamily

You have already seen the main use of the Font class. When you want to draw text you instantiate an instance of Font and pass it to the DrawString() method to indicate how the text should be drawn. A FontFamily instance is used to represent a family of fonts.

One use of the FontFamily class is if you know you want a font of a particular type (serif, sans serif or monospace), but don’t mind which font. The static properties GenericSerif, GenericSansSerif, and GenericMonospace return default fonts that satisfy these criteria:

  FontFamily sansSerifFont = FontFamily.GenericSansSerif; 

Generally speaking, however, if you’re writing a professional application, you will want to choose your font in a more sophisticated way. Most likely, you will implement your drawing code so that it checks the font families available and selects the appropriate one, perhaps by taking the first available one on a list of preferred fonts. And if you want your application to be very user-friendly, the first choice on the list will probably be the one that users selected the last time they ran your software. Usually, if you’re dealing with the most popular font families, such as Arial and Times New Roman, you’ll be safe. However, if you do try to display text using a font that doesn’t exist, the results aren’t always predictable and you’re quite likely to find that Windows just substitutes the standard system font, which is very easy for the system to draw but it doesn’t look very pleasant - and if it does appear in your document it’s likely to give the impression of software that is of poor quality.

You can find out what fonts are available on your system using a class called InstalledFontCollection, which is in the System.Drawing.Text namespace. This class implements a property, Families, which is an array of all the fonts that are available to use on your system:

  InstalledFontCollection insFont = new InstalledFontCollection(); FontFamily [] families = insFont.Families; foreach (FontFamily family in families) {    // do processing with this font family } 




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net