Exemplo n.º 1
0
        private void ChangeAtomToOrdinary(DummyAtom currentAtom, DummyAtom previousAtom, Atom nextAtom)
        {
            var type = currentAtom.GetLeftType();

            if (type == TexAtomType.BinaryOperator && (previousAtom == null ||
                                                       binaryOperatorChangeSet[(int)previousAtom.GetRightType()]))
            {
                currentAtom.Type = TexAtomType.Ordinary;
            }
            else if (nextAtom != null && currentAtom.GetRightType() == TexAtomType.BinaryOperator)
            {
                var nextType = nextAtom.GetLeftType();
                if (nextType == TexAtomType.Relation || nextType == TexAtomType.Closing || nextType == TexAtomType.Punctuation)
                {
                    currentAtom.Type = TexAtomType.Ordinary;
                }
            }
        }
Exemplo n.º 2
0
        public override Box CreateBox(TexEnvironment environment)
        {
            // Create result box.
            var resultBox = new HorizontalBox(environment.Foreground, environment.Background);

            // Create and add box for each atom in row.
            for (int i = 0; i < this.Elements.Count; i++)
            {
                var curAtom = new DummyAtom(this.Elements[i]);

                // Change atom type to Ordinary, if required.
                var hasNextAtom = i < this.Elements.Count - 1;
                var nextAtom    = hasNextAtom ? (Atom)this.Elements[i + 1] : null;
                ChangeAtomToOrdinary(curAtom, this.PreviousAtom, nextAtom);

                // Check if atom is part of ligature or should be kerned.
                var kern = 0d;
                if (hasNextAtom && curAtom.GetRightType() == TexAtomType.Ordinary && curAtom.IsCharSymbol)
                {
                    if (nextAtom is CharSymbol cs && ligatureKernChangeSet[(int)nextAtom.GetLeftType()])
                    {
                        var font = cs.GetStyledFont(environment);
                        curAtom.IsTextSymbol = true;
                        var leftAtomCharFont  = curAtom.GetCharFont(font);
                        var rightAtomCharFont = cs.GetCharFont(font);
                        var ligatureCharFont  = font.GetLigature(leftAtomCharFont, rightAtomCharFont);
                        if (ligatureCharFont == null)
                        {
                            // Atom should be kerned.
                            kern = font.GetKern(leftAtomCharFont, rightAtomCharFont, environment.Style);
                        }
                        else
                        {
                            // Atom is part of ligature.
                            curAtom.SetLigature(new FixedCharAtom(ligatureCharFont));
                            i++;
                        }
                    }
                }

                // Create and add glue box, unless atom is first of row or previous/current atom is kern.
                if (i != 0 && this.PreviousAtom != null && !this.PreviousAtom.IsKern && !curAtom.IsKern)
                {
                    resultBox.Add(Glue.CreateBox(this.PreviousAtom.GetRightType(), curAtom.GetLeftType(), environment));
                }

                // Create and add box for atom.
                curAtom.PreviousAtom = this.PreviousAtom;
                var curBox = curAtom.CreateBox(environment);
                resultBox.Add(curBox);
                environment.LastFontId = curBox.GetLastFontId();

                // Insert kern, if required.
                if (kern > TexUtilities.FloatPrecision)
                {
                    resultBox.Add(new StrutBox(0, kern, 0, 0));
                }

                if (!curAtom.IsKern)
                {
                    this.PreviousAtom = curAtom;
                }
            }

            // Reset previous atom.
            this.PreviousAtom = null;

            return(resultBox);
        }
Exemplo n.º 3
0
        public Atom WithPreviousAtom(DummyAtom previousAtom)
        {
            var rowAtom = this.RowAtom.WithPreviousAtom(previousAtom);

            return(new StyledAtom(rowAtom, this.Background, this.Foreground));
        }
Exemplo n.º 4
0
 public Atom WithPreviousAtom(DummyAtom previousAtom) =>
 new RowAtom(previousAtom, this.Elements);
Exemplo n.º 5
0
 private RowAtom(DummyAtom previousAtom, ReadOnlyCollection <Atom> elements)
 {
     this.PreviousAtom = previousAtom;
     this.Elements     = elements;
 }
Exemplo n.º 6
0
 private void ChangeAtomToOrdinary(DummyAtom currentAtom, DummyAtom previousAtom, Atom nextAtom)
 {
     var type = currentAtom.GetLeftType();
     if (type == TexAtomType.BinaryOperator && (previousAtom == null ||
         binaryOperatorChangeSet[(int)previousAtom.GetRightType()]))
     {
         currentAtom.Type = TexAtomType.Ordinary;
     }
     else if (nextAtom != null && currentAtom.GetRightType() == TexAtomType.BinaryOperator)
     {
         var nextType = nextAtom.GetLeftType();
         if (nextType == TexAtomType.Relation || nextType == TexAtomType.Closing || nextType == TexAtomType.Punctuation)
             currentAtom.Type = TexAtomType.Ordinary;
     }
 }
Exemplo n.º 7
0
        public override Box CreateBox(TexEnvironment environment)
        {
            var texFont = environment.TexFont;

            // Create result box.
            var resultBox = new HorizontalBox(environment.Foreground, environment.Background);

            // Create and add box for each atom in row.
            for (int i = 0; i < this.Elements.Count; i++)
            {
                var curAtom = new DummyAtom(this.Elements[i]);

                // Change atom type to Ordinary, if required.
                var hasNextAtom = i < this.Elements.Count - 1;
                var nextAtom = hasNextAtom ? (Atom)this.Elements[i + 1] : null;
                ChangeAtomToOrdinary(curAtom, this.PreviousAtom, nextAtom);

                // Check if atom is part of ligature or should be kerned.
                var kern = 0d;
                if (hasNextAtom && curAtom.GetRightType() == TexAtomType.Ordinary && curAtom.IsCharSymbol)
                {
                    if (nextAtom is CharSymbol && ligatureKernChangeSet[(int)nextAtom.GetLeftType()])
                    {
                        curAtom.IsTextSymbol = true;
                        var leftAtomCharFont = curAtom.GetCharFont(texFont);
                        var rightAtomCharFont = ((CharSymbol)nextAtom).GetCharFont(texFont);
                        var ligatureCharFont = texFont.GetLigature(leftAtomCharFont, rightAtomCharFont);
                        if (ligatureCharFont == null)
                        {
                            // Atom should be kerned.
                            kern = texFont.GetKern(leftAtomCharFont, rightAtomCharFont, environment.Style);
                        }
                        else
                        {
                            // Atom is part of ligature.
                            curAtom.SetLigature(new FixedCharAtom(ligatureCharFont));
                            i++;
                        }
                    }
                }

                // Create and add glue box, unless atom is first of row or previous/current atom is kern.
                if (i != 0 && this.PreviousAtom != null && !this.PreviousAtom.IsKern && !curAtom.IsKern)
                    resultBox.Add(Glue.CreateBox(this.PreviousAtom.GetRightType(), curAtom.GetLeftType(), environment));

                // Create and add box for atom.
                curAtom.PreviousAtom = this.PreviousAtom;
                var curBox = curAtom.CreateBox(environment);
                resultBox.Add(curBox);
                environment.LastFontId = curBox.GetLastFontId();

                // Insert kern, if required.
                if (kern > TexUtilities.FloatPrecision)
                    resultBox.Add(new StrutBox(0, kern, 0, 0));

                if (!curAtom.IsKern)
                    this.PreviousAtom = curAtom;
            }

            // Reset previous atom.
            this.PreviousAtom = null;

            return resultBox;
        }