private void UpdateGlyphInfo(string text, GlyphTypeface glyphTypeface, float fontSize) { var glyphs = new ushort[text.Length]; var advances = new float[text.Length]; var scale = fontSize / glyphTypeface.DesignEmHeight; var width = 0f; var characters = text.AsSpan(); for (int i = 0; i < characters.Length; i++) { var c = characters[i]; float advance; ushort glyph; switch (c) { case (char)0: { glyph = glyphTypeface.GetGlyph(0x200B); advance = 0; break; } case '\t': { glyph = glyphTypeface.GetGlyph(' '); advance = glyphTypeface.GetGlyphAdvance(glyph) * scale * 4; break; } default: { glyph = glyphTypeface.GetGlyph(c); advance = glyphTypeface.GetGlyphAdvance(glyph) * scale; break; } } glyphs[i] = glyph; advances[i] = advance; width += advance; } _glyphs = new ReadOnlySlice <ushort>(glyphs); _advances = new ReadOnlySlice <float>(advances); }
public override void Render(DrawingContext context) { var c = (char)_rand.Next(65, 90); if (_fontSize + _direction > 200) { _direction = -10; } if (_fontSize + _direction < 20) { _direction = 10; } _fontSize += _direction; _glyphIndices[0] = _glyphTypeface.GetGlyph(c); _characters[0] = c; var glyphRun = new GlyphRun(_glyphTypeface, _fontSize, _characters, _glyphIndices); var geometry = glyphRun.BuildGeometry(); context.DrawGeometry(Brushes.Green, null, geometry); }
public FpsCounter(GlyphTypeface typeface) { for (var c = FirstChar; c <= LastChar; c++) { var s = new string((char)c, 1); var glyph = typeface.GetGlyph((uint)(s[0])); _runs[c - FirstChar] = new GlyphRun(typeface, 18, new ReadOnlySlice <char>(s.AsMemory()), new ushort[] { glyph }); } }
private void UpdateGlyphRun() { var c = (char)_rand.Next(65, 90); if (_fontSize + _direction > 200) { _direction = -10; } if (_fontSize + _direction < 20) { _direction = 10; } _fontSize += _direction; _glyphIndices[0] = _glyphTypeface.GetGlyph(c); _characters[0] = c; var scale = (double)_fontSize / _glyphTypeface.DesignEmHeight; var drawingGroup = new DrawingGroup(); var glyphRunDrawing = new GlyphRunDrawing { Foreground = Brushes.Black, GlyphRun = new GlyphRun(_glyphTypeface, _fontSize, _characters, _glyphIndices) }; drawingGroup.Children.Add(glyphRunDrawing); var geometryDrawing = new GeometryDrawing { Pen = new Pen(Brushes.Black), Geometry = new RectangleGeometry { Rect = new Rect(glyphRunDrawing.GlyphRun.Size) } }; drawingGroup.Children.Add(geometryDrawing); (_imageControl.Source as DrawingImage).Drawing = drawingGroup; }
public ShapedBuffer ShapeText(ReadOnlySlice <char> text, GlyphTypeface typeface, double fontRenderingEmSize, CultureInfo culture, sbyte bidiLevel) { var shapedBuffer = new ShapedBuffer(text, text.Length, typeface, fontRenderingEmSize, bidiLevel); for (var i = 0; i < shapedBuffer.Length;) { var glyphCluster = i + text.Start; var codepoint = Codepoint.ReadAt(text, i, out var count); var glyphIndex = typeface.GetGlyph(codepoint); shapedBuffer[i] = new GlyphInfo(glyphIndex, glyphCluster, 10); i += count; } return(shapedBuffer); }
private void UpdateGlyphRun() { var c = (uint)_rand.Next(65, 90); if (_fontSize + _direction > 200) { _direction = -10; } if (_fontSize + _direction < 20) { _direction = 10; } _fontSize += _direction; _glyphIndices[0] = _glyphTypeface.GetGlyph(c); var scale = (double)_fontSize / _glyphTypeface.DesignEmHeight; var drawingGroup = new DrawingGroup(); var glyphRunDrawing = new GlyphRunDrawing { Foreground = Brushes.Black, GlyphRun = new GlyphRun(_glyphTypeface, _fontSize, _glyphIndices), BaselineOrigin = new Point(0, -_glyphTypeface.Ascent * scale) }; drawingGroup.Children.Add(glyphRunDrawing); var geometryDrawing = new GeometryDrawing { Pen = new Pen(Brushes.Black), Geometry = new RectangleGeometry { Rect = glyphRunDrawing.GlyphRun.Bounds } }; drawingGroup.Children.Add(geometryDrawing); _drawingPresenter.Drawing = drawingGroup; }
double MeasureGlyphAt(int index) { return(_typeFace.GetGlyphAdvance( _typeFace.GetGlyph(_range[index])) * _scale); }