public override Box CreateBox(TexEnvironment environment) { var texFont = environment.TexFont; var style = environment.Style; // Create box for base atom. var baseBox = this.BaseAtom.CreateBox(environment); // Create result box. var resultBox = new HorizontalBox(); var axis = texFont.GetAxisHeight(style); var delta = Math.Max(baseBox.Height - axis, baseBox.Depth + axis); var minHeight = Math.Max((delta / 500) * delimeterFactor, 2 * delta - delimeterShortfall); // Create and add box for left delimeter. if (LeftDelimeter != null) { var leftDelimeterBox = DelimiterFactory.CreateBox(this.LeftDelimeter.Name, minHeight, environment); CentreBox(leftDelimeterBox, axis); resultBox.Add(leftDelimeterBox); } // add glueElement between left delimeter and base Atom, unless base Atom is whitespace. if (!(this.BaseAtom is SpaceAtom)) { resultBox.Add(Glue.CreateBox(TexAtomType.Opening, this.BaseAtom.GetLeftType(), environment)); } // add box for base Atom. resultBox.Add(baseBox); // add glueElement between right delimeter and base Atom, unless base Atom is whitespace. if (!(this.BaseAtom is SpaceAtom)) { resultBox.Add(Glue.CreateBox(this.BaseAtom.GetRightType(), TexAtomType.Closing, environment)); } // Create and add box for right delimeter. if (this.RightDelimeter != null) { var rightDelimeterBox = DelimiterFactory.CreateBox(this.RightDelimeter.Name, minHeight, environment); CentreBox(rightDelimeterBox, axis); resultBox.Add(rightDelimeterBox); } return(resultBox); }
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); }