示例#1
0
        public void TestCopyMathTable()
        {
            var table = new Table();

            Assert.IsType <Table>(table);
            var atom  = LaTeXSettings.Placeholder;
            var atom2 = LaTeXSettings.Times;
            var atom3 = LaTeXSettings.Divide;
            var list  = new MathList {
                atom, atom2, atom3
            };
            var list2 = new MathList {
                atom3, atom2
            };

            table.SetCell(list, 0, 1);
            table.SetCell(list2, 0, 2);
            table.SetAlignment(ColumnAlignment.Left, 2);
            table.SetAlignment(ColumnAlignment.Right, 1);

            var clone = table.Clone(false);

            CheckClone(table, clone);
            Assert.Equal(clone.InterColumnSpacing, table.InterColumnSpacing);
            Assert.Equal(clone.Alignments, table.Alignments);
            Assert.False(ReferenceEquals(clone.Alignments, table.Alignments));
            Assert.False(ReferenceEquals(clone.Cells, table.Cells));
            Assert.False(ReferenceEquals(clone.Cells[0], table.Cells[0]));
            Assert.Equal(clone.Cells[0].Count, table.Cells[0].Count);
            Assert.Empty(clone.Cells[0][0]);
            CheckClone(table.Cells[0][1], clone.Cells[0][1]);
            CheckClone(table.Cells[0][2], clone.Cells[0][2]);
            Assert.False(ReferenceEquals(clone.Cells[0][0], table.Cells[0][0]));
        }
示例#2
0
        public static void RemoveAt(this MathList self, ref MathListIndex index)
        {
            index ??= MathListIndex.Level0Index(0);
            if (index.AtomIndex > self.Atoms.Count)
            {
                throw new IndexOutOfRangeException($"Index {index.AtomIndex} is out of bounds for list of size {self.Atoms.Count}");
            }
            switch (index.SubIndexType)
            {
            case MathListSubIndexType.None:
                self.RemoveAt(index.AtomIndex);
                break;

            case var _ when index.SubIndex is null:
                throw new InvalidCodePathException("index.SubIndex is null despite non-None subindex type");

            case MathListSubIndexType.BetweenBaseAndScripts:
                var currentAtom = self.Atoms[index.AtomIndex];
                if (currentAtom.Subscript.IsEmpty() && currentAtom.Superscript.IsEmpty())
                {
                    throw new SubIndexTypeMismatchException(index);
                }
                var downIndex = index.LevelDown();
                if (downIndex is null)
                {
                    throw new InvalidCodePathException("downIndex is null");
                }
                if (index.AtomIndex > 0 &&
                    self.Atoms[index.AtomIndex - 1] is MathAtom previous &&
                    previous.Subscript.IsEmpty() &&
                    previous.Superscript.IsEmpty() &&
                    previous switch
                {
                    Atoms.BinaryOperator _ => false,
                    Atoms.UnaryOperator _ => false,
                    Atoms.Relation _ => false,
                    Atoms.Punctuation _ => false,
                    Atoms.Space _ => false,
                    _ => true
                })
                {
                    previous.Superscript.Append(currentAtom.Superscript);
                    previous.Subscript.Append(currentAtom.Subscript);
                    self.RemoveAt(index.AtomIndex);
                    // it was in the nucleus and we removed it, get out of the nucleus and get in the nucleus of the previous one.
                    index = downIndex.Previous is MathListIndex downPrev
              ? downPrev.LevelUpWithSubIndex(MathListSubIndexType.BetweenBaseAndScripts, MathListIndex.Level0Index(1))
              : downIndex;

                    break;
                }
                // insert placeholder since we couldn't place the scripts in previous atom
                var insertionAtom = LaTeXSettings.Placeholder;
                insertionAtom.Subscript.Append(currentAtom.Subscript);
                insertionAtom.Superscript.Append(currentAtom.Superscript);
                self.RemoveAt(index.AtomIndex);
                index = downIndex;
                self.InsertAndAdvance(ref index, insertionAtom, MathListSubIndexType.None);
                index = index.Previous ?? throw new InvalidCodePathException("Cannot go back after insertion?");
                return;
示例#3
0
        public void TestCreateMathTable()
        {
            var table = new Table();

            Assert.IsType <Table>(table);
            var atom1 = LaTeXSettings.Placeholder;
            var atom2 = LaTeXSettings.Times;
            var atom3 = LaTeXSettings.Divide;
            var list  = new MathList(atom1, atom2, atom3);
            var list2 = new MathList(atom3, atom2);

            table.SetCell(list, 3, 2);
            table.SetCell(list2, 1, 0);
            table.SetAlignment(ColumnAlignment.Left, 2);
            table.SetAlignment(ColumnAlignment.Right, 1);

            Assert.Equal(4, table.Cells.Count);
            Assert.Empty(table.Cells[0]);
            Assert.Single(table.Cells[1]);
            Assert.Empty(table.Cells[2]);
            Assert.Equal(3, table.Cells[3].Count);

            Assert.Equal(2, table.Cells[1][0].Atoms.Count);
            Assert.Equal(list2, table.Cells[1][0]);
            Assert.Empty(table.Cells[3][0].Atoms);
            Assert.Empty(table.Cells[3][1].Atoms);
            Assert.Equal(list, table.Cells[3][2]);

            Assert.Equal(4, table.NRows);
            Assert.Equal(3, table.NColumns);
            Assert.Equal(3, table.Alignments.Count);
            Assert.Equal(ColumnAlignment.Center, table.Alignments[0]);
            Assert.Equal(ColumnAlignment.Right, table.Alignments[1]);
            Assert.Equal(ColumnAlignment.Left, table.Alignments[2]);
        }
示例#4
0
        public void TestSimpleVariable()
        {
            var list = new MathList {
                MathAtoms.ForCharacter('x')
            };
            var display = _context.CreateLine(list, _font, LineStyle.Display);

            Assert.NotNull(display);
            Assert.Equal(LinePosition.Regular, display.LinePosition);
            Assert.Equal(new PointF(), display.Position);
            Assert.Equal(new Range(0, 1), display.Range);
            Assert.False(display.HasScript);
            Assert.Equal(int.MinValue, display.IndexInParent);
            Assert.Single(display.Displays);
            var sub0 = display.Displays[0];

            Assert.True(sub0 is TextLineDisplay <TFont, TGlyph>);
            var line = sub0 as TextLineDisplay <TFont, TGlyph>;

            Assert.Single(line.Atoms); // have to think about these; doesn't really work atm

            Assert.Equal("x", line.StringText());
            Assert.Equal(new PointF(), line.Position);
            Assert.Equal(new Range(0, 1), line.Range);
            Assert.False(line.HasScript);
            var descent = display.Descent;

            Assertions.ApproximatelyEqual(14, display.Ascent, 0.01);
            Assertions.ApproximatelyEqual(4, descent, 0.01);
            Assertions.ApproximatelyEqual(10, display.Width, 0.01);
            Assert.Equal(display.Ascent, line.Ascent);
            Assert.Equal(display.Descent, line.Descent);
            Assert.Equal(display.Width, line.Width);
        }
示例#5
0
        private void RunScriptTest(string input, Func <IMathAtom, IMathList> scriptGetter, MathAtomType[][] atomTypes, string output)
        {
            var builder = new MathListBuilder(input);
            var list    = builder.Build();

            Assert.Null(builder.Error);

            var expandedList = new MathList(list, false);

            expandedList.ExpandGroups();
            CheckAtomTypes(expandedList, atomTypes[0]);

            IMathAtom firstAtom = expandedList[0];
            var       types     = atomTypes[1];

            if (types.Count() > 0)
            {
                Assert.NotNull(scriptGetter(firstAtom));
            }
            var scriptList = scriptGetter(firstAtom);

            CheckAtomTypes(scriptList, atomTypes[1]);
            if (atomTypes.Count() == 3)
            {
                // one more level
                var firstScript      = scriptList[0];
                var scriptScriptList = scriptGetter(firstScript);
                CheckAtomTypes(scriptScriptList, atomTypes[2]);
            }

            string latex = MathListBuilder.MathListToString(list);

            Assert.Equal(output, latex);
        }
示例#6
0
        public void TestCopyFraction()
        {
            var atom  = LaTeXSettings.Placeholder;
            var atom2 = LaTeXSettings.Times;
            var atom3 = LaTeXSettings.Divide;
            var list  = new MathList {
                atom, atom2, atom3
            };
            var list2 = new MathList {
                atom3, atom2
            };
            var frac = new Fraction(list, list2, false)
            {
                LeftDelimiter  = "a",
                RightDelimiter = "b"
            };

            Assert.IsType <Fraction>(frac);

            var copy = frac.Clone(false);

            CheckClone(copy, frac);
            CheckClone(copy.Numerator, frac.Numerator);
            Assert.False(copy.HasRule);
            Assert.Equal("a", copy.LeftDelimiter);
            Assert.Equal("b", copy.RightDelimiter);
        }
示例#7
0
        public void TestAddErrors()
        {
            var list = new MathList();

            Assert.Throws <InvalidOperationException>(() => list.Add(null));
            Assert.Throws <InvalidOperationException>(() => list.Add(MathAtoms.Create(MathAtomType.Boundary, "")));
        }
示例#8
0
        public void TestAppend()
        {
            var list1 = new MathList();
            var atom1 = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Operator("+", false);
            var atom3 = MathAtoms.Operator("-", false);

            list1.Add(atom1);
            list1.Add(atom2);
            list1.Add(atom3);

            var list2 = new MathList();
            var atom5 = MathAtoms.Times;
            var atom6 = MathAtoms.Divide;

            list2.Add(atom5);
            list2.Add(atom6);

            Assert.Equal(3, list1.Count);
            Assert.Equal(2, list2.Count);

            list1.Append(list2);
            Assert.Equal(5, list1.Count);
            Assert.Equal(atom5, list1[3]);
            Assert.Equal(atom6, list1[4]);
        }
示例#9
0
        public void TestSubscript()
        {
            var input     = @"-52x^{13+y}_{15-} + (-12.3 *)\frac{-12}{15.2}";
            var list      = MathLists.FromString(input);
            var finalized = new MathList(list, true);

            MathListValidator.CheckListContents(finalized);
            var reFinalized = new MathList(finalized, true);

            MathListValidator.CheckListContents(reFinalized);
        }
示例#10
0
        /// <summary>Safe to call with a null list. Types cannot be null however.</summary>
        private void CheckAtomTypes(MathList list, params Type[] types)
        {
            int atomCount = (list == null) ? 0 : list.Atoms.Count;

            Assert.Equal(types.Length, atomCount);
            for (int i = 0; i < atomCount; i++)
            {
                var atom = list[i];
                Assert.NotNull(atom);
                Assert.IsType(types[i], atom);
            }
        }
示例#11
0
        public void TestSuperScript()
        {
            var mathList    = new MathList();
            var x           = MathAtoms.ForCharacter('x');
            var superscript = new MathList {
                MathAtoms.ForCharacter('2')
            };

            x.Superscript = superscript;
            mathList.Add(x);

            var display = Typesetter <TFont, TGlyph> .CreateLine(mathList, _font, _context, LineStyle.Display);

            Assert.NotNull(display);

            Assert.Equal(LinePosition.Regular, display.LinePosition);
            Assert.Equal(new PointF(), display.Position);
            Assert.Equal(new Range(0, 1), display.Range);
            Assert.False(display.HasScript);
            Assert.Equal(display.IndexInParent, Range.UndefinedInt);
            Assert.Equal(2, display.Displays.Count());

            var super0 = display.Displays[0];
            var line   = super0 as TextLineDisplay <TFont, TGlyph>;

            Assert.NotNull(line);
            Assert.Single(line.Atoms);
            Assert.Equal("x", line.StringText());
            Assert.Equal(new PointF(), line.Position);
            Assert.True(line.HasScript);

            var super1 = display.Displays[1] as ListDisplay <TFont, TGlyph>;

            Assert.NotNull(super1);
            Assert.Equal(LinePosition.Superscript, super1.LinePosition);
            var super1Position = super1.Position;

            Assertions.ApproximatePoint(10.32, 7.26, super1Position, 0.01); // may change as we implement more details?
            Assert.Equal(new Range(0, 1), super1.Range);
            Assert.False(super1.HasScript);
            Assert.Equal(0, super1.IndexInParent);
            Assert.Single(super1.Displays);

            var super10 = super1.Displays[0] as TextLineDisplay <TFont, TGlyph>;

            Assert.NotNull(super10);
            Assert.Single(super10.Atoms);
            Assert.Equal(new PointF(), super10.Position);
            Assert.False(super10.HasScript);

            Assertions.ApproximatelyEqual(17.06, display.Ascent, 0.01);
            Assertions.ApproximatelyEqual(4, display.Descent, 0.01);
        }
示例#12
0
 public MathKeyboard(TypesettingContext <TFont, TGlyph> context, TFont font, double blinkMilliseconds = DefaultBlinkMilliseconds)
 {
     Context             = context;
     Font                = font;
     blinkTimer          = new Timer(blinkMilliseconds);
     blinkTimer.Elapsed += (sender, e) => {
         if (!(MathList.AtomAt(_insertionIndex) is Atoms.Placeholder) || LaTeXSettings.PlaceholderBlinks)
         {
             InsertionPositionHighlighted = !InsertionPositionHighlighted;
         }
     };
     blinkTimer.Start();
 }
示例#13
0
        public void TestCopyAccent()
        {
            var atom1  = LaTeXSettings.Placeholder;
            var atom2  = LaTeXSettings.Times;
            var atom3  = LaTeXSettings.Divide;
            var list   = new MathList(atom1, atom2, atom3);
            var accent = new Accent("^", list);

            var copy = accent.Clone(false);

            CheckClone(copy, accent);
            CheckClone(copy.InnerList, accent.InnerList);
        }
示例#14
0
            static void CheckListContents(MathList list)
            {
                Assert.Collection(list.Atoms,
                                  CheckAtomNucleusAndRange <UnaryOperator>("\u2212", 0, 1),
                                  CheckAtomNucleusAndRange <Number>("52", 1, 2),
                                  CheckAtomNucleusAndRange <Variable>("x", 3, 1),
                                  CheckAtomNucleusAndRange <BinaryOperator>("+", 4, 1),
                                  CheckAtomNucleusAndRange <Open>("(", 5, 1),
                                  CheckAtomNucleusAndRange <UnaryOperator>("\u2212", 6, 1),
                                  CheckAtomNucleusAndRange <Number>("12.3", 7, 4),
                                  CheckAtomNucleusAndRange <UnaryOperator>("*", 11, 1),
                                  CheckAtomNucleusAndRange <Close>(")", 12, 1),
                                  CheckAtomNucleusAndRange <Fraction>("", 13, 1),
                                  CheckAtomNucleusAndRange <LargeOperator>("∫", 14, 1),
                                  CheckAtomNucleusAndRange <Variable>("θ", 15, 1)
                                  );
                Assert.Collection(list.Atoms[2].Superscript,
                                  CheckAtomNucleusAndRange <Number>("13", 0, 2),
                                  CheckAtomNucleusAndRange <BinaryOperator>("+", 2, 1),
                                  CheckAtomNucleusAndRange <Variable>("y", 3, 1)
                                  );
                Assert.Collection(list.Atoms[2].Subscript,
                                  CheckAtomNucleusAndRange <Number>("15", 0, 2),
                                  CheckAtomNucleusAndRange <BinaryOperator>("\u2212", 2, 1)
                                  );
                var fraction = Assert.IsType <Fraction>(list.Atoms[9]);

                Assert.Collection(fraction.Numerator,
                                  CheckAtomNucleusAndRange <UnaryOperator>("\u2212", 0, 1),
                                  CheckAtomNucleusAndRange <Number>("12", 1, 2)
                                  );
                Assert.Collection(fraction.Denominator,
                                  CheckAtomNucleusAndRange <Number>("15.2", 0, 4)
                                  );
                var integral = Assert.IsType <LargeOperator>(list.Atoms[10]);

                Assert.Collection(integral.Subscript,
                                  CheckAtomNucleusAndRange <Number>("0", 0, 1)
                                  );
                var radical = Assert.IsType <Radical>(Assert.Single(integral.Superscript));

                Assert.Collection(radical.Degree,
                                  CheckAtomNucleusAndRange <Close>("!", 0, 1),
                                  CheckAtomNucleusAndRange <Ordinary>(" ", 1, 1)
                                  );
                Assert.Collection(radical.Radicand,
                                  CheckAtomNucleusAndRange <Relation>("=", 0, 1),
                                  CheckAtomNucleusAndRange <Open>("(", 1, 1)
                                  );
            }
示例#15
0
        public void TestRadical()
        {
            var mathList = new MathList {
                new Radical {
                    Radicand = new MathList {
                        MathAtoms.ForCharacter('1')
                    }
                }
            };

            var display = Typesetter <TFont, TGlyph> .CreateLine(mathList, _font, _context, LineStyle.Display);

            Assert.Equal(LinePosition.Regular, display.LinePosition);
            Assert.Equal(new PointF(), display.Position);
            Assert.Equal(new Range(0, 1), display.Range);
            Assert.False(display.HasScript);
            Assert.Equal(Range.UndefinedInt, display.IndexInParent);
            Assert.Single(display.Displays);

            var radical = display.Displays[0] as RadicalDisplay <TFont, TGlyph>;

            Assert.Equal(new Range(0, 1), radical.Range);
            Assert.False(radical.HasScript);
            Assert.Equal(new PointF(), radical.Position);
            Assert.NotNull(radical.Radicand);
            Assert.Null(radical.Degree);

            var display2 = radical.Radicand as ListDisplay <TFont, TGlyph>;

            Assert.NotNull(display2);
            Assert.Equal(LinePosition.Regular, display2.LinePosition);
            Assertions.ApproximatePoint(10, 0, display2.Position, 0.01);
            Assert.Equal(new Range(0, 1), display2.Range);
            Assert.False(display2.HasScript);
            Assert.Equal(Range.UndefinedInt, display2.IndexInParent);
            Assert.Single(display2.Displays);

            var line2 = display2.Displays[0] as TextLineDisplay <TFont, TGlyph>;

            Assert.Single(line2.Atoms);
            Assert.Equal("1", line2.StringText());
            Assert.Equal(new PointF(), line2.Position);
            Assert.Equal(new Range(0, 1), line2.Range);
            Assert.False(line2.HasScript);

            Assertions.ApproximatelyEqual(18.56, display.Ascent, 0.01);
            Assertions.ApproximatelyEqual(4, display.Descent, 0.01);
            Assertions.ApproximatelyEqual(20, display.Width, 0.01);
        }
示例#16
0
        public void TestListCopy()
        {
            var list  = new MathList();
            var atom  = LaTeXSettings.Placeholder;
            var atom2 = LaTeXSettings.Times;
            var atom3 = LaTeXSettings.Divide;

            list.Add(atom);
            list.Add(atom2);
            list.Add(atom3);

            var list2 = list.Clone(false);

            CheckClone(list, list2);
        }
示例#17
0
        public void TestCopyRadical()
        {
            var atom    = LaTeXSettings.Placeholder;
            var atom2   = LaTeXSettings.Times;
            var atom3   = LaTeXSettings.Divide;
            var list    = new MathList(atom, atom2, atom3);
            var list2   = new MathList(atom3, atom2);
            var radical = new Radical(list2, list);

            var copy = radical.Clone(false);

            CheckClone(copy, radical);
            CheckClone(copy.Radicand, radical.Radicand);
            CheckClone(copy.Degree, radical.Degree);
        }
示例#18
0
        public void TestCopyOverline()
        {
            var atom1 = LaTeXDefaults.Placeholder;
            var atom2 = LaTeXDefaults.Times;
            var atom3 = LaTeXDefaults.Divide;
            var list  = new MathList(atom1, atom2, atom3);
            var over  = new Overline(list);

            Assert.IsType <Overline>(over);

            var copy = over.Clone(false);

            CheckClone(copy, over);
            CheckClone(copy.InnerList, over.InnerList);
        }
示例#19
0
        public void TestListCopy()
        {
            var list  = new MathList();
            var atom  = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Times;
            var atom3 = MathAtoms.Divide;

            list.Add(atom);
            list.Add(atom2);
            list.Add(atom3);

            var list2 = AtomCloner.Clone(list, false);

            CheckClone(list, list2);
        }
示例#20
0
        public void TestCopyUnderline()
        {
            var atom1 = LaTeXSettings.Placeholder;
            var atom2 = LaTeXSettings.Times;
            var atom3 = LaTeXSettings.Divide;
            var list  = new MathList(atom1, atom2, atom3);
            var under = new Underline(list);

            Assert.IsType <Underline>(under);

            var copy = under.Clone(false);

            CheckClone(copy, under);
            CheckClone(copy.InnerList, under.InnerList);
        }
示例#21
0
        public void TestRemoveAtomAtIndex()
        {
            var list  = new MathList();
            var atom  = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Times;

            list.Add(atom);
            list.Add(atom2);
            Assert.Equal(2, list.Count);
            list.RemoveAt(0);
            Assert.Single(list);
            Assert.Equal(atom2, list[0]);
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(1));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(2));
        }
示例#22
0
        public void TestAdd()
        {
            var list = new MathList();

            Assert.Empty(list);
            var atom = MathAtoms.Placeholder;

            list.Add(atom);
            Assert.Single(list);
            Assert.Equal(atom, list[0]);
            var atom2 = MathAtoms.Times;

            list.Add(atom2);
            Assert.Equal(2, list.Count);
            Assert.Equal(atom2, list[1]);
        }
示例#23
0
        public void TestRemoveAtomsInRange()
        {
            var list  = new MathList();
            var atom  = MathAtoms.Placeholder;
            var atom2 = MathAtoms.Times;
            var atom3 = MathAtoms.Divide;

            list.Add(atom);
            list.Add(atom2);
            list.Add(atom3);
            Assert.Equal(3, list.Count);
            list.RemoveAtoms(new Range(1, 2));
            Assert.Single(list);
            Assert.Equal(atom, list[0]);
            Assert.Throws <ArgumentException>(() => list.RemoveAtoms(new Range(1, 1)));
        }
        public PlotModel(MathList mathList, Variable var, Interval interval)
        {
            _pointsArrays = new List <DataPoint> [mathList.getOperands().Count];
            for (int p = 0; p < _pointsArrays.Length; p++)
            {
                _pointsArrays[p] = new List <DataPoint>();
            }
            _mathList = mathList;
            _variable = var;

            _interval = interval;
            double length = ((Number)_interval.getOperands()[1]).getValue()
                            - ((Number)_interval.getOperands()[0]).getValue();

            step = length / stepCount;

            calculatePoints();
        }
示例#25
0
        public void TestCopyOpen()
        {
            var list = new MathList {
                LaTeXDefaults.Placeholder, LaTeXDefaults.Times, LaTeXDefaults.Divide
            };
            var list2 = new MathList {
                LaTeXDefaults.Divide, LaTeXDefaults.Times
            };
            var open = new Open("(")
            {
                Subscript = list, Superscript = list2
            };

            var clone = open.Clone(false);

            CheckClone(open, clone);
            CheckClone(open.Superscript, clone.Superscript);
            CheckClone(open.Subscript, clone.Subscript);
        }
示例#26
0
        public void TestCopyInner()
        {
            var atom1 = LaTeXSettings.Placeholder;
            var atom2 = LaTeXSettings.Times;
            var atom3 = LaTeXSettings.Divide;
            var list  = new MathList(atom1, atom2, atom3);
            var inner = new Inner(
                new Boundary("("),
                list,
                new Boundary(")")
                );

            Assert.IsType <Inner>(inner);

            var copy = inner.Clone(false);

            CheckClone(inner, copy);
            CheckClone(inner.InnerList, copy.InnerList);
        }
示例#27
0
        public void TestRemoveLast()
        {
            var list = new MathList();
            var atom = MathAtoms.Placeholder;

            list.Add(atom);
            Assert.Single(list);
            list.RemoveLastAtom();
            Assert.Empty(list);
            list.RemoveLastAtom(); // should not throw; just noop in this case
            Assert.Empty(list);
            var atom2 = MathAtoms.Times;

            list.Add(atom);
            list.Add(atom2);
            Assert.Equal(2, list.Count);
            list.RemoveLastAtom();
            Assert.Single(list);
            Assert.Equal(atom, list[0]);
        }
示例#28
0
        static void ResetPlaceholders(MathList mathList)
        {
            foreach (var mathAtom in mathList.Atoms)
            {
                ResetPlaceholders(mathAtom.Superscript);
                ResetPlaceholders(mathAtom.Subscript);
                switch (mathAtom)
                {
                case Atoms.Placeholder _:
                    mathAtom.Nucleus = "\u25A1";
                    break;

                case IMathListContainer container:
                    foreach (var list in container.InnerLists)
                    {
                        ResetPlaceholders(list);
                    }
                    break;
                }
            }
        }
示例#29
0
        public void TestRaiseBox()
        {
            var mathList = new MathList {
                new Atoms.Extension.RaiseBox {
                    InnerList = new MathList {
                        MathAtoms.ForCharacter('r')
                    },
                    Raise = new Space(3 * Structures.Space.Point)
                }
            };

            var display = Typesetter <TFont, TGlyph> .CreateLine(mathList, _font, _context, LineStyle.Display);

            Assert.Equal(LinePosition.Regular, display.LinePosition);
            Assert.Equal(new Range(0, 1), display.Range);
            Assert.False(display.HasScript);
            Assert.Equal(Range.UndefinedInt, display.IndexInParent);
            Assert.Single(display.Displays);

            var display2 = display.Displays[0] as ListDisplay <TFont, TGlyph>;

            Assert.Equal(LinePosition.Regular, display2.LinePosition);
            Assert.Equal(new PointF(0, 3), display2.Position);
            Assert.Equal(new Range(0, 1), display2.Range);
            Assert.False(display2.HasScript);
            Assert.Equal(Range.UndefinedInt, display2.IndexInParent);
            Assert.Equal(1, display2.Displays.Count);

            var line = display2.Displays[0] as TextLineDisplay <TFont, TGlyph>;

            Assert.Single(line.Atoms);
            Assert.Equal("r", line.StringText());
            Assert.Equal(new PointF(), line.Position);
            Assert.False(line.HasScript);

            Assertions.ApproximatelyEqual(17, display.Ascent, 0.01);
            Assertions.ApproximatelyEqual(1, display.Descent, 0.01);
            Assertions.ApproximatelyEqual(10, display.Width, 0.01);
        }
示例#30
0
        static void ResetPlaceholders(MathList mathList)
        {
            foreach (var mathAtom in mathList.Atoms)
            {
                ResetPlaceholders(mathAtom.Superscript);
                ResetPlaceholders(mathAtom.Subscript);
                switch (mathAtom)
                {
                case Atoms.Placeholder placeholder:
                    placeholder.Color   = LaTeXSettings.PlaceholderRestingColor;
                    placeholder.Nucleus = LaTeXSettings.PlaceholderRestingNucleus;
                    break;

                case IMathListContainer container:
                    foreach (var list in container.InnerLists)
                    {
                        ResetPlaceholders(list);
                    }
                    break;
                }
            }
        }