Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }