Glyphs

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents a set of glyphs that are used for rendering fixed text.

<Glyphs   .../>

Properties

Canvas.Left, Canvas.Top, Canvas.ZIndex, Clip, Cursor, Effect (Silverlight 3), Fill (Glyphs)FontRenderingEmSizeFontUriGrid.Column (Silverlight 2), Grid.ColumnSpan (Silverlight 2), Grid.Row (Silverlight 2), Grid.RowSpan (Silverlight 2), Height (UIElement)HorizontalAlignment (Silverlight 2), IndicesMargin (Silverlight 2), MaxHeight (Silverlight 2), MaxWidth (Silverlight 2), MinHeight (Silverlight 2), MinWidth (Silverlight 2), Name (DependencyObject)Opacity (UIElement)OpacityMaskOriginXOriginYProjection (Silverlight 3), RenderTransformRenderTransformOriginResourcesStyle (Silverlight 2), StyleSimulationsTagProjection (Silverlight 3), TriggersUnicodeStringVerticalAlignment (Silverlight 2), Visibility, Width (UIElement)

Managed Equivalent

Glyphs

Remarks

Glyphs does not have a content property (you do not define the glyphs by declaring text as the inner text of a Glyphs object element). Instead, you specify the individual glyphs through one of two properties:

  • UnicodeString—a string value that captures the Unicode in an XML-compatible encoding.

  • Indices—also a string, but this property uses a specialized mini-language that references glyphs by their font index order, and optionally specifies advance and offset spacings.

Of these techniques, UnicodeString is probably the most common because it is the easiest to capture from the output of applications that are used to compose text.

In addition to the glyph information, a Glyphs element must always specify a FontUri property value. There is no default or fallback characteristic that will provide a valid value. If you are defining Glyphs in XAML, a parser error will be raised if you fail to specify a FontUri value or fail to specify any glyph information either by UnicodeString or GlyphIndex values in the Indices property.

One way to use Glyphs is with the XML Paper Specification (XPS) document format output of a document-producing application such as Microsoft Office Word 2007. The XPS format produces packages that define the document. One part of this package format is a XAML page that declares a FixedPage element defined by the XPS schema (this schema has the namespace https://schemas.microsoft.com/xps/2005/06). Glyphs is also an element of that schema. You can open up the package, find your FixedPage parts, extract the Glyphs from them, and paste the Glyphs into your XAML for Silverlight.

Note that the XPS Glyphs uses some attributes, such as BidiLevel, that are not part of the XAML subset for Silverlight, so you might have to remove some attributes before the transferred Glyphs is valid for Silverlight. Also, the transferred Glyphs will frequently reference a FontUri value already. The URI it references is another part of the XPS package, and it generally references a font that is obfuscated, subsetted, and packaged explicitly for the XPS content that was authored. To use this same Glyphs in Silverlight, extract that font information from the XPS package, save it as a file with the appropriate extension, and make that font information available and downloadable as part of your application. Depending on your deployment and application structure, you might need to slightly adjust the path in the FontUri output from the original XPS. However, do not change the file name or extension of the obfuscated font file; changing the name will almost always invalidate the file.

Another technique for obtaining the necessary parts to use Glyphs in Silverlight is to use the XPS printer driver that is a component of Microsoft Windows Vista.

Note that the default Fill value for Glyphs is null, and the default FontRenderingEmSize value is 0. Therefore, in order to render anything with Glyphs, you should specify working values either in XAML or script. This is in contrast to the TextBlock object, which has default values of Black and 14.666, respectively, for its analogous properties.

NoteNote:

As with most types of software, font files are licensed, rather than sold, and licenses that govern the use of fonts vary from vendor to vendor. As a developer, it is your responsibility to ensure that you have the required license rights for any font you embed in a document or application, or otherwise redistribute.

Example

The following example defines a Glyphs element in XAML. The source for this Glyphs output is an XPS package, which is then modified slightly for XAML conformance in Silverlight and for the FontUri path. The referenced FontUri is the GUID-named subsetted font that was also produced in the XPS output. The Indices attribute is also set based on that output. The Indices adjust the advances (not the actual glyph index information), with the Glyphs information in the UnicodeString.

<Canvas
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
        <Glyphs Fill="#FF000000"
  FontUri="Resources/23460227-2793-4F9D-DB34-7D3834712823.odttf"
  FontRenderingEmSize="18" StyleSimulations="None" OriginX="72.024"
  OriginY="87.624" UnicodeString="Hello, World!"
  Indices=",85.333;,64;,57.333;,57.333;,70.667;,30.667;,25.333;,113.33;,70.667;,68;,57.333;,70.667;">
  </Glyphs>
  </Canvas>