FREE BOOK

Chapter 9: OpenType Font Support

Posted by Manning Publication Free Book | Silverlight January 19, 2012
In this chapter, we’ll take a look at OpenType support including ligatures, alternatives and stylistic sets, font capitals, fractions and number formats, and variants including superscript and subscript.

Another way to modify the appearance of text is to convert it to all caps. You could do this simply by using ALL CAPS when you type the text, but many fonts include alternate representations for small caps, petite caps, titling case and others. In Silverlight, this is supported by the Typography.Capitals attached property.

Silverlight supports the following optional types of capitals via the Capitals property: Normal, All Petite Caps, All Small Caps, Petite Caps, Small Caps, Titling, and Unicase. The appearance of the type depends on how the font designer created it and could vary significantly from one font to the next.

Figure 3 shows how
Normal and AllSmallCaps appear in Gabriola.
 


 

Figure 3 A comparison between normal text with capital letters, and the AllSmallCaps OpenType setting.

You can see that the word "ROCKS" is smaller in the All Small Caps version, as is expected. In addition, there are some slight differences in spacing, like between the O and C, and the K and S. It's not necessarily the same as an algorithmic resizing of the letters; the designer has control over how the smaller letters appear.

Listing 3 shows how to use AllSmallCaps and Normal to create the text shown in figure 3.

Listing 3 Display text as all caps using OpenType

<Grid x:Name="LayoutRoot" Background="White">
  <StackPanel>
    <StackPanel.Resources>
      <Style TargetType="TextBlock">
        <Setter Property="Text" Value="Silverlight ROCKS" />
        <Setter Property="FontFamily" Value="Gabriola" />
        <Setter Property="FontSize" Value="75" />
        <Setter Property="HorizontalAlignment" Value="Center" />
      </Style>
    </StackPanel.Resources>
 
    <TextBlock Typography.Capitals="Normal"/>
    <TextBlock Typography.Capitals="AllSmallCaps" /> #A
 
  </StackPanel>
</Grid>
#A All caps

As in the previous listing, I used the same resource block to eliminate repetition throughout the listing. The key thing to notice here is the
Typography.Capitals attached property on the TextBlock.

Total Pages : 7 34567

comments