Ejemplo n.º 1
0
        public void pinning_tests_for_text_measurer_centered_large_middle_string()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(2, 3));

            var textMeasurer = new BoundedText(
                new Point(100, 200),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(new FormattedTextFragment("Short top string\nlooooooooooong.... middle.... string\nshort bottom", fontMetrics, Color.White)));

            textMeasurer.TopLeftOfText().Should().Be(new Point(14, 96));

            // textMeasurer.Lines.Should().HaveCount(3);
            // textMeasurer.Lines[0].TextContent.Should().Be("Short top string");
            textMeasurer.GetRectOfLine(0).Location.X.Should().Be(34);
            textMeasurer.GetRectOfLine(0).Location.Y.Should().Be(96);

            // textMeasurer.Lines[1].TextContent.Should().Be("looooooooooong.... middle.... string");
            textMeasurer.GetRectOfLine(1).Location.X.Should().Be(14);
            textMeasurer.GetRectOfLine(1).Location.Y.Should().Be(99);

            // textMeasurer.Lines[2].TextContent.Should().Be("short bottom");
            textMeasurer.GetRectOfLine(2).Location.X.Should().Be(38);
            textMeasurer.GetRectOfLine(2).Location.Y.Should().Be(102);
        }
Ejemplo n.º 2
0
        public void pinning_tests_for_text_measurer_bottomright()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(2, 3));

            var textMeasurer = new BoundedText(
                new Point(100, 200),
                Alignment.BottomRight,
                Overflow.Elide,
                new FormattedText(new FormattedTextFragment("This is a very long string. I thought about referencing some meme here in this string.\nBut then I changed my mind.", fontMetrics, Color.White)));

            textMeasurer.TopLeftOfText().Should().Be(new Point(12, 191));

            // textMeasurer.Lines.Should().HaveCount(3);
            // textMeasurer.Lines[0].TextContent.Should().Be("This is a very long string. I thought about ");
            textMeasurer.GetRectOfLine(0).Location.X.Should().Be(12);
            textMeasurer.GetRectOfLine(0).Location.Y.Should().Be(191);

            // textMeasurer.Lines[1].TextContent.Should().Be("referencing some meme here in this string.");
            textMeasurer.GetRectOfLine(1).Location.X.Should().Be(16);
            textMeasurer.GetRectOfLine(1).Location.Y.Should().Be(194);

            // textMeasurer.Lines[2].TextContent.Should().Be("But then I changed my mind.");
            textMeasurer.GetRectOfLine(2).Location.X.Should().Be(46);
            textMeasurer.GetRectOfLine(2).Location.Y.Should().Be(197);
        }
Ejemplo n.º 3
0
        public void formatted_text_from_string()
        {
            var font    = new MonospacedFontMetrics(new Point(4, 4));
            var subject = FormattedText.FromString("Hello in blue.", font, Color.Blue);

            subject.OutputString.Should().Be("Hello in blue.");
            subject.OutputFragments().Should().HaveCount(5);
        }
Ejemplo n.º 4
0
        public void occlude_zero_characters_by_default()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));

            var textMeasurer = new BoundedText(new Point(60, 40), Alignment.Center, Overflow.Elide, new FormattedText(new FormattedTextFragment("This is a test", fontMetrics, Color.White)));
            var textList     = textMeasurer.GetRenderedText();

            textList.Should().HaveCount(7);
            textList[6].Text.Should().Be("test");
        }
Ejemplo n.º 5
0
        public void parse_instructions_to_make_formatted_text()
        {
            var font    = new MonospacedFontMetrics(new Point(4, 4));
            var subject = FormattedText.FromParseString("Hello in [#color:0000ff]blue[#color:ffffff].", font, Color.White);

            subject.OutputString.Should().Be("Hello in blue.");
            var renderedText = subject.GetRenderedText();

            renderedText.Count.Should().Be(6);
        }
Ejemplo n.º 6
0
        public void occlude_entire_last_token()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));

            var textMeasurer = new BoundedText(new Point(60, 40), Alignment.Center, Overflow.Elide, new FormattedText(new FormattedTextFragment("This is a test", fontMetrics, Color.White)));
            var textList     = textMeasurer.GetRenderedText(occludedCharactersCount: 4);

            textList.Should().HaveCount(6);
            textList[5].Text.Should().Be(" ");
        }
Ejemplo n.º 7
0
        public void occlude_way_too_much()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));


            var textMeasurer = new BoundedText(new Point(60, 40), Alignment.Center, Overflow.Elide, new FormattedText(new FormattedTextFragment("Hi", fontMetrics, Color.White)));
            var textList     = textMeasurer.GetRenderedText(occludedCharactersCount: 999999);

            textList.Should().HaveCount(0);
        }
Ejemplo n.º 8
0
        public void occlude_half_of_string()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));


            var textMeasurer = new BoundedText(new Point(60, 40), Alignment.Center, Overflow.Elide, new FormattedText(new FormattedTextFragment("Ragglest the Fragglest", fontMetrics, Color.White)));
            var textList     = textMeasurer.GetRenderedText(occludedCharactersCount: 12);

            textList.Should().HaveCount(3);
            textList[2].Text.Should().Be("t");
        }
Ejemplo n.º 9
0
        public void text_rendering_pinning_approval()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));

            var textMeasurer = new BoundedText(
                new Point(60, 40),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(new FormattedTextFragment("I'm the rootinest tootinest gunslinger on this here side of the mississouri.\n\nSo watch out!", fontMetrics, Color.White)));

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 10
0
        public void newlines_are_not_counted_as_rendered_text()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));

            var textMeasurer = new BoundedText(new Point(60, 40), Alignment.Center, Overflow.Elide, new FormattedText(new FormattedTextFragment("New\nLine", fontMetrics, Color.White)));

            var renderedText = textMeasurer.GetRenderedText();

            renderedText.Should().HaveCount(2);
            renderedText[0].Text.Should().Be("New");
            renderedText[1].Text.Should().Be("Line");
        }
Ejemplo n.º 11
0
        public void formatted_text_gets_right_number_of_tokens()
        {
            var font1 = new MonospacedFontMetrics(new Point(4, 4));
            var font2 = new MonospacedFontMetrics(new Point(4, 5));

            var subject = new FormattedText(
                new FormattedTextFragment("Hello in blue. ", font1, Color.Blue),
                new FormattedTextFragment("Hello in red!", font2, Color.Red)
                );

            subject.OutputString.Should().Be("Hello in blue. Hello in red!");
            subject.OutputFragments().Should().HaveCount(11);
        }
Ejemplo n.º 12
0
        public void can_get_used_space_not_elided()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(25, 25),
                Alignment.Center,
                Overflow.Ignore,
                new FormattedText(
                    new FormattedTextFragment("Really big string\nHow big is this?", font, Color.Orange)
                    )
                );

            textMeasurer.UsedSize.Should().Be(new Point(24, 24));
        }
Ejemplo n.º 13
0
        public void formatted_text_can_render_itself()
        {
            var font1 = new MonospacedFontMetrics(new Point(4, 4));
            var font2 = new MonospacedFontMetrics(new Point(4, 5));

            var subject = new FormattedText(
                new FormattedTextFragment("Hello in blue. ", font1, Color.Blue),
                new FormattedTextFragment("Hello in red!", font2, Color.Red)
                );

            var renderedText = subject.GetRenderedText();

            Approvals.Verify(TextMeasureUtils.DrawRenderedText(new AsciiDrawPanel(new Point(113, 5)), renderedText));
        }
Ejemplo n.º 14
0
        public void can_get_used_space_elided()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(25, 25),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("How\nbig\nis\nthis?", font, Color.Orange)
                    )
                );

            textMeasurer.UsedSize.Should().Be(new Point(20, 16));
        }
Ejemplo n.º 15
0
        public void can_get_used_space_with_forced_linebreak()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(100, 100),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("Really loooooonnnng string that will linebreak\nHow big is this?", font, Color.Orange)
                    )
                );

            textMeasurer.UsedSize.Should().Be(new Point(80, 16));
        }
Ejemplo n.º 16
0
        public void allow_free_overflow()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(25, 25),
                Alignment.Center,
                Overflow.Ignore,
                new FormattedText(
                    new FormattedTextFragment("It is OK that we overflow here", font, Color.Orange)
                    )
                );

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 17
0
        public void elide_words_many_short_words()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(50, 30),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("I'm about to walk\noff the edge of the string\nhere I go!\na b c d e f g", font, Color.Orange)
                    )
                );

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 18
0
        public void elide_words_narrow_box()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(10, 30),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("O Nothing fits in this box", font, Color.Orange)
                    )
                );

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 19
0
        public void elide_one_line_long_word()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(50, 4),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("let's goooooooooooooo!", font, Color.Orange)
                    )
                );

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 20
0
        public void several_linebreaks_back_to_back()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(50, 30),
                Alignment.TopLeft,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("One line\nTwo lines\n\nThree lines\n\n\nDone!", font, Color.Orange)
                    )
                );

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 21
0
        public void can_get_used_space_with_extra_room()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(100, 100),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("Really big string\nHow big is this?", font, Color.Orange)
                    )
                );

            textMeasurer.UsedSize.Should().Be(new Point(68, 8));
        }
Ejemplo n.º 22
0
        public void elide_words_on_next_line_exact_length()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(50, 30),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    // the typo in "aand" is intentional here
                    new FormattedTextFragment("I'm about to walk\noff the edge of the string\nhere I go! aand more words words words", font, Color.Orange)
                    )
                );

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 23
0
        public void multi_line_with_image()
        {
            var font         = new MonospacedFontMetrics(new Point(4, 4));
            var textMeasurer = new BoundedText(
                new Point(50, 30),
                Alignment.TopLeft,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("Wordswords\n", font, Color.Orange),
                    new ImageTextFragment(new Point(8, 8), null),
                    new FormattedTextFragment("words words", font, Color.LightBlue)
                    )
                );

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 24
0
        public void formatted_text_draws_things_that_are_not_text()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));
            var subject     = new FormattedText(
                new FormattedTextFragment("Text", fontMetrics, Color.White),
                new ImageTextFragment(new Point(20, 20), (spriteBatch, args) => { }),
                new FormattedTextFragment("and more text", fontMetrics, Color.White)
                );
            var outputFragment = new List <TextOutputFragment>(subject.OutputFragments());

            subject.OutputString.Should().Be("Text{symbol}and more text");

            outputFragment.Should().HaveCount(7);

            Approvals.Verify(TextMeasureUtils.DrawRenderedText(new AsciiDrawPanel(new Point(88, 20)), subject.GetRenderedText()));
        }
Ejemplo n.º 25
0
        public void changing_fonts_can_cause_natural_linebreaks()
        {
            var small  = new MonospacedFontMetrics(new Point(4, 4));
            var medium = new MonospacedFontMetrics(new Point(6, 6));

            var textMeasurer = new BoundedText(
                new Point(50, 30),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("Changing fonts can cause a natural line", small, Color.White),
                    new FormattedTextFragment("break", medium, Color.White)
                    )
                );

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 26
0
        public void output_fragments_know_what_parts_of_the_string_they_own()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));
            var subject     = new FormattedText(new FormattedTextFragment("This is a string used for testing.", fontMetrics, Color.White));

            var outputFragment = new List <TextOutputFragment>(subject.OutputFragments());

            outputFragment.Should().HaveCount(13);
            outputFragment[0].CharacterPosition.Should().Be(0);
            outputFragment[0].CharacterLength.Should().Be(4);

            outputFragment[1].CharacterPosition.Should().Be(4);
            outputFragment[1].CharacterLength.Should().Be(1);

            outputFragment[2].CharacterPosition.Should().Be(5);
            outputFragment[2].CharacterLength.Should().Be(2);

            outputFragment[3].CharacterPosition.Should().Be(7);
            outputFragment[3].CharacterLength.Should().Be(1);
        }
Ejemplo n.º 27
0
        public void get_fragments_from_commands()
        {
            var commands = new FormattedTextCommand[]
            {
                FormattedTextCommand.PlainText.WithArguments("words "),
                FormattedTextCommand.Color.WithArguments("aeaeae"),
                FormattedTextCommand.PlainText.WithArguments("words words "),
                FormattedTextCommand.Color.WithArguments("a3ef37"),
                FormattedTextCommand.PlainText.WithArguments("words "),
                FormattedTextCommand.Color.WithArguments("aaaaaa"),
                FormattedTextCommand.PlainText.WithArguments("words "),
                FormattedTextCommand.Color.WithArguments("bbbbbb"),
                FormattedTextCommand.PlainText.WithArguments("words")
            };

            var font      = new MonospacedFontMetrics(new Point(4, 4));
            var fragments = FormattedTextParser.GetFragmentsFromCommands(commands, font, Color.White);

            fragments.Should().HaveCount(5);
        }
Ejemplo n.º 28
0
        public void bounded_text_can_have_multiple_fragments()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));


            var textMeasurer = new BoundedText(new Point(60, 40), Alignment.Center, Overflow.Elide,
                                               new FormattedText(
                                                   new FormattedTextFragment("He", fontMetrics, Color.White),
                                                   new FormattedTextFragment("llo ", fontMetrics, Color.White),
                                                   new FormattedTextFragment("World!", fontMetrics, Color.White)
                                                   ));
            var textList = textMeasurer.GetRenderedText();

            textList.Should().HaveCount(4);
            textList[0].Text.Should().Be("He");
            textList[1].Text.Should().Be("llo");
            textList[2].Text.Should().Be(" ");
            textList[3].Text.Should().Be("World!");

            textMeasurer.UsedSize.Should().Be(new Point(48, 4));
        }
Ejemplo n.º 29
0
        public void bounded_text_can_support_different_font_sizes()
        {
            var small  = new MonospacedFontMetrics(new Point(4, 4));
            var tall   = new MonospacedFontMetrics(new Point(4, 8));
            var medium = new MonospacedFontMetrics(new Point(6, 6));
            var big    = new MonospacedFontMetrics(new Point(12, 12));

            var textMeasurer = new BoundedText(
                new Point(82, 20),
                Alignment.Center,
                Overflow.Elide,
                new FormattedText(
                    new FormattedTextFragment("Go", small, Color.White),
                    new FormattedTextFragment("big", big, Color.White),
                    new FormattedTextFragment("or", tall, Color.White),
                    new FormattedTextFragment("go", medium, Color.White),
                    new FormattedTextFragment("home", small, Color.White)
                    ));

            Approvals.Verify(TextMeasureUtils.DrawResult(textMeasurer));
        }
Ejemplo n.º 30
0
        public void formatted_text_can_include_things_that_are_not_text()
        {
            var fontMetrics = new MonospacedFontMetrics(new Point(4, 4));
            var subject     = new FormattedText(
                new FormattedTextFragment("Text", fontMetrics, Color.White),
                new ImageTextFragment(new Point(20, 20), (spriteBatch, args) => { }),
                new FormattedTextFragment("and more text", fontMetrics, Color.White)
                );
            var outputFragment = new List <TextOutputFragment>(subject.OutputFragments());

            subject.OutputString.Should().Be("Text{symbol}and more text");

            outputFragment.Should().HaveCount(7);


            outputFragment[0].CharacterPosition.Should().Be(0);
            outputFragment[0].CharacterLength.Should().Be(4);

            outputFragment[1].CharacterPosition.Should().Be(4);
            outputFragment[1].CharacterLength.Should().Be(1);

            outputFragment[2].CharacterPosition.Should().Be(5);
            outputFragment[2].CharacterLength.Should().Be(3);


            outputFragment[3].CharacterPosition.Should().Be(8);
            outputFragment[3].CharacterLength.Should().Be(1);

            outputFragment[4].CharacterPosition.Should().Be(9);
            outputFragment[4].CharacterLength.Should().Be(4);

            outputFragment[5].CharacterPosition.Should().Be(13);
            outputFragment[5].CharacterLength.Should().Be(1);

            outputFragment[6].CharacterPosition.Should().Be(14);
            outputFragment[6].CharacterLength.Should().Be(4);

            subject.TotalCharacterCount.Should().Be(18);
        }