示例#1
0
        public override Box CreateBox(TexStyle style)
        {
            // Create box for base atom.
            var baseBox = BaseAtom == null ? StrutBox.Empty : BaseAtom.CreateBox(style);

            // Create boxes for over and under atoms.
            Box overBox = null, underBox = null;
            var maxWidth = baseBox.width;

            if (OverAtom != null)
            {
                overBox  = OverAtom.CreateBox(OverScriptSmaller ? TexUtility.GetSuperscriptStyle(style) : style);
                maxWidth = Mathf.Max(maxWidth, overBox.width);
            }

            if (UnderAtom != null)
            {
                underBox = UnderAtom.CreateBox(UnderScriptSmaller ? TexUtility.GetSubscriptStyle(style) : style);
                maxWidth = Mathf.Max(maxWidth, underBox.width);
            }

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

            // Create and add box for over atom.
            if (OverAtom != null)
            {
                resultBox.Add(ChangeWidth(overBox, maxWidth));
                resultBox.Add(TexUtility.GetBox(SpaceAtom.Get(0, OverSpace, 0), style));
            }

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

            float totalHeight = resultBox.height + resultBox.depth - baseBox.depth;

            // Create and add box for under atom.
            if (UnderAtom != null)
            {
                resultBox.Add(TexUtility.GetBox(SpaceAtom.Get(0, UnderSpace, 0), style));
                resultBox.Add(ChangeWidth(underBox, maxWidth));
            }

            resultBox.depth  = resultBox.height + resultBox.depth - totalHeight;
            resultBox.height = totalHeight;

            return(resultBox);
        }
示例#2
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);
        }
示例#3
0
        public override Box CreateBox(TexStyle style)
        {
            // Create box for base atom.
            var baseBox = (BaseAtom == null ? StrutBox.Empty : BaseAtom.CreateBox(style));

            if (SubscriptAtom == null && SuperscriptAtom == null)
            {
                return(baseBox);
            }

            // Save it shift and use it later
            var shift = baseBox.shift;

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

            var subscriptStyle   = TexUtility.GetSubscriptStyle(style);
            var superscriptStyle = TexUtility.GetSuperscriptStyle(style);

            // Set delta value and preliminary shift-up and shift-down amounts depending on type of base atom.
            var   delta = 0f;
            float shiftUp, shiftDown;

            if (BaseAtom is AccentedAtom)
            {
                var accentedBox = ((AccentedAtom)BaseAtom).BaseAtom.CreateBox(TexUtility.GetCrampedStyle(style));
                shiftUp   = accentedBox.height - TEXConfiguration.main.SupDrop * TexUtility.SizeFactor(superscriptStyle);
                shiftDown = accentedBox.depth + TEXConfiguration.main.SubDrop * TexUtility.SizeFactor(subscriptStyle);
            }
            else if (BaseAtom is CharSymbol)
            {
                var charFont = ((CharSymbol)BaseAtom).GetChar();
                if (!((CharSymbol)BaseAtom).IsTextSymbol)
                {
                    delta = TEXPreference.main.GetCharMetric(charFont, style).advanceDelta;
                }
                if (delta > TexUtility.FloatPrecision && SubscriptAtom == null)
                {
                    resultBox.Add(StrutBox.Get(delta, 0, 0, 0));
                    delta = 0;
                }

                shiftUp   = baseBox.height - TEXConfiguration.main.SupDrop * TexUtility.SizeFactor(superscriptStyle);
                shiftDown = baseBox.depth + TEXConfiguration.main.SubDrop * TexUtility.SizeFactor(subscriptStyle);
            }
            else
            {
                shiftUp   = baseBox.height - TEXConfiguration.main.SupDrop * TexUtility.SizeFactor(superscriptStyle);
                shiftDown = baseBox.depth + TEXConfiguration.main.SubDrop * TexUtility.SizeFactor(subscriptStyle);
            }

            Box superscriptBox          = null;
            Box superscriptContainerBox = null;
            Box subscriptBox            = null;
            Box subscriptContainerBox   = null;

            if (SuperscriptAtom != null)
            {
                // Create box for superscript atom.
                superscriptBox          = SuperscriptAtom.CreateBox(superscriptStyle);
                superscriptContainerBox = HorizontalBox.Get(superscriptBox);

                // Add box for script space.
                superscriptContainerBox.Add(scriptSpaceAtom.CreateBox(style));

                // Adjust shift-up amount.
                float p;
                if (style == TexStyle.Display)
                {
                    p = TEXConfiguration.main.SupMin * TexUtility.SizeFactor(style);
                }
                else                // if (TexUtility.GetCrampedStyle (style) == style)
                {
                    p = TEXConfiguration.main.SupMinNarrow * TexUtility.SizeFactor(style);
                }
                //else
                //	p = TEXConfiguration.main.SupMinNarrow * TexUtility.SizeFactor(style);
                shiftUp = Mathf.Max(shiftUp, p);
            }

            if (SubscriptAtom != null)
            {
                // Create box for subscript atom.
                subscriptBox          = SubscriptAtom.CreateBox(subscriptStyle);
                subscriptContainerBox = HorizontalBox.Get(subscriptBox);

                // Add box for script space.
                subscriptContainerBox.Add(scriptSpaceAtom.CreateBox(style));
            }

            // Check if only superscript is set.
            if (subscriptBox == null)
            {
                superscriptContainerBox.shift = -shiftUp;
                resultBox.Add(superscriptContainerBox);
                resultBox.height = shiftUp + superscriptBox.height;
                return(resultBox);
            }

            // Check if only subscript is set.
            if (superscriptBox == null)
            {
                subscriptBox.shift = Mathf.Max(shiftDown, TEXConfiguration.main.SubMinNoSup * TexUtility.SizeFactor(style));
                resultBox.Add(subscriptContainerBox);
                resultBox.depth = shiftDown + subscriptBox.depth;
                return(resultBox);
            }

            // Adjust shift-down amount.
            shiftDown = Mathf.Max(shiftDown, TEXConfiguration.main.SubMinOnSup * TexUtility.SizeFactor(style));

            // Space between subscript and superscript.
            float scriptsInterSpace = shiftUp - superscriptBox.depth + shiftDown - subscriptBox.height;

            /*if (scriptsInterSpace < 4 * defaultLineThickness)
             * {
             *      shiftUp += 4 * defaultLineThickness - scriptsInterSpace;
             *
             *      // Position bottom of superscript at least 4/5 of X-height above baseline.
             *      float psi = 0.8f * TexUtility.SizeFactor(style) - (shiftUp - superscriptBox.depth);
             *      if (psi > 0)
             *      {
             *              shiftUp += psi;
             *              shiftDown -= psi;
             *      }
             * }*/
            scriptsInterSpace = shiftUp - superscriptBox.depth + shiftDown - subscriptBox.height;

            // If baseAtom is null, make it right-aligned

            if (BaseAtom is SpaceAtom && ((SpaceAtom)BaseAtom).policy == StrutPolicy.Misc)
            {
                var max = Mathf.Max(superscriptContainerBox.width, subscriptContainerBox.width);
                if (superscriptContainerBox.width < max)
                {
                    superscriptContainerBox.Add(0, StrutBox.Get(max - superscriptContainerBox.width, 0, 0, 0));
                }
                if (subscriptContainerBox.width < max)
                {
                    subscriptContainerBox.Add(0, StrutBox.Get(max - subscriptContainerBox.width, 0, 0, 0));
                }
            }

            // Create box containing both superscript and subscript.
            var scriptsBox = VerticalBox.Get();

            scriptsBox.Add(superscriptContainerBox);
            scriptsBox.Add(StrutBox.Get(0, scriptsInterSpace, 0, 0));
            scriptsBox.Add(subscriptContainerBox);
            scriptsBox.height = shiftUp + superscriptBox.height;
            scriptsBox.depth  = shiftDown + subscriptBox.depth;
            scriptsBox.shift  = shift;
            resultBox.Add(scriptsBox);

            return(resultBox);
        }
示例#4
0
        public override Box CreateBox()
        {
            // Create box for base atom.

            // Save it shift and use it later

            // Create result box.


            // Set delta value and preliminary shift-up and shift-down amounts depending on type of base atom.
            float shiftUp = 0, shiftDown = 0;

            Box baseBox; HorizontalBox resultBox;

            if (SubscriptAtom == null && SuperscriptAtom == null)
            {
                return(BaseAtom == null ? StrutBox.Empty : BaseAtom.CreateBox());
            }
            if (BaseAtom is AccentedAtom)
            {
                TexContext.Environment.Push(TexUtility.GetCrampedStyle());
                baseBox = ((AccentedAtom)BaseAtom).BaseAtom.CreateBox();
                TexContext.Environment.Pop();
            }
            else
            {
                baseBox = (BaseAtom == null ? StrutBox.Empty : BaseAtom.CreateBox());
                //if (BaseAtom is CharSymbol)
                //{
                //    var delta = 0f;
                //    var ch = ((CharSymbol)BaseAtom).GetChar();
                //    if (!((CharSymbol)BaseAtom).IsTextSymbol)
                //        delta =  ch.italix + bearing - width;
                //    if (delta > TexUtility.FloatPrecision && SubscriptAtom == null)
                //    {
                //        resultBox.Add(StrutBox.Get(delta, 0, 0, 0));
                //        delta = 0;
                //    }
                //}
            }

            resultBox = HorizontalBox.Get(baseBox);

            var shift = baseBox.shift;


            Box           superscriptBox          = null;
            HorizontalBox superscriptContainerBox = null;
            Box           subscriptBox            = null;
            HorizontalBox subscriptContainerBox   = null;

            TexContext.Environment.Push(TexUtility.GetSuperscriptStyle());
            shiftUp = baseBox.height - TEXConfiguration.main.SupDrop * TexContext.Scale;

            if (SuperscriptAtom != null)
            {
                // Create box for superscript atom.
                superscriptBox          = SuperscriptAtom.CreateBox();
                superscriptContainerBox = HorizontalBox.Get(superscriptBox);

                // Add box for script space.
                superscriptContainerBox.Add(scriptSpaceAtom.CreateBox());

                // Adjust shift-up amount.
                float p;
                if (TexContext.Environment.value == TexEnvironment.Display)
                {
                    p = TEXConfiguration.main.SupMin * TexContext.Scale;
                }
                else
                {
                    p = TEXConfiguration.main.SupMinNarrow * TexContext.Scale;
                }

                shiftUp = Mathf.Max(shiftUp, p);
            }

            TexContext.Environment.Pop();

            TexContext.Environment.Push(TexUtility.GetSubscriptStyle());
            shiftDown = baseBox.depth + TEXConfiguration.main.SubDrop * TexContext.Scale;

            if (SubscriptAtom != null)
            {
                // Create box for subscript atom.
                subscriptBox          = SubscriptAtom.CreateBox();
                subscriptContainerBox = HorizontalBox.Get(subscriptBox);

                // Add box for script space.
                subscriptContainerBox.Add(scriptSpaceAtom.CreateBox());
            }

            TexContext.Environment.Pop();

            // Check if only superscript is set.
            if (subscriptBox == null)
            {
                superscriptContainerBox.shift = -shiftUp;
                resultBox.Add(superscriptContainerBox);
                resultBox.height = shiftUp + superscriptBox.height;
                return(resultBox);
            }

            // Check if only subscript is set.
            if (superscriptBox == null)
            {
                subscriptBox.shift = Mathf.Max(shiftDown, TEXConfiguration.main.SubMinNoSup * TexContext.Scale);
                resultBox.Add(subscriptContainerBox);
                resultBox.depth = shiftDown + subscriptBox.depth;
                return(resultBox);
            }



            // Adjust shift-down amount.
            shiftDown = Mathf.Max(shiftDown, TEXConfiguration.main.SubMinOnSup * TexContext.Scale);

            // Space between subscript and superscript.
            float scriptsInterSpace = shiftUp - superscriptBox.depth + shiftDown - subscriptBox.height;


            scriptsInterSpace = shiftUp - superscriptBox.depth + shiftDown - subscriptBox.height;

            // If baseAtom is null, make it right-aligned

            if (BaseAtom is SpaceAtom && ((SpaceAtom)BaseAtom).policy == StrutPolicy.Misc)
            {
                var max = Mathf.Max(superscriptContainerBox.width, subscriptContainerBox.width);
                if (superscriptContainerBox.width < max)
                {
                    superscriptContainerBox.Add(0, StrutBox.Get(max - superscriptContainerBox.width, 0, 0, 0));
                }
                if (subscriptContainerBox.width < max)
                {
                    subscriptContainerBox.Add(0, StrutBox.Get(max - subscriptContainerBox.width, 0, 0, 0));
                }
            }

            // Create box containing both superscript and subscript.
            var scriptsBox = VerticalBox.Get();

            scriptsBox.Add(superscriptContainerBox);
            scriptsBox.Add(StrutBox.Get(0, scriptsInterSpace, 0, 0));
            scriptsBox.Add(subscriptContainerBox);
            scriptsBox.height = shiftUp + superscriptBox.height;
            scriptsBox.depth  = shiftDown + subscriptBox.depth;
            scriptsBox.shift  = shift;
            resultBox.Add(scriptsBox);

            return(resultBox);
        }