public void Should_Format_TextRuns_With_Multiple_Buffers()
        {
            using (Start())
            {
                var defaultTextRunStyle = new TextStyle(Typeface.Default, 12, Brushes.Black);

                var textSource = new MultiBufferTextSource(defaultTextRunStyle);

                var formatter = new SimpleTextFormatter();

                var textLine = formatter.FormatLine(textSource, 0, double.PositiveInfinity,
                                                    new TextParagraphProperties(defaultTextRunStyle));

                Assert.Equal(5, textLine.TextRuns.Count);

                Assert.Equal(50, textLine.Text.Length);
            }
        }
        public void Should_Get_CharacterHit_From_Distance()
        {
            using (Start())
            {
                var textSource = new MultiBufferTextSource(new TextStyle(Typeface.Default));

                var formatter = new SimpleTextFormatter();

                var textLine =
                    formatter.FormatLine(textSource, 0, double.PositiveInfinity, new TextParagraphProperties());

                var currentDistance = 0.0;

                CharacterHit characterHit;

                foreach (var run in textLine.TextRuns)
                {
                    var textRun = (ShapedTextRun)run;

                    var glyphRun = textRun.GlyphRun;

                    for (var i = 0; i < glyphRun.GlyphClusters.Length; i++)
                    {
                        var cluster = glyphRun.GlyphClusters[i];

                        var glyph = glyphRun.GlyphIndices[i];

                        var advance = glyphRun.GlyphTypeface.GetGlyphAdvance(glyph) * glyphRun.Scale;

                        characterHit = textLine.GetCharacterHitFromDistance(currentDistance);

                        Assert.Equal(cluster, characterHit.FirstCharacterIndex + characterHit.TrailingLength);

                        currentDistance += advance;
                    }
                }

                characterHit = textLine.GetCharacterHitFromDistance(textLine.LineMetrics.Size.Width);

                Assert.Equal(textSource.TextPointer.End, characterHit.FirstCharacterIndex);
            }
        }
        public void Should_Get_Distance_From_CharacterHit()
        {
            using (Start())
            {
                var textSource = new MultiBufferTextSource(new TextStyle(Typeface.Default));

                var formatter = new SimpleTextFormatter();

                var textLine =
                    formatter.FormatLine(textSource, 0, double.PositiveInfinity, new TextParagraphProperties());

                var currentDistance = 0.0;

                foreach (var run in textLine.TextRuns)
                {
                    var textRun = (ShapedTextRun)run;

                    var glyphRun = textRun.GlyphRun;

                    for (var i = 0; i < glyphRun.GlyphClusters.Length; i++)
                    {
                        var cluster = glyphRun.GlyphClusters[i];

                        var glyph = glyphRun.GlyphIndices[i];

                        var advance = glyphRun.GlyphTypeface.GetGlyphAdvance(glyph) * glyphRun.Scale;

                        var distance = textLine.GetDistanceFromCharacterHit(new CharacterHit(cluster));

                        Assert.Equal(currentDistance, distance);

                        currentDistance += advance;
                    }
                }

                Assert.Equal(currentDistance, textLine.GetDistanceFromCharacterHit(new CharacterHit(textSource.TextPointer.Length)));
            }
        }