using System.Windows.Media; // Create a GlyphRun object GlyphRun glyphRun = new GlyphRun(new System.Windows.Media.GlyphTypeface(new Uri("file://C:/Fonts/MyCustomFont.ttf")), 0, // bi-directional nesting level false, // isSideways 10, // device font size new ushort[] { 33 }, // glyph indices new Point(0, 0), // baseline origin position new double[] { 10.0 }, // advance widths null, // glyph offset null, // characters null, // cluster map null, // caret stops null); // language // Draw the glyph run on the drawing surface drawingContext.DrawGlyphRun(Brushes.Black, glyphRun);
using System.Windows.Media; // Create a GlyphRun object GlyphRun glyphRun = new GlyphRun(new System.Windows.Media.GlyphTypeface(new Uri("file://C:/Fonts/MyCustomFont.ttf")), 0, // bi-directional nesting level false, // isSideways 10, // device font size new ushort[] { 33 }, // glyph indices new Point(0, 0), // baseline origin position new double[] { 10.0 }, // advance widths null, // glyph offset null, // characters null, // cluster map null, // caret stops null); // language // Create a custom brush LinearGradientBrush brush = new LinearGradientBrush(Colors.Yellow, Colors.Red, 90); // Translate the glyph run by (25, 25) TranslateTransform transform = new TranslateTransform(25, 25); // Apply the brush and transform to the glyph run and draw drawingContext.PushTransform(transform); drawingContext.PushOpacity(0.7); drawingContext.DrawGlyphRun(brush, glyphRun); drawingContext.Pop(); drawingContext.Pop();This example creates a GlyphRun object and a custom brush. Then, it applies a translation transform to the glyph run and pushes the transform onto the drawing context. It also reduces the opacity of the drawing context before drawing the glyph run.