コード例 #1
0
        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));
        }
コード例 #2
0
 static VisualElement()
 {
     Symbol        = GetSymbol();
     runProperties = TextConfiguration.GetGlobalTextRunProperties();
     textSource    = new SimpleTextSource(Symbol, runProperties);
     charSize      = TextConfiguration.GetCharSize();
 }
コード例 #3
0
        public void Should_Format_TextRuns_With_Default_Style()
        {
            using (Start())
            {
                const string text = "0123456789";

                var defaultTextRunStyle = new TextStyle(Typeface.Default, 12, Brushes.Black);

                var textSource = new SimpleTextSource(text, defaultTextRunStyle);

                var formatter = new SimpleTextFormatter();

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

                Assert.Single(textLine.TextRuns);

                var textRun = textLine.TextRuns[0];

                Assert.Equal(defaultTextRunStyle.TextFormat, textRun.Style.TextFormat);

                Assert.Equal(defaultTextRunStyle.Foreground, textRun.Style.Foreground);

                Assert.Equal(text.Length, textRun.Text.Length);
            }
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        public static VisualTextLine Create(IEnumerable <string> linesToCollapse, string precedingText, string followingText, int index, string collapseRepresentation)
        {
            var textSourceBeforeCollapse = new SimpleTextSource(precedingText, TextConfiguration.GetGlobalTextRunProperties());
            var textSourceAfterCollapse  = new SimpleTextSource(followingText, TextConfiguration.GetGlobalTextRunProperties());

            return(new CollapsedVisualTextLine(
                       linesToCollapse.Select(line => new SimpleTextSource(line, TextConfiguration.GetGlobalTextRunProperties())), textSourceBeforeCollapse, textSourceAfterCollapse, index, collapseRepresentation));
        }
コード例 #6
0
 public void Setup()
 {
     _manager = new DefaultTextManager {
         CurrentLanguage = () => new LanguageInfo {
             Key = "en-US"
         }
     };
     _manager.Texts.Sources.Add(new PrioritizedTextSource(_source = new SimpleTextSource()));
     LocalizationConfig.TextManagerResolver = () => _manager;
 }
コード例 #7
0
        public ITextSource GetSource(Umbraco.Foundation.Localization.TextManager textManager, Assembly referenceAssembly, string targetNamespace)
        {
            var source = new SimpleTextSource();
            source.Texts.Add(new LocalizedText
            {
                Namespace = targetNamespace,
                Key = "FactoryTest",
                Pattern = "I'm from a factory",
                Language = "en-US",
                Source = new TextSourceInfo { TextSource = source, ReferenceAssembly = referenceAssembly }
            });

            return source;
        }
コード例 #8
0
        public void Should_Wrap_Text(string text, string familyName, int numberOfCharactersPerLine)
        {
            using (Start())
            {
                var lineBreaker = new LineBreakEnumerator(text.AsMemory());

                var expected = new List <int>();

                while (lineBreaker.MoveNext())
                {
                    expected.Add(lineBreaker.Current.PositionWrap - 1);
                }

                var typeface = new Typeface("resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#" +
                                            familyName);

                var defaultStyle = new TextStyle(typeface);

                var textSource = new SimpleTextSource(text, defaultStyle);

                var formatter = new SimpleTextFormatter();

                var glyph = typeface.GlyphTypeface.GetGlyph('a');

                var advance = typeface.GlyphTypeface.GetGlyphAdvance(glyph) *
                              (12.0 / typeface.GlyphTypeface.DesignEmHeight);

                var paragraphWidth = advance * numberOfCharactersPerLine;

                var currentPosition = 0;

                while (currentPosition < text.Length)
                {
                    var textLine =
                        formatter.FormatLine(textSource, currentPosition, paragraphWidth,
                                             new TextParagraphProperties(defaultStyle, textWrapping: TextWrapping.Wrap));

                    Assert.True(expected.Contains(textLine.Text.End));

                    var index = expected.IndexOf(textLine.Text.End);

                    for (var i = 0; i <= index; i++)
                    {
                        expected.RemoveAt(0);
                    }

                    currentPosition += textLine.Text.Length;
                }
            }
        }
コード例 #9
0
        public void Should_Produce_Unique_Runs(string text, int numberOfRuns)
        {
            using (Start())
            {
                var textSource = new SimpleTextSource(text, new TextStyle(Typeface.Default));

                var formatter = new SimpleTextFormatter();

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

                Assert.Equal(numberOfRuns, textLine.TextRuns.Count);
            }
        }
コード例 #10
0
        public void Should_Split_Run_On_Script()
        {
            using (Start())
            {
                const string text = "1234الدولي";

                var textSource = new SimpleTextSource(text, new TextStyle(Typeface.Default));

                var formatter = new SimpleTextFormatter();

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

                Assert.Equal(4, textLine.TextRuns[0].Text.Length);
            }
        }
コード例 #11
0
        public void Text_Line_Should_Generate_Text_Runs()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

            SimpleTextSource textSource = new SimpleTextSource("hello", CreateDefaultTextProperties());

            TextLineImpl textLine = TextLineImpl.Create(
                CreateDefaultParagraphProperties(), 0, 5, textSource);

            Assert.AreEqual(2, textLine.LineRuns.Length);
            Assert.AreEqual("hello", textLine.LineRuns[0].StringRange.ToString());
            Assert.IsTrue(textLine.LineRuns[1].IsEnd);
        }
コード例 #12
0
        public void Text_Line_Run_Should_Update_StringRange_When_Word_Wrap()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl()));

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

            var paragraphProperties = CreateDefaultParagraphProperties();

            TextLineRun run = TextLineRun.Create(s, 0, 0, MockGlyphTypeface.GlyphAdvance * 13, paragraphProperties);

            Assert.AreEqual("0123456789 ", run.StringRange.ToString());
        }
コード例 #13
0
        public ITextSource GetSource(TextManager textManager, Assembly referenceAssembly, string targetNamespace)
        {
            var source = new SimpleTextSource();

            source.Texts.Add(new LocalizedText
            {
                Namespace = targetNamespace,
                Key       = "Tulips1",
                Pattern   = "resource:TestPlugin.Koala.jpg",
                Language  = "da-DK",
                Source    = new TextSourceInfo {
                    TextSource = source, ReferenceAssembly = referenceAssembly
                }
            });

            return(source);
        }
コード例 #14
0
        public void Text_Line_Run_Should_Not_Wrap_Line_When_There_Is_Enough_Available_Space()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

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

            var paragraphProperties = CreateDefaultParagraphProperties();

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

            Assert.AreEqual(10, run.Length);
        }
コード例 #15
0
        public void Simple_Run_Should_Have_Valid_Baseline()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

            SimpleTextSource s = new SimpleTextSource(
                "a\ta",
                CreateDefaultTextProperties());

            var paragraphProperties = CreateDefaultParagraphProperties();

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

            Assert.AreEqual(MockGlyphTypeface.GlyphAscent, run.Baseline);
        }
コード例 #16
0
        public ITextSource GetSource(Umbraco.Foundation.Localization.TextManager textManager, Assembly referenceAssembly, string targetNamespace)
        {
            var source = new SimpleTextSource();

            source.Texts.Add(new LocalizedText
            {
                Namespace = targetNamespace,
                Key       = "FactoryTest",
                Pattern   = "I'm from a factory",
                Language  = "en-US",
                Source    = new TextSourceInfo {
                    TextSource = source, ReferenceAssembly = referenceAssembly
                }
            });

            return(source);
        }
コード例 #17
0
        public void Text_Line_Run_Should_Perform_Character_Line_Wrapping_When_Space_Not_Found()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

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

            var paragraphProperties = CreateDefaultParagraphProperties();

            TextLineRun run = TextLineRun.Create(s, 0, 0, MockGlyphTypeface.GlyphAdvance * 3, paragraphProperties);

            Assert.AreEqual(3, run.Length);
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        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));
        }
コード例 #20
0
        public void Text_Line_Should_Wrap_In_Two_Runs_Option_Enabled()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

            SimpleTextSource s = new SimpleTextSource(
                "hello world",
                CreateDefaultTextProperties());

            TextParagraphProperties paraProps = CreateDefaultParagraphProperties();

            paraProps.TextWrapping = TextWrapping.Wrap;

            TextLineImpl textLine = TextLineImpl.Create(
                paraProps, 0, MockGlyphTypeface.GlyphAdvance * 7, s);

            Assert.AreEqual("hello ".Length, textLine.LineRuns[0].Length);
        }
コード例 #21
0
        public void Tab_Block_Should_Split_Runs()
        {
            using var app = UnitTestApplication.Start(new TestServices().With(
                                                          renderInterface: new MockPlatformRenderInterface(),
                                                          fontManagerImpl: new MockFontManagerImpl(),
                                                          formattedTextImpl: Mock.Of <IFormattedTextImpl>()));

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

            TextLineImpl textLine = TextLineImpl.Create(
                CreateDefaultParagraphProperties(), 0, 2, s);

            var textRuns = textLine.GetTextRuns();

            Assert.AreEqual(3, textRuns.Count);
            Assert.IsTrue(textLine.LineRuns[0].IsTab);
            Assert.IsTrue(textLine.LineRuns[1].IsTab);
            Assert.IsTrue(textLine.LineRuns[2].IsEnd);
        }
コード例 #22
0
 public void Setup()
 {
     _manager = new DefaultTextManager { CurrentLanguage = () => new LanguageInfo { Key = "en-US" } };
     _manager.Texts.Sources.Add(new PrioritizedTextSource(_source = new SimpleTextSource()));
     LocalizationConfig.TextManagerResolver = () => _manager;
 }
コード例 #23
0
 public CollapsedVisualTextLine(IEnumerable <SimpleTextSource> textSourcesToCollapse, SimpleTextSource precedingSource, SimpleTextSource followingSource, int index, string collapseRepresentation)
 {
     collapsedContent   = new List <string>(textSourcesToCollapse.Select(source => source.Text));
     textBeforeCollapse = precedingSource.Text;
     textAfterCollapse  = followingSource.Text;
     Index = index;
     this.collapseRepresentation = collapseRepresentation;
 }
コード例 #24
0
 public SingleVisualTextLine(SimpleTextSource textSource, int index)
 {
     this.textSource = textSource;
     Index           = index;
 }