Ejemplo n.º 1
0
        public override Box CreateBox(TexEnvironment environment)
        {
            // Create boxes for base, delimeter, and script atoms.
            var baseBox      = BaseAtom is null ? StrutBox.Empty : BaseAtom.CreateBox(environment);
            var delimeterBox = DelimiterFactory.CreateBox(Symbol.Name, baseBox.Width, environment);
            var scriptBox    = Script?.CreateBox(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, Kern.CreateBox(environment).Height, Over));
        }
Ejemplo n.º 2
0
        public override Box CreateBox(TexEnvironment environment)
        {
            var texFont = environment.TexFont;
            var style   = environment.Style;

            // Create box for base atom.
            var baseBox = 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(LeftDelimeter.Name, minHeight, environment);
                CentreBox(leftDelimeterBox, axis);
                resultBox.Add(leftDelimeterBox);
            }

            // add glueElement between left delimeter and base Atom, unless base Atom is whitespace.
            if (!(BaseAtom is SpaceAtom))
            {
                resultBox.Add(Glue.CreateBox(TexAtomType.Opening, 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 (!(BaseAtom is SpaceAtom))
            {
                resultBox.Add(Glue.CreateBox(BaseAtom.GetRightType(), TexAtomType.Closing, environment));
            }

            // Create and add box for right delimeter.
            if (RightDelimeter is null)
            {
                return(resultBox);
            }

            var rightDelimeterBox = DelimiterFactory.CreateBox(RightDelimeter.Name, minHeight, environment);

            CentreBox(rightDelimeterBox, axis);
            resultBox.Add(rightDelimeterBox);

            return(resultBox);
        }
Ejemplo n.º 3
0
        public override Box CreateBox(TexEnvironment environment)
        {
            var tex_font = environment.TexFont;
            var style    = environment.Style;

            // Calculate minimum clearance amount.
            var default_rule_thickness = tex_font.GetDefaultLineThickness(style);
            var clearance = style < TexStyle.Text ? tex_font.GetXHeight(style, tex_font.GetCharInfo(__SqrtSymbol, style).FontId) : default_rule_thickness;

            clearance = default_rule_thickness + Math.Abs(clearance) / 4;

            // Create box for base atom, in cramped style.
            var base_box = BaseAtom.CreateBox(environment.GetCrampedStyle());

            // Create box for radical sign.
            var total_height     = base_box.Height + base_box.Depth;
            var radical_sign_box = DelimiterFactory.CreateBox(__SqrtSymbol, total_height + clearance + default_rule_thickness,
                                                              environment);

            // Add half of excess height to clearance.
            var delta = radical_sign_box.Depth - (total_height + clearance);

            clearance += delta / 2;

            // Create box for square-root containing base box.
            radical_sign_box.Shift = -(base_box.Height + clearance);
            var over_bar = new OverBar(base_box, clearance, radical_sign_box.Height)
            {
                Shift = -(base_box.Height + clearance + default_rule_thickness)
            };
            var radical_container_box = new HorizontalBox(radical_sign_box);

            radical_container_box.Add(over_bar);

            // If atom is simple radical, just return square-root box.
            if (DegreeAtom is null)
            {
                return(radical_container_box);
            }

            // Atom is complex radical (nth-root).

            // Create box for root atom.
            var root_box     = DegreeAtom.CreateBox(environment.GetRootStyle());
            var bottom_shift = __Scale * (radical_container_box.Height + radical_container_box.Depth);

            root_box.Shift = radical_container_box.Depth - root_box.Depth - bottom_shift;

            // Create result box.
            var result_box = new HorizontalBox();

            // Add box for negative kern.
            var negative_kern = new SpaceAtom(TexUnit.Mu, -10, 0, 0).CreateBox(environment);
            var x_pos         = root_box.Width + negative_kern.Width;

            if (x_pos < 0)
            {
                result_box.Add(new StrutBox(-x_pos, 0, 0, 0));
            }

            result_box.Add(root_box);
            result_box.Add(negative_kern);
            result_box.Add(radical_container_box);

            return(result_box);
        }