public void ReadFontDefinition()
 {
     if (m_fontInfo != null)
     {
         m_characterDictionary = new Dictionary <int, GlyphInfo>();
         foreach (GlyphInfo glyphInfo2 in m_glyphInfoList)
         {
             if (!m_characterDictionary.ContainsKey(glyphInfo2.id))
             {
                 m_characterDictionary.Add(glyphInfo2.id, glyphInfo2);
             }
         }
         GlyphInfo glyphInfo = new GlyphInfo();
         if (m_characterDictionary.ContainsKey(32))
         {
             m_characterDictionary[32].width   = m_fontInfo.Ascender / 5f;
             m_characterDictionary[32].height  = m_fontInfo.Ascender - m_fontInfo.Descender;
             m_characterDictionary[32].yOffset = m_fontInfo.Ascender;
         }
         else
         {
             glyphInfo          = new GlyphInfo();
             glyphInfo.id       = 32;
             glyphInfo.x        = 0f;
             glyphInfo.y        = 0f;
             glyphInfo.width    = m_fontInfo.Ascender / 5f;
             glyphInfo.height   = m_fontInfo.Ascender - m_fontInfo.Descender;
             glyphInfo.xOffset  = 0f;
             glyphInfo.yOffset  = m_fontInfo.Ascender;
             glyphInfo.xAdvance = m_fontInfo.PointSize / 4f;
             m_characterDictionary.Add(32, glyphInfo);
         }
         if (!m_characterDictionary.ContainsKey(10))
         {
             glyphInfo          = new GlyphInfo();
             glyphInfo.id       = 10;
             glyphInfo.x        = 0f;
             glyphInfo.y        = 0f;
             glyphInfo.width    = 0f;
             glyphInfo.height   = 0f;
             glyphInfo.xOffset  = 0f;
             glyphInfo.yOffset  = 0f;
             glyphInfo.xAdvance = 0f;
             m_characterDictionary.Add(10, glyphInfo);
             m_characterDictionary.Add(13, glyphInfo);
         }
         int num = 10;
         if (!m_characterDictionary.ContainsKey(9))
         {
             glyphInfo          = new GlyphInfo();
             glyphInfo.id       = 9;
             glyphInfo.x        = m_characterDictionary[32].x;
             glyphInfo.y        = m_characterDictionary[32].y;
             glyphInfo.width    = m_characterDictionary[32].width * (float)num;
             glyphInfo.height   = m_characterDictionary[32].height;
             glyphInfo.xOffset  = m_characterDictionary[32].xOffset;
             glyphInfo.yOffset  = m_characterDictionary[32].yOffset;
             glyphInfo.xAdvance = m_characterDictionary[32].xAdvance * (float)num;
             m_characterDictionary.Add(9, glyphInfo);
         }
         m_fontInfo.TabWidth = m_characterDictionary[32].xAdvance;
         m_kerningDictionary = new Dictionary <int, KerningPair>();
         List <KerningPair> kerningPairs = m_kerningInfo.kerningPairs;
         for (int i = 0; i < kerningPairs.Count; i++)
         {
             KerningPair    kerningPair    = kerningPairs[i];
             KerningPairKey kerningPairKey = new KerningPairKey(kerningPair.AscII_Left, kerningPair.AscII_Right);
             if (!m_kerningDictionary.ContainsKey(kerningPairKey.key))
             {
                 m_kerningDictionary.Add(kerningPairKey.key, kerningPair);
             }
             else
             {
                 Debug.Log("Kerning Key for [" + kerningPairKey.ascii_Left + "] and [" + kerningPairKey.ascii_Right + "] already exists.");
             }
         }
         m_lineBreakingInfo = new LineBreakingTable();
         TextAsset textAsset = Resources.Load("LineBreaking Leading Characters", typeof(TextAsset)) as TextAsset;
         if (textAsset != null)
         {
             m_lineBreakingInfo.leadingCharacters = GetCharacters(textAsset);
         }
         TextAsset textAsset2 = Resources.Load("LineBreaking Following Characters", typeof(TextAsset)) as TextAsset;
         if (textAsset2 != null)
         {
             m_lineBreakingInfo.followingCharacters = GetCharacters(textAsset2);
         }
         string name = base.name;
         fontHashCode = 0;
         for (int j = 0; j < name.Length; j++)
         {
             fontHashCode = (fontHashCode << 5) - fontHashCode + name[j];
         }
         string name2 = material.name;
         materialHashCode = 0;
         for (int k = 0; k < name2.Length; k++)
         {
             materialHashCode = (materialHashCode << 5) - materialHashCode + name2[k];
         }
     }
 }
示例#2
0
        public void ReadFontDefinition()
        {
            //Debug.Log("Reading Font Definition for " + this.name + ".");
            // Make sure that we have a Font Asset file assigned.
            if (m_fontInfo == null)
            {
                return;
            }

            // Check Font Asset type
            //Debug.Log(name + "   " + fontAssetType);

            // Create new instance of GlyphInfo Dictionary for fast access to glyph info.
            m_characterDictionary = new Dictionary <int, GlyphInfo>();
            foreach (GlyphInfo glyph in m_glyphInfoList)
            {
                if (!m_characterDictionary.ContainsKey(glyph.id))
                {
                    m_characterDictionary.Add(glyph.id, glyph);
                }
            }


            //Debug.Log("PRE: BaseLine:" + m_fontInfo.Baseline + "  Ascender:" + m_fontInfo.Ascender + "  Descender:" + m_fontInfo.Descender); // + "  Centerline:" + m_fontInfo.CenterLine);

            GlyphInfo temp_charInfo = new GlyphInfo();

            // Add Character (10) LineFeed, (13) Carriage Return & Space (32) to Dictionary if they don't exists.
            if (m_characterDictionary.ContainsKey(32))
            {
                m_characterDictionary[32].width   = m_characterDictionary[32].xAdvance; // m_fontInfo.Ascender / 5;
                m_characterDictionary[32].height  = m_fontInfo.Ascender - m_fontInfo.Descender;
                m_characterDictionary[32].yOffset = m_fontInfo.Ascender;
            }
            else
            {
                //Debug.Log("Adding Character 32 (Space) to Dictionary for Font (" + m_fontInfo.Name + ").");
                temp_charInfo          = new GlyphInfo();
                temp_charInfo.id       = 32;
                temp_charInfo.x        = 0;
                temp_charInfo.y        = 0;
                temp_charInfo.width    = m_fontInfo.Ascender / 5;
                temp_charInfo.height   = m_fontInfo.Ascender - m_fontInfo.Descender;
                temp_charInfo.xOffset  = 0;
                temp_charInfo.yOffset  = m_fontInfo.Ascender;
                temp_charInfo.xAdvance = m_fontInfo.PointSize / 4;
                m_characterDictionary.Add(32, temp_charInfo);
            }

            // Add Non-Breaking Space (160)
            if (!m_characterDictionary.ContainsKey(160))
            {
                temp_charInfo = GlyphInfo.Clone(m_characterDictionary[32]);
                m_characterDictionary.Add(160, temp_charInfo);
            }


            if (m_characterDictionary.ContainsKey(10) == false)
            {
                //Debug.Log("Adding Character 10 (Linefeed) to Dictionary for Font (" + m_fontInfo.Name + ").");

                temp_charInfo          = new GlyphInfo();
                temp_charInfo.id       = 10;
                temp_charInfo.x        = 0;  // m_characterDictionary[32].x;
                temp_charInfo.y        = 0;  // m_characterDictionary[32].y;
                temp_charInfo.width    = 10; // m_characterDictionary[32].width;
                temp_charInfo.height   = m_characterDictionary[32].height;
                temp_charInfo.xOffset  = 0;  // m_characterDictionary[32].xOffset;
                temp_charInfo.yOffset  = m_characterDictionary[32].yOffset;
                temp_charInfo.xAdvance = 0;
                m_characterDictionary.Add(10, temp_charInfo);

                if (!m_characterDictionary.ContainsKey(13))
                {
                    m_characterDictionary.Add(13, temp_charInfo);
                }
            }

            // Add Tab Character to Dictionary. Tab is Tab Size * Space Character Width.
            if (m_characterDictionary.ContainsKey(9) == false)
            {
                //Debug.Log("Adding Character 9 (Tab) to Dictionary for Font (" + m_fontInfo.Name + ").");

                temp_charInfo          = new GlyphInfo();
                temp_charInfo.id       = 9;
                temp_charInfo.x        = m_characterDictionary[32].x;
                temp_charInfo.y        = m_characterDictionary[32].y;
                temp_charInfo.width    = m_characterDictionary[32].width * TabSize + (m_characterDictionary[32].xAdvance - m_characterDictionary[32].width) * (TabSize - 1);
                temp_charInfo.height   = m_characterDictionary[32].height;
                temp_charInfo.xOffset  = m_characterDictionary[32].xOffset;
                temp_charInfo.yOffset  = m_characterDictionary[32].yOffset;
                temp_charInfo.xAdvance = m_characterDictionary[32].xAdvance * TabSize;
                m_characterDictionary.Add(9, temp_charInfo);
            }

            // Centerline is located at the center of character like { or in the middle of the lowercase o.
            //m_fontInfo.CenterLine = m_characterDictionary[111].yOffset - m_characterDictionary[111].height * 0.5f;

            // Tab Width is using the same xAdvance as space (32).
            m_fontInfo.TabWidth = m_characterDictionary[9].xAdvance;


            // Populate Dictionary with Kerning Information
            m_kerningDictionary = new Dictionary <int, KerningPair>();
            List <KerningPair> pairs = m_kerningInfo.kerningPairs;

            //Debug.Log(m_fontInfo.Name + " has " + pairs.Count +  " Kerning Pairs.");
            for (int i = 0; i < pairs.Count; i++)
            {
                KerningPair    pair      = pairs[i];
                KerningPairKey uniqueKey = new KerningPairKey(pair.AscII_Left, pair.AscII_Right);

                if (m_kerningDictionary.ContainsKey(uniqueKey.key) == false)
                {
                    m_kerningDictionary.Add(uniqueKey.key, pair);
                }
                else
                {
                    Debug.Log("Kerning Key for [" + uniqueKey.ascii_Left + "] and [" + uniqueKey.ascii_Right + "] already exists.");
                }
            }

            // Add Line Breaking Characters
            m_lineBreakingInfo = new LineBreakingTable();


            TextAsset leadingCharFile = Resources.Load("LineBreaking Leading Characters", typeof(TextAsset)) as TextAsset;

            if (leadingCharFile != null)
            {
                m_lineBreakingInfo.leadingCharacters = GetCharacters(leadingCharFile);
            }

            TextAsset followingCharFile = Resources.Load("LineBreaking Following Characters", typeof(TextAsset)) as TextAsset;

            if (followingCharFile != null)
            {
                m_lineBreakingInfo.followingCharacters = GetCharacters(followingCharFile);
            }


            // Compute Hashcode for the font asset name
            fontHashCode = TMP_TextUtilities.GetSimpleHashCode(this.name);

            // Compute Hashcode for the material name
            materialHashCode = TMP_TextUtilities.GetSimpleHashCode(material.name);
        }