예제 #1
0
        public override Box CreateBox(TexStyle style)
        {
            var pref   = TEXPreference.main;
            var font   = FontIndex == -2 ? TexUtility.RenderFont : FontIndex;
            var FStyle = FontStyle == TexUtility.FontStyleDefault ? TexUtility.RenderFontStyle : FontStyle;

            if (font >= 0 && !pref.IsCharAvailable(font, Character))
            {
                // It's unicode, do return Unicode
                CharacterInfo info;
                var           c = pref.fontData[font].CreateCharacterDataOnTheFly(Character, TexUtility.SizeFactor(style), out info);
                return(UnicodeBox.Get(c, font, info));
            }
            else
            {
                if (font == -1)
                {
                    //var chSymbol = pref.charMapData[Character, -1];
                    //if (chSymbol == -1)
                    return(CharBox.Get(style, pref.GetCharMetric(Character, style), FStyle));
                }
                else
                {
                    return(CharBox.Get(style, pref.GetCharMetric(font, Character, style), FStyle));
                }
            }
        }
예제 #2
0
        public override Box CreateBox(TexStyle style)
        {
            // Create box for base atom.
            var baseBox = BaseAtom == null ? StrutBox.Empty : BaseAtom.CreateBox(TexUtility.GetCrampedStyle(style));
            // Find character of best scale for accent symbol.
            TexCharMetric accentChar = TEXPreference.main.GetCharMetric(AccentAtom.Name, style);

            while (accentChar.ch.nextLargerExist)
            {
                var nextLargerChar = TEXPreference.main.GetCharMetric(accentChar.ch.nextLarger, style);
                if (nextLargerChar.width > baseBox.width)
                {
                    break;
                }
                accentChar = nextLargerChar;
            }

            var resultBox = VerticalBox.Get();

            // Create and add box for accent symbol.
            var accentBox   = CharBox.Get(style, accentChar);
            var accentWidth = (accentBox.bearing + accentBox.italic) * .5f;

            accentBox.italic  = accentWidth + (accentBox.width * .5f);
            accentBox.bearing = accentWidth - (accentBox.width * .5f);
            //accentBox. = accentBox.width + accentBox.italic - accentBox.bearing;
            resultBox.Add((accentBox));

            //var delta = Mathf.Min(-accentChar.depth, baseBox.height);
            resultBox.Add(StrutBox.Get(0, TEXConfiguration.main.AccentMargin * TexUtility.SizeFactor(style), 0, 0));

            // Centre and add box for base atom. Centre base box and accent box with respect to each other.
            var boxWidthsDiff = (baseBox.width - accentBox.width) / 2f;

            accentBox.shift = Mathf.Max(boxWidthsDiff, 0);
            if (boxWidthsDiff < 0)
            {
                baseBox = HorizontalBox.Get(baseBox, accentBox.width, TexAlignment.Center);
            }
            resultBox.Add(baseBox);

            // Adjust height and depth of result box.
            var depth       = baseBox.depth;
            var totalHeight = resultBox.height + resultBox.depth;

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

            return(resultBox);
        }
예제 #3
0
 public override Box CreateBox()
 {
     return(CharBox.Get(Character));
 }
예제 #4
0
 public static RotatedCharBox Get(CharBox ch)
 {
     // this old charbox will get flushed
     ch.Flush();
     return(Get(ch.ch));
 }
예제 #5
0
        public static Box CreateBoxHorizontal(string symbol, float minWidth, TexStyle style)
        {
            var charInfo = TEXPreference.main.GetCharMetric(symbol, style);

            var  charInfo2           = TEXPreference.main.GetChar(symbol);
            bool isAlreadyHorizontal = true;

            while (charInfo2 != null)
            {
                if (charInfo2.extensionExist && !charInfo2.extensionHorizontal)
                {
                    isAlreadyHorizontal = false;
                    break;
                }
                charInfo2 = charInfo2.nextLarger;
            }

            // Find first version of character that has at least minimum width.
            var totalWidth = isAlreadyHorizontal ? charInfo.bearing + charInfo.italic : charInfo.totalHeight;

            while (totalWidth < minWidth && charInfo.ch.nextLargerExist)
            {
                charInfo   = TEXPreference.main.GetCharMetric(charInfo.ch.nextLarger, style);
                totalWidth = isAlreadyHorizontal ? charInfo.bearing + charInfo.italic : charInfo.totalHeight;
            }

            if (totalWidth >= minWidth)
            {
                // Character of sufficient height was found.
                if (isAlreadyHorizontal)
                {
                    return(CharBox.Get(style, charInfo));
                }
                else
                {
                    return(RotatedCharBox.Get(style, charInfo));
                }
            }
            else if (charInfo.ch.extensionExist)
            {
                var resultBox = HorizontalBox.Get();
                resultBox.ExtensionMode = true;
                // Construct box from extension character.
                var extension = charInfo.ch.GetExtentMetrics(style);
                if (isAlreadyHorizontal)
                {
                    if (extension[0] != null)
                    {
                        resultBox.Add(CharBox.Get(style, extension[0]));
                    }
                    if (extension[1] != null)
                    {
                        resultBox.Add(CharBox.Get(style, extension[1]));
                    }
                    if (extension[2] != null)
                    {
                        resultBox.Add(CharBox.Get(style, extension[2]));
                    }
                }
                else
                {
                    if (extension[2] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(style, extension[2]));
                    }
                    if (extension[1] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(style, extension[1]));
                    }
                    if (extension[0] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(style, extension[0]));
                    }
                }

                // Insert repeatable part multiple times until box is high enough.
                if (extension[3] != null)
                {
                    Box repeatBox;
                    if (isAlreadyHorizontal)
                    {
                        repeatBox = CharBox.Get(style, extension[3]);
                    }
                    else
                    {
                        repeatBox = RotatedCharBox.Get(style, extension[3]);
                    }
                    do
                    {
                        if (extension[0] != null && extension[2] != null)
                        {
                            resultBox.Add(1, repeatBox);
                            if (extension[1] != null)
                            {
                                resultBox.Add(resultBox.children.Count - 1, repeatBox);
                            }
                        }
                        else if (extension[2] != null)
                        {
                            resultBox.Add(0, repeatBox);
                        }
                        else
                        {
                            resultBox.Add(repeatBox);
                        }
                    }while (resultBox.width < minWidth);
                }
                return(resultBox);
            }
            else
            {
                // No extensions available, so use tallest available version of character.
                if (isAlreadyHorizontal)
                {
                    return(CharBox.Get(style, charInfo));
                }
                else
                {
                    return(RotatedCharBox.Get(style, charInfo));
                }
            }
        }
예제 #6
0
        public static Box CreateBox(string symbol, float minHeight, TexStyle style)
        {
            minHeight += TEXConfiguration.main.DelimiterRecursiveOffset;
            var charInfo = TEXPreference.main.GetCharMetric(symbol, style);

            // Find first version of character that has at least minimum height.
            var totalHeight = charInfo.height + charInfo.depth;

            //var alter = 0;
            while (totalHeight <= minHeight && charInfo.ch.nextLargerExist)
            {
                //Debug.LogWarningFormat("will: {3} min: {0} cur: {1}+{2}", minHeight, charInfo.height, charInfo.depth, alter);
                charInfo    = TEXPreference.main.GetCharMetric(charInfo.ch.nextLarger, style);
                totalHeight = charInfo.height + charInfo.depth;
                //alter++;
            }

            if (totalHeight > minHeight)
            {
                // Character of sufficient height was found.
                //Debug.LogFormat("owning: {2} min: {0} cur: {1}", minHeight, totalHeight, alter);
                return(CharBox.Get(style, charInfo));
            }
            else if (charInfo.ch.extensionExist && !charInfo.ch.extensionHorizontal)
            {
                var resultBox = VerticalBox.Get();
                resultBox.ExtensionMode = true;
                // Construct box from extension character.
                var extension = charInfo.ch.GetExtentMetrics(style);
                if (extension[0] != null)
                {
                    resultBox.Add(CharBox.Get(style, extension[0]));
                }
                if (extension[1] != null)
                {
                    resultBox.Add(CharBox.Get(style, extension[1]));
                }
                if (extension[2] != null)
                {
                    resultBox.Add(CharBox.Get(style, extension[2]));
                }

                // Insert repeatable part multiple times until box is high enough.
                if (extension[3] != null)
                {
                    var repeatBox = CharBox.Get(style, extension[3]);
                    if (repeatBox.totalHeight <= 0)
                    {
                        throw new ArgumentOutOfRangeException("PULL CHAR DEL ZERO");
                    }
                    while (resultBox.height + resultBox.depth <= minHeight)
                    {
                        if (extension[0] != null && extension[2] != null)
                        {
                            resultBox.Add(1, repeatBox);
                            if (extension[1] != null)
                            {
                                resultBox.Add(resultBox.children.Count - 1, repeatBox);
                            }
                        }
                        else if (extension[2] != null)
                        {
                            resultBox.Add(0, repeatBox);
                        }
                        else
                        {
                            resultBox.Add(repeatBox);
                        }
                    }
                }
                return(resultBox);
            }
            else
            {
                // No extensions available, so use tallest available version of character.
                return(CharBox.Get(style, charInfo));
            }
        }
예제 #7
0
        public override Box CreateBox(TexStyle style)
        {
            // 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.GetCharMetric(((SymbolAtom)BaseAtom).Name, style);
                if (style < TexStyle.Text && opChar.ch.nextLargerExist)
                {
                    opChar = TEXPreference.main.GetCharMetric(opChar.ch.nextLarger, style);
                }
                var charBox = CharBox.Get(style, opChar);
                charBox.shift = -(charBox.height + charBox.depth) / 2;
                baseBox       = HorizontalBox.Get(charBox);

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

            // Create boxes for upper and lower limits.
            Box      upperLimitBox, lowerLimitBox;
            TexStyle superScriptStyle = MakeSuperScripts ? TexStyle.ScriptScript : TexUtility.GetSuperscriptStyle(style);

            if (UpperLimitAtom is SymbolAtom)
            {
                upperLimitBox = DelimiterFactory.CreateBoxHorizontal(((SymbolAtom)UpperLimitAtom).Name, baseBox.width, superScriptStyle);
            }
            else
            {
                upperLimitBox = UpperLimitAtom == null ? null : UpperLimitAtom.CreateBox(superScriptStyle);
            }
            TexStyle subScriptStyle = MakeSuperScripts ? TexStyle.ScriptScript : TexUtility.GetSubscriptStyle(style);

            if (LowerLimitAtom is SymbolAtom)
            {
                lowerLimitBox = DelimiterFactory.CreateBoxHorizontal(((SymbolAtom)LowerLimitAtom).Name, baseBox.width, subScriptStyle);
            }
            else
            {
                lowerLimitBox = LowerLimitAtom == null ? null : LowerLimitAtom.CreateBox(subScriptStyle);
            }

            // 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 * TexUtility.SizeFactor(style);
            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 * TexUtility.SizeFactor(style),
                                 TEXConfiguration.main.BigOpUpperGap * TexUtility.SizeFactor(style) - 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 * TexUtility.SizeFactor(style),
                                                        TEXConfiguration.main.BigOpLowerGap * TexUtility.SizeFactor(style) - 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;
//            TexUtility.AlignToBaseline(resultBox, 3);
            return(resultBox);
        }
예제 #8
0
        //public TexChar(TexFont Font, int Index, char CharIndex, bool Supported, float scale)
        //{
        //    fontIndex = Font.index;
        //    index = Index;
        //    characterIndex = CharIndex;
        //    supported = Supported;
        //    extentTopHash = -1;
        //    extentMiddleHash = -1;
        //    extentBottomHash = -1;
        //    extentRepeatHash = -1;
        //    if (supported) {
        //        if (Font.type == TexFontType.Font) {
        //            CharacterInfo c = getCharInfo(Font.Font_Asset, CharIndex);
        //            UpdateGlyph(Font.Font_Asset, c);
        //        } else {
        //            depth = 0;
        //            height = scale;
        //            bearing = 0;
        //            italic = scale;
        //            width = scale;
        //        }
        //    }
        //}

        //public void UpdateGlyph(Font font, CharacterInfo c)
        //{
        //    font_reqGlyphSize = c.size == 0 ? font.fontSize : c.size;
        //    float ratio = font_reqGlyphSize;
        //    depth = -c.minY / ratio;
        //    height = c.maxY / ratio;
        //    bearing = -c.minX / ratio;
        //    italic = c.maxX / ratio;
        //    width = c.advance / ratio;

        //}

        //static CharacterInfo getCharInfo(Font font, char ch)
        //{
        //    string s = new string(ch, 1);
        //    font.RequestCharactersInTexture(s);
        //    CharacterInfo o;
        //    if (font.GetCharacterInfo(ch, out o))
        //        return o;
        //    else
        //        return new CharacterInfo();
        //}

        public CharBox GetMetric()
        {
            return(CharBox.Get(this));
        }