Esempio n. 1
0
        private Box LongDivision__colon__right__equals__right(TexEnvironment environment)
        {
            var divisor_dividend_quotient = new HorizontalBox();

            var dividendbox = this.DividendAtom == null ? StrutBox.Empty : this.DividendAtom.CreateBox(environment);
            var leftsep     = SymbolAtom.GetAtom("colon", this.Source).CreateBox(environment);
            var divisorbox  = this.DivisorAtom == null ? StrutBox.Empty : this.DivisorAtom.CreateBox(environment);
            var rightsep    = SymbolAtom.GetAtom("equals", this.Source).CreateBox(environment);
            var quotientbox = this.QuotientAtom == null ? StrutBox.Empty : this.QuotientAtom.CreateBox(environment);

            divisor_dividend_quotient.Add(dividendbox);
            divisor_dividend_quotient.Add(leftsep);
            divisor_dividend_quotient.Add(divisorbox);
            divisor_dividend_quotient.Add(rightsep);
            divisor_dividend_quotient.Add(quotientbox);

            var otherbox = this.OtherAtom == null ? StrutBox.Empty : this.OtherAtom.CreateBox(environment);


            var resultBox = new VerticalBox();

            resultBox.Add(divisor_dividend_quotient);
            resultBox.Add(otherbox);

            return(resultBox);
        }
Esempio n. 2
0
        private Box LongDivisionStyle_shortstackedrightright(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var divisor_quotient = new VerticalBox();
            var divisorbox       = this.DivisorAtom == null ? StrutBox.Empty : this.DivisorAtom.CreateBox(environment);
            var quotientbox      = this.QuotientAtom == null ? StrutBox.Empty : this.QuotientAtom.CreateBox(environment);
            var hlineseparator   = new HorizontalRule(environment, defaultLineThickness, quotientbox.TotalWidth, 0);

            divisor_quotient.Add(divisorbox);
            divisor_quotient.Add(hlineseparator);
            divisor_quotient.Add(quotientbox);

            var dividend_other = new VerticalBox();
            var dividendbox    = this.DividendAtom == null ? StrutBox.Empty : this.DividendAtom.CreateBox(environment);
            var otherbox       = this.OtherAtom == null ? StrutBox.Empty : this.OtherAtom.CreateBox(environment);

            dividend_other.Add(dividendbox);
            dividend_other.Add(otherbox);

            //double divquotheightsum =divisor_quotient.TotalHeight;
            var vlineseparator = new VerticalRule(environment, defaultLineThickness, divisorbox.TotalHeight + defaultLineThickness, -divisorbox.TotalHeight);

            var resultBox = new HorizontalBox();

            resultBox.Add(dividend_other);
            resultBox.Add(vlineseparator);
            resultBox.Add(divisor_quotient);

            return(resultBox);
        }
Esempio n. 3
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            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 (this.LeftDelimeter != null && this.LeftDelimeter.Name != SymbolAtom.EmptyDelimiterName)
            {
                var leftDelimeterBox = DelimiterFactory.CreateBox(this.LeftDelimeter.Name, minHeight, environment);
                leftDelimeterBox.Source = this.LeftDelimeter.Source;
                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 && this.RightDelimeter.Name != SymbolAtom.EmptyDelimiterName)
            {
                var rightDelimeterBox = DelimiterFactory.CreateBox(this.RightDelimeter.Name, minHeight, environment);
                rightDelimeterBox.Source = this.RightDelimeter.Source;
                CentreBox(rightDelimeterBox, axis);
                resultBox.Add(rightDelimeterBox);
            }

            return(resultBox);
        }
Esempio n. 4
0
        private Box Enclosure_downdiagonalstrike(TexEnvironment environment, Box morphbox)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var ddrule = new DownDiagonalRule(environment, 1, -morphbox.TotalWidth, morphbox.TotalHeight, -morphbox.TotalHeight);
            var resbx  = new HorizontalBox();

            resbx.Add(morphbox);
            resbx.Add(new StrutBox(-morphbox.Width, -morphbox.Height, 0, 0));
            resbx.Add(ddrule);
            return(resbx);
        }
Esempio n. 5
0
        private Box Enclosure_roundedbox(TexEnvironment environment, Box morphbox)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var recbox    = new RoundedRectangleBox(environment, morphbox.Height + morphbox.Depth, morphbox.TotalWidth, 0, 4, 4);
            var resultbox = new HorizontalBox();

            resultbox.Add(morphbox);
            resultbox.Add(new StrutBox(-morphbox.Width, -morphbox.Height, 0, 0));
            resultbox.Add(recbox);
            return(resultbox);
        }
Esempio n. 6
0
        private Box Enclosure_verticalstrike(TexEnvironment environment, Box morphbox)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var vrule = new VerticalRule(environment, defaultLineThickness, morphbox.Height + morphbox.Depth, -morphbox.Height);
            var resbx = new HorizontalBox();

            resbx.Add(morphbox);
            resbx.Add(new StrutBox(-morphbox.Width / 2, -morphbox.Height, 0, 0));
            resbx.Add(vrule);
            return(resbx);
        }
Esempio n. 7
0
        private Box Enclosure_bottom(TexEnvironment environment, Box morphbox)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var hrule = new HorizontalRule(environment, defaultLineThickness, morphbox.Width, 0);
            var resbx = new HorizontalBox();

            resbx.Add(morphbox);
            resbx.Add(new StrutBox(-morphbox.Width, -morphbox.Height + hrule.Height, 0, 0));
            resbx.Add(hrule);
            return(resbx);
        }
Esempio n. 8
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var resultBox   = new HorizontalBox();
            var innermatrix = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment);
            var heightdiff  = innermatrix.Depth - innermatrix.Height;

            var leftparen = DelimiterFactory.CreateBox("lbrace", innermatrix.TotalHeight + heightdiff, environment);

            leftparen.Shift   = -innermatrix.Height;
            innermatrix.Shift = heightdiff / 2;
            resultBox.Add(leftparen);
            resultBox.Add(innermatrix);

            return(resultBox);
        }
Esempio n. 9
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var baseBox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment);

            var ddrule = new UpDiagonalRule(environment, 1.3, -baseBox.TotalWidth, baseBox.TotalHeight, 0);
            var resbx  = new HorizontalBox();

            resbx.Add(baseBox);
            resbx.Add(new StrutBox(-baseBox.Width, -baseBox.Height, 0, 0));
            resbx.Add(ddrule);
            return(resbx);
        }
Esempio n. 10
0
        private Box Enclosure_circle(TexEnvironment environment, Box morphbox)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var orule = new OvalRule(environment, morphbox.Height - morphbox.Depth, morphbox.Width, 0);
            // Create result box.
            var resultBox = new HorizontalBox();

            resultBox.Add(morphbox);
            resultBox.Add(new StrutBox(-morphbox.Width, -morphbox.Height, 0, 0));
            resultBox.Add(orule);

            return(resultBox);
        }
Esempio n. 11
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var defaultRuleThickness = texFont.GetDefaultLineThickness(style);
            var basebox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment);

            var rectbox = new RectangleBox(environment, basebox.TotalHeight + 4 * defaultRuleThickness, basebox.TotalWidth + 4 * defaultRuleThickness, 0)
            {
                Shift = basebox.Depth + 2 * defaultRuleThickness
            };
            var resultbox = new HorizontalBox();

            resultbox.Add(basebox);
            resultbox.Add(new StrutBox(-rectbox.TotalWidth + 2 * defaultRuleThickness, -rectbox.TotalHeight, 0, 0));
            resultbox.Add(rectbox);
            return(resultbox);
        }
Esempio n. 12
0
        private Box LongDivisionStyle_lefttop(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var    dividend_divisor = new HorizontalBox();
            var    divisorbox       = this.DivisorAtom == null ? StrutBox.Empty : this.DivisorAtom.CreateBox(environment);
            var    leftsep          = SymbolAtom.GetAtom("rbrack", this.Source).CreateBox(environment);
            var    dividendbox      = this.DividendAtom == null ? StrutBox.Empty : this.DividendAtom.CreateBox(environment);
            double barwidth         = leftsep.TotalWidth + dividendbox.TotalWidth;
            var    separatorbar     = new HorizontalRule(environment, defaultLineThickness, barwidth, -dividendbox.TotalHeight - defaultLineThickness);


            dividend_divisor.Add(divisorbox);
            dividend_divisor.Add(leftsep);
            dividend_divisor.Add(dividendbox);
            dividend_divisor.Add(new StrutBox(-barwidth, dividendbox.TotalHeight, 0, 0));
            dividend_divisor.Add(separatorbar);

            var quotient_pad      = new HorizontalBox();
            var quotientbox       = this.QuotientAtom == null ? StrutBox.Empty : this.QuotientAtom.CreateBox(environment);
            var leftspace         = dividend_divisor.TotalWidth - quotientbox.TotalWidth;
            var quot_leftspacebox = new StrutBox(leftspace, quotientbox.TotalHeight, 0, 0);

            quotient_pad.Add(quot_leftspacebox);
            quotient_pad.Add(quotientbox);

            var otherbox = this.OtherAtom == null ? StrutBox.Empty : this.OtherAtom.CreateBox(environment);


            var resultBox = new VerticalBox();

            resultBox.Add(quotient_pad);
            resultBox.Add(dividend_divisor);
            resultBox.Add(otherbox);

            return(resultBox);
        }
Esempio n. 13
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var resultBox   = new HorizontalBox();
            var innermatrix = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment);
            var heightdiff  = innermatrix.Depth - innermatrix.Height;

            var leftparen = DelimiterFactory.CreateBox("Vert", innermatrix.TotalHeight, environment);

            leftparen.Shift = -innermatrix.Height + heightdiff;

            var rightparen = DelimiterFactory.CreateBox("Vert", innermatrix.TotalHeight, environment);

            rightparen.Shift = -innermatrix.Height + heightdiff;

            innermatrix.Shift = -(environment.MathFont.GetAxisHeight(environment.Style) - heightdiff) / 3;

            resultBox.Add(leftparen);
            resultBox.Add(innermatrix);
            resultBox.Add(rightparen);

            return(resultBox);
        }
Esempio n. 14
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var resultBox  = new HorizontalBox();
            var leftmatrix = this.LeftBaseAtom == null ? StrutBox.Empty : this.LeftBaseAtom.CreateBox(environment);
            var heightdiff = leftmatrix.Depth - leftmatrix.Height;

            var vbarseparator = DelimiterFactory.CreateBox("vert", leftmatrix.TotalHeight, environment);

            vbarseparator.Shift = -leftmatrix.Height + heightdiff;

            var rightmatrix = this.RightBaseAtom == null ? StrutBox.Empty : this.RightBaseAtom.CreateBox(environment);
            var heightdiff1 = rightmatrix.Depth - rightmatrix.Height;//apparently, its the same as "heightdiff"

            leftmatrix.Shift  = -(environment.MathFont.GetAxisHeight(environment.Style) - heightdiff) / 3;
            rightmatrix.Shift = -(environment.MathFont.GetAxisHeight(environment.Style) - heightdiff1) / 3;

            resultBox.Add(leftmatrix);
            resultBox.Add(vbarseparator);

            resultBox.Add(rightmatrix);

            return(resultBox);
        }
Esempio n. 15
0
        private Box LongDivisionStyle_righttop(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);
            var defaultLineThickness = texFont.GetDefaultLineThickness(style);

            var quotientbox = this.QuotientAtom == null ? StrutBox.Empty : this.QuotientAtom.CreateBox(environment);

            var dividend_divisor = new HorizontalBox();
            var dividendbox      = this.DividendAtom == null ? StrutBox.Empty : this.DividendAtom.CreateBox(environment);
            var divisorbox       = this.DivisorAtom == null ? StrutBox.Empty : this.DivisorAtom.CreateBox(environment);
            var divisorLpad      = new StrutBox(divisorbox.TotalWidth / 3, divisorbox.TotalHeight, 0, 0);
            var minorVsepline    = new VerticalRule(environment, defaultLineThickness, dividendbox.TotalHeight, 0);
            var minorHsepline    = new HorizontalRule(environment, defaultLineThickness, divisorbox.TotalWidth + divisorLpad.Width, 0);


            dividend_divisor.Add(dividendbox);
            dividend_divisor.Add(divisorbox);
            dividend_divisor.Add(minorVsepline);
            dividend_divisor.Add(new StrutBox(-(divisorbox.TotalWidth + divisorLpad.Width), 0, 0, 0));
            dividend_divisor.Add(minorHsepline);

            var majorsepline = new HorizontalRule(environment, defaultLineThickness, dividend_divisor.TotalWidth, 0);

            var otherbox = this.OtherAtom == null ? StrutBox.Empty : this.OtherAtom.CreateBox(environment);

            var resultBox = new VerticalBox();

            resultBox.Add(quotientbox);
            resultBox.Add(majorsepline);
            resultBox.Add(dividend_divisor);
            resultBox.Add(otherbox);

            return(resultBox);
        }
Esempio n. 16
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.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);
        }
Esempio n. 17
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;

            // Create box for base atom.
            var baseBox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment);

            if (this.SubscriptAtom == null && this.SuperscriptAtom == null)
            {
                if (baseBox is CharBox)
                {
                    // This situation should only happen when CreateBox called on a temporary ScriptsAtom created from
                    // BigOperatorAtom.CreateBox. The CharBox's Shift should then be fixed up.
                    baseBox.Shift = -(baseBox.Height + baseBox.Depth) / 2
                                    - environment.MathFont.GetAxisHeight(environment.Style);
                }

                return(baseBox);
            }

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

            // Get last font used or default Mu font.
            int lastFontId = baseBox.GetLastFontId();

            if (lastFontId == TexFontUtilities.NoFontId)
            {
                lastFontId = texFont.GetMuFontId();
            }

            var subscriptStyle   = environment.GetSubscriptStyle();
            var superscriptStyle = environment.GetSuperscriptStyle();

            // Set delta value and preliminary shift-up and shift-down amounts depending on type of base atom.
            var    delta = 0d;
            double shiftUp, shiftDown;

            if (this.BaseAtom is AccentedAtom)
            {
                var accentedBox = ((AccentedAtom)this.BaseAtom).BaseAtom.CreateBox(environment.GetCrampedStyle());
                shiftUp   = accentedBox.Height - texFont.GetSupDrop(superscriptStyle.Style);
                shiftDown = accentedBox.Depth + texFont.GetSubDrop(subscriptStyle.Style);
            }
            else if (this.BaseAtom is SymbolAtom && this.BaseAtom.Type == TexAtomType.BigOperator)
            {
                var charInfo = texFont.GetCharInfo(((SymbolAtom)this.BaseAtom).Name, style).Value;
                if (style < TexStyle.Text && texFont.HasNextLarger(charInfo))
                {
                    charInfo = texFont.GetNextLargerCharInfo(charInfo, style);
                }
                var charBox = new CharBox(environment, charInfo);

                charBox.Shift = -(charBox.Height + charBox.Depth) / 2 - environment.MathFont.GetAxisHeight(
                    environment.Style);
                resultBox = new HorizontalBox(charBox);

                delta = charInfo.Metrics.Italic;
                if (delta > TexUtilities.FloatPrecision && this.SubscriptAtom == null)
                {
                    resultBox.Add(new StrutBox(delta, 0, 0, 0));
                }

                shiftUp   = resultBox.Height - texFont.GetSupDrop(superscriptStyle.Style);
                shiftDown = resultBox.Depth + texFont.GetSubDrop(subscriptStyle.Style);
            }
            else if (this.BaseAtom is CharSymbol charSymbol)
            {
                var charFont = charSymbol.GetCharFont(texFont).Value;
                if (!charSymbol.IsTextSymbol || !texFont.HasSpace(charFont.FontId))
                {
                    delta = texFont.GetCharInfo(charFont, style).Value.Metrics.Italic;
                }
                if (delta > TexUtilities.FloatPrecision && this.SubscriptAtom == null)
                {
                    resultBox.Add(new StrutBox(delta, 0, 0, 0));
                    delta = 0;
                }

                shiftUp   = 0;
                shiftDown = 0;
            }
            else
            {
                shiftUp   = baseBox.Height - texFont.GetSupDrop(superscriptStyle.Style);
                shiftDown = baseBox.Depth + texFont.GetSubDrop(subscriptStyle.Style);
            }

            Box superscriptBox          = null;
            Box superscriptContainerBox = null;
            Box subscriptBox            = null;
            Box subscriptContainerBox   = null;

            if (this.SuperscriptAtom != null)
            {
                // Create box for superscript atom.
                superscriptBox          = this.SuperscriptAtom.CreateBox(superscriptStyle);
                superscriptContainerBox = new HorizontalBox(superscriptBox);

                // Add box for script space.
                superscriptContainerBox.Add(scriptSpaceAtom.CreateBox(environment));

                // Adjust shift-up amount.
                double p;
                if (style == TexStyle.Display)
                {
                    p = texFont.GetSup1(style);
                }
                else if (environment.GetCrampedStyle().Style == style)
                {
                    p = texFont.GetSup3(style);
                }
                else
                {
                    p = texFont.GetSup2(style);
                }
                shiftUp = Math.Max(Math.Max(shiftUp, p), superscriptBox.Depth + Math.Abs(texFont.GetXHeight(
                                                                                             style, lastFontId)) / 4);
            }

            if (this.SubscriptAtom != null)
            {
                // Create box for subscript atom.
                subscriptBox          = this.SubscriptAtom.CreateBox(subscriptStyle);
                subscriptContainerBox = new HorizontalBox(subscriptBox);

                // Add box for script space.
                subscriptContainerBox.Add(scriptSpaceAtom.CreateBox(environment));
            }

            // Check if only superscript is set.
            if (subscriptBox == null)
            {
                superscriptContainerBox.Shift = -shiftUp;
                resultBox.Add(superscriptContainerBox);
                return(resultBox);
            }

            // Check if only subscript is set.
            if (superscriptBox == null)
            {
                subscriptContainerBox.Shift = Math.Max(Math.Max(shiftDown, texFont.GetSub1(style)), subscriptBox.Height - 4 *
                                                       Math.Abs(texFont.GetXHeight(style, lastFontId)) / 5);
                resultBox.Add(subscriptContainerBox);
                return(resultBox);
            }

            // Adjust shift-down amount.
            shiftDown = Math.Max(shiftDown, texFont.GetSub2(style));

            // Reposition both subscript and superscript.
            double defaultLineThickness = texFont.GetDefaultLineThickness(style);
            // Space between subscript and superscript.
            double scriptsInterSpace = shiftUp - superscriptBox.Depth + shiftDown - subscriptBox.Height;

            if (scriptsInterSpace < 4 * defaultLineThickness)
            {
                shiftUp += 4 * defaultLineThickness - scriptsInterSpace;

                // Position bottom of superscript at least 4/5 of X-height above baseline.
                double psi = 0.8 * Math.Abs(texFont.GetXHeight(style, lastFontId)) - (shiftUp - superscriptBox.Depth);
                if (psi > 0)
                {
                    shiftUp   += psi;
                    shiftDown -= psi;
                }
            }
            scriptsInterSpace = shiftUp - superscriptBox.Depth + shiftDown - subscriptBox.Height;

            // Create box containing both superscript and subscript.
            var scriptsBox = new VerticalBox();

            superscriptContainerBox.Shift = delta;
            scriptsBox.Add(superscriptContainerBox);
            scriptsBox.Add(new StrutBox(0, scriptsInterSpace, 0, 0));
            scriptsBox.Add(subscriptContainerBox);
            scriptsBox.Height = shiftUp + superscriptBox.Height;
            scriptsBox.Depth  = shiftDown + subscriptBox.Depth;
            resultBox.Add(scriptsBox);

            return(resultBox);
        }
Esempio n. 18
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;

            // Create box for base atom.
            var baseBox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment);

            if (this.SubscriptAtom == null && this.SuperscriptAtom == null)
            {
                if (baseBox is CharBox)
                {
                    // This situation should only happen when CreateBox called on a temporary ScriptsAtom created from
                    // BigOperatorAtom.CreateBox. The CharBox's Shift should then be fixed up.
                    baseBox.Shift = -(baseBox.Height + baseBox.Depth) / 2
                                    - environment.MathFont.GetAxisHeight(environment.Style);
                }

                return(baseBox);
            }

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

            // Get last font used or default Mu font.
            int lastFontId = baseBox.GetLastFontId();

            if (lastFontId == TexFontUtilities.NoFontId)
            {
                lastFontId = texFont.GetMuFontId();
            }

            var subscriptStyle   = environment.GetSubscriptStyle();
            var superscriptStyle = environment.GetSuperscriptStyle();

            // Set delta value and preliminary shift-up and shift-down amounts depending on type of base atom.
            var    delta = 0d;
            double shiftUp, shiftDown;

            if (this.BaseAtom is AccentedAtom)
            {
                var accentedBox = ((AccentedAtom)this.BaseAtom).BaseAtom.CreateBox(environment.GetCrampedStyle());
                shiftUp   = accentedBox.Height - texFont.GetSupDrop(superscriptStyle.Style);
                shiftDown = accentedBox.Depth + texFont.GetSubDrop(subscriptStyle.Style);
            }
            else if (this.BaseAtom is SymbolAtom && this.BaseAtom.Type == TexAtomType.BigOperator)
            {
                var charInfo = texFont.GetCharInfo(((SymbolAtom)this.BaseAtom).Name, style).Value;
                if (style < TexStyle.Text && texFont.HasNextLarger(charInfo))
                {
                    charInfo = texFont.GetNextLargerCharInfo(charInfo, style);
                }
                var charBox = new CharBox(environment, charInfo);

                charBox.Shift = -(charBox.Height + charBox.Depth) / 2 - environment.MathFont.GetAxisHeight(
                    environment.Style);
                resultBox = new HorizontalBox(charBox);

                delta = charInfo.Metrics.Italic;
                if (delta > TexUtilities.FloatPrecision && this.SubscriptAtom == null)
                {
                    resultBox.Add(new StrutBox(delta, 0, 0, 0));
                }

                shiftUp   = resultBox.Height - texFont.GetSupDrop(superscriptStyle.Style);
                shiftDown = resultBox.Depth + texFont.GetSubDrop(subscriptStyle.Style);
            }
            else if (this.BaseAtom is CharSymbol charSymbol &&
                     charSymbol.IsSupportedByFont(texFont, style))
            {
                var charFont = charSymbol.GetCharFont(texFont).Value;
                if (!charSymbol.IsTextSymbol || !texFont.HasSpace(charFont.FontId))
                {
                    delta = texFont.GetCharInfo(charFont, style).Value.Metrics.Italic;
                }
                if (delta > TexUtilities.FloatPrecision && this.SubscriptAtom == null)
                {
                    resultBox.Add(new StrutBox(delta, 0, 0, 0));
                    delta = 0;
                }

                shiftUp   = 0;
                shiftDown = 0;
            }
Esempio n. 19
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;
            var axis    = texFont.GetAxisHeight(style);

            //Region for adjustment vars
            double maxrowWidth = 0;

            //stores the max cell height for each row
            var RowsMaxCellHeight = new List <double>();

            for (int i = 0; i < RowCount; i++)
            {
                RowsMaxCellHeight.Add(0);
            }
            //stores the max cell width for each column
            var ColumnsMaxCellWidth = new List <double>();

            for (int i = 0; i < ColumnCount; i++)
            {
                ColumnsMaxCellWidth.Add(0);
            }
            //Create a vertical box to hold the rows and their cells
            var resultBox = new VerticalBox();

            for (int i = 0; i < RowCount; i++)
            {
                //row top pad
                resultBox.Add(new StrutBox(maxrowWidth, CellBottomTopPadding / 2, 0, 0));

                var rowbox = new HorizontalBox()
                {
                    Tag = $"Row:{i}",
                };

                for (int j = 0; j < ColumnCount; j++)
                {
                    double maxrowHeight = 0;
                    //cell left pad
                    var cellleftpad = new StrutBox(CellLeftRightPadding / 2, 0, 0, 0)
                    {
                        Tag   = $"CellLeftPad{i}:{j}",
                        Shift = 0,
                    };

                    //cell right pad
                    var cellrightpad = new StrutBox(CellLeftRightPadding / 2, 0, 0, 0)
                    {
                        Tag   = $"CellRightPad{i}:{j}",
                        Shift = 0,
                    };

                    //cell box
                    var rowcellbox = TableCells[i][j] == null ? StrutBox.Empty : TableCells[i][j].CreateBox(environment);
                    ColumnsMaxCellWidth[j] = rowcellbox.TotalWidth > ColumnsMaxCellWidth[j] ? rowcellbox.TotalWidth : ColumnsMaxCellWidth[j];
                    rowcellbox.Tag         = "innercell";
                    //cell box holder
                    var rowcolbox = new VerticalBox()
                    {
                        Tag = $"Cell{i}:{j}", ShowBounds = false
                    };

                    var celltoppad = new StrutBox(rowcellbox.TotalWidth, CellBottomTopPadding / 2, 0, 0)
                    {
                        Tag = $"CellTopPad{i}:{j}",
                    };
                    var cellbottompad = new StrutBox(rowcellbox.TotalWidth, CellBottomTopPadding / 2, 0, 0)
                    {
                        Tag = $"CellBottomPad{i}:{j}",
                    };
                    rowcolbox.Add(celltoppad);
                    rowcolbox.Add(rowcellbox);
                    rowcolbox.Add(cellbottompad);

                    //maxrowHeight += rowcolbox.TotalHeight;
                    maxrowHeight   += rowcellbox.TotalHeight + CellBottomTopPadding;
                    rowcolbox.Width = rowcellbox.TotalWidth;
                    //rowcolbox.Height = maxrowHeight;

                    rowbox.Add(cellleftpad);
                    rowbox.Add(rowcolbox);
                    rowbox.Add(cellrightpad);

                    RowsMaxCellHeight[i] = maxrowHeight > RowsMaxCellHeight[i] ? maxrowHeight : RowsMaxCellHeight[i];
                }

                rowbox.Shift = 0;
                resultBox.Add(rowbox);
                //row bottom pad
                resultBox.Add(new StrutBox(maxrowWidth, CellBottomTopPadding / 2, 0, 0));
            }

            int rows    = 0;
            int columns = 0;
            //1->Left and right, 2->Top and Bottom
            //create the item below to hold the left-right gaps(Tuple.Item1) and top-bottom gaps (Tuple.Item2) for the rows
            List <List <Tuple <double, double> > > TableCellGaps = new List <List <Tuple <double, double> > >();

            for (int i = 0; i < resultBox.Children.Count; i++)
            {
                var tablerowitem = resultBox.Children[i];
                List <Tuple <double, double> > RowGaps = new List <Tuple <double, double> >();

                if (tablerowitem is HorizontalBox && tablerowitem.Tag.ToString() == $"Row:{rows}")
                {
                    for (int j = 0; j < ((HorizontalBox)tablerowitem).Children.Count; j++)
                    {
                        var rowcolitem = ((HorizontalBox)tablerowitem).Children[j];
                        if (rowcolitem is StrutBox)
                        {
                            rowcolitem.Height = RowsMaxCellHeight[rows];
                        }
                        else if (rowcolitem is VerticalBox && rowcolitem.Tag.ToString() == $"Cell{rows}:{columns}")
                        {
                            double cellVShift = RowsMaxCellHeight[rows] - rowcolitem.TotalHeight;

                            double cellHShift = ColumnsMaxCellWidth[columns] - rowcolitem.TotalWidth;

                            ((HorizontalBox)tablerowitem).Children[j - 1].Shift = rowcolitem.Depth; // + (cellVShift / 2);//.Width += cellHShift / 2;
                            ((HorizontalBox)tablerowitem).Children[j + 1].Shift = rowcolitem.Depth; // +(cellVShift / 2);// Width += cellHShift / 2;
                            RowGaps.Add(new Tuple <double, double> (cellHShift / 2, cellVShift / 2));

                            columns++;
                        }
                    }

                    columns = 0;
                    rows++;
                    TableCellGaps.Add(RowGaps);
                }
            }

            rows    = 0;
            columns = 0;
            for (int i = 0; i < resultBox.Children.Count; i++)
            {
                var tablerowitem = resultBox.Children[i];

                if (tablerowitem is HorizontalBox && tablerowitem.Tag.ToString() == $"Row:{rows}")
                {
                    double rowwidth = 0;
                    for (int j = 0; j < ((HorizontalBox)tablerowitem).Children.Count; j++)
                    {
                        var currowcolitem  = ((HorizontalBox)tablerowitem).Children[j];
                        var prevrowcolitem = j > 0 ? ((HorizontalBox)tablerowitem).Children[j - 1] : ((HorizontalBox)tablerowitem).Children[j];
                        var nextrowcolitem = j < ((HorizontalBox)tablerowitem).Children.Count - 1 ? ((HorizontalBox)tablerowitem).Children[j + 1] : ((HorizontalBox)tablerowitem).Children[j];

                        if (currowcolitem is VerticalBox && Regex.IsMatch(currowcolitem.Tag.ToString(), @"Cell[0-9]+:[0-9]+"))
                        {
                            rowwidth += currowcolitem.TotalWidth;
                            var leftstructboxtag  = $"CellLeftPad{rows}:{columns}";
                            var rightstructboxtag = $"CellRightPad{rows}:{columns}";

                            switch (CellHorizontalAlignment)
                            {
                            case HorizontalAlignment.Left:
                            {
                                if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag)
                                {
                                    //prevrowcolitem.Width += TableCellGaps[a][b].Item1;
                                    rowwidth += prevrowcolitem.TotalWidth;
                                }
                                if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag)
                                {
                                    nextrowcolitem.Width += 2 * TableCellGaps[rows][columns].Item1;
                                    rowwidth             += nextrowcolitem.TotalWidth;
                                }
                                break;
                            }

                            case HorizontalAlignment.Right:
                            {
                                if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag)
                                {
                                    prevrowcolitem.Width += 2 * TableCellGaps[rows][columns].Item1;
                                    rowwidth             += prevrowcolitem.TotalWidth;
                                }
                                if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag)
                                {
                                    //nextrowcolitem.Width += TableCellGaps[a][b].Item1;
                                    rowwidth += nextrowcolitem.TotalWidth;
                                }
                                break;
                            }

                            case HorizontalAlignment.Center:
                            {
                                if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag)
                                {
                                    prevrowcolitem.Width += TableCellGaps[rows][columns].Item1;
                                    rowwidth             += prevrowcolitem.TotalWidth;
                                }
                                if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag)
                                {
                                    nextrowcolitem.Width += TableCellGaps[rows][columns].Item1;
                                    rowwidth             += nextrowcolitem.TotalWidth;
                                }
                                break;
                            }

                            case HorizontalAlignment.Stretch:
                            {
                                if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag)
                                {
                                    prevrowcolitem.Width  = 0;
                                    prevrowcolitem.Italic = 0;
                                    rowwidth += prevrowcolitem.TotalWidth;
                                }
                                if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag)
                                {
                                    nextrowcolitem.Width  = 0;
                                    nextrowcolitem.Italic = 0;
                                    rowwidth += nextrowcolitem.TotalWidth;
                                }
                                break;
                            }

                            default:
                                break;
                            }

                            double cellheight = 0;
                            //check the vertical cell gap size and increase appropriately
                            for (int k = 0; k < ((VerticalBox)currowcolitem).Children.Count; k++)
                            {
                                var curcellitem  = ((VerticalBox)currowcolitem).Children[k];
                                var prevcellitem = k > 0? ((VerticalBox)currowcolitem).Children[k - 1]:((VerticalBox)currowcolitem).Children[k];
                                var nextcellitem = k < (((VerticalBox)currowcolitem).Children.Count - 1)? ((VerticalBox)currowcolitem).Children[k + 1]:((VerticalBox)currowcolitem).Children[k];

                                if (curcellitem.Tag.ToString() == "innercell")
                                {
                                    cellheight += curcellitem.TotalHeight;
                                    var topstructboxtag    = $"CellTopPad{rows}:{columns}";
                                    var bottomstructboxtag = $"CellBottomPad{rows}:{columns}";

                                    switch (CellVerticalAlignment)
                                    {
                                    case VerticalAlignment.Bottom:
                                    {
                                        if (prevcellitem.Tag.ToString() == topstructboxtag)
                                        {
                                            prevcellitem.Height += 2 * TableCellGaps[rows][columns].Item2;
                                            //prevcellitem.Background = Brushes.Aquamarine;
                                            cellheight += prevcellitem.TotalHeight;
                                            if (prevcellitem.Height > (currowcolitem.Height / 2))
                                            {
                                            }
                                        }
                                        if (nextcellitem.Tag.ToString() == bottomstructboxtag)
                                        {
                                            //nextcellitem.Height += TableCellGaps[a][b].Item2;
                                            //nextcellitem.Background = Brushes.BurlyWood;
                                            cellheight += nextcellitem.TotalHeight;
                                        }
                                        break;
                                    }

                                    case VerticalAlignment.Center:
                                    {
                                        if (prevcellitem.Tag.ToString() == topstructboxtag)
                                        {
                                            prevcellitem.Height += TableCellGaps[rows][columns].Item2;
                                            //prevcellitem.Background = Brushes.Aquamarine;
                                            cellheight += prevcellitem.TotalHeight;
                                            if (prevcellitem.Height > (currowcolitem.Height / 2))
                                            {
                                            }
                                        }
                                        if (nextcellitem.Tag.ToString() == bottomstructboxtag)
                                        {
                                            nextcellitem.Height += TableCellGaps[rows][columns].Item2;
                                            //nextcellitem.Background = Brushes.BurlyWood;
                                            cellheight += nextcellitem.TotalHeight;
                                        }
                                        break;
                                    }

                                    case VerticalAlignment.Stretch:
                                    {
                                        if (prevcellitem.Tag.ToString() == topstructboxtag)
                                        {
                                            prevcellitem.Height = 0;
                                            prevcellitem.Depth  = 0;
                                            //prevcellitem.Background = Brushes.Aquamarine;
                                            cellheight += prevcellitem.TotalHeight;
                                            if (prevcellitem.Height > (currowcolitem.Height / 2))
                                            {
                                            }
                                        }
                                        if (nextcellitem.Tag.ToString() == bottomstructboxtag)
                                        {
                                            nextcellitem.Height = 0;
                                            nextcellitem.Depth  = 0;
                                            //nextcellitem.Background = Brushes.BurlyWood;
                                            cellheight += nextcellitem.TotalHeight;
                                        }
                                        break;
                                    }

                                    case VerticalAlignment.Top:
                                    {
                                        if (prevcellitem.Tag.ToString() == topstructboxtag)
                                        {
                                            //prevcellitem.Height += TableCellGaps[a][b].Item2;
                                            //prevcellitem.Background = Brushes.Aquamarine;
                                            cellheight += prevcellitem.TotalHeight;
                                            if (prevcellitem.Height > (currowcolitem.Height / 2))
                                            {
                                            }
                                        }
                                        if (nextcellitem.Tag.ToString() == bottomstructboxtag)
                                        {
                                            nextcellitem.Height += 2 * TableCellGaps[rows][columns].Item2;
                                            //nextcellitem.Background = Brushes.BurlyWood;
                                            cellheight += nextcellitem.TotalHeight;
                                        }
                                        break;
                                    }

                                    default:
                                        break;
                                    }

                                    if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag)
                                    {
                                        prevrowcolitem.Shift += TableCellGaps[rows][columns].Item2;
                                    }
                                    if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag)
                                    {
                                        nextrowcolitem.Shift += TableCellGaps[rows][columns].Item2;
                                    }
                                    //currowcolitem.Shift -= TableCellGaps[a][b].Item2; ;
                                }
                            }
                            //currowcolitem.Height = cellheight;
                            columns++;
                        }
                    }

                    tablerowitem.Width = rowwidth;
                    columns            = 0;
                    rows++;
                }
            }

            double sigmaTotalHeight = 0;
            double adjustedwidth    = 0;

            foreach (var item in resultBox.Children)
            {
                sigmaTotalHeight += item.TotalHeight;
                if (item.TotalWidth > adjustedwidth)
                {
                    adjustedwidth = item.TotalWidth;
                }
            }

            double adjustedTotalHeight = RowsMaxCellHeight.Sum() + (RowCount * CellBottomTopPadding);

            resultBox.Depth  = 0;
            resultBox.Height = adjustedTotalHeight > sigmaTotalHeight?adjustedTotalHeight:sigmaTotalHeight;
            resultBox.Width  = adjustedwidth > resultBox.TotalWidth?adjustedwidth:resultBox.TotalWidth;
            var enviroYDiff = axis >= resultBox.TotalHeight ? -(axis - resultBox.TotalHeight) / 2: (resultBox.TotalHeight - axis) / 2;

            resultBox.Shift = enviroYDiff;

            var finalbox = new HorizontalBox();

            finalbox.Add(new StrutBox(CellLeftRightPadding / 8, 0, 0, 0));
            finalbox.Add(resultBox);
            finalbox.Add(new StrutBox(CellLeftRightPadding / 8, 0, 0, 0));

            return(finalbox);
        }
Esempio n. 20
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            var texFont = environment.MathFont;
            var style   = environment.Style;

            if ((this.UseVerticalLimits.HasValue && !this.UseVerticalLimits.Value) ||
                (!this.UseVerticalLimits.HasValue && style >= TexStyle.Text))
            {
                // Attach atoms for limits as scripts.
                return(new ScriptsAtom(this.Source, this.BaseAtom, this.LowerLimitAtom, this.UpperLimitAtom)
                       .CreateBox(environment));
            }

            // Create box for base atom.
            Box    baseBox;
            double delta;

            if (this.BaseAtom is SymbolAtom && this.BaseAtom.Type == TexAtomType.BigOperator)
            {
                // Find character of best scale for operator symbol.
                var opChar = texFont.GetCharInfo(((SymbolAtom)this.BaseAtom).Name, style).Value;
                if (style < TexStyle.Text && texFont.HasNextLarger(opChar))
                {
                    opChar = texFont.GetNextLargerCharInfo(opChar, style);
                }
                var charBox = new CharBox(environment, opChar)
                {
                    Source = this.BaseAtom.Source
                };
                charBox.Shift = -(charBox.Height + charBox.Depth) / 2 -
                                environment.MathFont.GetAxisHeight(environment.Style);
                baseBox = new HorizontalBox(charBox);

                delta = opChar.Metrics.Italic;
                if (delta > TexUtilities.FloatPrecision)
                {
                    baseBox.Add(new StrutBox(delta, 0, 0, 0));
                }
            }
            else
            {
                baseBox = new HorizontalBox(this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment));
                delta   = 0;
            }

            // Create boxes for upper and lower limits.
            var upperLimitBox = this.UpperLimitAtom == null ? null : this.UpperLimitAtom.CreateBox(
                environment.GetSuperscriptStyle());
            var lowerLimitBox = this.LowerLimitAtom == null ? null : this.LowerLimitAtom.CreateBox(
                environment.GetSubscriptStyle());

            // Make all component boxes equally wide.
            var maxWidth = Math.Max(Math.Max(baseBox.Width, upperLimitBox == null ? 0 : upperLimitBox.Width),
                                    lowerLimitBox == null ? 0 : lowerLimitBox.Width);

            if (baseBox != null)
            {
                baseBox = ChangeWidth(baseBox, maxWidth);
            }
            if (upperLimitBox != null)
            {
                upperLimitBox = ChangeWidth(upperLimitBox, maxWidth);
            }
            if (lowerLimitBox != null)
            {
                lowerLimitBox = ChangeWidth(lowerLimitBox, maxWidth);
            }

            var resultBox  = new VerticalBox();
            var opSpacing5 = texFont.GetBigOpSpacing5(style);
            var kern       = 0d;

            // Create and add box for upper limit.
            if (this.UpperLimitAtom != null)
            {
                resultBox.Add(new StrutBox(0, opSpacing5, 0, 0));
                upperLimitBox.Shift = delta / 2;
                resultBox.Add(upperLimitBox);
                kern = Math.Max(texFont.GetBigOpSpacing1(style), texFont.GetBigOpSpacing3(style) -
                                upperLimitBox.Depth);
                resultBox.Add(new StrutBox(0, kern, 0, 0));
            }

            // Add box for base atom.
            resultBox.Add(baseBox);

            // Create and add box for lower limit.
            if (this.LowerLimitAtom != null)
            {
                resultBox.Add(new StrutBox(0, Math.Max(texFont.GetBigOpSpacing2(style), texFont.GetBigOpSpacing4(style) -
                                                       lowerLimitBox.Height), 0, 0));
                lowerLimitBox.Shift = -delta / 2;
                resultBox.Add(lowerLimitBox);
                resultBox.Add(new StrutBox(0, opSpacing5, 0, 0));
            }

            // Adjust height and depth of result box.
            var baseBoxHeight = baseBox.Height;
            var totalHeight   = resultBox.Height + resultBox.Depth;

            if (upperLimitBox != null)
            {
                baseBoxHeight += opSpacing5 + kern + upperLimitBox.Height + upperLimitBox.Depth;
            }
            resultBox.Height = baseBoxHeight;
            resultBox.Depth  = totalHeight - baseBoxHeight;

            return(resultBox);
        }
Esempio n. 21
0
        private VerticalBox ApplyCellPaddings(
            TexEnvironment environment,
            IList <List <Box> > matrix,
            int columnCount,
            IList <List <CellGaps> > matrixCellGaps)
        {
            var rowsContainer = new VerticalBox();

            for (var i = 0; i < matrix.Count; ++i)
            {
                var rowContainer = new HorizontalBox();
                for (var j = 0; j < columnCount; ++j)
                {
                    var cell = matrix[i][j];

                    var cellContainer = new VerticalBox();
                    var(topPadding, bottomPadding) = GetVerticalPadding(i, j);
                    cellContainer.Add(topPadding);
                    cellContainer.Add(cell);
                    cellContainer.Add(bottomPadding);
                    cellContainer.Height = cellContainer.TotalHeight;
                    cellContainer.Depth  = 0;

                    var(leftPadding, rightPadding) = GetHorizontalPadding(i, j);
                    if (leftPadding != null)
                    {
                        rowContainer.Add(leftPadding);
                    }
                    rowContainer.Add(cellContainer);
                    rowContainer.Add(rightPadding);
                }

                rowsContainer.Add(rowContainer);
            }

            var axis            = environment.MathFont.GetAxisHeight(environment.Style);
            var containerHeight = rowsContainer.TotalHeight;

            rowsContainer.Depth  = containerHeight / 2 - axis;
            rowsContainer.Height = containerHeight / 2 + axis;

            return(rowsContainer);

            (Box TopPadding, Box BottomPadding) GetVerticalPadding(int i, int j)
            {
                var value     = matrixCellGaps[i][j].Vertical;
                var topBox    = new StrutBox(0.0, VerticalPadding / 2 + value, 0.0, VerticalPadding);
                var bottomBox = new StrutBox(0.0, VerticalPadding / 2 + value, 0.0, VerticalPadding);

                return(topBox, bottomBox);
            }

            (Box LeftPadding, Box RightPadding) GetHorizontalPadding(int i, int j)
            {
                var value        = matrixCellGaps[i][j].Horizontal;
                var leftPadding  = MatrixCellAlignment == MatrixCellAlignment.Left ? 0.0 : value;
                var rightPadding = MatrixCellAlignment == MatrixCellAlignment.Left ? value * 2 : value;
                var leftBox      = MatrixCellAlignment == MatrixCellAlignment.Left
                    ? null
                    : new StrutBox(HorizontalPadding / 2 + leftPadding, 0.0, 0.0, 0.0);
                var rightBox = new StrutBox(HorizontalPadding / 2 + rightPadding, 0.0, 0.0, 0.0);

                return(leftBox, rightBox);
            }
        }
Esempio n. 22
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            CharSymbol GetBaseChar()
            {
                var baseAtom = this.BaseAtom;

                while (baseAtom is AccentedAtom a)
                {
                    baseAtom = a.BaseAtom;
                }

                return(baseAtom as CharSymbol);
            }

            var texFont = environment.MathFont;
            var style   = environment.Style;

            // Create box for base atom.
            var baseBox      = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment.GetCrampedStyle());
            var baseCharFont = GetBaseChar()?.GetCharFont(texFont).Value;
            var skew         = baseCharFont == null ? 0.0 : texFont.GetSkew(baseCharFont, style);

            // Find character of best scale for accent symbol.
            var accentChar = texFont.GetCharInfo(this.AccentAtom.Name, style).Value;

            while (texFont.HasNextLarger(accentChar))
            {
                var nextLargerChar = texFont.GetNextLargerCharInfo(accentChar, style);
                if (nextLargerChar.Metrics.Width > baseBox.Width)
                {
                    break;
                }
                accentChar = nextLargerChar;
            }

            var resultBox = new VerticalBox();

            // Create and add box for accent symbol.
            Box accentBox;
            var accentItalicWidth = accentChar.Metrics.Italic;

            if (accentItalicWidth > TexUtilities.FloatPrecision)
            {
                accentBox = new HorizontalBox(new CharBox(environment, accentChar));
                accentBox.Add(new StrutBox(accentItalicWidth, 0, 0, 0));
            }
            else
            {
                accentBox = new CharBox(environment, accentChar);
            }
            resultBox.Add(accentBox);

            var delta = Math.Min(baseBox.Height, texFont.GetXHeight(style, accentChar.FontId));

            resultBox.Add(new StrutBox(0, -delta, 0, 0));

            // Centre and add box for base atom. Centre base box and accent box with respect to each other.
            var boxWidthsDiff = (baseBox.Width - accentBox.Width) / 2;

            accentBox.Shift = skew + Math.Max(boxWidthsDiff, 0);
            if (boxWidthsDiff < 0)
            {
                baseBox = new HorizontalBox(baseBox, accentBox.Width, TexAlignment.Center);
            }
            resultBox.Add(baseBox);

            // Adjust height and depth of result box.
            var depth       = baseBox.Depth;
            var totalHeight = resultBox.Height + resultBox.Depth;

            resultBox.Depth  = depth;
            resultBox.Height = totalHeight - depth;

            return(resultBox);
        }
Esempio n. 23
0
        protected override Box CreateBoxCore(TexEnvironment environment)
        {
            // Create result box.
            var resultBox = new HorizontalBox(environment.Foreground, environment.Background);

            var previousAtom = this.PreviousAtom;

            // 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;
                curAtom = ChangeAtomToOrdinary(curAtom, previousAtom, nextAtom);

                // Check if atom is part of ligature or should be kerned.
                var kern = 0d;
                if (hasNextAtom && curAtom.GetRightType() == TexAtomType.Ordinary && curAtom.Atom is CharSymbol cs)
                {
                    if (nextAtom is CharSymbol ns && ligatureKernChangeSet[(int)nextAtom.GetLeftType()])
                    {
                        var font  = ns.GetStyledFont(environment);
                        var style = environment.Style;
                        curAtom = curAtom.AsTextSymbol();
                        if (font.SupportsMetrics && cs.IsSupportedByFont(font, style))
                        {
                            var leftAtomCharFont  = curAtom.GetCharFont(font).Value;
                            var rightAtomCharFont = ns.GetCharFont(font).Value;
                            var ligatureCharFont  = font.GetLigature(leftAtomCharFont, rightAtomCharFont);
                            if (ligatureCharFont == null)
                            {
                                // Atom should be kerned.
                                kern = font.GetKern(leftAtomCharFont, rightAtomCharFont, style);
                            }
                            else
                            {
                                // Atom is part of ligature.
                                curAtom = DummyAtom.CreateLigature(new FixedCharAtom(null, ligatureCharFont));
                                i++;
                            }
                        }
                    }
                }

                // Create and add glue box, unless atom is first of row or previous/current atom is kern.
                if (i != 0 && previousAtom != null && !previousAtom.IsKern && !curAtom.IsKern)
                {
                    resultBox.Add(Glue.CreateBox(previousAtom.GetRightType(), curAtom.GetLeftType(), environment));
                }

                // Create and add box for atom.
                var curBox = curAtom.WithPreviousAtom(previousAtom).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)
                {
                    previousAtom = curAtom;
                }
            }

            return(resultBox);
        }