#336 – Intellisense Shows Fonts Available on Development System

When you use the XAML editor in Visual Studio 2010 to enter a value for the FontFamily property, Intellisense in the editor will show you a list of fonts available on the development system.  In the example below, the dropdown shows the Parsons font as a possible font choice, since it has been installed on the development system.

This font will appear correctly when the application is run on the development system, but will get displayed on a target system only if it is also installed on that system.  If the font is not present, some other font will be substituted.

Advertisement

#335 – How WPF Finds Fonts on a Target System

A WPF application specifies a font that it wants using the properties FontFamily, FontStyle, FontWeight, FontStretch and FontSize.  At runtime, WPF decides the exact font to use on the target system where the application is running. This decision is based on matching the first four properties (ignoring FontSize for the moment) to a physical font file that is installed on that system.

WPF starts by matching the supplied FontFamily against the names of the fonts found on the system.  It then tries to find a font that most closely matches the requested FontStretch, FontStyle and FontWeight property values.  Matching FontStretch is the highest priority, followed by FontStyle and then FontWeight.

If WPF can’t find a matching font, it “falls back” to a default font installed with WPF, C:\Windows\Fonts\GlobalUserInterface.CompositeFont.  This is a composite font that tries to map individual characters to fonts likely to be present on the system.

#334 – Specifying Values for FontFamily

The FontFamily property of a Control indicates what typeface the control’s text should be rendered in.  The value of the property can be the name of any of the fonts currently installed on the system where a WPF application is running.  In Windows 7, there are a number of fonts installed by default that can be assumed to always be present.

        <TextBlock Margin="20,20,20,0" FontSize="18" FontFamily="Candara" TextWrapping="Wrap">
            Freedom is never voluntarily given by the oppressor; it must be demanded by the oppressed.<LineBreak/>
            --Martin Luther King, Jr.
        </TextBlock>

        <TextBlock Margin="20,40,20,0" FontSize="18" FontFamily="Constantia" TextWrapping="Wrap">
            Freedom is never dear at any price. It is the breath of life. What would a man not pay for living?<LineBreak/>
            --Mohandas Gandhi
        </TextBlock>

#268 – Default FontFamily and FontSize

In WPF, the default font family for text displayed on controls (like Label and Button) is Segoe UI, with a default size of 12.0 device-independent units.

Because a device-independent unit is 1/96 inch, a FontSize value of 12 represents characters whose capitals are 1/8″ high.  This is also equivalent to a size of 9 points.

Windows also uses 9 point Segoe UI as its default system font (in Windows 7).

Most books use a font that is 11 or 12 pts (14-16 WPF units).  Paperbacks often have slightly smaller type, e.g. 10 pt (13-1/3 WPF Units).

Web sites will also typically use fonts for body text that results in text that ranges from 10-12 points.

Microsoft Word uses 11 pt as its default font size.

 

 

#266 – Specifying Values for FontSize

When specifying character size using the FontSize property, you can express the font size in one of several different units.

  • WPF device independent units (the default) – 1/96 in = 1 pixel at 96 dpi
  • Points – Traditional metric for font size, 1/72 in
  • Inches
  • Centimeters

In all cases, the text will render at the requested size, regardless of the display device.

Here’s an example of several different font size values.

<Paragraph FontSize="8 pt">8 pt - Sphinx of black quartz</Paragraph>
<Paragraph FontSize="10 pt">10 pt - Sphinx of black quartz</Paragraph>
<Paragraph FontSize="12 pt">12 pt - Sphinx of black quartz</Paragraph>
<Paragraph FontSize="13">13 units - Sphinx of black quartz</Paragraph>
<Paragraph FontSize="16">16 units - Sphinx of black quartz</Paragraph>
<Paragraph FontSize="0.2 in">0.2 in - Sphinx of black quartz</Paragraph>
<Paragraph FontSize="0.5 cm">0.5 cm - Sphinx of black quartz</Paragraph>
<Paragraph FontSize="32">32 units - Sphinx of black quartz</Paragraph>

#265 – Specifying Values for FontStyle

You can specify a number of different values for the FontStyle property of a Control, to indicate whether you want an italic (slanted letters) style.

The different possible values for FontStyle are:

  • Normal – Regular text, not slanted
  • Italic – Standard italic font
  • Oblique – Slant the letters so that they appear italic.

The Oblique choice is typically used when the font being used doesn’t have an italic variant.

The three font style choices are shown below, for the Arial typeface.  (Arial does have an italic variant).

Here’s another example, for the Georgia typeface.  Notice that the Italic version looks a little more professional, while the Oblique variant just slants the letters, relative to the Normal style.

#264 – Specifying Values for FontWeight

You can specify a number of different values for the FontWeight property of a Control, to specify the thickness, or “weight” of a font.  Each possible value is a request to the font for a different thickness.

Listed in order from lightest weight to heaviest, the possible choices for FontWeight are:

  • Thin
  • ExtraLight
  • Light
  • Normal
  • Medium
  • DemiBold
  • Bold
  • ExtraBold
  • Black
  • ExtraBlack

The number of distinct weights that you’ll get will depend on the font.  Many fonts have just two weights–Normal and Bold.  The weight value specified in the FontWeight setting is just a request.  Windows will return a font whose weight best matches the requested weight.

Below is an example with the Arial typeface.  We request all ten different weights, but we see that there are only three different weights for Arial in Windows.

The Segoe UI font has four different weights:

#263 – Specifying Font Properties

In WPF, you specify the font for text elements by specifying values for one or more font-related properties.

There are five main properties for specifying font characteristics, found in the Control class.

  • FontFamily – The typeface, e.g. Arial
  • FontSize – The size of the text, in device independent units, points, inches, or centimeters
  • FontStretch – Optionally stretch/compress the font
  • FontStyle – Set font as italic (e.g. Italic, Oblique)
  • FontWeight – Set font as bold or light (e.g. Bold, Light, Extra-Bold, etc)

Below is a simple example.

	<TextBlock FontFamily="Cambria" FontSize="14 pt" FontStyle="Normal" FontWeight="Normal"
		HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" Height="100" TextWrapping="Wrap">
		A man who carries a cat by the tail learns something he can learn in no other way.
	</TextBlock>

#262 – Font Sample Sheets

When selecting fonts, it’s helpful to have sample sheets handy that show the font at various sizes and displaying sample text.

I’ve created sample sheets for the 25 fonts installed with Windows 7.  There is a single page for each font, showing samples of text rendered with that font.

Below is a screen capture of the page for the Verdana font.  To download a Word document containing all 25 sample sheets, click here:  FontSamples

Here’s a .pdf version: FontSamples PDF

(NOTE: If you open the document on a system that does not have all of the fonts installed, they will not be displayed properly).

(Click the image below to see the sheet at full size)

#261 – Standard Fonts in Windows 7

A number of fonts are installed by default in Windows 7.  Excluding fonts containing exclusively non-English characters (e.g. Arabic, Asian), the standard fonts are listed below.

  • Arial
  • Calibri
  • Cambria
  • Candara
  • Comic Sans MS
  • Consolas
  • Constantia
  • Corbel
  • Courier New
  • Ebrima
  • Franklin Gothic Medium
  • Gabriola
  • Georgia
  • Impact
  • Lucida Console
  • Lucida Sans
  • Microsoft Sans Serif
  • Palatino Linotype
  • Segoe Print
  • Segoe Script
  • Segoe UI
  • Tahoma
  • Times New Roman
  • Trebuchet MS
  • Verdana

Below are some sample sheets that show samples for each font, in four styles: Regular, Bold, Italic, and Bold-Italic.  All fonts are rendered in 12 pt, on a 96 dpi monitor.