Example #1
0
        Box CreateGenericRadicalBox(Box baseBox, string genericSymbol)
        {
            float clearance;
            var   lineThickness = TEXConfiguration.main.LineThickness * TexContext.Scale;

            clearance = lineThickness;

            // Create box for radical sign.
            var totalHeight    = baseBox.totalHeight;
            var radicalSignBox = DelimiterFactory.CreateBox(genericSymbol, totalHeight + clearance + lineThickness);

            // Add half of excess height to clearance.
            //lineThickness = Mathf.Max(radicalSignBox.height, lineThickness);
            clearance = radicalSignBox.totalHeight - totalHeight - lineThickness * 2;

            // Create box for square-root containing base box.
            TexUtility.CentreBox(radicalSignBox);
            var overBar = OverBar.Get(baseBox, clearance, lineThickness);

            var expansion = radicalSignBox.width - CustomizedGenericDelimOffset(genericSymbol, radicalSignBox.totalHeight) * radicalSignBox.width;

            overBar.children[0].width += expansion;
            overBar.children[0].shift -= expansion;

            TexUtility.CentreBox(overBar);
            var radicalContainerBox = HorizontalBox.Get(radicalSignBox);

            radicalContainerBox.Add(overBar);

            // There is no generic root then ...
            return(radicalContainerBox);
        }
Example #2
0
        Box CreateBoxDefault(TexStyle style, Box baseBox)
        {
            var factor        = TexUtility.SizeFactor(style);
            var clearance     = TEXConfiguration.main.RootMargin * factor;
            var lineThickness = TEXConfiguration.main.LineThickness * factor;

            // Create box for radical sign.
            var totalHeight    = baseBox.totalHeight;
            var radicalSignBox = DelimiterFactory.CreateBox(rootSymbol, totalHeight + clearance + lineThickness,
                                                            style);

            // Add some clearance to left and right side
            baseBox = HorizontalBox.Get(baseBox, baseBox.width + clearance * 2, TexAlignment.Center);

            // Add half of excess height to clearance.
            lineThickness = Mathf.Max(radicalSignBox.height, lineThickness);
            clearance     = radicalSignBox.totalHeight - totalHeight - lineThickness * 2;

            // Create box for square-root containing base box.
            TexUtility.CentreBox(radicalSignBox, style);
            var overBar = OverBar.Get(baseBox, clearance, lineThickness);

            TexUtility.CentreBox(overBar, style);
            var radicalContainerBox = HorizontalBox.Get(radicalSignBox);

            radicalContainerBox.Add(overBar);

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

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

            // Create box for root atom.
            var rootBox     = DegreeAtom.CreateBox(TexUtility.GetRootStyle());
            var bottomShift = scale * (radicalContainerBox.height + radicalContainerBox.depth);

            rootBox.shift = radicalContainerBox.depth - rootBox.depth - bottomShift;

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

            // Add box for negative kern.
            var negativeKern = SpaceAtom.Get(-((radicalSignBox.width) / 2f), 0, 0).CreateBox(TexStyle.Display);
            var xPos         = rootBox.width + negativeKern.width;

            if (xPos < 0)
            {
                resultBox.Add(StrutBox.Get(-xPos, 0, 0, 0));
            }

            resultBox.Add(rootBox);
            resultBox.Add(negativeKern);
            resultBox.Add(radicalContainerBox);

            return(resultBox);
        }