Esempio n. 1
0
        private void parseCharacterDefinition(string line, CCBMFontDef characterDefinition)
        {
            //////////////////////////////////////////////////////////////////////////
            // line to parse:
            // char id=32   x=0     y=0     width=0     height=0     xoffset=0     yoffset=44    xadvance=14     page=0  chnl=0
            //////////////////////////////////////////////////////////////////////////

            // Character ID
            int    index  = line.IndexOf("id=");
            int    index2 = line.IndexOf(' ', index);
            string value  = line.Substring(index, index2 - index);

            characterDefinition.charID = Cocos2D.CCUtils.CCParseInt(value.Replace("id=", ""));
            //CCAssert(characterDefinition->charID < kCCBMFontMaxChars, "BitmpaFontAtlas: CharID bigger than supported");

            // Character x
            index  = line.IndexOf("x=");
            index2 = line.IndexOf(' ', index);
            value  = line.Substring(index, index2 - index);
            characterDefinition.rect.Origin.X = Cocos2D.CCUtils.CCParseFloat(value.Replace("x=", ""));

            // Character y
            index  = line.IndexOf("y=");
            index2 = line.IndexOf(' ', index);
            value  = line.Substring(index, index2 - index);
            characterDefinition.rect.Origin.Y = Cocos2D.CCUtils.CCParseFloat(value.Replace("y=", ""));

            // Character width
            index  = line.IndexOf("width=");
            index2 = line.IndexOf(' ', index);
            value  = line.Substring(index, index2 - index);
            characterDefinition.rect.Size.Width = Cocos2D.CCUtils.CCParseFloat(value.Replace("width=", ""));

            // Character height
            index  = line.IndexOf("height=");
            index2 = line.IndexOf(' ', index);
            value  = line.Substring(index, index2 - index);
            characterDefinition.rect.Size.Height = Cocos2D.CCUtils.CCParseFloat(value.Replace("height=", ""));

            // Character xoffset
            index  = line.IndexOf("xoffset=");
            index2 = line.IndexOf(' ', index);
            value  = line.Substring(index, index2 - index);
            characterDefinition.xOffset = Cocos2D.CCUtils.CCParseInt(value.Replace("xoffset=", ""));

            // Character yoffset
            index  = line.IndexOf("yoffset=");
            index2 = line.IndexOf(' ', index);
            value  = line.Substring(index, index2 - index);
            characterDefinition.yOffset = Cocos2D.CCUtils.CCParseInt(value.Replace("yoffset=", ""));

            // Character xadvance
            index  = line.IndexOf("xadvance=");
            index2 = line.IndexOf(' ', index);
            value  = line.Substring(index, index2 - index);
            characterDefinition.xAdvance = Cocos2D.CCUtils.CCParseInt(value.Replace("xadvance=", ""));
        }
Esempio n. 2
0
        private void parseCharacterDefinition(string line, CCBMFontDef characterDefinition)
        {
            //////////////////////////////////////////////////////////////////////////
            // line to parse:
            // char id=32   x=0     y=0     width=0     height=0     xoffset=0     yoffset=44    xadvance=14     page=0  chnl=0 letter=\"f\"\r
            //////////////////////////////////////////////////////////////////////////

            StringBuilder sbuf  = new StringBuilder();
            string        token = null;
            string        value = null;
            int           mode  = 0; // 0 = token, 1 = value, 2 = munger

            for (int i = 0; i < line.Length; i++)
            {
                char c = line[i];
                if (c == '=' && mode == 0)
                {
                    token       = sbuf.ToString();
                    sbuf.Length = 0;
                    mode        = 1; // expecting a value now
                }
                else if ((char.IsWhiteSpace(c) || i == (line.Length - 1)) && mode == 1)
                {
                    // End of value, save it
                    value       = sbuf.ToString();
                    sbuf.Length = 0;
                    mode        = 2; // expecting to munge noise
                    // Process the token/value
                    switch (token)
                    {
                    case "char id":
                        characterDefinition.charID = Cocos2D.CCUtils.CCParseInt(value);
                        break;

                    case "x":
                        characterDefinition.rect.Origin.X = Cocos2D.CCUtils.CCParseFloat(value);
                        break;

                    case "y":
                        characterDefinition.rect.Origin.Y = Cocos2D.CCUtils.CCParseFloat(value);
                        break;

                    case "width":
                        characterDefinition.rect.Size.Width = Cocos2D.CCUtils.CCParseFloat(value);
                        break;

                    case "height":
                        characterDefinition.rect.Size.Height = Cocos2D.CCUtils.CCParseFloat(value);
                        break;

                    case "xoffset":
                        characterDefinition.xOffset = Cocos2D.CCUtils.CCParseInt(value);
                        break;

                    case "yoffset":
                        characterDefinition.yOffset = Cocos2D.CCUtils.CCParseInt(value);
                        break;

                    case "xadvance":
                        characterDefinition.xAdvance = Cocos2D.CCUtils.CCParseInt(value);
                        break;

                    case "page":
                        break;

                    case "chnl":
                        break;

                    case "letter":
                        break;
                    }
                }
                else if (mode == 2 && !char.IsWhiteSpace(c))
                {
                    mode = 0; // token time
                    sbuf.Append(c);
                }
                else if (mode == 0 || mode == 1)
                {
                    sbuf.Append(c);
                }
            }

            /*
             * // Character ID
             * int index = line.IndexOf("id=");
             * int index2 = line.IndexOf(' ', index);
             * string value = line.Substring(index, index2 - index);
             * characterDefinition.charID = Cocos2D.CCUtils.CCParseInt(value.Replace("id=", ""));
             * //CCAssert(characterDefinition->charID < kCCBMFontMaxChars, "BitmpaFontAtlas: CharID bigger than supported");
             *
             * // Character x
             * index = line.IndexOf("x=");
             * index2 = line.IndexOf(' ', index);
             * value = line.Substring(index, index2 - index);
             * characterDefinition.rect.Origin.X = Cocos2D.CCUtils.CCParseFloat(value.Replace("x=", ""));
             *
             * // Character y
             * index = line.IndexOf("y=");
             * index2 = line.IndexOf(' ', index);
             * value = line.Substring(index, index2 - index);
             * characterDefinition.rect.Origin.Y = Cocos2D.CCUtils.CCParseFloat(value.Replace("y=", ""));
             *
             * // Character width
             * index = line.IndexOf("width=");
             * index2 = line.IndexOf(' ', index);
             * value = line.Substring(index, index2 - index);
             * characterDefinition.rect.Size.Width = Cocos2D.CCUtils.CCParseFloat(value.Replace("width=", ""));
             *
             * // Character height
             * index = line.IndexOf("height=");
             * index2 = line.IndexOf(' ', index);
             * value = line.Substring(index, index2 - index);
             * characterDefinition.rect.Size.Height = Cocos2D.CCUtils.CCParseFloat(value.Replace("height=", ""));
             *
             * // Character xoffset
             * index = line.IndexOf("xoffset=");
             * index2 = line.IndexOf(' ', index);
             * value = line.Substring(index, index2 - index);
             * characterDefinition.xOffset = Cocos2D.CCUtils.CCParseInt(value.Replace("xoffset=", ""));
             *
             * // Character yoffset
             * index = line.IndexOf("yoffset=");
             * index2 = line.IndexOf(' ', index);
             * value = line.Substring(index, index2 - index);
             * characterDefinition.yOffset = Cocos2D.CCUtils.CCParseInt(value.Replace("yoffset=", ""));
             *
             * // Character xadvance
             * index = line.IndexOf("xadvance=");
             * index2 = line.IndexOf(' ', index);
             * value = line.Substring(index, index2 - index);
             * characterDefinition.xAdvance = Cocos2D.CCUtils.CCParseInt(value.Replace("xadvance=", ""));
             */
        }
Esempio n. 3
0
        private List <int> ParseConfigFile(string pBuffer, string fntFile)
        {
            long nBufSize = pBuffer.Length;

            Debug.Assert(pBuffer != null, "CCBMFontConfiguration::parseConfigFile | Open file error.");

            if (string.IsNullOrEmpty(pBuffer))
            {
                return(null);
            }

            var validCharsString = new List <int>();

            // parse spacing / padding
            string line;
            string strLeft = pBuffer;

            while (strLeft.Length > 0)
            {
                int pos = strLeft.IndexOf('\n');

                if (pos != -1)
                {
                    // the data is more than a line.get one line
                    line    = strLeft.Substring(0, pos);
                    strLeft = strLeft.Substring(pos + 1);
                }
                else
                {
                    // get the left data
                    line    = strLeft;
                    strLeft = null;
                }

                if (line.StartsWith("info face"))
                {
                    // XXX: info parsing is incomplete
                    // Not needed for the Hiero editors, but needed for the AngelCode editor
                    //			[self parseInfoArguments:line];
                    parseInfoArguments(line);
                }

                // Check to see if the start of the line is something we are interested in
                else if (line.StartsWith("common lineHeight"))
                {
                    parseCommonArguments(line);
                }

                else if (line.StartsWith("page id"))
                {
                    parseImageFileName(line, fntFile);
                }

                else if (line.StartsWith("chars c"))
                {
                    // Ignore this line
                }
                else if (line.StartsWith("char"))
                {
                    // Parse the current line and create a new CharDef
                    var characterDefinition = new CCBMFontDef();
                    parseCharacterDefinition(line, characterDefinition);

                    m_pFontDefDictionary.Add(characterDefinition.charID, characterDefinition);

                    validCharsString.Add(characterDefinition.charID);
                }
                //else if (line.StartsWith("kernings count"))
                //{
                //    this.parseKerningCapacity(line);
                //}
                else if (line.StartsWith("kerning first"))
                {
                    parseKerningEntry(line);
                }
            }

            return(validCharsString);
        }
        private List<int> ParseConfigFile(string pBuffer, string fntFile)
        {
            long nBufSize = pBuffer.Length;

            Debug.Assert(pBuffer != null, "CCBMFontConfiguration::parseConfigFile | Open file error.");

            if (string.IsNullOrEmpty(pBuffer))
            {
                return null;
            }

            var validCharsString = new List<int>();

            // parse spacing / padding
            string line;
            string strLeft = pBuffer;
            while (strLeft.Length > 0)
            {
                int pos = strLeft.IndexOf('\n');

                if (pos != -1)
                {
                    // the data is more than a line.get one line
                    line = strLeft.Substring(0, pos);
                    strLeft = strLeft.Substring(pos + 1);
                }
                else
                {
                    // get the left data
                    line = strLeft;
                    strLeft = null;
                }

                if (line.StartsWith("info face"))
                {
                    // XXX: info parsing is incomplete
                    // Not needed for the Hiero editors, but needed for the AngelCode editor
                    //			[self parseInfoArguments:line];
                    parseInfoArguments(line);
                }

                    // Check to see if the start of the line is something we are interested in
                else if (line.StartsWith("common lineHeight"))
                {
                    parseCommonArguments(line);
                }

                else if (line.StartsWith("page id"))
                {
                    parseImageFileName(line, fntFile);
                }

                else if (line.StartsWith("chars c"))
                {
                    // Ignore this line
                }
                else if (line.StartsWith("char"))
                {
                    // Parse the current line and create a new CharDef
                    var characterDefinition = new CCBMFontDef();
                    parseCharacterDefinition(line, characterDefinition);

                    m_pFontDefDictionary.Add(characterDefinition.charID, characterDefinition);

                    validCharsString.Add(characterDefinition.charID);
                }
                //else if (line.StartsWith("kernings count"))
                //{
                //    this.parseKerningCapacity(line);
                //}
                else if (line.StartsWith("kerning first"))
                {
                    parseKerningEntry(line);
                }
            }

            return validCharsString;
        }
        private void parseCharacterDefinition(string line, CCBMFontDef characterDefinition)
        {
            //////////////////////////////////////////////////////////////////////////
            // line to parse:
            // char id=32   x=0     y=0     width=0     height=0     xoffset=0     yoffset=44    xadvance=14     page=0  chnl=0 
            //////////////////////////////////////////////////////////////////////////

            // Character ID
            int index = line.IndexOf("id=");
            int index2 = line.IndexOf(' ', index);
            string value = line.Substring(index, index2 - index);
            characterDefinition.charID = Cocos2D.CCUtils.CCParseInt(value.Replace("id=", ""));
            //CCAssert(characterDefinition->charID < kCCBMFontMaxChars, "BitmpaFontAtlas: CharID bigger than supported");

            // Character x
            index = line.IndexOf("x=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.rect.Origin.X = Cocos2D.CCUtils.CCParseFloat(value.Replace("x=", ""));

            // Character y
            index = line.IndexOf("y=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.rect.Origin.Y = Cocos2D.CCUtils.CCParseFloat(value.Replace("y=", ""));

            // Character width
            index = line.IndexOf("width=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.rect.Size.Width = Cocos2D.CCUtils.CCParseFloat(value.Replace("width=", ""));

            // Character height
            index = line.IndexOf("height=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.rect.Size.Height = Cocos2D.CCUtils.CCParseFloat(value.Replace("height=", ""));

            // Character xoffset
            index = line.IndexOf("xoffset=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.xOffset = Cocos2D.CCUtils.CCParseInt(value.Replace("xoffset=", ""));

            // Character yoffset
            index = line.IndexOf("yoffset=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.yOffset = Cocos2D.CCUtils.CCParseInt(value.Replace("yoffset=", ""));

            // Character xadvance
            index = line.IndexOf("xadvance=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.xAdvance = Cocos2D.CCUtils.CCParseInt(value.Replace("xadvance=", ""));
        }
        private void parseCharacterDefinition(string line, CCBMFontDef characterDefinition)
        {
            //////////////////////////////////////////////////////////////////////////
            // line to parse:
            // char id=32   x=0     y=0     width=0     height=0     xoffset=0     yoffset=44    xadvance=14     page=0  chnl=0 letter=\"f\"\r
            //////////////////////////////////////////////////////////////////////////

            StringBuilder sbuf = new StringBuilder();
            string token = null;
            string value = null;
            int mode = 0; // 0 = token, 1 = value, 2 = munger
            for (int i = 0; i < line.Length; i++)
            {
                char c = line[i];
                if (c == '=' && mode == 0)
                {
                    token = sbuf.ToString();
                    sbuf.Length = 0;
                    mode = 1; // expecting a value now
                }
                else if ((char.IsWhiteSpace(c) || i == (line.Length-1)) && mode == 1)
                {
                    // End of value, save it
                    value = sbuf.ToString();
                    sbuf.Length = 0;
                    mode = 2; // expecting to munge noise
                    // Process the token/value
                    switch (token)
                    {
                        case "char id":
                            characterDefinition.charID = Cocos2D.CCUtils.CCParseInt(value);
                            break;
                        case "x":
                            characterDefinition.rect.Origin.X = Cocos2D.CCUtils.CCParseFloat(value);
                            break;
                        case "y":
                            characterDefinition.rect.Origin.Y = Cocos2D.CCUtils.CCParseFloat(value);
                            break;
                        case "width":
                            characterDefinition.rect.Size.Width = Cocos2D.CCUtils.CCParseFloat(value);
                            break;
                        case "height":
                            characterDefinition.rect.Size.Height = Cocos2D.CCUtils.CCParseFloat(value);
                            break;
                        case "xoffset":
                            characterDefinition.xOffset = Cocos2D.CCUtils.CCParseInt(value);
                            break;
                        case "yoffset":
                            characterDefinition.yOffset = Cocos2D.CCUtils.CCParseInt(value);
                            break;
                        case "xadvance":
                            characterDefinition.xAdvance = Cocos2D.CCUtils.CCParseInt(value);
                            break;
                        case "page":
                            break;
                        case "chnl":
                            break;
                        case "letter":
                            break;
                    }
                }
                else if (mode == 2 && !char.IsWhiteSpace(c))
                {
                    mode = 0; // token time
                    sbuf.Append(c);
                }
                else if (mode == 0 || mode == 1)
                {
                    sbuf.Append(c);
                }
            }
            /*
            // Character ID
            int index = line.IndexOf("id=");
            int index2 = line.IndexOf(' ', index);
            string value = line.Substring(index, index2 - index);
            characterDefinition.charID = Cocos2D.CCUtils.CCParseInt(value.Replace("id=", ""));
            //CCAssert(characterDefinition->charID < kCCBMFontMaxChars, "BitmpaFontAtlas: CharID bigger than supported");

            // Character x
            index = line.IndexOf("x=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.rect.Origin.X = Cocos2D.CCUtils.CCParseFloat(value.Replace("x=", ""));

            // Character y
            index = line.IndexOf("y=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.rect.Origin.Y = Cocos2D.CCUtils.CCParseFloat(value.Replace("y=", ""));

            // Character width
            index = line.IndexOf("width=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.rect.Size.Width = Cocos2D.CCUtils.CCParseFloat(value.Replace("width=", ""));

            // Character height
            index = line.IndexOf("height=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.rect.Size.Height = Cocos2D.CCUtils.CCParseFloat(value.Replace("height=", ""));

            // Character xoffset
            index = line.IndexOf("xoffset=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.xOffset = Cocos2D.CCUtils.CCParseInt(value.Replace("xoffset=", ""));

            // Character yoffset
            index = line.IndexOf("yoffset=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.yOffset = Cocos2D.CCUtils.CCParseInt(value.Replace("yoffset=", ""));

            // Character xadvance
            index = line.IndexOf("xadvance=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.xAdvance = Cocos2D.CCUtils.CCParseInt(value.Replace("xadvance=", ""));
             */
        }