protected override Box CreateBoxCore(TexEnvironment environment) { // Create boxes for base, delimeter, and script atoms. var baseBox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment); var delimeterBox = DelimiterFactory.CreateBox(this.Symbol.Name, baseBox.Width, environment); var scriptBox = this.Script == null ? null : this.Script.CreateBox(this.Over ? environment.GetSuperscriptStyle() : environment.GetSubscriptStyle()); // Create centered horizontal box if any box is smaller than maximum width. var maxWidth = GetMaxWidth(baseBox, delimeterBox, scriptBox); if (Math.Abs(maxWidth - baseBox.Width) > TexUtilities.FloatPrecision) { baseBox = new HorizontalBox(baseBox, maxWidth, TexAlignment.Center); } if (Math.Abs(maxWidth - delimeterBox.Height - delimeterBox.Depth) > TexUtilities.FloatPrecision) { delimeterBox = new VerticalBox(delimeterBox, maxWidth, TexAlignment.Center); } if (scriptBox != null && Math.Abs(maxWidth - scriptBox.Width) > TexUtilities.FloatPrecision) { scriptBox = new HorizontalBox(scriptBox, maxWidth, TexAlignment.Center); } return(new OverUnderBox(baseBox, delimeterBox, scriptBox, this.Kern.CreateBox(environment).Height, this.Over)); }
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) { 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).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); // 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(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); }
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 == null? StrutBox.Empty: 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 root base containing base box. var overBar = new OverBar(environment, baseBox, clearance, radicalSignBox.Height) { Shift = -defaultRuleThickness, }; //Create box to hold the radical and the degree atom(if it exists) var radicalContainerBox = new VerticalBox(); //Create a box for creating a space for the radical sign box's left shift and width var horizoverlapbox = new StrutBox(0, 0, 0, 0); radicalContainerBox.Add(horizoverlapbox); radicalContainerBox.Add(radicalSignBox); // Create box for root atom. var radrootBox = this.DegreeAtom == null ?(this.DegreeSpecified? StrutBox.Empty:NullAtom.NullBox) : this.DegreeAtom.CreateBox(environment.GetRootStyle()); var bottomShift = scale * (radicalSignBox.Height + radicalSignBox.Depth); var rcbItemsdiff = radicalSignBox.TotalHeight - radrootBox.TotalHeight; bottomShift = rcbItemsdiff; radrootBox.Shift = 0; if (radrootBox.TotalHeight < radicalSignBox.TotalHeight / 2) { bottomShift = (radicalSignBox.TotalHeight / 2) + radrootBox.TotalHeight; } var Vnegspace = new StrutBox(0, -bottomShift, 0, 0); radicalContainerBox.Add(Vnegspace); radicalContainerBox.Add(radrootBox); var leftshift = this.DegreeAtom == null? 0: radrootBox.TotalWidth - radicalSignBox.TotalWidth / 2; if (radrootBox.TotalWidth < (radicalSignBox.TotalWidth / 2)) { leftshift = 0; } radicalSignBox.Shift = leftshift; //increase the left overlap width horizoverlapbox.Width = leftshift + radicalSignBox.Width; // Create result box. var resultBox = new HorizontalBox(); resultBox.Add(radicalContainerBox); //adjust the vertical shift of the radicalContainerBox radicalContainerBox.Shift = -defaultRuleThickness - radicalContainerBox.Depth; var leftpad = radicalContainerBox.TotalWidth - radicalSignBox.Shift - radicalSignBox.TotalWidth; resultBox.Add(new StrutBox(leftpad, 0, 0, 0)); overBar.Shift = -defaultRuleThickness - radicalContainerBox.Depth; resultBox.Add(overBar); return(resultBox); }