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 void parseCharacterDefinition(string line, ccBMFontDef characterDefinition) { int num = line.IndexOf("id="); int num1 = line.IndexOf(' ', num); string str = line.Substring(num, num1 - num); characterDefinition.charID = ccUtils.ccParseInt(str.Replace("id=", "")); num = line.IndexOf("x="); num1 = line.IndexOf(' ', num); str = line.Substring(num, num1 - num); characterDefinition.rect.origin.x = ccUtils.ccParseFloat(str.Replace("x=", "")); num = line.IndexOf("y="); num1 = line.IndexOf(' ', num); str = line.Substring(num, num1 - num); characterDefinition.rect.origin.y = ccUtils.ccParseFloat(str.Replace("y=", "")); num = line.IndexOf("width="); num1 = line.IndexOf(' ', num); str = line.Substring(num, num1 - num); characterDefinition.rect.size.width = ccUtils.ccParseFloat(str.Replace("width=", "")); num = line.IndexOf("height="); num1 = line.IndexOf(' ', num); str = line.Substring(num, num1 - num); characterDefinition.rect.size.height = ccUtils.ccParseFloat(str.Replace("height=", "")); num = line.IndexOf("xoffset="); num1 = line.IndexOf(' ', num); str = line.Substring(num, num1 - num); characterDefinition.xOffset = ccUtils.ccParseInt(str.Replace("xoffset=", "")); num = line.IndexOf("yoffset="); num1 = line.IndexOf(' ', num); str = line.Substring(num, num1 - num); characterDefinition.yOffset = ccUtils.ccParseInt(str.Replace("yoffset=", "")); num = line.IndexOf("xadvance="); num1 = line.IndexOf(' ', num); str = line.Substring(num, num1 - num); characterDefinition.xAdvance = ccUtils.ccParseInt(str.Replace("xadvance=", "")); }
private void parseConfigFile(string controlFile) { CCContent data = CCApplication.sharedApplication().content.Load<CCContent>(controlFile); string pBuffer = data.Content; long nBufSize = data.Content.Length; Debug.Assert(pBuffer != null, "CCBMFontConfiguration::parseConfigFile | Open file error."); if (string.IsNullOrEmpty(pBuffer)) { return; } // 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]; this.parseInfoArguments(line); } // Check to see if the start of the line is something we are interested in if (line.StartsWith("common lineHeight")) { this.parseCommonArguments(line); } if (line.StartsWith("page id")) { this.parseImageFileName(line, controlFile); } if (line.StartsWith("chars c")) { // Ignore this line continue; } if (line.StartsWith("char")) { // Parse the current line and create a new CharDef ccBMFontDef characterDefinition = new ccBMFontDef(); this.parseCharacterDefinition(line, characterDefinition); // Add the CharDef returned to the charArray m_pBitmapFontArray.Add(characterDefinition.charID, characterDefinition); } if (line.StartsWith("kernings count")) { this.parseKerningCapacity(line); } if (line.StartsWith("kerning first")) { this.parseKerningEntry(line); } } }
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 = int.Parse(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 = float.Parse(value.Replace("x=", "")); // Character y index = line.IndexOf("y="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.rect.origin.y = float.Parse(value.Replace("y=", "")); // Character width index = line.IndexOf("width="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.rect.size.width = float.Parse(value.Replace("width=", "")); // Character height index = line.IndexOf("height="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.rect.size.height = float.Parse(value.Replace("height=", "")); // Character xoffset index = line.IndexOf("xoffset="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.xOffset = int.Parse(value.Replace("xoffset=", "")); // Character yoffset index = line.IndexOf("yoffset="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.yOffset = int.Parse(value.Replace("yoffset=", "")); // Character xadvance index = line.IndexOf("xadvance="); index2 = line.IndexOf(' ', index); value = line.Substring(index, index2 - index); characterDefinition.xAdvance = int.Parse(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; }
private void parseConfigFile(string controlFile) { CCContent data = CCApplication.sharedApplication().content.Load <CCContent>(controlFile); string pBuffer = data.Content; long nBufSize = data.Content.Length; Debug.Assert(pBuffer != null, "CCBMFontConfiguration::parseConfigFile | Open file error."); if (string.IsNullOrEmpty(pBuffer)) { return; } // parse spacing / padding string line; string strLeft = pBuffer; if (strLeft.StartsWith("<?xml")) { throw (new ArgumentException("FNT control file is XML, expecting it to be plain text.")); } // TDOO: Add an xml parser 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]; this.parseInfoArguments(line); } // Check to see if the start of the line is something we are interested in if (line.StartsWith("common lineHeight")) { this.parseCommonArguments(line); } if (line.StartsWith("page id")) { this.parseImageFileName(line, controlFile); } if (line.StartsWith("chars c")) { // Ignore this line continue; } if (line.StartsWith("char")) { // Parse the current line and create a new CharDef ccBMFontDef characterDefinition = new ccBMFontDef(); this.parseCharacterDefinition(line, characterDefinition); // Add the CharDef returned to the charArray m_pBitmapFontArray.Add(characterDefinition.charID, characterDefinition); } if (line.StartsWith("kernings count")) { this.parseKerningCapacity(line); } if (line.StartsWith("kerning first")) { this.parseKerningEntry(line); } } }
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 parseConfigFile(string controlFile) { string str; CCContent cCContent = CCApplication.sharedApplication().content.Load <CCContent>(controlFile); string content = cCContent.Content; int length = cCContent.Content.Length; if (string.IsNullOrEmpty(content)) { return; } string str1 = content; if (str1.StartsWith("<?xml")) { throw new ArgumentException("FNT control file is XML, expecting it to be plain text."); } while (str1.Length > 0) { int num = str1.IndexOf('\n'); if (num == -1) { str = str1; str1 = null; } else { str = str1.Substring(0, num); str1 = str1.Substring(num + 1); } if (str.StartsWith("info face")) { this.parseInfoArguments(str); } if (str.StartsWith("common lineHeight")) { this.parseCommonArguments(str); } if (str.StartsWith("page id")) { this.parseImageFileName(str, controlFile); } if (str.StartsWith("chars c")) { continue; } if (str.StartsWith("char")) { ccBMFontDef _ccBMFontDef = new ccBMFontDef(); this.parseCharacterDefinition(str, _ccBMFontDef); this.m_pBitmapFontArray.Add(_ccBMFontDef.charID, _ccBMFontDef); } if (str.StartsWith("kernings count")) { this.parseKerningCapacity(str); } if (!str.StartsWith("kerning first")) { continue; } this.parseKerningEntry(str); } }
public void createFontChars() { int item = 0; int mUCommonHeight = 0; int num = -1; int num1 = 0; CCSize cCSize = new CCSize(0f, 0f); int num2 = 0; int mUCommonHeight1 = 0; int num3 = 1; int length = this.m_sString.Length; if (length == 0) { return; } for (int i = 0; i < length - 1; i++) { if (this.m_sString[i] == 10) { num3++; } } mUCommonHeight1 = this.m_pConfiguration.m_uCommonHeight * num3; mUCommonHeight = -(this.m_pConfiguration.m_uCommonHeight - this.m_pConfiguration.m_uCommonHeight * num3); for (int j = 0; j < length; j++) { int mSString = this.m_sString[j]; if ((long)mSString >= (long)2048) { object[] objArray = new object[] { "LabelBMFont: character ", this.m_sString[j], " outside of max font characters, which is ", (uint)2048 }; throw new ArgumentException(string.Concat(objArray)); } if (mSString != 10) { num1 = this.kerningAmountForFirst(num, mSString); if (!this.m_pConfiguration.m_pBitmapFontArray.ContainsKey(mSString)) { throw new ArgumentException(string.Concat("Character ", mSString, " in LabelBMFont is not in the font definition.")); } ccBMFontDef _ccBMFontDef = this.m_pConfiguration.m_pBitmapFontArray[mSString]; CCRect cCRect = _ccBMFontDef.rect; CCSprite childByTag = (CCSprite)base.getChildByTag(j); if (childByTag != null) { childByTag.setTextureRectInPixels(cCRect, false, cCRect.size); childByTag.visible = true; childByTag.Opacity = 255; } else { childByTag = new CCSprite(); childByTag.initWithBatchNodeRectInPixels(this, cCRect); this.addChild(childByTag, 0, j); } float single = (float)(this.m_pConfiguration.m_uCommonHeight - _ccBMFontDef.yOffset); childByTag.positionInPixels = new CCPoint((float)(item + _ccBMFontDef.xOffset) + _ccBMFontDef.rect.size.width / 2f + (float)num1, (float)mUCommonHeight + single - cCRect.size.height / 2f); item = item + this.m_pConfiguration.m_pBitmapFontArray[mSString].xAdvance + num1; num = mSString; childByTag.IsOpacityModifyRGB = this.m_bIsOpacityModifyRGB; childByTag.Color = this.m_tColor; if (this.m_cOpacity != 255) { childByTag.Opacity = this.m_cOpacity; } if (num2 < item) { num2 = item; } } else { item = 0; mUCommonHeight = mUCommonHeight - this.m_pConfiguration.m_uCommonHeight; } } cCSize.width = (float)num2; cCSize.height = (float)mUCommonHeight1; base.contentSizeInPixels = cCSize; }
/// <summary> /// updates the font chars based on the string to render /// </summary> public void createFontChars() { int nextFontPositionX = 0; int nextFontPositionY = 0; int prev = -1; int kerningAmount = 0; CCSize tmpSize = new CCSize(0, 0); int longestLine = 0; int totalHeight = 0; int quantityOfLines = 1; int stringLen = m_sString.Length; if (0 == stringLen) { return; } for (int i = 0; i < stringLen - 1; ++i) { ushort c = m_sString[i]; if (c == '\n') { quantityOfLines++; } } totalHeight = m_pConfiguration.m_uCommonHeight * quantityOfLines; nextFontPositionY = -(m_pConfiguration.m_uCommonHeight - m_pConfiguration.m_uCommonHeight * quantityOfLines); for (int i = 0; i < stringLen; i++) { int c = m_sString[i]; if (c >= kCCBMFontMaxChars) { throw (new ArgumentException("LabelBMFont: character " + m_sString[i] + " outside of max font characters, which is " + kCCBMFontMaxChars)); } if (c == '\n') { nextFontPositionX = 0; nextFontPositionY -= (int)m_pConfiguration.m_uCommonHeight; continue; } kerningAmount = this.kerningAmountForFirst(prev, c); if (!m_pConfiguration.m_pBitmapFontArray.ContainsKey(c)) { throw(new ArgumentException("Character " + c + " in LabelBMFont is not in the font definition.")); } ccBMFontDef fontDef = m_pConfiguration.m_pBitmapFontArray[c]; CCRect rect = fontDef.rect; CCSprite fontChar = (CCSprite)(this.getChildByTag(i)); if (fontChar == null) { fontChar = new CCSprite(); fontChar.initWithBatchNodeRectInPixels(this, rect); this.addChild(fontChar, 0, i); } else { // reusing fonts //fontChar = new CCSprite(); fontChar.setTextureRectInPixels(rect, false, rect.size); // restore to default in case they were modified fontChar.visible = true; fontChar.Opacity = 255; } float yOffset = (float)(m_pConfiguration.m_uCommonHeight - fontDef.yOffset); fontChar.positionInPixels = (new CCPoint(nextFontPositionX + fontDef.xOffset + fontDef.rect.size.width / 2.0f + kerningAmount, (float)nextFontPositionY + yOffset - rect.size.height / 2.0f)); // NSLog(@"position.y: %f", fontChar.position.y); // update kerning nextFontPositionX += m_pConfiguration.m_pBitmapFontArray[c].xAdvance + kerningAmount; prev = c; // Apply label properties fontChar.IsOpacityModifyRGB = m_bIsOpacityModifyRGB; // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on fontChar.Color = m_tColor; // only apply opaccity if it is different than 255 ) // to prevent modifying the color too (issue #610) if (m_cOpacity != 255) { fontChar.Opacity = m_cOpacity; } if (longestLine < nextFontPositionX) { longestLine = nextFontPositionX; } } tmpSize.width = (float)longestLine; tmpSize.height = (float)totalHeight; this.contentSizeInPixels = tmpSize; }