0 out of 1 rated this helpful - Rate this topic

GlyphRun Class

Represents a sequence of glyphs from a single face of a single font at a single size, and with a single rendering style.

System.Object
  System.Windows.Media.GlyphRun

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
public class GlyphRun : ISupportInitialize

The GlyphRun type exposes the following members.

  Name Description
Public method GlyphRun() Initializes a new instance of the GlyphRun class.
Public method GlyphRun(GlyphTypeface, Int32, Boolean, Double, IList<UInt16>, Point, IList<Double>, IList<Point>, IList<Char>, String, IList<UInt16>, IList<Boolean>, XmlLanguage) Initializes a new instance of the GlyphRun class by specifying properties of the class.
Top
  Name Description
Public property AdvanceWidths Gets or sets the list of Double values that represent the advance widths corresponding to the glyph indices.
Public property BaselineOrigin Gets or sets the baseline origin of the GlyphRun.
Public property BidiLevel Gets or sets the bidirectional nesting level of the GlyphRun.
Public property CaretStops Gets or sets the list of Boolean values that determine whether there are caret stops for every UTF16 code point in the Unicode representing the GlyphRun.
Public property Characters Gets or sets the list of UTF16 code points that represent the Unicode content of the GlyphRun.
Public property ClusterMap Gets or sets the list of UInt16 values that maps characters in the GlyphRun to glyph indices.
Public property DeviceFontName Gets or sets the specific device font for which the GlyphRun has been optimized.
Public property FontRenderingEmSize Gets or sets the em size used for rendering the GlyphRun.
Public property GlyphIndices Gets or sets an array of UInt16 values that represent the glyph indices in the rendering physical font.
Public property GlyphOffsets Gets or sets an array of Point values representing the offsets of the glyphs in the GlyphRun.
Public property GlyphTypeface Gets or sets the GlyphTypeface for the GlyphRun.
Public property IsHitTestable Gets a value indicating whether there are any valid caret character hits within the GlyphRun.
Public property IsSideways Gets or sets a value indicating whether to rotate glyphs.
Public property Language Gets or sets the XmlLanguage for the GlyphRun.
Top
  Name Description
Public method BuildGeometry Retrieves the Geometry for the GlyphRun.
Public method ComputeAlignmentBox Retrieves the alignment box for the GlyphRun.
Public method ComputeInkBoundingBox Retrieves the ink bounding box for the GlyphRun.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetCaretCharacterHitFromDistance Retrieves the CharacterHit value that represents the character hit of the caret of the GlyphRun.
Public method GetDistanceFromCaretCharacterHit Retrieves the offset from the leading edge of the GlyphRun to the leading or trailing edge of a caret stop containing the specified character hit.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetNextCaretCharacterHit Retrieves the next valid caret character hit in the logical direction in the GlyphRun.
Public method GetPreviousCaretCharacterHit Retrieves the previous valid caret character hit in the logical direction in the GlyphRun.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Explicit interface implemetation Private method ISupportInitialize.BeginInit For a description of this member, see ISupportInitialize.BeginInit.
Explicit interface implemetation Private method ISupportInitialize.EndInit For a description of this member, see ISupportInitialize.EndInit.
Top

The GlyphRun object includes font details such as glyph indices and individual glyph positions. In addition, The GlyphRun object contains the original Unicode code points the run was generated from, character to glyph buffer offset mapping information, and per-character and per-glyph flags.

The Glyphs element represents the output of a GlyphRun in XAML. The following markup syntax is used to describe the Glyphs element.


<!-- The example shows how to use a Glyphs object. -->
<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  >

   <StackPanel Background="PowderBlue">

      <Glyphs
         FontUri             = "C:\WINDOWS\Fonts\TIMES.TTF"
         FontRenderingEmSize = "100"
         StyleSimulations    = "BoldSimulation"
         UnicodeString       = "Hello World!"
         Fill                = "Black"
         OriginX             = "100"
         OriginY             = "200"
      />

   </StackPanel>
</Page>


Each glyph defines metrics that specify how it aligns with other Glyphs. The following graphic defines the various typographic qualities of two different glyph characters.

Various typographic qualities of two different glyph characters

Diagraph of glyph measurements

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
This class can be fast!
This is the lowest level text rendering primitive in WPF, but if you use it naively, it seems to be very slow.

The trick to this class is that it the constructor is stragely slow. I can't see why it would be, but just creating a large number of GlyphRuns and throwing them away is almost as expensive as creating and drawing with them. It's odd.

But what this means is that reusing GlyphRuns pays; hold onto them if you will draw the same text again.

It also turns out that you can use the same run more than once with the a single DrawingContext. If yuo are drawing repeated text, you can use the same GlyphRun repeatedly to do it faster.

The GlyphRun records the position to draw the text at construction. You can overcome this by pushing TranslateTransforms onto your DrawingContext to move the drawing around. This is still fast, as long as you don't recreate your GlyphRuns.