Exemplo n.º 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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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;
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
 double MeasureGlyphAt(int index)
 {
     return(_typeFace.GetGlyphAdvance(
                _typeFace.GetGlyph(_range[index])) * _scale);
 }