Beispiel #1
0
        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);
        }
 double MeasureGlyphAt(int index)
 {
     return(_typeFace.GetGlyphAdvance(
                _typeFace.GetGlyph(_range[index])) * _scale);
 }