Exemple #1
0
        public override Box CreateBox(TexEnvironment environment)
        {
            var texFont = environment.TexFont;
            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(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;
        }
        public override Box CreateBox(TexEnvironment environment)
        {
            // Create box for base atom, in cramped style.
            var baseBox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment.GetCrampedStyle());

            // Create result box.
            var defaultLineThickness = environment.TexFont.GetDefaultLineThickness(environment.Style);
            var resultBox            = new OverBar(environment, baseBox, 3 * defaultLineThickness, defaultLineThickness);

            // Adjust height and depth of result box.
            resultBox.Height = baseBox.Height + 5 * defaultLineThickness;
            resultBox.Depth  = baseBox.Depth;

            return(resultBox);
        }
Exemple #3
0
        public override Box CreateBox(TexEnvironment environment)
        {
            // Create box for base atom, in cramped style.
            var baseBox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment.GetCrampedStyle());

            // Create result box.
            var defaultLineThickness = environment.TexFont.GetDefaultLineThickness(environment.Style);
            var resultBox = new OverBar(baseBox, 3 * defaultLineThickness, defaultLineThickness);

            // Adjust height and depth of result box.
            resultBox.Height = baseBox.Height + 5 * defaultLineThickness;
            resultBox.Depth = baseBox.Depth;

            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);
        }
Exemple #5
0
        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);
        }