public void Spaces_Plus_Tab_Line_Run_Should_Have_Correct_Glyph_Widths()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

            SimpleTextSource s = new SimpleTextSource(
                " \t ",
                CreateDefaultTextProperties());

            var paragraphProperties = CreateDefaultParagraphProperties();

            TextLineRun run = TextLineRun.Create(s, 0, 0, 32000, paragraphProperties);

            double[] expectedLengths = new double[]
            {
                0,
                MockGlyphTypeface.GlyphAdvance * 1,
                MockGlyphTypeface.GlyphAdvance * 1 + paragraphProperties.DefaultIncrementalTab,
                MockGlyphTypeface.GlyphAdvance * 2 + paragraphProperties.DefaultIncrementalTab
            };

            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual(expectedLengths[i], run.GetDistanceFromCharacter(i));
            }
        }
        public void Tab_Line_Run_Should_Have_Same_Width_As_Indentation_Size()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

            SimpleTextSource s1 = new SimpleTextSource(
                "\ta",
                CreateDefaultTextProperties());

            SimpleTextSource s2 = new SimpleTextSource(
                "    a",
                CreateDefaultTextProperties());

            var textParagraphProperties = new TextParagraphProperties()
            {
                DefaultIncrementalTab = 4 * MockGlyphTypeface.GlyphAdvance,
                Indent = 4
            };

            TextLineRun run1 = TextLineRun.Create(s1, 0, 0, 32000, textParagraphProperties);
            TextLineRun run2 = TextLineRun.Create(s2, 0, 0, 32000, textParagraphProperties);

            Assert.AreEqual(
                run1.GetDistanceFromCharacter(1),
                run2.GetDistanceFromCharacter(4));
        }
        public void TextEmbeddedObject_Line_Run_Should_Have_Fixed_Glyph_Width()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

            int runWidth = 50;

            TextLine textLine = Mock.Of <TextLine>(
                t => t.WidthIncludingTrailingWhitespace == runWidth);

            SpecialCharacterTextRun f = new SpecialCharacterTextRun(
                new FormattedTextElement("BEL", 1)
            {
                TextLine = textLine
            },
                CreateDefaultTextProperties());

            Mock <TextSource> ts = new Mock <TextSource>();

            ts.Setup(s => s.GetTextRun(It.IsAny <int>())).Returns(f);

            TextLineRun run = TextLineRun.Create(ts.Object, 0, 0, 1, CreateDefaultParagraphProperties());

            Assert.AreEqual(
                runWidth + SpecialCharacterTextRun.BoxMargin,
                run.GetDistanceFromCharacter(1));
        }
        public void Text_Line_Run_Should_Have_Valid_Glyph_Widths()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

            SimpleTextSource s = new SimpleTextSource(
                "0123",
                CreateDefaultTextProperties());

            TextLineRun run = TextLineRun.Create(s, 0, 0, 32000, CreateDefaultParagraphProperties());

            Assert.AreEqual(MockGlyphTypeface.GlyphAdvance * 0, run.GetDistanceFromCharacter(0));
            Assert.AreEqual(MockGlyphTypeface.GlyphAdvance * 1, run.GetDistanceFromCharacter(1));
            Assert.AreEqual(MockGlyphTypeface.GlyphAdvance * 2, run.GetDistanceFromCharacter(2));
            Assert.AreEqual(MockGlyphTypeface.GlyphAdvance * 3, run.GetDistanceFromCharacter(3));
        }
        public void Tab_Line_Run_Should_Have_Fixed_Glyph_Width()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

            SimpleTextSource s = new SimpleTextSource(
                "\t",
                CreateDefaultTextProperties());

            var paragraphProperties = CreateDefaultParagraphProperties();

            TextLineRun run = TextLineRun.Create(s, 0, 0, 1, paragraphProperties);

            Assert.AreEqual(paragraphProperties.DefaultIncrementalTab, run.GetDistanceFromCharacter(1));
        }