示例#1
0
        public void IndentTest()
        {
            using (var formatter = TextFormatter.Create())
            {
                List <string> log        = new List <string> ();
                var           textSource = new LoggingTextSource(log);
                textSource.AddContents("test test2");
                textSource.AddContents(new TextEndOfLine(1));
                var textParagraphProperties = new LoggingTextParagraphProperties(log);
                textParagraphProperties.alwaysCollapsible = true;
                textParagraphProperties.indent            = 20;
                log.Clear();
                var line = formatter.FormatLine(textSource, 0, 530.0, textParagraphProperties, null);
                Assert.AreEqual(147.18 + 0.02 / 3.0, line.Height, "line.Height");
                Assert.AreEqual(5, line.Length, "line.Length");
                Assert.AreEqual(0, line.NewlineLength, "line.NewlineLength");
                Assert.AreEqual(117.97, line.Baseline, 0.000000001, "line.Baseline");
                Assert.AreEqual(67894 / 300.0, line.Width, 0.000000001, "line.Width");
                Assert.IsFalse(line.HasOverflowed, "line.HasOverflowed");
                Assert.AreEqual(78563 / 300.0, line.WidthIncludingTrailingWhitespace, 0.000000001, "line.WidthIncludingTrailingWhitespace");
                AssertTextRunSpans(
                    new int[] { 5 },
                    new TextRun[] { textSource.contents[0] },
                    line);
                Assert.IsNull(line.GetTextLineBreak(), "GetTextLineBreak");
                Assert.AreEqual(0, line.Start, "line.Start");

                AssertCharacterHit(line, 25.0, 0, 0);
            }
        }
示例#2
0
 public void OverflowTest()
 {
     using (var formatter = TextFormatter.Create())
     {
         List <string> log        = new List <string> ();
         var           textSource = new LoggingTextSource(log);
         textSource.AddContents("test test");
         textSource.AddContents(new TextEndOfLine(1));
         var textParagraphProperties = new LoggingTextParagraphProperties(log);
         textParagraphProperties.alwaysCollapsible = true;
         textParagraphProperties.textWrapping      = TextWrapping.NoWrap;
         log.Clear();
         var line = formatter.FormatLine(textSource, 0, 256.0, textParagraphProperties, null);
         Assert.AreEqual(147.18 + 0.02 / 3.0, line.Height, "line.Height");
         Assert.AreEqual(10, line.Length, "line.Length");
         Assert.AreEqual(1, line.NewlineLength, "line.NewlineLength");
         Assert.AreEqual(117.97, line.Baseline, 0.000000001, "line.Baseline");
         Assert.AreEqual(448.19, line.Width, 0.000000001, "line.Width");
         Assert.IsTrue(line.HasOverflowed, "line.HasOverflowed");
         Assert.AreEqual(448.19, line.WidthIncludingTrailingWhitespace, 0.000000001, "line.WidthIncludingTrailingWhitespace");
         AssertTextRunSpans(
             new int[] { 9, 1 },
             new TextRun[] { textSource.contents[0], new TextEndOfLine(1) },
             line);
         Assert.IsNull(line.GetTextLineBreak(), "GetTextLineBreak");
         Assert.AreEqual(0, line.Start, "line.Start");
     }
 }
示例#3
0
 public void SingleWordTahomaTest()
 {
     using (var formatter = TextFormatter.Create())
     {
         List <string> log       = new List <string> ();
         var           textProps = new LoggingTextRunProperties(log, "Tahoma");
         textProps.typeface = new Typeface("Tahoma");
         var textSource = new LoggingTextSource(log);
         textSource.AddContents("test", textProps);
         textSource.AddContents(new TextEndOfLine(1));
         var textParagraphProperties = new LoggingTextParagraphProperties(log);
         log.Clear();
         var line = formatter.FormatLine(textSource, 0, 256.0, textParagraphProperties, null);
         Assert.AreEqual(154.5, line.Height, "line.Height");
         Assert.AreEqual(5, line.Length, "line.Length");
         Assert.AreEqual(1, line.NewlineLength, "line.NewlineLength");
         Assert.AreEqual(128.06 + 0.01 / 3.0, line.Baseline, "line.Baseline");
         Assert.AreEqual(210.12 + 0.02 / 3.0, line.Width, 0.000000001, "line.Width");
         Assert.IsFalse(line.HasOverflowed, "line.HasOverflowed");
         Assert.AreEqual(210.12 + 0.02 / 3.0, line.WidthIncludingTrailingWhitespace, 0.000000001, "line.WidthIncludingTrailingWhitespace");
         AssertTextRunSpans(
             new int[] { 4, 1 },
             new TextRun[] { textSource.contents[0], new TextEndOfLine(1) },
             line);
         Assert.AreEqual(new string[] {
             "DefaultTextRunProperties",
             "DefaultTextRunProperties.Typeface",
             "DefaultTextRunProperties.FontRenderingEmSize",
             "Indent",
             "LineHeight",
             "FlowDirection",
             "AlwaysCollapsible",
             "TextAlignment",
             "FirstLineInParagraph",
             "TextMarkerProperties",
             "TextWrapping",
             "GetTextRun(0)",
             "Tahoma.FontRenderingEmSize",
             "Tahoma.CultureInfo",
             "Tahoma.Typeface",
             "Tahoma.TextEffects",
             "Tahoma.TextDecorations",
             "GetTextRun(4)",
         }, log);
         Assert.IsNull(line.GetTextLineBreak(), "GetTextLineBreak");
         Assert.AreEqual(0, line.Start, "line.Start");
     }
 }
示例#4
0
 public void EmptyLineTest()
 {
     using (var formatter = TextFormatter.Create())
     {
         List <string> log        = new List <string> ();
         var           textSource = new LoggingTextSource(log);
         textSource.AddContents(new TextEndOfLine(1));
         var textParagraphProperties = new LoggingTextParagraphProperties(log);
         Assert.AreEqual(2355 / 2048.0, textParagraphProperties.DefaultTextRunProperties.Typeface.FontFamily.LineSpacing);
         log.Clear();
         var line = formatter.FormatLine(textSource, 0, 256.0, textParagraphProperties, null);
         Assert.AreEqual(147.18 + 0.02 / 3.0, line.Height, "line.Height");
         Assert.AreEqual(1, line.Length, "line.Length");
         Assert.AreEqual(1, line.NewlineLength, "line.NewlineLength");
         Assert.AreEqual(117.97, line.Baseline, 0.000000001, "line.Baseline");
         Assert.AreEqual(0, line.Width, "line.Width");
         Assert.IsFalse(line.HasOverflowed, "line.HasOverflowed");
         Assert.AreEqual(0, line.WidthIncludingTrailingWhitespace, "line.WidthIncludingTrailingWhitespace");
         AssertTextRunSpans(
             new int[] { 1 },
             new TextRun[] { new TextEndOfLine(1) },
             line);
         Assert.AreEqual(new string[] {
             "DefaultTextRunProperties",
             "DefaultTextRunProperties.Typeface",
             "DefaultTextRunProperties.FontRenderingEmSize",
             "Indent",
             "LineHeight",
             "FlowDirection",
             "AlwaysCollapsible",
             "TextAlignment",
             "FirstLineInParagraph",
             "TextMarkerProperties",
             "TextWrapping",
             "GetTextRun(0)",
         }, log);
         Assert.IsNull(line.GetTextLineBreak(), "GetTextLineBreak");
         Assert.AreEqual(0, line.Start, "line.Start");
     }
 }
示例#5
0
 public void EmptyLineCollapsibleTest()
 {
     using (var formatter = TextFormatter.Create())
     {
         List <string> log        = new List <string> ();
         var           textSource = new LoggingTextSource(log);
         textSource.AddContents(new TextEndOfLine(1));
         var textParagraphProperties = new LoggingTextParagraphProperties(log);
         textParagraphProperties.alwaysCollapsible = true;
         Assert.AreEqual(2355 / 2048.0, textParagraphProperties.DefaultTextRunProperties.Typeface.FontFamily.LineSpacing);
         log.Clear();
         var line = formatter.FormatLine(textSource, 0, 256.0, textParagraphProperties, null);
         Assert.AreEqual(147.18 + 0.02 / 3.0, line.Height, "line.Height");
         Assert.AreEqual(1, line.Length, "line.Length");
         Assert.AreEqual(1, line.NewlineLength, "line.NewlineLength");
         Assert.AreEqual(117.97, line.Baseline, 0.000000001, "line.Baseline");
         Assert.AreEqual(0, line.Width, "line.Width");
         Assert.IsFalse(line.HasOverflowed, "line.HasOverflowed");
         Assert.AreEqual(0, line.WidthIncludingTrailingWhitespace, "line.WidthIncludingTrailingWhitespace");
         AssertTextRunSpans(
             new int[] { 1 },
             new TextRun[] { new TextEndOfLine(1) },
             line);
         Assert.IsNull(line.GetTextLineBreak(), "GetTextLineBreak");
         Assert.AreEqual(0, line.Start, "line.Start");
         var glyphRuns = new List <IndexedGlyphRun>(line.GetIndexedGlyphRuns());
         Assert.AreEqual(0, glyphRuns.Count);
         AssertCharacterHit(line, -1.0, 0, 0);
         AssertCharacterHit(line, 0.0, 0, 0);
         AssertCharacterHit(line, 1.0, 0, 0);
         var tb = line.GetTextBounds(0, 1);
         Assert.AreEqual(1, tb.Count, "TextBounds.Count");
         Assert.AreEqual(FlowDirection.LeftToRight, tb[0].FlowDirection, "TextBounds.FlowDirection");
         Assert.AreEqual(new Rect(0, 0, 0, 44156 / 300.0), tb[0].Rectangle, "TextBounds.Rectangle");
         Assert.IsNull(tb[0].TextRunBounds, "TextBounds.TextRunBounds");
         AssertCharacterHit(0, 0, line.GetPreviousCaretCharacterHit(new CharacterHit(0, 0)), "previous 0,0");
         AssertCharacterHit(0, 0, line.GetNextCaretCharacterHit(new CharacterHit(0, 0)), "next 0,0");
     }
 }
示例#6
0
        public void WrapTest()
        {
            using (var formatter = TextFormatter.Create())
            {
                List <string> log        = new List <string> ();
                var           textSource = new LoggingTextSource(log);
                textSource.AddContents("test test2");
                textSource.AddContents(new TextEndOfLine(1));
                var textParagraphProperties = new LoggingTextParagraphProperties(log);
                textParagraphProperties.alwaysCollapsible = true;
                log.Clear();
                var line = formatter.FormatLine(textSource, 0, 256.0, textParagraphProperties, null);
                Assert.AreEqual(147.18 + 0.02 / 3.0, line.Height, "line.Height");
                Assert.AreEqual(5, line.Length, "line.Length");
                Assert.AreEqual(0, line.NewlineLength, "line.NewlineLength");
                Assert.AreEqual(117.97, line.Baseline, 0.000000001, "line.Baseline");
                Assert.AreEqual(206.31 + 0.01 / 3.0, line.Width, 0.000000001, "line.Width");
                Assert.IsFalse(line.HasOverflowed, "line.HasOverflowed");
                Assert.AreEqual(241.87 + 0.02 / 3.0, line.WidthIncludingTrailingWhitespace, 0.000000001, "line.WidthIncludingTrailingWhitespace");
                AssertTextRunSpans(
                    new int[] { 5 },
                    new TextRun[] { textSource.contents[0] },
                    line);
                Assert.IsNull(line.GetTextLineBreak(), "GetTextLineBreak");
                Assert.AreEqual(0, line.Start, "line.Start");

                var glyphRuns = new List <IndexedGlyphRun>(line.GetIndexedGlyphRuns());
                Assert.AreEqual(1, glyphRuns.Count, "glyphRuns.Count");
                var glyphRun = glyphRuns[0];
                Assert.AreEqual(0, glyphRun.TextSourceCharacterIndex, "TextSourceCharacterIndex");
                Assert.AreEqual(5, glyphRun.TextSourceLength, "TextSourceLength");
                Assert.AreEqual(0, glyphRun.GlyphRun.BidiLevel, "BidiLevel");
                Assert.AreEqual(false, glyphRun.GlyphRun.IsSideways, "IsSideways");
                Assert.AreEqual(128.0, glyphRun.GlyphRun.FontRenderingEmSize, "FontRenderingEmSize");
                Assert.AreEqual(1.0, glyphRun.GlyphRun.PixelsPerDip, "PixelsPerDip");
                Assert.AreEqual(5, glyphRun.GlyphRun.GlyphIndices.Count, "GlyphIndices");
                Assert.AreEqual(0, glyphRun.GlyphRun.BaselineOrigin.X, "BaselineOrigin.X");
                Assert.AreEqual(0, glyphRun.GlyphRun.BaselineOrigin.Y, "BaselineOrigin.Y");
                Assert.AreEqual(new double[] { 10669 / 300.0, 21356 / 300.0, 19200 / 300.0, 10669 / 300.0, 10669 / 300.0 }, glyphRun.GlyphRun.AdvanceWidths, "AdvanceWidths");
                Assert.AreEqual(new char[] { 't', 'e', 's', 't', ' ' }, glyphRun.GlyphRun.Characters, "Characters");
                Assert.IsNull(glyphRun.GlyphRun.DeviceFontName, "DeviceFontName");
                Assert.AreEqual(new ushort[] { 0, 1, 2, 3, 4 }, glyphRun.GlyphRun.ClusterMap, "ClusterMap");
                Assert.IsNull(glyphRun.GlyphRun.CaretStops, "CaretStops");

                AssertCharacterHit(line, -1.0, 0, 0);
                AssertCharacterHit(line, 0.0, 0, 0);
                AssertCharacterHit(line, 0.1, 0, 0);
                AssertCharacterHit(line, 25.0, 0, 1);

                AssertCharacterHit(line, -1.0, 0, 0);
                AssertCharacterHit(line, 0.0, 0, 0);
                AssertCharacterHit(line, 0.1, 0, 0);
                AssertCharacterHit(line, 25.0, 0, 1);
                AssertCharacterHit(line, 50.0, 1, 0);
                AssertCharacterHit(line, 206.30, 3, 1);
                AssertCharacterHit(line, 206.32, 4, 0);
                AssertCharacterHit(line, 226.32, 4, 1);
                AssertCharacterHit(line, 241.86, 4, 1);
                AssertCharacterHit(line, 243.0, 4, 1);
                AssertCharacterHit(line, 1000.0, 4, 1);

                var tb = line.GetTextBounds(1, 2);
                Assert.AreEqual(1, tb.Count, "TextBounds.Count");
                Assert.AreEqual(FlowDirection.LeftToRight, tb[0].FlowDirection, "TextBounds.FlowDirection");
                Assert.AreEqual(new Rect(10669 / 300.0, 0, 40556 / 300.0, 44156 / 300.0), tb[0].Rectangle, "TextBounds.Rectangle");
                Assert.AreEqual(1, tb[0].TextRunBounds.Count, "TextBounds.TextRunBounds.Count");
                Assert.AreEqual(2, tb[0].TextRunBounds[0].Length, "TextRunBounds.Length");
                Assert.AreEqual(new Rect(10669 / 300.0, 0, 40556 / 300.0, 44156 / 300.0), tb[0].TextRunBounds[0].Rectangle, "TextRunBounds.Rectangle");
                // We get the text run containing the characters, not the one starting at the specified index
                AssertTextRun(textSource.contents[0], tb[0].TextRunBounds[0].TextRun, "TextRunBounds.TextRun");
                Assert.AreEqual(1, tb[0].TextRunBounds[0].TextSourceCharacterIndex, "TextRunBounds.TextSourceCharacterIndex");

                tb = line.GetTextBounds(0, 6);
                Assert.AreEqual(1, tb.Count, "TextBounds2.Count");
                Assert.AreEqual(FlowDirection.LeftToRight, tb[0].FlowDirection, "TextBounds2.FlowDirection");
                Assert.AreEqual(0, tb[0].Rectangle.X, "TextBounds2.Rectangle.X");
                Assert.AreEqual(0, tb[0].Rectangle.Y, "TextBounds2.Rectangle.Y");
                Assert.AreEqual(72563 / 300.0, tb[0].Rectangle.Width, 0.000000001, "TextBounds2.Rectangle.Width");
                Assert.AreEqual(44156 / 300.0, tb[0].Rectangle.Height, 0.000000001, "TextBounds2.Rectangle.Height");
                Assert.AreEqual(1, tb[0].TextRunBounds.Count, "TextBounds2.TextRunBounds.Count");
                Assert.AreEqual(5, tb[0].TextRunBounds[0].Length, "TextBounds2.TextRunBounds.Length");
                Assert.AreEqual(0, tb[0].TextRunBounds[0].Rectangle.X, "TextRunBounds2.Rectangle.X");
                Assert.AreEqual(0, tb[0].TextRunBounds[0].Rectangle.Y, "TextRunBounds2.Rectangle.Y");
                Assert.AreEqual(72563 / 300.0, tb[0].TextRunBounds[0].Rectangle.Width, 0.000000001, "TextRunBounds2.Rectangle.Width");
                Assert.AreEqual(44156 / 300.0, tb[0].TextRunBounds[0].Rectangle.Height, 0.000000001, "TextRunBounds2.Rectangle.Height");
                AssertTextRun(textSource.contents[0], tb[0].TextRunBounds[0].TextRun, "TextRunBounds2.TextRun");
                Assert.AreEqual(0, tb[0].TextRunBounds[0].TextSourceCharacterIndex, "TextRunBounds2.TextSourceCharacterIndex");

                AssertCharacterHit(0, 0, line.GetPreviousCaretCharacterHit(new CharacterHit(0, 0)), "previous 0,0");
                AssertCharacterHit(0, 0, line.GetPreviousCaretCharacterHit(new CharacterHit(0, 1)), "previous 0,1");
                AssertCharacterHit(0, 0, line.GetPreviousCaretCharacterHit(new CharacterHit(1, 0)), "previous 1,0");
                AssertCharacterHit(1, 0, line.GetPreviousCaretCharacterHit(new CharacterHit(1, 1)), "previous 1,1");
                AssertCharacterHit(0, 1, line.GetNextCaretCharacterHit(new CharacterHit(0, 0)), "next 0,0");
                AssertCharacterHit(1, 1, line.GetNextCaretCharacterHit(new CharacterHit(0, 1)), "next 0,1");
                AssertCharacterHit(1, 1, line.GetNextCaretCharacterHit(new CharacterHit(1, 0)), "next 1,0");
                AssertCharacterHit(2, 1, line.GetNextCaretCharacterHit(new CharacterHit(1, 1)), "next 1,1");
                AssertCharacterHit(4, 1, line.GetNextCaretCharacterHit(new CharacterHit(4, 1)), "next 4,1");

                line = formatter.FormatLine(textSource, 5, 300.0, textParagraphProperties, null);
                Assert.AreEqual(147.18 + 0.02 / 3.0, line.Height, "line.Height");
                Assert.AreEqual(6, line.Length, "line.Length");
                Assert.AreEqual(1, line.NewlineLength, "line.NewlineLength");
                Assert.AreEqual(117.97, line.Baseline, 0.000000001, "line.Baseline");
                Assert.AreEqual(277.5, line.Width, 0.000000001, "line.Width");
                Assert.IsFalse(line.HasOverflowed, "line.HasOverflowed");
                Assert.AreEqual(277.5, line.WidthIncludingTrailingWhitespace, 0.000000001, "line.WidthIncludingTrailingWhitespace");
                AssertTextRunSpans(
                    new int[] { 5, 1 },
                    new TextRun[] { textSource.contents[5], new TextEndOfLine(1) },
                    line);
                Assert.IsNull(line.GetTextLineBreak(), "GetTextLineBreak");
                Assert.AreEqual(0, line.Start, "line.Start");
            }
        }