Ejemplo n.º 1
0
 private bool ReadTextKerning(int idx, ref string line, ref List<CharacterInfo> list)
 {
     if (!line.StartsWith("kerning")) return false;
     string[] keys;
     string[] values;
     SplitParts(line, out keys, out values);
     Kerning kerning = new Kerning();
     for (int i = keys.Length - 1; i >= 0; i--)
     {
         switch (keys[i])
         {
             case "first" : kerning.first = int.Parse(values[i]); break;
             case "second": kerning.second = int.Parse(values[i]); break;
             case "amount": kerning.amount = int.Parse(values[i]); break;
         }
     }
     kernings[idx] = kerning;
     return true;
 }
Ejemplo n.º 2
0
        private static void UpdateKernings(SerializedObject so, Kerning[] kernings)
        {
            int len = kernings != null ? kernings.Length : 0;
            SerializedProperty kerningsProp = so.FindProperty("m_KerningValues");
            //so.Update();

            if (len == 0)
            {
                kerningsProp.ClearArray();
                return;
            }

            int propLen = kerningsProp.arraySize;
            for (int i = 0; i < len; i++)
            {
                if (propLen <= i)
                {
                    kerningsProp.InsertArrayElementAtIndex(i);
                }

                SerializedProperty kerningProp = kerningsProp.GetArrayElementAtIndex(i);
                kerningProp.FindPropertyRelative("second").floatValue = kernings[i].amount;
                SerializedProperty pairProp = kerningProp.FindPropertyRelative("first");
                pairProp.Next(true);
                pairProp.intValue = kernings[i].first;
                pairProp.Next(false);
                pairProp.intValue = kernings[i].second;
            }
            for (int i = propLen - 1; i >= len; i--)
            {
                kerningsProp.DeleteArrayElementAtIndex(i);
            }
        }
Ejemplo n.º 3
0
        public void DoXMLPase(ref string content)
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(content);

            XmlNode info = xml.GetElementsByTagName("info")[0];
            XmlNode common = xml.GetElementsByTagName("common")[0];
            XmlNode page = xml.GetElementsByTagName("pages")[0].FirstChild;
            XmlNodeList chars = xml.GetElementsByTagName("chars")[0].ChildNodes;

            fontName = info.Attributes.GetNamedItem("face").InnerText;
            fontSize = ToInt(info, "size");

            lineHeight = ToInt(common, "lineHeight");
            lineBaseHeight = ToInt(common, "base");
            textureWidth = ToInt(common, "scaleW");
            textureHeight = ToInt(common, "scaleH");
            textureName = page.Attributes.GetNamedItem("file").InnerText;

            charInfos = new CharacterInfo[chars.Count];
            for (int i = 0; i < chars.Count; i++)
            {
                XmlNode charNode = chars[i];
                charInfos[i] =  CreateCharInfo(
                    ToInt(charNode, "id"),
                    ToInt(charNode, "x"),
                    ToInt(charNode, "y"),
                    ToInt(charNode, "width"),
                    ToInt(charNode, "height"),
                    ToInt(charNode, "xoffset"),
                    ToInt(charNode, "yoffset"),
                    ToInt(charNode, "xadvance"));
            }

            // kernings
            XmlNode kerningsNode = xml.GetElementsByTagName("kernings")[0];
            if (kerningsNode != null && kerningsNode.HasChildNodes)
            {
                XmlNodeList kerns = kerningsNode.ChildNodes;
                kernings = new Kerning[kerns.Count];
                for (int i = 0; i < kerns.Count; i++)
                {
                    XmlNode kerningNode = kerns[i];
                    kernings[i] = new Kerning();
                    kernings[i].first = ToInt(kerningNode, "first");
                    kernings[i].second = ToInt(kerningNode, "second");
                    kernings[i].amount = ToInt(kerningNode, "amount");
                }
            }
        }
Ejemplo n.º 4
0
        public void DoXMLPase(ref string content)
        {
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(content);

            XmlNode     info   = xml.GetElementsByTagName("info")[0];
            XmlNode     common = xml.GetElementsByTagName("common")[0];
            XmlNodeList pages  = xml.GetElementsByTagName("pages")[0].ChildNodes;
            XmlNodeList chars  = xml.GetElementsByTagName("chars")[0].ChildNodes;


            fontName = info.Attributes.GetNamedItem("face").InnerText;
            fontSize = ToInt(info, "size");

            lineHeight     = ToInt(common, "lineHeight");
            lineBaseHeight = ToInt(common, "base");
            textureWidth   = ToInt(common, "scaleW");
            textureHeight  = ToInt(common, "scaleH");
            int pageNum = ToInt(common, "pages");

            textureNames = new string[pageNum];

            for (int i = 0; i < pageNum; i++)
            {
                XmlNode page   = pages[i];
                int     pageId = ToInt(page, "id");
                textureNames[pageId] = page.Attributes.GetNamedItem("file").InnerText;
            }

            charInfos = new CharacterInfo[chars.Count];
            for (int i = 0; i < chars.Count; i++)
            {
                XmlNode charNode = chars[i];
                charInfos[i] = CreateCharInfo(
                    ToInt(charNode, "id"),
                    ToInt(charNode, "x"),
                    ToInt(charNode, "y"),
                    ToInt(charNode, "width"),
                    ToInt(charNode, "height"),
                    ToInt(charNode, "xoffset"),
                    ToInt(charNode, "yoffset"),
                    ToInt(charNode, "xadvance"),
                    ToInt(charNode, "page"));
            }

            // kernings
            XmlNode kerningsNode = xml.GetElementsByTagName("kernings")[0];

            if (kerningsNode != null && kerningsNode.HasChildNodes)
            {
                XmlNodeList kerns = kerningsNode.ChildNodes;
                kernings = new Kerning[kerns.Count];
                for (int i = 0; i < kerns.Count; i++)
                {
                    XmlNode kerningNode = kerns[i];
                    kernings[i]        = new Kerning();
                    kernings[i].first  = ToInt(kerningNode, "first");
                    kernings[i].second = ToInt(kerningNode, "second");
                    kernings[i].amount = ToInt(kerningNode, "amount");
                }
            }
        }