Exemplo n.º 1
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, TMP_Glyph>();
            foreach (TMP_Glyph 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);

            TMP_Glyph temp_charInfo = new TMP_Glyph();

            // 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 TMP_Glyph();
                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 = TMP_Glyph.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 TMP_Glyph();
                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 TMP_Glyph();
                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;

            // Adjust Font Scale for compatibility reasons
            if (m_fontInfo.Scale == 0)
                m_fontInfo.Scale = 1.0f;

            // 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);

        }
Exemplo n.º 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;
            }

            // 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_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);
            }


            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    = 0; // m_characterDictionary[32].width;
                temp_charInfo.height   = 0; // m_characterDictionary[32].height;
                temp_charInfo.xOffset  = 0; // m_characterDictionary[32].xOffset;
                temp_charInfo.yOffset  = 0; // m_characterDictionary[32].yOffset;
                temp_charInfo.xAdvance = 0;
                m_characterDictionary.Add(10, temp_charInfo);

                m_characterDictionary.Add(13, temp_charInfo);
            }

            // Add Tab Character to Dictionary. Tab is Tab Size * Space Character Width.
            int tabSize = 10;

            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;
                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[32].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);
            }
        }
Exemplo n.º 3
0
 public void ReadFontDefinition()
 {
     if (this.m_fontInfo != null)
     {
         this.m_characterDictionary = new Dictionary <int, GlyphInfo>();
         foreach (GlyphInfo info in this.m_glyphInfoList)
         {
             if (!this.m_characterDictionary.ContainsKey(info.id))
             {
                 this.m_characterDictionary.Add(info.id, info);
             }
         }
         GlyphInfo info2 = new GlyphInfo();
         if (this.m_characterDictionary.ContainsKey(0x20))
         {
             this.m_characterDictionary[0x20].width   = this.m_fontInfo.Ascender / 5f;
             this.m_characterDictionary[0x20].height  = this.m_fontInfo.Ascender - this.m_fontInfo.Descender;
             this.m_characterDictionary[0x20].yOffset = this.m_fontInfo.Ascender;
         }
         else
         {
             info2 = new GlyphInfo {
                 id       = 0x20,
                 x        = 0f,
                 y        = 0f,
                 width    = this.m_fontInfo.Ascender / 5f,
                 height   = this.m_fontInfo.Ascender - this.m_fontInfo.Descender,
                 xOffset  = 0f,
                 yOffset  = this.m_fontInfo.Ascender,
                 xAdvance = this.m_fontInfo.PointSize / 4f
             };
             this.m_characterDictionary.Add(0x20, info2);
         }
         if (!this.m_characterDictionary.ContainsKey(10))
         {
             info2 = new GlyphInfo {
                 id       = 10,
                 x        = 0f,
                 y        = 0f,
                 width    = 0f,
                 height   = 0f,
                 xOffset  = 0f,
                 yOffset  = 0f,
                 xAdvance = 0f
             };
             this.m_characterDictionary.Add(10, info2);
             this.m_characterDictionary.Add(13, info2);
         }
         if (!this.m_characterDictionary.ContainsKey(9))
         {
             info2 = new GlyphInfo {
                 id       = 9,
                 x        = this.m_characterDictionary[0x20].x,
                 y        = this.m_characterDictionary[0x20].y,
                 width    = this.m_characterDictionary[0x20].width * this.TabSize,
                 height   = this.m_characterDictionary[0x20].height,
                 xOffset  = this.m_characterDictionary[0x20].xOffset,
                 yOffset  = this.m_characterDictionary[0x20].yOffset,
                 xAdvance = this.m_characterDictionary[0x20].xAdvance * this.TabSize
             };
             this.m_characterDictionary.Add(9, info2);
         }
         this.m_fontInfo.TabWidth = this.m_characterDictionary[0x20].xAdvance;
         this.m_kerningDictionary = new Dictionary <int, KerningPair>();
         List <KerningPair> kerningPairs = this.m_kerningInfo.kerningPairs;
         for (int i = 0; i < kerningPairs.Count; i++)
         {
             KerningPair    pair = kerningPairs[i];
             KerningPairKey key  = new KerningPairKey(pair.AscII_Left, pair.AscII_Right);
             if (!this.m_kerningDictionary.ContainsKey(key.key))
             {
                 this.m_kerningDictionary.Add(key.key, pair);
             }
             else
             {
                 Debug.Log(string.Concat(new object[] { "Kerning Key for [", key.ascii_Left, "] and [", key.ascii_Right, "] already exists." }));
             }
         }
         this.m_lineBreakingInfo = new LineBreakingTable();
         TextAsset file = Resources.Load("LineBreaking Leading Characters", typeof(TextAsset)) as TextAsset;
         if (file != null)
         {
             this.m_lineBreakingInfo.leadingCharacters = this.GetCharacters(file);
         }
         TextAsset asset2 = Resources.Load("LineBreaking Following Characters", typeof(TextAsset)) as TextAsset;
         if (asset2 != null)
         {
             this.m_lineBreakingInfo.followingCharacters = this.GetCharacters(asset2);
         }
         string name = base.name;
         this.fontHashCode = 0;
         for (int j = 0; j < name.Length; j++)
         {
             this.fontHashCode = ((this.fontHashCode << 5) - this.fontHashCode) + name[j];
         }
         string str2 = this.material.name;
         this.materialHashCode = 0;
         for (int k = 0; k < str2.Length; k++)
         {
             this.materialHashCode = ((this.materialHashCode << 5) - this.materialHashCode) + str2[k];
         }
     }
 }
Exemplo n.º 4
0
 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_characterDictionary[32].xAdvance;
             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(160))
         {
             glyphInfo = GlyphInfo.Clone(m_characterDictionary[32]);
             m_characterDictionary.Add(160, glyphInfo);
         }
         if (!m_characterDictionary.ContainsKey(10))
         {
             glyphInfo          = new GlyphInfo();
             glyphInfo.id       = 10;
             glyphInfo.x        = 0f;
             glyphInfo.y        = 0f;
             glyphInfo.width    = 10f;
             glyphInfo.height   = m_characterDictionary[32].height;
             glyphInfo.xOffset  = 0f;
             glyphInfo.yOffset  = m_characterDictionary[32].yOffset;
             glyphInfo.xAdvance = 0f;
             m_characterDictionary.Add(10, glyphInfo);
             if (!m_characterDictionary.ContainsKey(13))
             {
                 m_characterDictionary.Add(13, glyphInfo);
             }
         }
         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)(int)TabSize + (m_characterDictionary[32].xAdvance - m_characterDictionary[32].width) * (float)(TabSize - 1);
             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)(int)TabSize;
             m_characterDictionary.Add(9, glyphInfo);
         }
         m_fontInfo.TabWidth = m_characterDictionary[9].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);
         }
         fontHashCode     = TMP_TextUtilities.GetSimpleHashCode(base.name);
         materialHashCode = TMP_TextUtilities.GetSimpleHashCode(material.name);
     }
 }
Exemplo n.º 5
0
        public void ReadFontDefinition()
        {
            if (this.m_fontInfo == null)
            {
                return;
            }
            this.m_characterDictionary = new Dictionary <int, GlyphInfo>();
            using (List <GlyphInfo> .Enumerator enumerator = this.m_glyphInfoList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    GlyphInfo current = enumerator.get_Current();
                    if (!this.m_characterDictionary.ContainsKey(current.id))
                    {
                        this.m_characterDictionary.Add(current.id, current);
                    }
                }
            }
            GlyphInfo glyphInfo = new GlyphInfo();

            if (this.m_characterDictionary.ContainsKey(32))
            {
                this.m_characterDictionary.get_Item(32).width   = this.m_fontInfo.Ascender / 5f;
                this.m_characterDictionary.get_Item(32).height  = this.m_fontInfo.Ascender - this.m_fontInfo.Descender;
                this.m_characterDictionary.get_Item(32).yOffset = this.m_fontInfo.Ascender;
            }
            else
            {
                glyphInfo          = new GlyphInfo();
                glyphInfo.id       = 32;
                glyphInfo.x        = 0f;
                glyphInfo.y        = 0f;
                glyphInfo.width    = this.m_fontInfo.Ascender / 5f;
                glyphInfo.height   = this.m_fontInfo.Ascender - this.m_fontInfo.Descender;
                glyphInfo.xOffset  = 0f;
                glyphInfo.yOffset  = this.m_fontInfo.Ascender;
                glyphInfo.xAdvance = this.m_fontInfo.PointSize / 4f;
                this.m_characterDictionary.Add(32, glyphInfo);
            }
            if (!this.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;
                this.m_characterDictionary.Add(10, glyphInfo);
                this.m_characterDictionary.Add(13, glyphInfo);
            }
            if (!this.m_characterDictionary.ContainsKey(9))
            {
                glyphInfo          = new GlyphInfo();
                glyphInfo.id       = 9;
                glyphInfo.x        = this.m_characterDictionary.get_Item(32).x;
                glyphInfo.y        = this.m_characterDictionary.get_Item(32).y;
                glyphInfo.width    = this.m_characterDictionary.get_Item(32).width *(float)this.TabSize;
                glyphInfo.height   = this.m_characterDictionary.get_Item(32).height;
                glyphInfo.xOffset  = this.m_characterDictionary.get_Item(32).xOffset;
                glyphInfo.yOffset  = this.m_characterDictionary.get_Item(32).yOffset;
                glyphInfo.xAdvance = this.m_characterDictionary.get_Item(32).xAdvance *(float)this.TabSize;
                this.m_characterDictionary.Add(9, glyphInfo);
            }
            this.m_fontInfo.TabWidth = this.m_characterDictionary.get_Item(32).xAdvance;
            this.m_kerningDictionary = new Dictionary <int, KerningPair>();
            List <KerningPair> kerningPairs = this.m_kerningInfo.kerningPairs;

            for (int i = 0; i < kerningPairs.get_Count(); i++)
            {
                KerningPair    kerningPair    = kerningPairs.get_Item(i);
                KerningPairKey kerningPairKey = new KerningPairKey(kerningPair.AscII_Left, kerningPair.AscII_Right);
                if (!this.m_kerningDictionary.ContainsKey(kerningPairKey.key))
                {
                    this.m_kerningDictionary.Add(kerningPairKey.key, kerningPair);
                }
                else
                {
                    Debug.Log(string.Concat(new object[]
                    {
                        "Kerning Key for [",
                        kerningPairKey.ascii_Left,
                        "] and [",
                        kerningPairKey.ascii_Right,
                        "] already exists."
                    }));
                }
            }
            this.m_lineBreakingInfo = new LineBreakingTable();
            TextAsset textAsset = Resources.Load("LineBreaking Leading Characters", typeof(TextAsset)) as TextAsset;

            if (textAsset != null)
            {
                this.m_lineBreakingInfo.leadingCharacters = this.GetCharacters(textAsset);
            }
            TextAsset textAsset2 = Resources.Load("LineBreaking Following Characters", typeof(TextAsset)) as TextAsset;

            if (textAsset2 != null)
            {
                this.m_lineBreakingInfo.followingCharacters = this.GetCharacters(textAsset2);
            }
            string name = base.name;

            this.fontHashCode = 0;
            for (int j = 0; j < name.get_Length(); j++)
            {
                this.fontHashCode = (this.fontHashCode << 5) - this.fontHashCode + (int)name.get_Chars(j);
            }
            string name2 = this.material.name;

            this.materialHashCode = 0;
            for (int k = 0; k < name2.get_Length(); k++)
            {
                this.materialHashCode = (this.materialHashCode << 5) - this.materialHashCode + (int)name2.get_Chars(k);
            }
        }
 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];
         }
     }
 }
Exemplo n.º 7
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, TMP_Glyph>();
            foreach (TMP_Glyph 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);

            TMP_Glyph temp_charInfo = new TMP_Glyph();

            // 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 TMP_Glyph();
                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 = TMP_Glyph.Clone(m_characterDictionary[32]);
                m_characterDictionary.Add(160, temp_charInfo);
            }

            // Add Zero Width Space (8203)
            if (!m_characterDictionary.ContainsKey(8203))
            {
                temp_charInfo          = TMP_Glyph.Clone(m_characterDictionary[32]);
                temp_charInfo.width    = 0;
                temp_charInfo.xAdvance = 0;
                m_characterDictionary.Add(8203, temp_charInfo);
            }

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

                temp_charInfo          = new TMP_Glyph();
                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 TMP_Glyph();
                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;

            // Adjust Font Scale for compatibility reasons
            if (m_fontInfo.Scale == 0)
            {
                m_fontInfo.Scale = 1.0f;
            }

            // 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
            hashCode = TMP_TextUtilities.GetSimpleHashCode(this.name);

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


            // Initialize Font Weights if needed
            //InitializeFontWeights();
        }