Exemple #1
0
        public override Box CreateBox()
        {
            float factor = TexContext.Scale;

            return(StrutBox.Get((width + TexContext.Kerning.value) * factor,
                                height * factor, depth * factor, 0, policy));
        }
Exemple #2
0
        public override Box CreateBox(TexStyle style)
        {
            if (BaseAtom == null)
            {
                return(StrutBox.Empty);
            }
            else
            {
                Box box;
                if (UnderLink)
                {
                    var   baseBox = BaseAtom.CreateBox(style);
                    float margin  = TEXConfiguration.main.NegateMargin * TexUtility.SizeFactor(style) / 2;
                    float thick   = TEXConfiguration.main.LineThickness * TexUtility.SizeFactor(style) / 2;

                    box = HorizontalBox.Get(baseBox);
                    box.Add(StrutBox.Get(-box.width, 0, 0, 0));
                    box.Add(StrikeBox.Get(baseBox.height, baseBox.width, baseBox.depth,
                                          margin, thick, StrikeBox.StrikeMode.underline, 0, 0));
                    return(AttrLinkBox.Get(box, MetaKey));
                }
                else
                {
                    return(AttrLinkBox.Get(BaseAtom.CreateBox(style), MetaKey));
                }
            }
        }
Exemple #3
0
        public override Box CreateBox()
        {
            if (BaseAtom == null)
            {
                return(StrutBox.Empty);
            }
            else
            {
                if (UnderLink)
                {
                    var baseBox = BaseAtom.CreateBox();
                    var box     = HorizontalBox.Get(baseBox);

                    float factor = TexContext.Scale / 2;
                    float thick  = TEXConfiguration.main.LineThickness * factor;

                    box.Add(StrutBox.Get(-box.width, 0, 0, 0));
                    box.Add(StrikeBox.Get(baseBox.height, baseBox.width, baseBox.depth,
                                          0, thick, StrikeBox.StrikeMode.underline, 0, 0));

                    return(AttrLinkBox.Get(box, MetaKey, Margin));
                }
                else
                {
                    return(AttrLinkBox.Get(BaseAtom.CreateBox(), MetaKey, Margin));
                }
            }
        }
Exemple #4
0
        public static VerticalBox Get(Box box, float kern, float thickness)
        {
            var atom = VerticalBox.Get();

            atom.Add(HorizontalRule.Get(thickness, box.width, box.shift));
            kern += thickness;
            atom.Add(StrutBox.Get(0, kern / 2, 0, 0));
            atom.Add(box);
            atom.Add(StrutBox.Get(0, kern / 2, 0, 0));
            return(atom);
        }
Exemple #5
0
        public override Box CreateBox()
        {
            if (BaseAtom == null)
                return StrutBox.Empty;
            var factor = TexContext.Scale / 2;
            var margin = useMargin ? TEXConfiguration.main.NegateMargin * factor : 0;
            var thick = TEXConfiguration.main.LineThickness * factor;
            var baseBox = BaseAtom.CreateBox();
            var result = HorizontalBox.Get();

            var negateBox = StrikeBox.Get(baseBox.height, baseBox.width, baseBox.depth,
                                margin, thick, (StrikeBox.StrikeMode)mode, offsetM, offsetP);
            negateBox.shift = baseBox.shift;
            result.Add(negateBox);
            result.Add(StrutBox.Get(-baseBox.width, 0, 0, 0));
            result.Add(baseBox);
            return result;
        }
Exemple #6
0
        public override Box CreateBox()
        {
            var defaultLineThickness = TEXConfiguration.main.LineThickness * TexContext.Scale;

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

            // Create result box.
            var resultBox = VerticalBox.Get();

            resultBox.Add(baseBox);
            resultBox.Add(StrutBox.Get(0, 3 * defaultLineThickness, 0, 0));
            resultBox.Add(HorizontalRule.Get(defaultLineThickness, baseBox.width, 0));

            resultBox.depth  = baseBox.depth + 5 * defaultLineThickness;
            resultBox.height = baseBox.height;

            return(resultBox);
        }
        public override Box CreateBox(TexStyle style)
        {
            if (BaseAtom == null)
            {
                return(StrutBox.Empty);
            }
            var factor  = TexUtility.SizeFactor(style) / 2;
            var margin  = useMargin ? TEXConfiguration.main.NegateMargin * factor : 0;
            var thick   = TEXConfiguration.main.LineThickness * factor;
            var baseBox = BaseAtom.CreateBox(style);
            var result  = HorizontalBox.Get();

            var negateBox = StrikeBox.Get(baseBox.height, baseBox.width, baseBox.depth,
                                          margin, thick, (StrikeBox.StrikeMode)mode, offsetM, offsetP);

            negateBox.shift = baseBox.shift;
            result.Add(negateBox);
            result.Add(StrutBox.Get(-baseBox.width, 0, 0, 0));
            result.Add(baseBox);
            return(result);
        }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
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);
            }
        }
Exemple #11
0
        public override Box CreateBox(TexStyle style)
        {
            float factor = TexUtility.SizeFactor(style);

            return(StrutBox.Get((width + TexUtility.AdditionalGlueSpace) * factor, height * factor, depth * factor, 0, policy));
        }
Exemple #12
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);
        }
Exemple #13
0
        public override Box CreateBox()
        {
            float lineHeight = lineThickness * TexContext.Scale;

            // Create boxes for numerator and demoninator atoms, and make them of equal width.
            TexContext.Environment.Push(TexUtility.GetNumeratorStyle());
            var numeratorBox = numerator == null ? StrutBox.Empty : numerator.CreateBox();

            TexContext.Environment.Pop();

            TexContext.Environment.Push(TexUtility.GetDenominatorStyle());
            var denominatorBox = denominator == null ? StrutBox.Empty : denominator.CreateBox();

            TexContext.Environment.Pop();

            float maxWidth = (numeratorBox.width < denominatorBox.width ? denominatorBox.width : numeratorBox.width) + TEXConfiguration.main.FractionMargin * TexContext.Scale;

            numeratorBox   = HorizontalBox.Get(numeratorBox, maxWidth, numeratorAlignment);
            denominatorBox = HorizontalBox.Get(denominatorBox, maxWidth, denominatorAlignment);

            // Calculate preliminary shift-up and shift-down amounts.
            float shiftUp, shiftDown;
            var   styleFactor = TexContext.Scale;

            if (TexContext.Environment.value >= TexEnvironment.Text)
            {
                styleFactor *= TEXConfiguration.main.FractionNarrowFactor;
            }

            shiftUp   = TEXConfiguration.main.NumeratorShift * styleFactor;
            shiftDown = TEXConfiguration.main.DenominatorShift * styleFactor;

            // Create result box.
            var resultBox = VerticalBox.Get();

            // add box for numerator.
            resultBox.Add(numeratorBox);

            // Calculate clearance and adjust shift amounts.
            //var axis = TEXConfiguration.main.AxisHeight * TexContext.Scale;

            // Calculate clearance amount.
            float clearance = lineHeight > 0 ? TEXConfiguration.main.FractionGap : TEXConfiguration.main.FractionGapNoLine;

            // Adjust shift amounts.
            var kern1  = shiftUp - numeratorBox.depth;
            var kern2  = shiftDown - denominatorBox.height;
            var delta1 = clearance - kern1;
            var delta2 = clearance - kern2;

            if (delta1 > 0)
            {
                shiftUp += delta1;
                kern1   += delta1;
            }
            if (delta2 > 0)
            {
                shiftDown += delta2;
                kern2     += delta2;
            }

            if (lineHeight > 0)
            {
                // Draw fraction line.

                resultBox.Add(StrutBox.Get(0, kern1, 0, 0));
                resultBox.Add(HorizontalRule.Get(lineHeight, numeratorBox.width, 0));
                resultBox.Add(StrutBox.Get(0, kern2, 0, 0));
            }
            else
            {
                // Do not draw fraction line.

                var kern = kern1 + kern2;
                resultBox.Add(StrutBox.Get(0, kern, 0, 0));
            }

            // add box for denominator.
            resultBox.Add(denominatorBox);

            // Adjust height and depth of result box.
            resultBox.height = shiftUp + numeratorBox.height;
            resultBox.depth  = shiftDown + lineHeight + denominatorBox.depth;

            TexUtility.CentreBox(resultBox);
            return(resultBox);
        }