private void parseCharacterDefinition(string line, CCBMGlyphDef 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.Character = CocosSharp.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.Subrect.Origin.X = CocosSharp.CCUtils.CCParseFloat(value.Replace("x=", "")); // Character y index = line.IndexOf("y="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.Subrect.Origin.Y = CocosSharp.CCUtils.CCParseFloat(value.Replace("y=", "")); // Character width index = line.IndexOf("width="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.Subrect.Size.Width = CocosSharp.CCUtils.CCParseFloat(value.Replace("width=", "")); // Character height index = line.IndexOf("height="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.Subrect.Size.Height = CocosSharp.CCUtils.CCParseFloat(value.Replace("height=", "")); // Character xoffset index = line.IndexOf("xoffset="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.XOffset = CocosSharp.CCUtils.CCParseInt(value.Replace("xoffset=", "")); // Character yoffset index = line.IndexOf("yoffset="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.YOffset = CocosSharp.CCUtils.CCParseInt(value.Replace("yoffset=", "")); // Character xadvance index = line.IndexOf("xadvance="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.XAdvance = CocosSharp.CCUtils.CCParseInt(value.Replace("xadvance=", "")); }
private List<int> ParseConfigFile(string pBuffer, string fntFile) { Debug.Assert(pBuffer != null, "CCBMFontConfiguration::parseConfigFile | Open file error."); long nBufSize = pBuffer.Length; 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 CCBMGlyphDef(); parseCharacterDefinition(line, characterDefinition); Glyphs.Add(characterDefinition.Character, characterDefinition); validCharsString.Add(characterDefinition.Character); } //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 CCBMGlyphDef(); parseCharacterDefinition(line, characterDefinition); Glyphs.Add(characterDefinition.Character, characterDefinition); validCharsString.Add(characterDefinition.Character); } //else if (line.StartsWith("kernings count")) //{ // this.parseKerningCapacity(line); //} else if (line.StartsWith("kerning first")) { parseKerningEntry(line); } } return(validCharsString); }