Exemple #1
0
        public void ShapedStringBuilder_ExpandsWhenCapacityIsExceeded()
        {
            var sstrb = new ShapedStringBuilder();

            GivenAnUltravioletApplicationWithNoWindow()
            .WithPlugin(new FreeTypeFontPlugin())
            .WithContent(content =>
            {
                var font = content.Load <UltravioletFont>("Fonts/FiraSans");
                using (var textShaper = new HarfBuzzTextShaper(content.Ultraviolet))
                {
                    textShaper.SetUnicodeProperties(TextDirection.LeftToRight, TextScript.Latin, "en");
                    textShaper.Append("Hello, world!");

                    sstrb.Append(textShaper, font);
                    textShaper.Clear();

                    textShaper.SetUnicodeProperties(TextDirection.LeftToRight, TextScript.Latin, "en");
                    textShaper.Append(" Goodbye, world!");

                    sstrb.Append(textShaper, font);
                }
            })
            .RunForOneFrame();

            TheResultingValue(sstrb.Capacity).ShouldBe(36);
            TheResultingValue(sstrb.Length).ShouldBe(29);
        }
Exemple #2
0
        public void ShapedString_ProvidesCorrectSourceIndices_WhenGivenAnExplicitOffset()
        {
            var sstr1 = default(ShapedString);
            var sstr2 = default(ShapedString);

            GivenAnUltravioletApplicationWithNoWindow()
            .WithPlugin(new FreeTypeFontPlugin())
            .WithContent(content =>
            {
                var font = content.Load <UltravioletFont>("Fonts/NotoColorEmoji");
                using (var textShaper = new HarfBuzzTextShaper(content.Ultraviolet))
                {
                    textShaper.SetUnicodeProperties(TextDirection.LeftToRight, TextScript.Latin, "en");
                    textShaper.Append("Hello, world!");

                    sstr1 = textShaper.CreateShapedString(font.Regular);

                    textShaper.Clear();
                    textShaper.Append(" Goodbye, world!");

                    sstr2 = textShaper.CreateShapedString(font.Regular, "Hello, world!".Length);
                }
            })
            .RunForOneFrame();

            var chars1 = new ShapedChar[sstr1.Length];

            sstr1.CopyTo(0, chars1, 0, sstr1.Length);

            var sourceIndices1 = chars1.Select(x => x.SourceIndex).ToArray();

            TheResultingCollection(sourceIndices1)
            .ShouldBeExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

            var chars2 = new ShapedChar[sstr2.Length];

            sstr2.CopyTo(0, chars2, 0, sstr2.Length);

            var sourceIndices2 = chars2.Select(x => x.SourceIndex).ToArray();

            TheResultingCollection(sourceIndices2)
            .ShouldBeExactly(13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28);
        }