Пример #1
0
        public void TestFraction(string latex, double lineThickness) =>
        TestOuter(latex, 1, 27.54, 17.72, 10,
                  d => {
            var fraction = Assert.IsType <FractionDisplay <TFont, TGlyph> >(d);
            Assert.Equal(new Range(0, 1), fraction.Range);
            Assert.Equal(new PointF(), fraction.Position);
            Assert.False(fraction.HasScript);
            Approximately.Equal(lineThickness, fraction.LineThickness);

            TestList(1, 14, 4, 10, 0, 13.54, LinePosition.Regular, Range.UndefinedInt,
                     dd => {
                var subNumerator = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(dd);
                Assert.Single(subNumerator.Atoms);
                AssertText("1", subNumerator);
                Assert.Equal(new PointF(), subNumerator.Position);
                Assert.Equal(new Range(0, 1), subNumerator.Range);
                Assert.False(subNumerator.HasScript);
            })(fraction.Numerator);

            TestList(1, 14, 4, 10, 0, -13.72, LinePosition.Regular, Range.UndefinedInt,
                     dd => {
                var subDenominator = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(dd);
                Assert.Single(subDenominator.Atoms);
                AssertText("3", subDenominator);
                Assert.Equal(new PointF(), subDenominator.Position);
                Assert.Equal(new Range(0, 1), subDenominator.Range);
                Assert.False(subDenominator.HasScript);
            })(fraction.Denominator);
        });
Пример #2
0
        [Theory, InlineData('[', ']'), InlineData('(', '}'), InlineData('{', ']')] // Using ) confuses the test explorer...
        public void TestInner(char left, char right) =>
        TestOuter($@"a\left{left}x\right{right}", 2, 14, 4, 43.333,
                  d => Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d),
                  d => {
            var inner = Assert.IsType <InnerDisplay <TFont, TGlyph> >(d);
            Approximately.At(13.333, 0, inner.Position);
            Assert.Equal(new Range(1, 1), inner.Range);
            Assert.Equal(14, inner.Ascent);
            Assert.Equal(4, inner.Descent);
            Assert.Equal(30, inner.Width);

            var glyph = Assert.IsType <GlyphDisplay <TFont, TGlyph> >(inner.Left);
            Approximately.At(13.333, 0, glyph.Position);
            Assert.Equal(Range.NotFound, glyph.Range);
            Assert.False(glyph.HasScript);
            Assert.Equal(left, glyph.Glyph);

            TestList(1, 14, 4, 10, 23.333, 0, LinePosition.Regular, Range.UndefinedInt,
                     d => {
                var line = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
                Assert.Single(line.Atoms);
                AssertText("x", line);
                Assert.Equal(new PointF(), line.Position);
                Assert.Equal(new Range(0, 1), d.Range);
                Assert.False(line.HasScript);
            })(inner.Inner);

            var glyph2 = Assert.IsType <GlyphDisplay <TFont, TGlyph> >(inner.Right);
            Approximately.At(33.333, 0, glyph2.Position);
            Assert.Equal(Range.NotFound, glyph2.Range);
            Assert.False(glyph2.HasScript);
            Assert.Equal(right, glyph2.Glyph);
        });
Пример #3
0
 public void TestSuperSubscript() =>
 TestOuter("x^2_1", 1, 19.48, 8.92, 17.32,
           d => {
     var line = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
     Assert.Single(line.Atoms);
     AssertText("x", line);
     Assert.Equal(new PointF(), line.Position);
     Assert.True(line.HasScript);
 },
           TestList(1, 9.8, 2.8, 7, 10.32, 9.68, LinePosition.Superscript, 0,
                    d => {
     var line2 = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
     Assert.Single(line2.Atoms);
     AssertText("2", line2);
     Assert.Equal(new PointF(), line2.Position);
     Assert.False(line2.HasScript);
     Approximately.Equal(20.12, 10.32 + line2.Ascent);
 }),
           // Because both subscript and superscript are present, coords are
           // different from the subscript-only case.
           TestList(1, 9.8, 2.8, 7, 10, -6.12, LinePosition.Subscript, 0,
                    d => {
     var line3 = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
     Assert.Single(line3.Atoms);
     AssertText("1", line3);
     Assert.Equal(new PointF(), line3.Position);
     Assert.False(line3.HasScript);
     Approximately.Equal(8.92, line3.Descent - (-6.12));
 }));
Пример #4
0
        public void TestGlyphBoundsWithoutM()
        {
            string hello    = "Hello";
            var    font     = new TestFont(10);
            var    provider = TestGlyphBoundsProvider.Instance;
            var    glyphRun = new AttributedGlyphRun <TestFont, TGlyph>(hello, hello, font);
            var    width    = provider.GetTypographicWidth(font, glyphRun);

            Approximately.Equal(width, 25, 0.01);
        }
Пример #5
0
        public void TestGlyphBoundsWithM()
        {
            string america  = "America";
            var    font     = new TestFont(10);
            var    provider = TestGlyphBoundsProvider.Instance;
            var    glyphRun = new AttributedGlyphRun <TestFont, TGlyph>(america, america, font);
            var    width    = provider.GetTypographicWidth(font, glyphRun);

            Approximately.Equal(width, 40, 0.01);
        }
Пример #6
0
 public void TestLimit() =>
 TestOuter(@"\infty = \lim_{x\to 0^+} \frac{1}{x}", 4, 27.54, 21.186, 84.444,
           d => {
     var textBefore = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
     AssertText("∞=", textBefore);
     Assert.Equal(new Range(0, 2), textBefore.Range);
 },
           d => {
     var largeOp = Assert.IsType <LargeOpLimitsDisplay <TFont, TGlyph> >(d);
     Assert.Equal(new Range(2, 1), largeOp.Range);
     var largeOpText = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(largeOp.NucleusDisplay);
     AssertText("lim", largeOpText);
     Approximately.Equal(new PointF(31.111f, 0), largeOpText.Position);
     Assert.False(largeOpText.HasScript);
     TestList(3, 11.046, 2.8, 26, 38.111, -18.386, LinePosition.Regular, Range.UndefinedInt,
              d => {
         var subscript = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         AssertText("x→0", subscript);
         Assert.Equal(3, subscript.Atoms.Count);
         Assert.Equal(new PointF(), subscript.Position);
         Assert.True(subscript.HasScript);
         Assert.Equal(new Range(0, 3), subscript.Range);
     },
              TestList(1, 7, 2, 5, 21, 4.046, LinePosition.Superscript, 2,
                       d => {
         var superscript = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         AssertText("+", superscript);
         Assert.Single(superscript.Atoms);
         Assert.Equal(new PointF(), superscript.Position);
         Assert.False(superscript.HasScript);
         Assert.Equal(new Range(0, 1), superscript.Range);
     }))(largeOp.LowerLimit);
 },
           d => {
     var fraction = Assert.IsType <FractionDisplay <TFont, TGlyph> >(d);
     Assert.Equal(new Range(3, 1), fraction.Range);
     TestList(1, 14, 4, 10, 74.444, 13.54, LinePosition.Regular, Range.UndefinedInt,
              d => {
         var superscript = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         AssertText("1", superscript);
         Assert.Single(superscript.Atoms);
         Assert.Equal(new PointF(), superscript.Position);
         Assert.False(superscript.HasScript);
         Assert.Equal(new Range(0, 1), superscript.Range);
     })(fraction.Numerator);
     TestList(1, 14, 4, 10, 74.444, -13.72, LinePosition.Regular, Range.UndefinedInt,
              d => {
         var subscript = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         AssertText("x", subscript);
         Assert.Single(subscript.Atoms);
         Assert.Equal(new PointF(), subscript.Position);
         Assert.False(subscript.HasScript);
         Assert.Equal(new Range(0, 1), subscript.Range);
     })(fraction.Denominator);
 });
Пример #7
0
        public void TestGlyphBoundsWithoutM()
        {
            string hello    = "Hello";
            var    font     = new TestFont(10);
            var    provider = TestGlyphBoundsProvider.Instance;
            var    glyphRun = new AttributedGlyphRun <TestFont, TGlyph>(hello, hello.EnumerateRunes(), font);

            Assert.All(glyphRun.GlyphInfos, glyphInfo => Assert.Null(glyphInfo.Foreground));
            var width = provider.GetTypographicWidth(font, glyphRun);

            Approximately.Equal(width, 25, 0.01);
        }
Пример #8
0
 System.Action <IDisplay <TFont, TGlyph>?> TestList(int rangeMax, double ascent, double descent, double width, double x, double y,
                                                    LinePosition linePos, int indexInParent, params System.Action <IDisplay <TFont, TGlyph> >[] inspectors) => d => {
     var list = Assert.IsType <ListDisplay <TFont, TGlyph> >(d);
     Assert.False(list.HasScript);
     Assert.Equal(new Range(0, rangeMax), list.Range);
     Approximately.Equal(ascent, list.Ascent);
     Approximately.Equal(descent, list.Descent);
     Approximately.Equal(width, list.Width);
     Approximately.At(x, y, list.Position); // may change as we implement more details?
     Assert.Equal(linePos, list.LinePosition);
     Assert.Equal(indexInParent, list.IndexInParent);
     Assert.Collection(list.Displays, inspectors);
 };
Пример #9
0
        [Theory, InlineData("[", "]"), InlineData("(", @"\}"), InlineData(@"\{", "]")] // Using ) confuses the test explorer...
        public void TestInner(string left, string right) =>
        TestOuter($@"a\left{left}x\right{right}", 2, 14, 4, 43.333,
                  d => Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d),
                  d => {
            var inner = Assert.IsType <InnerDisplay <TFont, TGlyph> >(d);
            Approximately.At(13.333, 0, inner.Position);
            Assert.Equal(new Range(1, 1), inner.Range);
            Assert.Equal(14, inner.Ascent);
            Assert.Equal(4, inner.Descent);
            Assert.Equal(30, inner.Width);

            var glyph = Assert.IsType <GlyphDisplay <TFont, TGlyph> >(inner.Left);
            Approximately.At(13.333, 0, glyph.Position);
            Assert.Equal(Range.NotFound, glyph.Range);
            Assert.False(glyph.HasScript);
            Assert.Equal(left[^ 1], glyph.Glyph);
Пример #10
0
 public void TestAccent() =>
 TestOuter(@"\bar{x}", 1, 19, 9, 10.16, d => {
     var accent = Assert.IsType <AccentDisplay <TFont, TGlyph> >(d);
     Assert.Equal(0, accent.Accent.ShiftDown);
     Assert.Equal('\u0304', accent.Accent.Glyph);
     Approximately.Equal(new PointF(0.16f, 5), accent.Accent.Position);
     Assert.False(accent.Accent.HasScript);
     Assert.Equal(new Range(0, 1), accent.Accent.Range);
     TestList(1, 14, 4, 10, 0, 0, LinePosition.Regular, Range.UndefinedInt,
              d => {
         var line = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(d);
         Assert.Single(line.Atoms);
         AssertText("x", line);
         Assert.Equal(new PointF(), line.Position);
         Assert.False(line.HasScript);
     })(accent.Accentee);
 });
Пример #11
0
 public void TestBinomial(string latex) =>
 TestOuter(latex, 1, 27.54, 17.72, 30,
           TestList(1, 27.54, 17.72, 30, 0, 0, LinePosition.Regular, Range.UndefinedInt,
                    d => {
     var glyph = Assert.IsType <GlyphDisplay <TFont, TGlyph> >(d);
     Assert.Equal(new PointF(), glyph.Position);
     Assert.Equal(Range.NotFound, glyph.Range);
     Assert.False(glyph.HasScript);
 },
                    d => {
     var subFraction = Assert.IsType <FractionDisplay <TFont, TGlyph> >(d);
     Assert.Equal(new Range(0, 1), subFraction.Range);
     Assert.False(subFraction.HasScript);
     Approximately.At(10, 0, subFraction.Position);
     TestList(1, 14, 4, 10, 10, 13.54, LinePosition.Regular, Range.UndefinedInt,
              dd => {
         var subNumerator = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(dd);
         Assert.Single(subNumerator.Atoms);
         AssertText("1", subNumerator);
         Assert.Equal(new PointF(), subNumerator.Position);
         Assert.Equal(new Range(0, 1), subNumerator.Range);
         Assert.False(subNumerator.HasScript);
     })(subFraction.Numerator);
     TestList(1, 14, 4, 10, 10, -13.72, LinePosition.Regular, Range.UndefinedInt,
              dd => {
         var subDenominator = Assert.IsType <TextLineDisplay <TFont, TGlyph> >(dd);
         Assert.Single(subDenominator.Atoms);
         AssertText("3", subDenominator);
         Assert.Equal(new PointF(), subDenominator.Position);
         Assert.Equal(new Range(0, 1), subDenominator.Range);
         Assert.False(subDenominator.HasScript);
     })(subFraction.Denominator);
 },
                    d => {
     var subRight = Assert.IsType <GlyphDisplay <TFont, TGlyph> >(d);
     Assert.False(subRight.HasScript);
     Assert.Equal(Range.NotFound, subRight.Range);
     Approximately.At(20, 0, subRight.Position);
 }));