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