Esempio n. 1
0
        public override Box CreateBox()
        {
            var width  = size.x;
            var height = size.y;

            Box result;

            if (BaseAtom == null)
            {
                result = StrutBox.Get(width, height, 0, 0);
            }
            else if (BaseAtom is SpaceAtom)
            {
                result = StrutBox.Get(width, height, 0, 0);
            }
            else if (width == 0 && BaseAtom is SymbolAtom)
            {
                result = VerticalBox.Get(DelimiterFactory.CreateBox(((SymbolAtom)BaseAtom).Name, height), height, align);
            }
            else if (height == 0 && BaseAtom is SymbolAtom)
            {
                result = HorizontalBox.Get(DelimiterFactory.CreateBoxHorizontal(((SymbolAtom)BaseAtom).Name, width), width, align);
            }
            else if (width == 0)
            {
                result = VerticalBox.Get(BaseAtom.CreateBox(), height, align);
            }
            else if (height == 0)
            {
                result = HorizontalBox.Get(BaseAtom.CreateBox(), width, align);
            }
            else
            {
                result = VerticalBox.Get(HorizontalBox.Get(BaseAtom.CreateBox(), width, align), height, align);
            }

            if (size.x + size.y > 1e-3f)
            {
                TexUtility.CentreBox(result);
            }
            return(result);
        }
Esempio n. 2
0
 public Box CreateBox(float minHeight)
 {
     return(DelimiterFactory.CreateBox(Name, minHeight));
 }
Esempio n. 3
0
        Box CreateBoxDefault(Box baseBox)
        {
            var factor        = TexContext.Scale;
            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);

            // 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);
            var overBar = OverBar.Get(baseBox, clearance, lineThickness);

            TexUtility.CentreBox(overBar);
            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.
            TexContext.Environment.Push(TexUtility.GetRootStyle());
            var rootBox = DegreeAtom.CreateBox();

            TexContext.Environment.Pop();

            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.
            TexContext.Environment.Push(TexEnvironment.Display);
            var negativeKern = SpaceAtom.Get(-((radicalSignBox.width) / 2f), 0, 0).CreateBox();

            TexContext.Environment.Pop();

            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);
        }