예제 #1
0
        public void FreeTypeFont_MeasuresShapedStringBuildersCorrectly()
        {
            var freetypeFont = default(FreeTypeFont);
            var size         = Size2.Zero;

            GivenAnUltravioletApplication()
            .WithPlugin(new FreeTypeFontPlugin())
            .WithContent(content =>
            {
                freetypeFont = content.Load <FreeTypeFont>("Fonts/FiraSans");

                using (var textShaper = new HarfBuzzTextShaper(content.Ultraviolet))
                {
                    textShaper.SetUnicodeProperties(TextDirection.LeftToRight, TextScript.Latin, "en");
                    textShaper.Append("Hello, world!");

                    var str = new ShapedStringBuilder();
                    str.Append(textShaper, freetypeFont.Regular);

                    size = freetypeFont.Regular.MeasureShapedString(str);
                }
            })
            .RunForOneFrame();

            TheResultingValue(size.Width).ShouldBe(92);
            TheResultingValue(size.Height).ShouldBe(20);
        }
예제 #2
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);
        }
예제 #3
0
        public void ShapedString_CombinesLigatures()
        {
            var sstr = 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("👨");
                    textShaper.Append("\u200D");
                    textShaper.Append("👩");
                    textShaper.Append("\u200D");
                    textShaper.Append("👧");
                    textShaper.Append("\u200D");
                    textShaper.Append("👦");

                    sstr = textShaper.CreateShapedString(font.Regular);
                }
            })
            .RunForOneFrame();

            TheResultingValue(sstr.Length).ShouldBe(1);
            TheResultingValue(sstr[0].GlyphIndex).ShouldBe(1687);
        }
예제 #4
0
        public void ShapedString_ProvidesCorrectShapingData_InEnglish()
        {
            var sstr = default(ShapedString);

            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!");

                    sstr = textShaper.CreateShapedString(font.Regular);
                }
            })
            .RunForOneFrame();

            var chars = new ShapedChar[sstr.Length];

            sstr.CopyTo(0, chars, 0, sstr.Length);

            var glyphIndices = chars.Select(x => x.GlyphIndex).ToArray();

            TheResultingCollection(glyphIndices)
            .ShouldBeExactly(111, 412, 514, 514, 555, 2122, 3, 696, 555, 609, 514, 393, 2125);

            var sourceIndices = chars.Select(x => x.SourceIndex).ToArray();

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

            var advances = chars.Select(x => x.Advance).ToArray();

            TheResultingCollection(advances)
            .ShouldBeExactly(11, 9, 5, 5, 9, 4, 4, 11, 9, 6, 5, 10, 4);

            var offsets_x = chars.Select(x => x.OffsetX).ToArray();

            TheResultingCollection(offsets_x)
            .ShouldContainTheSpecifiedNumberOfItems(13)
            .ShouldContainItemsSatisfyingTheCondition(x => x == 0);

            var offsets_y = chars.Select(x => x.OffsetY).ToArray();

            TheResultingCollection(offsets_y)
            .ShouldContainTheSpecifiedNumberOfItems(13)
            .ShouldContainItemsSatisfyingTheCondition(x => x == 0);
        }
예제 #5
0
        public void ShapedString_ProvidesCorrectShapingData_InArabic()
        {
            var sstr = default(ShapedString);

            GivenAnUltravioletApplicationWithNoWindow()
            .WithPlugin(new FreeTypeFontPlugin())
            .WithContent(content =>
            {
                var font = content.Load <UltravioletFont>("Fonts/FiraGO-Regular");
                using (var textShaper = new HarfBuzzTextShaper(content.Ultraviolet))
                {
                    textShaper.SetUnicodeProperties(TextDirection.RightToLeft, TextScript.Arabic, "ar");
                    textShaper.Append("مرحبا بالعالم");

                    sstr = textShaper.CreateShapedString(font.Regular);
                }
            })
            .RunForOneFrame();

            var chars = new ShapedChar[sstr.Length];

            sstr.CopyTo(0, chars, 0, sstr.Length);

            var glyphIndices = chars.Select(x => x.GlyphIndex).ToArray();

            TheResultingCollection(glyphIndices)
            .ShouldBeExactly(2531, 2513, 2150, 2392, 2513, 2150, 2173, 3, 2150, 2172, 2243, 2288, 2533);

            var sourceIndices = chars.Select(x => x.SourceIndex).ToArray();

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

            var advances = chars.Select(x => x.Advance).ToArray();

            TheResultingCollection(advances)
            .ShouldBeExactly(15, 5, 5, 13, 5, 5, 6, 6, 5, 7, 15, 9, 13);

            var offsets_x = chars.Select(x => x.OffsetX).ToArray();

            TheResultingCollection(offsets_x)
            .ShouldContainTheSpecifiedNumberOfItems(13)
            .ShouldContainItemsSatisfyingTheCondition(x => x == 0);

            var offsets_y = chars.Select(x => x.OffsetY).ToArray();

            TheResultingCollection(offsets_y)
            .ShouldContainTheSpecifiedNumberOfItems(13)
            .ShouldContainItemsSatisfyingTheCondition(x => x == 0);
        }
예제 #6
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);
        }
예제 #7
0
        public void ShapedStringBuilder_IsAppendedFromShaper_WhenSpecifyingSubstring()
        {
            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!");

                    textShaper.AppendTo(sstrb, font.Regular, 7, 5);
                }
            })
            .RunForOneFrame();

            TheResultingValue(sstrb.Length).ShouldBe(5);
        }
        public void TextShaper_AppendsMultipleStrings()
        {
            var textLength = default(Int32);

            GivenAnUltravioletApplicationInServiceMode()
            .WithInitialization(uv =>
            {
                using (var textShaper = new HarfBuzzTextShaper(uv))
                {
                    textShaper.SetUnicodeProperties(TextDirection.LeftToRight, TextScript.Latin, "en");
                    textShaper.Append("Hello,");
                    textShaper.Append(" ");
                    textShaper.Append("world!");

                    textLength = textShaper.RawLength;
                }
            })
            .RunForOneFrame();

            TheResultingValue(textLength).ShouldBe(13);
        }
예제 #9
0
        public void ShapedStringBuilder_CanSpecifyInitialValueAndCapacityInConstructor()
        {
            var sstrb = default(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 = new ShapedStringBuilder(textShaper.CreateShapedString(font), 128);
                }
            })
            .RunForOneFrame();

            TheResultingValue(sstrb.Capacity).ShouldBe(128);
            TheResultingValue(sstrb.Length).ShouldBe(13);
        }
예제 #10
0
        public void ShapedString_IsCreatedCorrectlyFromShaper_WhenSpecifyingSubstring()
        {
            var sstr = default(ShapedString);

            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!");

                    sstr = textShaper.CreateShapedString(font.Regular, 7, 5);
                }
            })
            .RunForOneFrame();

            TheResultingString(sstr.Language).ShouldBe("en");
            TheResultingValue(sstr.Script).ShouldBe(TextScript.Latin);
            TheResultingValue(sstr.Direction).ShouldBe(TextDirection.LeftToRight);
            TheResultingValue(sstr.Length).ShouldBe(5);
        }
예제 #11
0
        public void ShapedString_ProvidesCorrectSourceIndices()
        {
            var sstr = 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 ");
                    textShaper.Append("👨");
                    textShaper.Append("\u200D");
                    textShaper.Append("👩");
                    textShaper.Append("\u200D");
                    textShaper.Append("👧");
                    textShaper.Append("\u200D");
                    textShaper.Append("👦");
                    textShaper.Append("!");

                    sstr = textShaper.CreateShapedString(font.Regular);
                }
            })
            .RunForOneFrame();

            var chars = new ShapedChar[sstr.Length];

            sstr.CopyTo(0, chars, 0, sstr.Length);

            var sourceIndices = chars.Select(x => x.SourceIndex).ToArray();

            TheResultingCollection(sourceIndices)
            .ShouldBeExactly(0, 1, 2, 3, 4, 5, 6, 17);
        }