Example #1
0
 public CCBMFontConfiguration(cocos2d.CCBMFontConfiguration fnt)
 {
     AtlasName         = fnt.AtlasName;
     m_nCommonHeight   = fnt.m_nCommonHeight;
     m_tPadding.bottom = fnt.m_tPadding.bottom;
     m_tPadding.top    = fnt.m_tPadding.top;
     m_tPadding.left   = fnt.m_tPadding.left;
     m_tPadding.right  = fnt.m_tPadding.right;
     foreach (int key in fnt.m_pKerningDictionary.Keys)
     {
         tKerningHashElement tk;
         tk.key    = fnt.m_pKerningDictionary[key].key;
         tk.amount = fnt.m_pKerningDictionary[key].amount;
         m_pKerningDictionary[key] = tk;
     }
     foreach (int key in fnt.m_pFontDefDictionary.Keys)
     {
         ccBMFontDef tk = new ccBMFontDef();
         tk.charID                 = fnt.m_pFontDefDictionary[key].charID;
         tk.rect.Origin.X          = fnt.m_pFontDefDictionary[key].rect.Origin.X;
         tk.rect.Origin.Y          = fnt.m_pFontDefDictionary[key].rect.Origin.Y;
         tk.rect.Size.Width        = fnt.m_pFontDefDictionary[key].rect.Size.Width;
         tk.rect.Size.Height       = fnt.m_pFontDefDictionary[key].rect.Size.Height;
         tk.xAdvance               = fnt.m_pFontDefDictionary[key].xAdvance;
         tk.xOffset                = fnt.m_pFontDefDictionary[key].xOffset;
         tk.yOffset                = fnt.m_pFontDefDictionary[key].yOffset;
         m_pFontDefDictionary[key] = tk;
     }
 }
Example #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
            //////////////////////////////////////////////////////////////////////////

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

            characterDefinition.charID = 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 = 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 = 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 = 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 = CCUtils.CCParseFloat(value.Replace("height=", ""));

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

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

            // Character xadvance
            index  = line.IndexOf("xadvance=");
            index2 = line.IndexOf(' ', index);
            value  = line.Substring(index, index2 - index);
            characterDefinition.xAdvance = CCUtils.CCParseInt(value.Replace("xadvance=", ""));
        }
Example #3
0
        private bool ParseConfigFile(string pBuffer, string fntFile)
        {
            long nBufSize = pBuffer.Length;

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

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

            // 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);
                }
                //else if (line.StartsWith("kernings count"))
                //{
                //    this.parseKerningCapacity(line);
                //}
                else if (line.StartsWith("kerning first"))
                {
                    parseKerningEntry(line);
                }
            }

            return(true);
        }
        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 = 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 = 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 = 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 = 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 = CCUtils.CCParseFloat(value.Replace("height=", ""));

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

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

            // Character xadvance
            index = line.IndexOf("xadvance=");
            index2 = line.IndexOf(' ', index);
            value = line.Substring(index, index2 - index);
            characterDefinition.xAdvance = CCUtils.CCParseInt(value.Replace("xadvance=", ""));
        }
        private bool ParseConfigFile(string pBuffer, string fntFile)
        {
            long nBufSize = pBuffer.Length;

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

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

            // 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);
                }
                    //else if (line.StartsWith("kernings count"))
                    //{
                    //    this.parseKerningCapacity(line);
                    //}
                else if (line.StartsWith("kerning first"))
                {
                    parseKerningEntry(line);
                }
            }

            return true;
        }
 public CCBMFontConfiguration(cocos2d.CCBMFontConfiguration fnt)
 {
     AtlasName = fnt.AtlasName;
     m_nCommonHeight = fnt.m_nCommonHeight;
     m_tPadding.bottom = fnt.m_tPadding.bottom;
     m_tPadding.top = fnt.m_tPadding.top;
     m_tPadding.left = fnt.m_tPadding.left;
     m_tPadding.right = fnt.m_tPadding.right;
     foreach (int key in fnt.m_pKerningDictionary.Keys)
     {
         tKerningHashElement tk;
         tk.key = fnt.m_pKerningDictionary[key].key;
         tk.amount = fnt.m_pKerningDictionary[key].amount;
         m_pKerningDictionary[key] = tk;
     }
     foreach (int key in fnt.m_pFontDefDictionary.Keys)
     {
         ccBMFontDef tk = new ccBMFontDef();
         tk.charID = fnt.m_pFontDefDictionary[key].charID;
         tk.rect.Origin.X = fnt.m_pFontDefDictionary[key].rect.Origin.X;
         tk.rect.Origin.Y = fnt.m_pFontDefDictionary[key].rect.Origin.Y;
         tk.rect.Size.Width = fnt.m_pFontDefDictionary[key].rect.Size.Width;
         tk.rect.Size.Height = fnt.m_pFontDefDictionary[key].rect.Size.Height;
         tk.xAdvance = fnt.m_pFontDefDictionary[key].xAdvance;
         tk.xOffset = fnt.m_pFontDefDictionary[key].xOffset;
         tk.yOffset = fnt.m_pFontDefDictionary[key].yOffset;
         m_pFontDefDictionary[key] = tk;
     }
 }