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.

Stylistic sets are alternate representations of glyphs in a font. These can range from very subtle variations of characters, suitable for more formal documents, all the way up to very fancy and fantastic renderings of the loops, as well as decorative elements. It's up to the designer to create these in such a way as to stay consistent with the rest of the font but provide some interesting variation.

A font designer may include up to twenty optional stylistic sets in a font, and each stylistic set may include any subset of the characters of the font. The Gabriola font we're using here includes seven stylistic sets.

Figure 2 shows all seven Gabriola stylistic sets displayed in Silverlight.


Figure 2 Stylistic sets for the Gabriola font as rendered by Silverlight. Note not only the obvious changes but also the subtle treatment given to the "S" and "g" characters, the top of the "O," as well as the "l" and "h" characters. It's like having seven fonts in one.

The sets get progressively fancier, with sets 6 and 7 showing some real flare. Even sets 4 and 5 start to get going with the Mr. Rogers Neighborhood-style "R" and "K" descenders. I particularly like the treatment given to the lowercase "g" character.

Listing 2 shows how to enable the different stylistic sets from markup.

Listing 2 A number of alternates for the Gabriola font

<Grid x:Name="LayoutRoot" Background="White">
  <StackPanel>
    <StackPanel.Resources>
      <Style TargetType="TextBlock"> #A
        <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 />
    <TextBlock Typography.StylisticSet1="True"/>     #C
    <TextBlock Typography.StylisticSet2="True" />
    <TextBlock Typography.StylisticSet3="True" />
    <TextBlock Typography.StylisticSet4="True" /> 
    <TextBlock Typography.StylisticSet5="True" />
    <TextBlock Typography.StylisticSet6="True" />
    <TextBlock Typography.StylisticSet7="True" />
  </StackPanel>
</Grid>

#A Style

#B Stylistic Set
 

In this example, I used an implicit style to avoid repeating the same properties for every TextBlock. Think of it as simply repeating the declared values for each and every TextBlock on the page, so they all have the same Text, FontFamily, FontSize and HorizontalAlignment properties.

Selecting the stylistic set is as simple as setting its numbered StylisticSetN property to true. If there's no set in that spot, you will receive the default font. If you want to check for support for alternates, you can open up Microsoft Word, right-click the text and select the advanced font properties. You'll be able to easily browse many of the OpenType features of the font, including stylistic sets.

While not required, the ContextualAlternates property is often used with Stylistic Sets in order to fine-tune the relationships between the characters. The effects of this setting are typically more subtle.


Total Pages : 7 12345

comments