Working with Fonts in GDI+



This article has been excerpted from book "Graphics Programming with GDI+".

In this section we will concentrate on fonts .The discussion starts with a description of the types of fonts in the Windows operating system, followed by a little background material on fonts. After these basic concepts are covered the discussion turns to how fonts are handled in GDI+ and .NET.

Font Types in Windows

Windows supports two type of fonts: GDI fonts and device fonts. Device Fonts are native to output devices such as a monitor or a printer. GDI fonts are stored in files on your system normally in the Window/Fonts directory. Each font has its own file. For example, Arial, Arial Black, Arial Bold, Arial Italic, Arial Black Italic, Arial Bold Italic, Arial Narrow, Arial Narrow Bold Italic, and Arial Narrow Italic are different fonts in the Arial font family, and each one has its own file.

GDI fonts can be further divided into four major categories: raster, stroke, TrueType, and OpenType. The raster and stroke fonts are the oldest way to display text (they pre-date Windows 3.1).Raster fonts (also known as bitmap fonts) store each character in pixel format. Each raster font is designed for specific aspect ratio and character size, which are generally not scalable to other sizes. The main advantage of raster fonts is high performance because rendering a raster font usually just requires copying it to video memory. Raster fonts supports boldface, italics, underlining and strikethrough formatting.

Stroke fonts (also known as vector fonts) are defined as series of license and dots-in much the same way that characters are drawn with a pen plotter. Stroke fonts are thus quite scalable (they can be increased or decreased to any size), and they can be used with output device of any resolution. Examples of stroke fonts support boldface, italics, underlining, and strikethrough formatting.

Next we come to TrueType fonts, which were developed by Apple and Microsoft and supported by many manufactures. TrueType fonts are also called outline fonts because the individual characters are defined by filled outlines of straight lines and curves. Altering the coordinates that define the outlines provides great scalability .The original 13 Truetype fonts were:

  1. Courier New
  2. Courier New Bold
  3. Courier New Italic
  4. Courier New Bold Italic
  5. Times New Roman
  6. Times New Roman Bold
  7. Times New Roman Italic
  8. Times New Roman Bold Italic
  9. Arial
  10. Arial Bold
  11. Arial Italic
  12. Arial Bold Italic
  13. Symbol

Figure 5.5.gif

FIGURE 5.5: Fonts available in windows

Adobe and Microsoft announced yet another format in 1997, called Open type. It is a combination of TrueType and Type 1 outline format of Adobe's page-description language. Window 2000 installs 82 fonts, including TrueType fonts, OpenType fonts, and other types. The TrueType fonts are represented by a "T" icon, and Open type fonts are represented by an "O" icon in windows Explorer.

The file extension of both TrueType and OpenType fonts is .ttf. If you double-click on the Verdana OpenType font File, it displays the information shown in Figure 5.7.

The Arial Black Italic TrueType font file, on the other hand, looks like Figure 5.8.

Figure 5.6.gif

FIGURE 5.6: Font icons represent font types

In 1998 Microsoft announced a new display technology called ClearType. ClearType increase the readability and smoothness of text on existing LCDs (liquid crystal display), such as laptop screens, flat-screen monitors, and Pocket PC screens. In normal displays, a pixel has only two pixel states: on and off. ClearType technology adds additional information to a pixel besides the on and off states. With ClearType, the words on the display device look almost as sharp and clear as those on the printed page.

Figure 5.7.gif

FIGURE 5.7: An OpenType font

Figure 5.8.gif

FIGURE 5.8: A TrueTypefont

Note: To learn more about Microsoft's ClearType technology, visit http://www.microsoft.com/typography/cleartype/default.html

Conclusion

Hope the article would have helped you in understanding working with Fonts in GDI+. Read other articles on GDI+ on the website.

bookGDI.jpg
This book teaches .NET developers how to work with GDI+ as they develop applications that include graphics, or that interact with monitors or printers. It begins by explaining the difference between GDI and GDI+, and covering the basic concepts of graphics programming in Windows.


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.