Share via


Glyphs Object

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

XAML
<Glyphs .../>
Scripting
To create an object using scripting, see CreateFromXAML.

Properties

Canvas.Left, Canvas.Top, Canvas.ZIndex, Clip, Cursor, Fill, FontRenderingEmSize, FontUri, Height, Indices, Name, Opacity, OpacityMask, OriginX, OriginY, RenderTransform, RenderTransformOrigin, Resources, StyleSimulations, Tag, Triggers, UnicodeString, Width

Methods

AddEventListener, CaptureMouse, Equals, FindName, GetHost, GetParent, GetValue, ReleaseMouseCapture, RemoveEventListener, SetValue

Events

Loaded, MouseEnter, MouseLeave, MouseLeftButtonDown, MouseLeftButtonUp, MouseMove

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, which 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 also optionally specifies advance and offset spacings.

Of these techniques, using 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. There is no default or fallback characteristic that will provide a valid value. If you are defining Glyphs in XAML, failure to specify FontUri, and/or failure to specify any glyph information either by UnicodeString or GlyphIndex values in Indices, will raise a parser error.

One way to use Glyphs is to use the XPS document format output of a document producing application such as Microsoft Office Word 2007. The XPS format produces packages that define the document, and one of the parts 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 Silverlight XAML. Note that the XPS Glyphs uses some attributes that are not part of the Silverlight XAML subset, such as BidiLevel, so you might have to remove some attributes before the transferred Glyphs is valid for Silverlight. Also, note that the transferred Glyphs will frequently reference a FontUri 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 pathing in the FontUri output from the original XPS, but do not change the filename or extension of the obfuscated font file; changing the name will almost always invalidate the file.

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

Note that the default Fill for Glyphs is null, and the default FontRenderingEmSize 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 TextBlock, which defaults to Black and 14.666 for its analogous properties.

Note   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 within a document or application, or otherwise redistribute.

Examples

The following example defines a Glyphs element in XAML. The source for this Glyphs output is an XPS package, which was then modified slightly for Silverlight XAML conformance and FontUri pathing. 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.

XAML
  
  <Canvas
    xmlns="https://schemas.microsoft.com/client/2007"
    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>

This code produces the following fixed text.

Fixed text fom Glyphs example

Fixed text fom Glyphs example

See Also

Text and Fonts Overview