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; } } }
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; } }
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); }
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; }