Esempio n. 1
0
    public BMGlyph GetGlyph(int index, bool createIfMissing)
    {
        BMGlyph glyph = null;

        if (this.mDict.Count == 0)
        {
            int num   = 0;
            int count = this.mSaved.Count;
            while (num < count)
            {
                BMGlyph glyph2 = this.mSaved[num];
                this.mDict.Add(glyph2.index, glyph2);
                num++;
            }
        }
        if (!this.mDict.TryGetValue(index, out glyph) && createIfMissing)
        {
            glyph = new BMGlyph {
                index = index
            };
            this.mSaved.Add(glyph);
            this.mDict.Add(index, glyph);
        }
        return(glyph);
    }
Esempio n. 2
0
    public string GetEndOfLineThatFits(string text, float maxWidth, bool encoding, SymbolStyle symbolStyle)
    {
        if (this.mReplacement != null)
        {
            return(this.mReplacement.GetEndOfLineThatFits(text, maxWidth, encoding, symbolStyle));
        }
        int num = Mathf.RoundToInt(maxWidth * this.size);

        if (num < 1)
        {
            return(text);
        }
        int     length    = text.Length;
        int     num3      = num;
        BMGlyph glyph     = null;
        int     offset    = length;
        bool    flag      = (encoding && (symbolStyle != SymbolStyle.None)) && this.hasSymbols;
        bool    isDynamic = this.isDynamic;

        if (isDynamic)
        {
            this.mDynamicFont.textureRebuildCallback = new Font.FontTextureRebuildCallback(this.OnFontChanged);
            this.mDynamicFont.RequestCharactersInTexture(text, this.mDynamicFontSize, this.mDynamicFontStyle);
            this.mDynamicFont.textureRebuildCallback = null;
        }
        while ((offset > 0) && (num3 > 0))
        {
            char     index     = text[--offset];
            BMSymbol symbol    = !flag ? null : this.MatchSymbol(text, offset, length);
            int      mSpacingX = this.mSpacingX;
            if (!isDynamic)
            {
                if (symbol != null)
                {
                    mSpacingX += symbol.advance;
                    goto Label_017F;
                }
                BMGlyph glyph2 = this.mFont.GetGlyph(index);
                if (glyph2 != null)
                {
                    mSpacingX += glyph2.advance + ((glyph != null) ? glyph.GetKerning(index) : 0);
                    glyph      = glyph2;
                    goto Label_017F;
                }
                glyph = null;
                continue;
            }
            if (this.mDynamicFont.GetCharacterInfo(index, out mChar, this.mDynamicFontSize, this.mDynamicFontStyle))
            {
                mSpacingX += (int)mChar.width;
            }
Label_017F:
            num3 -= mSpacingX;
        }
        if (num3 < 0)
        {
            offset++;
        }
        return(text.Substring(offset, length - offset));
    }
 void CreateFont()
 {
     BMFontReader.Load(mbFont, textFnt.name, textFnt.bytes);          // 借用NGUI封装的读取类
     CharacterInfo[] characterInfo = new CharacterInfo[mbFont.glyphs.Count];
     for (int i = 0; i < mbFont.glyphs.Count; i++)
     {
         BMGlyph       bmInfo = mbFont.glyphs[i];
         CharacterInfo info   = new CharacterInfo();
         info.index     = bmInfo.index;
         info.uv.x      = (float)bmInfo.x / (float)mbFont.texWidth;
         info.uv.y      = 1 - (float)bmInfo.y / (float)mbFont.texHeight;
         info.uv.width  = (float)bmInfo.width / (float)mbFont.texWidth;
         info.uv.height = -1f * (float)bmInfo.height / (float)mbFont.texHeight;
         info.vert.x    = (float)bmInfo.offsetX;
         //info.vert.y = (float)bmInfo.offsetY;
         info.vert.y      = 0f;//自定义字库UV从下往上,所以这里不需要偏移,填0即可。
         info.vert.width  = (float)bmInfo.width;
         info.vert.height = (float)bmInfo.height;
         info.width       = (float)bmInfo.advance;
         characterInfo[i] = info;
     }
     bmFont.characterInfo = characterInfo;
     //AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(bmFont));
     EditorUtility.SetDirty(bmFont);
     AssetDatabase.SaveAssets();
     Debug.Log(AssetDatabase.GetAssetPath(bmFont));
     //AssetDatabase.WriteImportSettingsIfDirty(AssetDatabase.GetAssetPath(bmFont));
     AssetDatabase.Refresh();
 }
Esempio n. 4
0
    // Token: 0x06000338 RID: 824 RVA: 0x000258A4 File Offset: 0x00023AA4
    public string GetEndOfLineThatFits(string text, float maxWidth, bool encoding, UIFont.SymbolStyle symbolStyle)
    {
        if (this.mReplacement != null)
        {
            return(this.mReplacement.GetEndOfLineThatFits(text, maxWidth, encoding, symbolStyle));
        }
        int num = Mathf.RoundToInt(maxWidth * (float)this.size);

        if (num < 1)
        {
            return(text);
        }
        int     length    = text.Length;
        int     num2      = num;
        BMGlyph bmglyph   = null;
        int     num3      = length;
        bool    flag      = encoding && symbolStyle != UIFont.SymbolStyle.None && this.hasSymbols;
        bool    isDynamic = this.isDynamic;

        if (isDynamic)
        {
            this.mDynamicFont.textureRebuildCallback = new Font.FontTextureRebuildCallback(this.OnFontChanged);
            this.mDynamicFont.RequestCharactersInTexture(text, this.mDynamicFontSize, this.mDynamicFontStyle);
            this.mDynamicFont.textureRebuildCallback = null;
        }
        while (num3 > 0 && num2 > 0)
        {
            char     c        = text[--num3];
            BMSymbol bmsymbol = (!flag) ? null : this.MatchSymbol(text, num3, length);
            int      num4     = this.mSpacingX;
            if (!isDynamic)
            {
                if (bmsymbol != null)
                {
                    num4 += bmsymbol.advance;
                }
                else
                {
                    BMGlyph glyph = this.mFont.GetGlyph((int)c);
                    if (glyph == null)
                    {
                        bmglyph = null;
                        continue;
                    }
                    num4   += glyph.advance + ((bmglyph != null) ? bmglyph.GetKerning((int)c) : 0);
                    bmglyph = glyph;
                }
            }
            else if (this.mDynamicFont.GetCharacterInfo(c, out UIFont.mChar, this.mDynamicFontSize, this.mDynamicFontStyle))
            {
                num4 += (int)UIFont.mChar.width;
            }
            num2 -= num4;
        }
        if (num2 < 0)
        {
            num3++;
        }
        return(text.Substring(num3, length - num3));
    }
Esempio n. 5
0
    public static void BatchCreateArtistFont()
    {
        string dirName = "";
        string fntname = SelectObjectPathInfo(ref dirName).Split('.')[0];

        Debug.Log(fntname);
        Debug.Log(dirName);

        string fntFileName = dirName + fntname + ".fnt";

        Font CustomFont = new Font();
        {
            AssetDatabase.CreateAsset(CustomFont, dirName + fntname + ".fontsettings");
            AssetDatabase.SaveAssets();
        }

        TextAsset BMFontText = null;
        {
            BMFontText = AssetDatabase.LoadAssetAtPath(fntFileName, typeof(TextAsset)) as TextAsset;
        }

        BMFont mbFont = new BMFont();

        BMFontReader.Load(mbFont, BMFontText.name, BMFontText.bytes);          // 借用NGUI封装的读取类
        CharacterInfo[] characterInfo = new CharacterInfo[mbFont.glyphs.Count];
        for (int i = 0; i < mbFont.glyphs.Count; i++)
        {
            BMGlyph       bmInfo = mbFont.glyphs[i];
            CharacterInfo info   = new CharacterInfo();
            info.index       = bmInfo.index;
            info.uv.x        = (float)bmInfo.x / (float)mbFont.texWidth;
            info.uv.y        = 1 - (float)bmInfo.y / (float)mbFont.texHeight;
            info.uv.width    = (float)bmInfo.width / (float)mbFont.texWidth;
            info.uv.height   = -1f * (float)bmInfo.height / (float)mbFont.texHeight;
            info.vert.x      = (float)bmInfo.offsetX;
            info.vert.y      = (float)bmInfo.offsetY;
            info.vert.width  = (float)bmInfo.width;
            info.vert.height = (float)bmInfo.height;
            info.width       = (float)bmInfo.advance;
            characterInfo[i] = info;
        }
        CustomFont.characterInfo = characterInfo;


        string   textureFilename = dirName + mbFont.spriteName + ".png";
        Material mat             = null;

        {
            Shader shader = Shader.Find("Transparent/Diffuse");
            mat = new Material(shader);
            Texture tex = AssetDatabase.LoadAssetAtPath(textureFilename, typeof(Texture)) as Texture;
            mat.SetTexture("_MainTex", tex);
            AssetDatabase.CreateAsset(mat, dirName + fntname + ".mat");
            AssetDatabase.SaveAssets();
        }
        CustomFont.material = mat;
        EditorUtility.SetDirty(CustomFont);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Esempio n. 6
0
    /// <summary>
    /// Helper function that retrieves the specified glyph, creating it if necessary.
    /// </summary>

    public BMGlyph GetGlyph(int index, bool createIfMissing)
    {
        // Get the requested glyph
        BMGlyph glyph = null;

        if (mDict.Count == 0)
        {
            // Populate the dictionary for faster access
            for (int i = 0, imax = mSaved.Count; i < imax; ++i)
            {
                BMGlyph bmg = mSaved[i];
                mDict.Add(bmg.index, bmg);
            }
        }

        // Saved check is here so that the function call is not needed if it's true
        if (!mDict.TryGetValue(index, out glyph) && createIfMissing)
        {
            glyph       = new BMGlyph();
            glyph.index = index;
            mSaved.Add(glyph);
            mDict.Add(index, glyph);
        }
        return(glyph);
    }
Esempio n. 7
0
 override public bool GetGlyph(char ch, out float width, out float height, out float baseline)
 {
     if (ch == ' ')
     {
         width    = Mathf.RoundToInt(size * _scale / 2);
         height   = Mathf.RoundToInt(size * _scale);
         baseline = height;
         _glyph   = null;
         return(true);
     }
     else if (_dict.TryGetValue((int)ch, out _glyph))
     {
         width    = Mathf.RoundToInt(_glyph.advance * _scale);
         height   = Mathf.RoundToInt(_glyph.lineHeight * _scale);
         baseline = height;
         return(true);
     }
     else
     {
         width    = 0;
         height   = 0;
         baseline = 0;
         return(false);
     }
 }
Esempio n. 8
0
    public static void CreateBmFont()
    {
        NewFont();

        BMFontReader.Load(bmFont, fntData.name, fntData.bytes); // 借用NGUI封装的读取类
        CharacterInfo[] characterInfo = new CharacterInfo[bmFont.glyphs.Count];
        for (int i = 0; i < bmFont.glyphs.Count; i++)
        {
            BMGlyph bmInfo = bmFont.glyphs[i];
            CharacterInfo info = new CharacterInfo();
            info.index = bmInfo.index;
            info.uv.x = (float)bmInfo.x / (float)bmFont.texWidth;
            info.uv.y = 1 - (float)bmInfo.y / (float)bmFont.texHeight;
            info.uv.width = (float)bmInfo.width / (float)bmFont.texWidth;
            info.uv.height = -1f * (float)bmInfo.height / (float)bmFont.texHeight;
            info.vert.x = 0;
            info.vert.y = -(float)bmInfo.height;
            info.vert.width = (float)bmInfo.width;
            info.vert.height = (float)bmInfo.height;
            info.width = (float)bmInfo.advance;
            characterInfo[i] = info;
        }
        targetFont.characterInfo = characterInfo;
        if (fontMaterial)
        {
            fontMaterial.mainTexture = fontTexture;
        }
        targetFont.material = fontMaterial;

        EditorUtility.SetDirty(targetFont);

        Debug.Log("create font <" + targetFont.name + "> success");
    }
Esempio n. 9
0
 public bool LegacyCheck()
 {
     if ((this.mGlyphs != null) && (this.mGlyphs.Length > 0))
     {
         int index  = 0;
         int length = this.mGlyphs.Length;
         while (index < length)
         {
             BMGlyph item = this.mGlyphs[index];
             if (item != null)
             {
                 item.index = index;
                 this.mSaved.Add(item);
                 while (++index < length)
                 {
                     if (item != null)
                     {
                         item.index = index;
                         this.mSaved.Add(item);
                     }
                 }
                 this.mGlyphs = null;
                 return(true);
             }
             index++;
         }
         this.mGlyphs = null;
     }
     return(false);
 }
Esempio n. 10
0
    public unsafe override void Unity_NamedSerialize(int depth)
    {
        ISerializedNamedStateWriter arg_1F_0 = SerializedNamedStateWriter.Instance;
        int arg_1F_1 = this.mSize;

        byte[] var_0_cp_0 = $FieldNamesStorage.$RuntimeNames;
        int    var_0_cp_1 = 0;

        arg_1F_0.WriteInt32(arg_1F_1, &var_0_cp_0[var_0_cp_1] + 1659);
        SerializedNamedStateWriter.Instance.WriteInt32(this.mBase, &var_0_cp_0[var_0_cp_1] + 2092);
        SerializedNamedStateWriter.Instance.WriteInt32(this.mWidth, &var_0_cp_0[var_0_cp_1] + 2098);
        SerializedNamedStateWriter.Instance.WriteInt32(this.mHeight, &var_0_cp_0[var_0_cp_1] + 2105);
        SerializedNamedStateWriter.Instance.WriteString(this.mSpriteName, &var_0_cp_0[var_0_cp_1] + 2113);
        if (depth <= 7)
        {
            if (this.mSaved == null)
            {
                SerializedNamedStateWriter.Instance.BeginSequenceGroup(&var_0_cp_0[var_0_cp_1] + 2125, 0);
                SerializedNamedStateWriter.Instance.EndMetaGroup();
            }
            else
            {
                SerializedNamedStateWriter.Instance.BeginSequenceGroup(&var_0_cp_0[var_0_cp_1] + 2125, this.mSaved.Count);
                for (int i = 0; i < this.mSaved.Count; i++)
                {
                    BMGlyph arg_10A_0 = (this.mSaved[i] != null) ? this.mSaved[i] : new BMGlyph();
                    SerializedNamedStateWriter.Instance.BeginMetaGroup((IntPtr)0);
                    arg_10A_0.Unity_NamedSerialize(depth + 1);
                    SerializedNamedStateWriter.Instance.EndMetaGroup();
                }
                SerializedNamedStateWriter.Instance.EndMetaGroup();
            }
        }
    }
Esempio n. 11
0
    public BMGlyph GetGlyph(int index, bool createIfMissing)
    {
        BMGlyph glyph = null;

        if (mDict.Count == 0)
        {
            var num   = 0;
            var count = mSaved.Count;
            while (num < count)
            {
                var glyph2 = mSaved[num];
                mDict.Add(glyph2.index, glyph2);
                num++;
            }
        }

        if (!mDict.TryGetValue(index, out glyph) && createIfMissing)
        {
            glyph = new BMGlyph {
                index = index
            };
            mSaved.Add(glyph);
            mDict.Add(index, glyph);
        }

        return(glyph);
    }
Esempio n. 12
0
    public unsafe override void Unity_NamedDeserialize(int depth)
    {
        ISerializedNamedStateReader arg_1A_0 = SerializedNamedStateReader.Instance;

        byte[] var_0_cp_0 = $FieldNamesStorage.$RuntimeNames;
        int    var_0_cp_1 = 0;

        this.mSize       = arg_1A_0.ReadInt32(&var_0_cp_0[var_0_cp_1] + 1659);
        this.mBase       = SerializedNamedStateReader.Instance.ReadInt32(&var_0_cp_0[var_0_cp_1] + 2092);
        this.mWidth      = SerializedNamedStateReader.Instance.ReadInt32(&var_0_cp_0[var_0_cp_1] + 2098);
        this.mHeight     = SerializedNamedStateReader.Instance.ReadInt32(&var_0_cp_0[var_0_cp_1] + 2105);
        this.mSpriteName = (SerializedNamedStateReader.Instance.ReadString(&var_0_cp_0[var_0_cp_1] + 2113) as string);
        if (depth <= 7)
        {
            int num = SerializedNamedStateReader.Instance.BeginSequenceGroup(&var_0_cp_0[var_0_cp_1] + 2125);
            this.mSaved = new List <BMGlyph>(num);
            for (int i = 0; i < num; i++)
            {
                BMGlyph bMGlyph  = new BMGlyph();
                BMGlyph arg_C7_0 = bMGlyph;
                SerializedNamedStateReader.Instance.BeginMetaGroup((IntPtr)0);
                arg_C7_0.Unity_NamedDeserialize(depth + 1);
                SerializedNamedStateReader.Instance.EndMetaGroup();
                this.mSaved.Add(bMGlyph);
            }
            SerializedNamedStateReader.Instance.EndMetaGroup();
        }
    }
Esempio n. 13
0
    /// <summary>
    /// Different line wrapping functionality -- contributed by MightyM.
    /// http://www.tasharen.com/forum/index.php?topic=1049.0
    /// </summary>

    public string GetEndOfLineThatFits(string text, float maxWidth, bool encoding, SymbolStyle symbolStyle)
    {
        if (mReplacement != null)
        {
            return(mReplacement.GetEndOfLineThatFits(text, maxWidth, encoding, symbolStyle));
        }

        int lineWidth = Mathf.RoundToInt(maxWidth * size);

        if (lineWidth < 1)
        {
            return(text);
        }

        int     textLength            = text.Length;
        int     remainingWidth        = lineWidth;
        BMGlyph followingGlyph        = null;
        int     currentCharacterIndex = textLength;
        bool    useSymbols            = encoding && symbolStyle != SymbolStyle.None && hasSymbols;

        while (currentCharacterIndex > 0 && remainingWidth > 0)
        {
            char currentCharacter = text[--currentCharacterIndex];

            // See if there is a symbol matching this text
            BMSymbol symbol = useSymbols ? MatchSymbol(text, currentCharacterIndex, textLength) : null;

            // Calculate how wide this symbol or character is going to be
            int glyphWidth = mSpacingX;

            if (symbol != null && symbol.Validate(atlas))
            {
                glyphWidth += symbol.advance;
            }
            else
            {
                // Find the glyph for this character
                BMGlyph glyph = mFont.GetGlyph(currentCharacter);

                if (glyph != null)
                {
                    glyphWidth    += glyph.advance + ((followingGlyph == null) ? 0 : followingGlyph.GetKerning(currentCharacter));
                    followingGlyph = glyph;
                }
                else
                {
                    followingGlyph = null;
                    continue;
                }
            }

            // Remaining width after this glyph gets printed
            remainingWidth -= glyphWidth;
        }
        if (remainingWidth < 0)
        {
            ++currentCharacterIndex;
        }
        return(text.Substring(currentCharacterIndex, textLength - currentCharacterIndex));
    }
Esempio n. 14
0
    /// <summary>
    /// Trim the glyphs, making sure they never go past the trimmed texture bounds.
    /// </summary>

    void Trim()
    {
        Texture tex = mAtlas.texture;

        if (tex != null && mSprite != null)
        {
            Rect full    = NGUIMath.ConvertToPixels(mUVRect, texture.width, texture.height, true);
            Rect trimmed = (mAtlas.coordinates == UIAtlas.Coordinates.TexCoords) ?
                           NGUIMath.ConvertToPixels(mSprite.outer, tex.width, tex.height, true) : mSprite.outer;

            int xMin = Mathf.RoundToInt(trimmed.xMin - full.xMin);
            int yMin = Mathf.RoundToInt(trimmed.yMin - full.yMin);
            int xMax = Mathf.RoundToInt(trimmed.xMax - full.xMin);
            int yMax = Mathf.RoundToInt(trimmed.yMax - full.yMin);

            for (int i = 0; i < mFont.glyphCount; ++i)
            {
                BMGlyph glyph = mFont.GetGlyph(i);
                if (glyph != null)
                {
                    glyph.Trim(xMin, yMin, xMax, yMax);
                }
            }
        }
    }
Esempio n. 15
0
    public static void BatchCreateArtistFont()
    {
        string dirName = "";
        string fntname = EditorUtils.SelectObjectPathInfo(ref dirName).Split('.')[0];

        Debug.Log(fntname);
        Debug.Log(dirName);

        string fntFileName = dirName + fntname + ".fnt";

        Font CustomFont = new Font();
        {
            AssetDatabase.CreateAsset(CustomFont, dirName + fntname + ".fontsettings");
            AssetDatabase.SaveAssets();
        }

        TextAsset BMFontText = null;
        {
            BMFontText = AssetDatabase.LoadAssetAtPath(fntFileName, typeof(TextAsset)) as TextAsset;
        }

        BMFont mbFont = new BMFont();

        BMFontReader.Load(mbFont, BMFontText.name, BMFontText.bytes);  // 借用NGUI封装的读取类
        CharacterInfo[] characterInfo = new CharacterInfo[mbFont.glyphs.Count];
        for (int i = 0; i < mbFont.glyphs.Count; i++)
        {
            BMGlyph       bmInfo = mbFont.glyphs[i];
            CharacterInfo info   = new CharacterInfo();
            info.index         = bmInfo.index;
            info.uvTopLeft     = new Vector2((float)bmInfo.x / (float)mbFont.texWidth, (float)(bmInfo.y + bmInfo.height) / (float)mbFont.texHeight);
            info.uvTopRight    = new Vector2((float)(bmInfo.x + bmInfo.width) / (float)mbFont.texWidth, (float)(bmInfo.y + bmInfo.height) / (float)mbFont.texHeight);
            info.uvBottomLeft  = new Vector2((float)bmInfo.x / (float)mbFont.texWidth, (float)bmInfo.y / (float)mbFont.texHeight);
            info.uvBottomRight = new Vector2((float)(bmInfo.x + bmInfo.width) / (float)mbFont.texWidth, (float)(bmInfo.y) / (float)mbFont.texHeight);

            info.minX        = bmInfo.offsetX;
            info.minY        = bmInfo.offsetY;
            info.maxX        = bmInfo.width;
            info.maxY        = bmInfo.height;
            info.advance     = bmInfo.advance;
            characterInfo[i] = info;
        }
        CustomFont.characterInfo = characterInfo;


        string   textureFilename = dirName + mbFont.spriteName + ".png";
        Material mat             = null;

        {
            Shader shader = Shader.Find("UI/Unlit/Text");
            mat = new Material(shader);
            Texture tex = AssetDatabase.LoadAssetAtPath(textureFilename, typeof(Texture)) as Texture;
            mat.SetTexture("_MainTex", tex);
            AssetDatabase.CreateAsset(mat, dirName + fntname + ".mat");
            AssetDatabase.SaveAssets();
        }
        CustomFont.material = mat;
    }
Esempio n. 16
0
 public BMFont.GetOrCreateGlyphResult GetOrCreateGlyph(int index, out BMGlyph glyph)
 {
     if (!this.mDictMade)
     {
         this.mDictMade = true;
         this.mDictAny  = true;
         int count = this.mSaved.Count;
         if (count == 0 && this.LegacyCheck())
         {
             count = this.mSaved.Count;
         }
         if (count <= 0)
         {
             this.mDict = BMFont.CreateGlyphDictionary();
         }
         else
         {
             this.mDict = BMFont.CreateGlyphDictionary(count + 1);
             for (int i = count - 1; i >= 0; i--)
             {
                 BMGlyph item = this.mSaved[i];
                 this.mDict.Add(item.index, item);
                 if (item.index == index)
                 {
                     glyph = item;
                     while (true)
                     {
                         int num = i - 1;
                         i = num;
                         if (num < 0)
                         {
                             break;
                         }
                         item = this.mSaved[i];
                         this.mDict.Add(item.index, item);
                     }
                     return(BMFont.GetOrCreateGlyphResult.Found | BMFont.GetOrCreateGlyphResult.Created);
                 }
             }
         }
     }
     else if (!this.mDictAny)
     {
         this.mDict    = BMFont.CreateGlyphDictionary();
         this.mDictAny = true;
     }
     else if (this.mDict.TryGetValue(index, out glyph))
     {
         return(BMFont.GetOrCreateGlyphResult.Found | BMFont.GetOrCreateGlyphResult.Created);
     }
     glyph = new BMGlyph()
     {
         index = index
     };
     this.mDict.Add(index, glyph);
     return(BMFont.GetOrCreateGlyphResult.Created);
 }
Esempio n. 17
0
    public static CharacterInfo[] retriveCharInfos(BMFont bmFont)
    {
//		BMFont bmFont = new BMFont ();
//
//		// 读取fnt字体信息
//		BMFontReader.Load(bmFont, fntSettings.name, fntSettings.bytes);

        // 创建Unity自定义字体信息
        CharacterInfo[] characterInfo = new CharacterInfo[bmFont.glyphs.Count];
        for (int i = 0; i < bmFont.glyphs.Count; i++)
        {
            BMGlyph       bmInfo = bmFont.glyphs[i];
            CharacterInfo info   = new CharacterInfo();
            info.index = bmInfo.index;
            //             float x = (float)bmInfo.x / (float)mbFont.texWidth;
            //             float y = 1 - (float)bmInfo.y / (float)mbFont.texHeight;
            // info.uvBottomLeft = new Vector2(x, y);
//			info.uv.x = (float)bmInfo.x / (float)bmFont.texWidth;
//			info.uv.y = 1 - (float)bmInfo.y / (float)bmFont.texHeight;
//			info.uv.width = (float)bmInfo.width / (float)bmFont.texWidth;
//			info.uv.height = -1f * ((float)bmInfo.height )/ (float)bmFont.texHeight;
//			info.vert.x = (float)bmInfo.offsetX;
//			info.vert.y = 0f;
//			info.vert.width = (float)bmInfo.width;
//			info.vert.height = (float)bmInfo.height;
//			info.width = (float)bmInfo.advance;

            // 左上
            info.uvTopLeft = new Vector2((float)bmInfo.x / (float)bmFont.texWidth, 1.0f - (float)bmInfo.y / (float)bmFont.texHeight);

            // 右下
            info.uvBottomRight = new Vector2((float)(bmInfo.width + bmInfo.x) / (float)bmFont.texWidth,
                                             1.0f - ((float)(bmInfo.y + bmInfo.height)) / (float)bmFont.texHeight);

            info.minX    = bmInfo.offsetX;
            info.minY    = bmInfo.offsetY;
            info.maxX    = info.minX + bmInfo.width;
            info.maxY    = info.maxY + bmInfo.height;
            info.advance = bmInfo.advance;

//			info.uvBottomLeft.x = (float)bmInfo.x / (float)bmFont.texWidth;
//			info.uvBottomLeft.y = 1 - (float)bmInfo.y / (float)bmFont.texHeight;
//			info.uv.width = (float)bmInfo.width / (float)bmFont.texWidth;
//			info.uv.height = -1f * ((float)bmInfo.height )/ (float)bmFont.texHeight;
//			info.vert.x = (float)bmInfo.offsetX;
//			info.vert.y = 0f;
//			info.vert.width = (float)bmInfo.width;
//			info.vert.height = (float)bmInfo.height;
//			info.width = (float)bmInfo.advance;

            characterInfo[i] = info;
        }

//		_TargetFnt.characterInfo = characterInfo;

        return(characterInfo);
    }
Esempio n. 18
0
        public static void GenerateBMFont()
        {
            Font      selectedFont = null;
            TextAsset selectedData = null;
            BMFont    bmFont       = new BMFont();

            Object[] selectedObjects = Selection.objects;
            Object   selectedObject  = null;

            for (int selectedObjectIndex = 0; selectedObjectIndex < selectedObjects.Length; selectedObjectIndex++)
            {
                selectedObject = selectedObjects[selectedObjectIndex];
                if (selectedObject is Font)
                {
                    selectedFont = selectedObject as Font;
                }
                else if (selectedObject is TextAsset)
                {
                    selectedData = selectedObject as TextAsset;
                }
            }

            if (selectedFont == null || selectedData == null)
            {
                string fontNullInfo = selectedFont == null ? "Font is null." : string.Empty;
                string dataNullInfo = selectedData == null ? "Data is null." : string.Empty;
                Debugger.Log(fontNullInfo + dataNullInfo);
                return;
            }
            else
            {
                Debugger.Log(string.Format("Selected Font:{0}, Selected Data:{1}", selectedFont.name, selectedData.name));
                BMFontReader.Load(bmFont, selectedData.name, selectedData.bytes);
                CharacterInfo[] characterInfos      = new CharacterInfo[bmFont.glyphs.Count];
                int             characterInfoLength = bmFont.glyphs.Count;
                for (int index = 0; index < characterInfoLength; index++)
                {
                    BMGlyph       bmGlyph       = bmFont.glyphs[index];
                    CharacterInfo characterInfo = new CharacterInfo();
                    characterInfo.index     = bmGlyph.index;
                    characterInfo.uv.x      = (float)bmGlyph.x / (float)bmFont.texWidth;
                    characterInfo.uv.y      = 1 - (float)bmGlyph.y / (float)bmFont.texHeight;
                    characterInfo.uv.width  = (float)bmGlyph.width / (float)bmFont.texWidth;
                    characterInfo.uv.height = -1f * (float)bmGlyph.height / (float)bmFont.texHeight;

                    characterInfo.vert.x      = bmGlyph.offsetX;
                    characterInfo.vert.y      = bmGlyph.offsetY;
                    characterInfo.vert.width  = bmGlyph.width;
                    characterInfo.vert.height = bmGlyph.height;
                    characterInfo.width       = bmGlyph.advance;

                    characterInfos[index] = characterInfo;
                }
                selectedFont.characterInfo = characterInfos;
            }
        }
Esempio n. 19
0
        void OnWizardCreate()
        {
            string fontName = fntTex.name;
            string path     = AssetDatabase.GetAssetPath(fntTex);

            path = Path.GetDirectoryName(path);

            var matPath = Path.Combine(path, fontName + ".mat");
            var fntMat  = AssetDatabase.LoadAssetAtPath <Material>(matPath);

            if (fntMat == null)
            {
                fntMat             = new Material(Shader.Find("UI/Default"));
                fntMat.mainTexture = fntTex;
                AssetDatabase.CreateAsset(fntMat, matPath);
            }
            var fontPath = Path.Combine(path, fontName + ".fontsettings");
            var font     = AssetDatabase.LoadAssetAtPath <Font>(fontPath);

            if (font == null)
            {
                font = new Font(fontName);
                AssetDatabase.CreateAsset(font, fontPath);
            }

            font.material = fntMat;

            var bmFont = new BMFont();

            BMFontReader.Load(bmFont, fntTxt.name, fntTxt.bytes);
            var charInfos = new CharacterInfo[bmFont.glyphs.Count];

            for (int i = 0; i < bmFont.glyphs.Count; ++i)
            {
                BMGlyph glyph = bmFont.glyphs[i];
                //var rect = new Rect(glyph.x, glyph.y, glyph.width, glyph.height);
                var uvRect = new Rect(glyph.x / (float)bmFont.texWidth, 1 - glyph.y / (float)bmFont.texHeight,
                                      glyph.width / (float)bmFont.texWidth, -1 * glyph.height / (float)bmFont.texHeight);

                var info = new CharacterInfo();
                info.index       = glyph.index;
                info.glyphWidth  = glyph.width;
                info.glyphHeight = glyph.height;
                info.advance     = glyph.advance;
                info.uvTopLeft   = uvRect.min;// new Vector2(uvRect.xMin, uvRect.yMin);
                //info.uvBottomRight = new Vector2(uvRect.xMax, uvRect.yMin);
                //info.uvTopLeft = new Vector2(uvRect.xMin, uvRect.yMax);
                info.uvBottomRight = uvRect.max;// new Vector2(uvRect.xMax, uvRect.yMax);
                charInfos[i]       = info;
            }
            font.characterInfo = charInfos;

            //EditorUtility.DisplayDialog("提示", string.Format("功能未实现\nNot Implemented\n実装されていない\nKeine umsetzung"), "确定");
            EditorUtility.DisplayDialog("提示", string.Format("字体创建完成:{0}。\n注意:需要手动修改一下字体配置,否则退出后不会保存!", fontPath), "确定");
        }
Esempio n. 20
0
    public GetOrCreateGlyphResult GetOrCreateGlyph(int index, out BMGlyph glyph)
    {
        if (!this.mDictMade)
        {
            this.mDictMade = true;
            this.mDictAny  = true;
            int count = this.mSaved.Count;
            if ((count == 0) && this.LegacyCheck())
            {
                count = this.mSaved.Count;
            }
            if (count > 0)
            {
                this.mDict = CreateGlyphDictionary(count + 1);
                for (int i = count - 1; i >= 0; i--)
                {
                    BMGlyph glyph2 = this.mSaved[i];
                    this.mDict.Add(glyph2.index, glyph2);
                    if (glyph2.index == index)
                    {
                        glyph = glyph2;
                        while (--i >= 0)
                        {
                            glyph2 = this.mSaved[i];
                            this.mDict.Add(glyph2.index, glyph2);
                        }
                        return(GetOrCreateGlyphResult.Found);
                    }
                }
            }
            else
            {
                this.mDict = CreateGlyphDictionary();
            }
        }
        else if (this.mDictAny)
        {
            if (this.mDict.TryGetValue(index, out glyph))
            {
                return(GetOrCreateGlyphResult.Found);
            }
        }
        else
        {
            this.mDict    = CreateGlyphDictionary();
            this.mDictAny = true;
        }
        BMGlyph glyph3 = new BMGlyph {
            index = index
        };

        glyph = glyph3;
        this.mDict.Add(index, glyph);
        return(GetOrCreateGlyphResult.Created);
    }
Esempio n. 21
0
    public static void BatchCreateArtistFont()
    {
        string fntFilePath = AssetDatabase.GetAssetPath(Selection.activeObject);

        if (string.IsNullOrEmpty(fntFilePath) || !fntFilePath.Contains(".fnt"))
        {
            Debug.LogError("请选择字体文件,后缀为.fnt的文件");
            return;
        }

        string fntName = Path.GetFileNameWithoutExtension(fntFilePath);
        string dirName = Path.GetDirectoryName(fntFilePath);

        Font CustomFont = new Font();

        AssetDatabase.CreateAsset(CustomFont, Path.Combine(dirName, fntName + ".fontsettings"));
        CustomFont = AssetDatabase.LoadAssetAtPath <Font>(Path.Combine(dirName, fntName + ".fontsettings"));

        TextAsset BMFontText = AssetDatabase.LoadAssetAtPath(fntFilePath, typeof(TextAsset)) as TextAsset;

        BMFont mbFont = new BMFont();

        BMFontReader.Load(mbFont, BMFontText.name, BMFontText.bytes);  // 借用NGUI封装的读取类
        CharacterInfo[] characterInfo = new CharacterInfo[mbFont.glyphs.Count];
        for (int i = 0; i < mbFont.glyphs.Count; i++)
        {
            BMGlyph       bmInfo = mbFont.glyphs[i];
            CharacterInfo info   = new CharacterInfo();
            info.index       = bmInfo.index;
            info.uv.x        = (float)bmInfo.x / (float)mbFont.texWidth;
            info.uv.y        = 1 - (float)bmInfo.y / (float)mbFont.texHeight;
            info.uv.width    = (float)bmInfo.width / (float)mbFont.texWidth;
            info.uv.height   = -1f * (float)bmInfo.height / (float)mbFont.texHeight;
            info.vert.x      = (float)bmInfo.offsetX;
            info.vert.y      = (float)bmInfo.offsetY - (float)bmInfo.height / 2;
            info.vert.width  = (float)bmInfo.width;
            info.vert.height = (float)bmInfo.height;
            info.width       = (float)bmInfo.advance;
            characterInfo[i] = info;
        }
        CustomFont.characterInfo = characterInfo;

        string   textureFilename = Path.Combine(dirName, mbFont.spriteName + ".png");
        Shader   shader          = Shader.Find("GUI/Custom Text Shader");
        Material mat             = new Material(shader);
        Texture  tex             = AssetDatabase.LoadAssetAtPath(textureFilename, typeof(Texture)) as Texture;

        mat.SetTexture("_MainTex", tex);
        AssetDatabase.CreateAsset(mat, Path.Combine(dirName, fntName + ".mat"));
        CustomFont.material = mat;

        EditorUtility.SetDirty(CustomFont);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Esempio n. 22
0
/// <summary>
/// Trim the glyphs, ensuring that they will never go past the specified bounds.
/// </summary>

public void Trim(int xMin, int yMin, int xMax, int yMax)
{
    if (isValid)
    {
        for (int i = 0, imax = mSaved.Count; i < imax; ++i)
        {
            BMGlyph glyph = mSaved[i];
            if (glyph != null) glyph.Trim(xMin, yMin, xMax, yMax);
        }
    }
}
Esempio n. 23
0
 static public int get_index(IntPtr l)
 {
     try {
         BMGlyph self = (BMGlyph)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.index);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 24
0
    void OnGUI()
    {
        //改成拖动文件夹
        targetFont   = EditorGUILayout.ObjectField("Target Font", targetFont, typeof(Font), false) as Font;
        fntData      = EditorGUILayout.ObjectField("Fnt Data", fntData, typeof(TextAsset), false) as TextAsset;
        fontMaterial = EditorGUILayout.ObjectField("Font Material", fontMaterial, typeof(Material), false) as Material;
        fontTexture  = EditorGUILayout.ObjectField("Font Texture", fontTexture, typeof(Texture2D), false) as Texture2D;

        if (GUILayout.Button("Create BMFont"))
        {
            BMFontReader.Load(bmFont, fntData.name, fntData.bytes);             // 借用NGUI封装的读取类
            CharacterInfo[] characterInfo = new CharacterInfo[bmFont.glyphs.Count];
            for (int i = 0; i < bmFont.glyphs.Count; i++)
            {
                BMGlyph       bmInfo = bmFont.glyphs[i];
                CharacterInfo info   = new CharacterInfo();
                info.index = bmInfo.index;
                int width     = bmInfo.width;
                int height    = bmInfo.height;
                int texWidth  = bmFont.texWidth;
                int texHeight = bmFont.texHeight;

                float uvX      = 1f * bmInfo.x / texWidth;
                float uvY      = 1 - (1f * bmInfo.y / texHeight);           //UV的坐标轴是以左上为0点
                float uvWidth  = 1f * width / texWidth;
                float uvHeight = -1f * height / texHeight;

                info.uvBottomLeft  = new Vector2(uvX, uvY);
                info.uvBottomRight = new Vector2(uvX + uvWidth, uvY);
                info.uvTopLeft     = new Vector2(uvX, uvY + uvHeight);
                info.uvTopRight    = new Vector2(uvX + uvWidth, uvY + uvHeight);

                info.minX        = bmInfo.offsetX;
                info.minY        = bmInfo.offsetY + height / 2;
                info.maxX        = bmInfo.offsetX + width;         //todo test
                info.maxY        = bmInfo.offsetY + height;
                info.glyphWidth  = width;
                info.glyphHeight = -height;                 // 不知道为什么要用负的,可能跟unity纹理uv有关
                info.advance     = bmInfo.advance;
                characterInfo[i] = info;
            }
            targetFont.characterInfo = characterInfo;
            if (fontMaterial)
            {
                fontMaterial.mainTexture = fontTexture;
            }
            targetFont.material = fontMaterial;
            fontMaterial.shader = Shader.Find("UI/Default");

            Debug.Log("create font <" + targetFont.name + "> success");
            Close();
        }
    }
Esempio n. 25
0
    private static void ReadXml(BMFont font, string name, string text)
    {
        XmlDocument doc = new XmlDocument();

        doc.LoadXml(text);
        XmlNode commonNode = doc.SelectSingleNode("/font/common");

        if (commonNode != null)
        {
            font.charSize   = GetXmlInt(commonNode.Attributes["lineHeight"].Value);
            font.baseOffset = GetXmlInt(commonNode.Attributes["base"].Value);
            font.texWidth   = GetXmlInt(commonNode.Attributes["scaleW"].Value);
            font.texHeight  = GetXmlInt(commonNode.Attributes["scaleH"].Value);

            int pages = GetXmlInt(commonNode.Attributes["pages"].Value);
            if (pages != 1)
            {
                Debug.LogError("Font '" + name + "' must be created with only 1 texture, not " + pages);
                return;
            }
        }
        XmlNode pageNode = doc.SelectSingleNode("/font/pages/page");

        if (pageNode != null)
        {
            font.spriteName = pageNode.Attributes["file"].Value.Replace(".png", "");
        }
        XmlNodeList charNodes = doc.SelectNodes("/font/chars/char");

        foreach (XmlNode node in charNodes)
        {
            string  chnl    = node.Attributes["chnl"].Value;
            int     channel = string.IsNullOrWhiteSpace(chnl) ? 15 : GetXmlInt(chnl);
            int     id      = GetXmlInt(node.Attributes["id"].Value);
            BMGlyph glyph   = font.GetGlyph(id, true);
            if (glyph != null)
            {
                glyph.x       = GetXmlInt(node.Attributes["x"].Value);
                glyph.y       = GetXmlInt(node.Attributes["y"].Value);
                glyph.width   = GetXmlInt(node.Attributes["width"].Value);
                glyph.height  = GetXmlInt(node.Attributes["height"].Value);
                glyph.offsetX = GetXmlInt(node.Attributes["xoffset"].Value);
                glyph.offsetY = GetXmlInt(node.Attributes["yoffset"].Value);
                glyph.advance = GetXmlInt(node.Attributes["xadvance"].Value);
                glyph.channel = channel;
            }
            else
            {
                Debug.Log("Char: " + node.Attributes["id"] + " (" + id + ") is NULL");
            }
        }
    }
Esempio n. 26
0
 static public int constructor(IntPtr l)
 {
     try {
         BMGlyph o;
         o = new BMGlyph();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 27
0
 static public int set_index(IntPtr l)
 {
     try {
         BMGlyph      self = (BMGlyph)checkSelf(l);
         System.Int32 v;
         checkType(l, 2, out v);
         self.index = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 28
0
 static public int set_kerning(IntPtr l)
 {
     try {
         BMGlyph self = (BMGlyph)checkSelf(l);
         System.Collections.Generic.List <System.Int32> v;
         checkType(l, 2, out v);
         self.kerning = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 29
0
    public static LitJson.JsonData Export(BMGlyph glyph)
    {
        var data = new LitJson.JsonData();

        data["i"]  = glyph.index;
        data["x"]  = glyph.x;
        data["y"]  = glyph.y;
        data["w"]  = glyph.width;
        data["h"]  = glyph.height;
        data["ox"] = glyph.offsetX;
        data["oy"] = glyph.offsetY;
        data["a"]  = glyph.advance;
        data["c"]  = glyph.channel;
        return(data);
    }
Esempio n. 30
0
 static public int GetKerning(IntPtr l)
 {
     try {
         BMGlyph      self = (BMGlyph)checkSelf(l);
         System.Int32 a1;
         checkType(l, 2, out a1);
         var ret = self.GetKerning(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 31
0
 public BMGlyph GetGlyph(int index, bool createIfMissing)
 {
     BMGlyph glyph = null;
     if (this.mDict.Count == 0)
     {
         int num = 0;
         int count = this.mSaved.Count;
         while (num < count)
         {
             BMGlyph glyph2 = this.mSaved[num];
             this.mDict.Add(glyph2.index, glyph2);
             num++;
         }
     }
     if (!this.mDict.TryGetValue(index, out glyph) && createIfMissing)
     {
         glyph = new BMGlyph();
         glyph.index = index;
         this.mSaved.Add(glyph);
         this.mDict.Add(index, glyph);
     }
     return glyph;
 }
Esempio n. 32
0
 public bool GetGlyph(int index, out BMGlyph glyph)
 {
     if (!this.mDictMade)
     {
         this.mDictMade = true;
         int count = this.mSaved.Count;
         if (count == 0 && this.LegacyCheck())
         {
             count = this.mSaved.Count;
         }
         this.mDictAny = count > 0;
         if (this.mDictAny)
         {
             this.mDict = BMFont.CreateGlyphDictionary(count);
             for (int i = count - 1; i >= 0; i--)
             {
                 BMGlyph item = this.mSaved[i];
                 this.mDict.Add(item.index, item);
                 if (item.index == index)
                 {
                     glyph = item;
                     while (true)
                     {
                         int num = i - 1;
                         i = num;
                         if (num < 0)
                         {
                             break;
                         }
                         item = this.mSaved[i];
                         this.mDict.Add(item.index, item);
                     }
                     return true;
                 }
             }
         }
     }
     else if (this.mDictAny)
     {
         return this.mDict.TryGetValue(index, out glyph);
     }
     glyph = null;
     return false;
 }
Esempio n. 33
0
    /// <summary>
    /// Helper function that retrieves the specified glyph, creating it if necessary.
    /// </summary>
    public BMGlyph GetGlyph(int index, bool createIfMissing)
    {
        // Start with a standard UTF-8 character set
        if (mGlyphs == null)
        {
            if (!createIfMissing) return null;
            int size = GetArraySize(index);
            if (size == 0) return null;
            mGlyphs = new BMGlyph[size];
        }

        // If necessary, upgrade to a unicode character set
        if (index >= mGlyphs.Length)
        {
            if (!createIfMissing) return null;
            int size = GetArraySize(index);
            if (size == 0) return null;
            BMGlyph[] glyphs = new BMGlyph[size];
            for (int i = 0; i < mGlyphs.Length; ++i) glyphs[i] = mGlyphs[i];
            mGlyphs = glyphs;
        }

        // Get the requested glyph
        BMGlyph glyph = mGlyphs[index];

        // If the glyph doesn't exist, create it
        if (glyph == null && createIfMissing)
        {
            glyph = new BMGlyph();
            mGlyphs[index] = glyph;
        }
        return glyph;
    }
Esempio n. 34
0
 public BMGlyph GetGlyph(int index, bool createIfMissing)
 {
     BMGlyph bMGlyph = null;
     if (this.mDict.Count == 0)
     {
         int i = 0;
         int count = this.mSaved.Count;
         while (i < count)
         {
             BMGlyph bMGlyph2 = this.mSaved[i];
             this.mDict.Add(bMGlyph2.index, bMGlyph2);
             i++;
         }
     }
     if (!this.mDict.TryGetValue(index, out bMGlyph) && createIfMissing)
     {
         bMGlyph = new BMGlyph();
         bMGlyph.index = index;
         this.mSaved.Add(bMGlyph);
         this.mDict.Add(index, bMGlyph);
     }
     return bMGlyph;
 }
Esempio n. 35
0
    /// <summary>
    /// Helper function that retrieves the specified glyph, creating it if necessary.
    /// </summary>
    public BMGlyph GetGlyph(int index, bool createIfMissing)
    {
        // Get the requested glyph
        BMGlyph glyph = null;

        if (mDict.Count == 0)
        {
            // Legacy check for pre-1.84 fonts
            if (mSaved.Count == 0)
            {
                LegacyCheck();
            }
            else
            {
                // Populate the dictionary for faster access
                foreach (BMGlyph bmg in mSaved)
                {
                    mDict.Add(bmg.index, bmg);
                }
            }
        }

        // Saved check is here so that the function call is not needed if it's true
        if (!mDict.TryGetValue(index, out glyph) && createIfMissing)
        {
            glyph = new BMGlyph();
            glyph.index = index;
            mSaved.Add(glyph);
            mDict.Add(index, glyph);
        }
        return glyph;
    }
Esempio n. 36
0
	/// <summary>
	/// Helper function that retrieves the specified glyph, creating it if necessary.
	/// </summary>

	public BMGlyph GetGlyph (int index, bool createIfMissing)
	{
		// Get the requested glyph
		BMGlyph glyph = null;

		if (mDict.Count == 0)
		{
			// Populate the dictionary for faster access
			for (int i = 0, imax = mSaved.Count; i < imax; ++i)
			{
				BMGlyph bmg = mSaved[i];
				mDict.Add(bmg.index, bmg);
			}
		}

		// Saved check is here so that the function call is not needed if it's true
		if (!mDict.TryGetValue(index, out glyph) && createIfMissing)
		{
			glyph = new BMGlyph();
			glyph.index = index;
			mSaved.Add(glyph);
			mDict.Add(index, glyph);
		}
		return glyph;
	}
Esempio n. 37
0
 public void AddChar(char ch, BMGlyph glyph)
 {
     _dict[ch] = glyph;
 }
Esempio n. 38
0
 public BMFont.GetOrCreateGlyphResult GetOrCreateGlyph(int index, out BMGlyph glyph)
 {
     if (!this.mDictMade)
     {
         this.mDictMade = true;
         this.mDictAny = true;
         int count = this.mSaved.Count;
         if (count == 0 && this.LegacyCheck())
         {
             count = this.mSaved.Count;
         }
         if (count <= 0)
         {
             this.mDict = BMFont.CreateGlyphDictionary();
         }
         else
         {
             this.mDict = BMFont.CreateGlyphDictionary(count + 1);
             for (int i = count - 1; i >= 0; i--)
             {
                 BMGlyph item = this.mSaved[i];
                 this.mDict.Add(item.index, item);
                 if (item.index == index)
                 {
                     glyph = item;
                     while (true)
                     {
                         int num = i - 1;
                         i = num;
                         if (num < 0)
                         {
                             break;
                         }
                         item = this.mSaved[i];
                         this.mDict.Add(item.index, item);
                     }
                     return BMFont.GetOrCreateGlyphResult.Found | BMFont.GetOrCreateGlyphResult.Created;
                 }
             }
         }
     }
     else if (!this.mDictAny)
     {
         this.mDict = BMFont.CreateGlyphDictionary();
         this.mDictAny = true;
     }
     else if (this.mDict.TryGetValue(index, out glyph))
     {
         return BMFont.GetOrCreateGlyphResult.Found | BMFont.GetOrCreateGlyphResult.Created;
     }
     glyph = new BMGlyph()
     {
         index = index
     };
     this.mDict.Add(index, glyph);
     return BMFont.GetOrCreateGlyphResult.Created;
 }