internal Box CreateBox(TexEnvironment environment) { if (this.RootAtom == null) { return(StrutBox.Empty); } else { return(this.RootAtom.CreateBox(environment)); } }
public static Box CreateBox(string symbol, double minHeight, TexEnvironment environment, SourceSpan source = null) { var texFont = environment.MathFont; var style = environment.Style; var charInfo = texFont.GetCharInfo(symbol, style).Value; // Find first version of character that has at least minimum height. var metrics = charInfo.Metrics; var totalHeight = metrics.Height + metrics.Depth; while (totalHeight < minHeight && texFont.HasNextLarger(charInfo)) { charInfo = texFont.GetNextLargerCharInfo(charInfo, style); metrics = charInfo.Metrics; totalHeight = metrics.Height + metrics.Depth; } if (totalHeight >= minHeight) { // Character of sufficient height was found. return(new CharBox(environment, charInfo)); } else if (texFont.IsExtensionChar(charInfo)) { var resultBox = new VerticalBox() { Source = source }; // Construct box from extension character. var extension = texFont.GetExtension(charInfo, style); if (extension.Top != null) { resultBox.Add(new CharBox(environment, extension.Top) { Source = source }); } if (extension.Middle != null) { resultBox.Add(new CharBox(environment, extension.Middle) { Source = source }); } if (extension.Bottom != null) { resultBox.Add(new CharBox(environment, extension.Bottom) { Source = source }); } // Insert repeatable part multiple times until box is high enough. var repeatBox = new CharBox(environment, extension.Repeat) { Source = source }; do { if (extension.Top != null && extension.Bottom != null) { resultBox.Add(1, repeatBox); if (extension.Middle != null) { resultBox.Add(resultBox.Children.Count - 1, repeatBox); } } else if (extension.Bottom != null) { resultBox.Add(0, repeatBox); } else { resultBox.Add(repeatBox); } } while (resultBox.Height + resultBox.Depth < minHeight); return(resultBox); } else { // No extensions available, so use tallest available version of character. return(new CharBox(environment, charInfo) { Source = source }); } }
protected override Box CreateBoxCore(TexEnvironment environment) { var texFont = environment.MathFont; var style = environment.Style; // Calculate minimum clearance amount. double clearance; var defaultRuleThickness = texFont.GetDefaultLineThickness(style); if (style < TexStyle.Text) { clearance = texFont.GetXHeight(style, texFont.GetCharInfo(sqrtSymbol, style).Value.FontId); } else { clearance = defaultRuleThickness; } clearance = defaultRuleThickness + Math.Abs(clearance) / 4; // Create box for base atom, in cramped style. var baseBox = this.BaseAtom.CreateBox(environment.GetCrampedStyle()); // Create box for radical sign. var totalHeight = baseBox.Height + baseBox.Depth; var radicalSignBox = DelimiterFactory.CreateBox(sqrtSymbol, totalHeight + clearance + defaultRuleThickness, environment, Source); radicalSignBox.Source = Source; // Add half of excess height to clearance. var delta = radicalSignBox.Depth - (totalHeight + clearance); clearance += delta / 2; // Create box for square-root containing base box. radicalSignBox.Shift = -(baseBox.Height + clearance); var overBar = new OverBar(environment, baseBox, clearance, radicalSignBox.Height); overBar.Shift = -(baseBox.Height + clearance + defaultRuleThickness); var radicalContainerBox = new HorizontalBox(radicalSignBox); radicalContainerBox.Add(overBar); // If atom is simple radical, just return square-root box. if (this.DegreeAtom == null) { return(radicalContainerBox); } // Atom is complex radical (nth-root). // Create box for root atom. var rootBox = this.DegreeAtom.CreateBox(environment.GetRootStyle()); var bottomShift = scale * (radicalContainerBox.Height + radicalContainerBox.Depth); rootBox.Shift = radicalContainerBox.Depth - rootBox.Depth - bottomShift; // Create result box. var resultBox = new HorizontalBox(); // Add box for negative kern. var negativeKern = new SpaceAtom(null, TexUnit.Mu, -10, 0, 0).CreateBox(environment); var xPos = rootBox.Width + negativeKern.Width; if (xPos < 0) { resultBox.Add(new StrutBox(-xPos, 0, 0, 0)); } resultBox.Add(rootBox); resultBox.Add(negativeKern); resultBox.Add(radicalContainerBox); return(resultBox); }
public static Box CreateBox(TexAtomType leftAtomType, TexAtomType rightAtomType, TexEnvironment environment) { leftAtomType = leftAtomType > TexAtomType.Inner ? TexAtomType.Ordinary : leftAtomType; rightAtomType = rightAtomType > TexAtomType.Inner ? TexAtomType.Ordinary : rightAtomType; var glueType = glueRules[(int)leftAtomType, (int)rightAtomType, (int)environment.Style / 2]; return(glueTypes[glueType].CreateBox(environment)); }