Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public override Box CreateBox()
        {
            // Create box for base atom.
            Box   baseBox;
            float delta;

            if (BaseAtom is SymbolAtom && BaseAtom.Type == CharType.BigOperator)
            {
                // Find character of best scale for operator symbol.
                var opChar = TEXPreference.main.GetChar(((SymbolAtom)BaseAtom).Name).GetMetric();
                if (TexContext.Environment.value < TexEnvironment.Text && opChar.ch.nextLargerExist)
                {
                    opChar.Flush();
                    opChar = opChar.ch.nextLarger.GetMetric();
                }
                opChar.shift = -(opChar.height + opChar.depth) / 2;
                baseBox      = HorizontalBox.Get(opChar);

                delta = opChar.bearing;
            }
            else
            {
                baseBox = HorizontalBox.Get(BaseAtom == null ? StrutBox.Empty : BaseAtom.CreateBox());
                delta   = 0;
            }

            // Create boxes for upper and lower limits.
            Box upperLimitBox, lowerLimitBox;

            TexContext.Environment.Push(MakeSuperScripts ? TexEnvironment.ScriptScript : TexUtility.GetSuperscriptStyle());
            if (UpperLimitAtom is SymbolAtom)
            {
                upperLimitBox = DelimiterFactory.CreateBoxHorizontal(((SymbolAtom)UpperLimitAtom).Name, baseBox.width);
            }
            else
            {
                upperLimitBox = UpperLimitAtom == null ? null : UpperLimitAtom.CreateBox();
            }
            TexContext.Environment.Pop();

            TexContext.Environment.Push(MakeSuperScripts ? TexEnvironment.ScriptScript : TexUtility.GetSubscriptStyle());
            if (LowerLimitAtom is SymbolAtom)
            {
                lowerLimitBox = DelimiterFactory.CreateBoxHorizontal(((SymbolAtom)LowerLimitAtom).Name, baseBox.width);
            }
            else
            {
                lowerLimitBox = LowerLimitAtom == null ? null : LowerLimitAtom.CreateBox();
            }
            TexContext.Environment.Pop();

            // Make all component boxes equally wide.
            var maxWidth = Mathf.Max(Mathf.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  = VerticalBox.Get();
            var opSpacing5 = TEXConfiguration.main.BigOpMargin * TexContext.Scale;
            var kern       = 0f;

            // Create and add box for upper limit.
            if (UpperLimitAtom != null)
            {
                resultBox.Add(StrutBox.Get(0, opSpacing5, 0, 0));
                upperLimitBox.shift  = delta / 2;
                upperLimitBox.shift += TopOffset(BaseAtom);
                resultBox.Add(upperLimitBox);
                kern = Mathf.Max(TEXConfiguration.main.BigOpUpShift * TexContext.Scale,
                                 TEXConfiguration.main.BigOpUpperGap * TexContext.Scale - upperLimitBox.depth);
                resultBox.Add(StrutBox.Get(0, kern, 0, 0));
            }

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

            // Create and add box for lower limit.
            if (LowerLimitAtom != null)
            {
                resultBox.Add(StrutBox.Get(0, Mathf.Max(TEXConfiguration.main.BigOpLowShift * TexContext.Scale,
                                                        TEXConfiguration.main.BigOpLowerGap * TexContext.Scale - lowerLimitBox.height), 0, 0));
                lowerLimitBox.shift  = -delta / 2;
                lowerLimitBox.shift += BottomOffset(BaseAtom);
                resultBox.Add(lowerLimitBox);
                resultBox.Add(StrutBox.Get(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);
        }
Ejemplo n.º 5
0
 public Box CreateBox(float minHeight)
 {
     return(DelimiterFactory.CreateBox(Name, minHeight));
 }