CanvasGeometryCreateGlyphRun Method |
Namespace: Microsoft.Graphics.Canvas.Geometry
public static CanvasGeometry CreateGlyphRun( ICanvasResourceCreator resourceCreator, Vector2 point, CanvasFontFace fontFace, float fontSize, CanvasGlyph[] glyphs, bool isSideways, uint bidiLevel, CanvasTextMeasuringMode measuringMode, CanvasGlyphOrientation glyphOrientation )
A custom text renderer's implementation of DrawGlyphRun may choose to convert the glyph run data it was passed into a geometry. This expands the app's options for how it can draw the geometry, and do things not ordinarily possible through DrawGlyphRun Overload. Once text is turned into geometry, it can be manipulated with CombineWith Overload, or used to produce widened strokes, or read back by the app, like any arbitrary geometry.
For example, if an app needs to trace the contours of some individual glyph runs with a dashed line, it could do the following:
class MyTextRenderer : ICanvasTextRenderer { ... public void DrawGlyphRun( Microsoft.Graphics.Canvas.Numerics.Vector2 position, CanvasFontFace fontFace, float fontSize, CanvasGlyph[] glyphs, bool isSideways, uint bidiLevel, object brush, CanvasTextMeasuringMode measuringMode, string locale, string textString, int[] custerMapIndices, uint textPosition, CanvasGlyphOrientation glyphOrientation) { CanvasGeometry geometry = CanvasGeometry.CreateGlyphRun( resourceCreator, position, fontFace, fontSize, glyphs, isSideways, bidiLevel, measuringMode, glyphOrientation); CanvasStrokeStyle dashedStroke = new CanvasStrokeStyle() { DashStyle = CanvasDashStyle.Dash }; drawingSession.DrawGeometry(geometry, Colors.White, 2.0f, dashedStroke); }
For simple text-drawing scenarios which don't actually require text as geometry, it's recommended that you use DrawGlyphRun Overload to draw the glyph runs.
Creating geometry from text is a one-directional operation; it isn't possible to obtain text back from a geometry.
The resource creator parameter can be null if the geometry will never be drawn onto a CanvasDevice.