public GLFontData LoadGLFont(string a_szFontDataFile) { // safty checks: if (a_szFontDataFile == null) { return(null); } else if (a_szFontDataFile == "") { return(null); } // next we see if this string has been gend already: GLFontData oFontData; if (m_dicGLFonts.TryGetValue(a_szFontDataFile, out oFontData)) { oFontData.m_uiUseCount++; return(oFontData); } oFontData = new GLFontData(); // We have not loaded the font before so, set up new one: oFontData.m_szDataFile = a_szFontDataFile; // Set Data File path. oFontData.m_uiUseCount = 1; // Create some Working Vars and Buffers: string szTextureFile = ""; string szBuffer; char cBuffer = ' '; // first load in XML file. XmlTextReader oXMLReader = new XmlTextReader(a_szFontDataFile); try { // Get Texture path: if (oXMLReader.ReadToNextSibling("Font")) // works on windows. { szTextureFile = oXMLReader.GetAttribute("texture"); } else if (oXMLReader.ReadToDescendant("Font")) // works on linux! { szTextureFile = oXMLReader.GetAttribute("texture"); } else { #if LOG4NET_ENABLED logger.Error("Couldn't find texture path for " + a_szFontDataFile); #endif } // Move to first Charecter element oXMLReader.ReadToDescendant("Character"); // Loop through all Char elements and get out UV coords for each charcter, save them to the Dic. do { /// <summary> /// All of the System.Globalization stuff is due ot the fact that the default float.TryParse behaves differently on different computers. thanks microsoft. /// </summary> GLFontData.UVCoords oUVCoords = new GLFontData.UVCoords(); System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US"); float minX = 0.0f, minY = 0.0f, maxX = 0.0f, maxY = 0.0f; szBuffer = oXMLReader.GetAttribute("Umin"); bool r1 = float.TryParse(szBuffer, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out minX); //bool r1 = float.TryParse(szBuffer, out minX); szBuffer = oXMLReader.GetAttribute("Umax"); bool r2 = float.TryParse(szBuffer, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out maxX); //bool r2 = float.TryParse(szBuffer, out maxX); szBuffer = oXMLReader.GetAttribute("Vmin"); bool r3 = float.TryParse(szBuffer, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out minY); //bool r3 = float.TryParse(szBuffer, out minY); szBuffer = oXMLReader.GetAttribute("Vmax"); bool r4 = float.TryParse(szBuffer, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out maxY); //bool r4 = float.TryParse(szBuffer, out maxY); oUVCoords.m_v2UVMin.X = minX; oUVCoords.m_v2UVMax.X = maxX; oUVCoords.m_v2UVMin.Y = minY; oUVCoords.m_v2UVMax.Y = maxY; szBuffer = oXMLReader.GetAttribute("Char"); foreach (char c in szBuffer) { cBuffer = c; } oFontData.m_dicCharMap.Add(cBuffer, oUVCoords); if (r1 == false || r2 == false || r3 == false || r4 == false) { #if LOG4NET_ENABLED logger.Info("ResourceManager.cs Char: " + szBuffer + " Coordinates: " + oUVCoords.m_v2UVMin.X + "/" + oUVCoords.m_v2UVMin.Y + "," + oUVCoords.m_v2UVMax.X + "/" + oUVCoords.m_v2UVMax.Y + "|" + r1 + " " + r2 + " " + r3 + " " + r4); #endif } } while (oXMLReader.ReadToNextSibling("Character")); // Move to Next Charcter Element #if LOG4NET_ENABLED logger.Info("Loaded GLFont Data File " + a_szFontDataFile); #endif } catch (XmlException e) { // XML Error occured, catch and log. #if LOG4NET_ENABLED logger.Error("Error: faild to load Font Data file " + a_szFontDataFile); logger.Error("Font Exception: " + e.Message); logger.Info("You May have an unsupported Charcter in thoe font data file, inclundg <, >, &"); #endif } finally { // Close the XMl file. oXMLReader.Close(); } // load font texture. oFontData.m_uiTextureID = ResourceManager.Instance.LoadTexture(szTextureFile); // Add to list of loaded fonts: m_dicGLFonts.Add(oFontData.m_szDataFile, oFontData); return(oFontData); }
public GLFontData LoadGLFont(string a_szFontDataFile) { // safty checks: if (a_szFontDataFile == null) { return null; } else if (a_szFontDataFile == "") { return null; } // next we see if this string has been gend already: GLFontData oFontData; if (m_dicGLFonts.TryGetValue(a_szFontDataFile, out oFontData)) { oFontData.m_uiUseCount++; return oFontData; } oFontData = new GLFontData(); // We have not loaded the font before so, set up new one: oFontData.m_szDataFile = a_szFontDataFile; // Set Data File path. oFontData.m_uiUseCount = 1; // Create some Working Vars and Buffers: string szTextureFile = ""; string szBuffer; char cBuffer = ' '; // first load in XML file. XmlTextReader oXMLReader = new XmlTextReader(a_szFontDataFile); try { // Get Texture path: if (oXMLReader.ReadToNextSibling("Font")) // works on windows. { szTextureFile = oXMLReader.GetAttribute("texture"); } else if (oXMLReader.ReadToDescendant("Font")) // works on linux! { szTextureFile = oXMLReader.GetAttribute("texture"); } else { #if LOG4NET_ENABLED logger.Error("Couldn't find texture path for " + a_szFontDataFile); #endif } // Move to first Charecter element oXMLReader.ReadToDescendant("Character"); // Loop through all Char elements and get out UV coords for each charcter, save them to the Dic. do { /// <summary> /// All of the System.Globalization stuff is due ot the fact that the default float.TryParse behaves differently on different computers. thanks microsoft. /// </summary> GLFontData.UVCoords oUVCoords = new GLFontData.UVCoords(); System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US"); float minX = 0.0f, minY = 0.0f, maxX = 0.0f, maxY = 0.0f; szBuffer = oXMLReader.GetAttribute("Umin"); bool r1 = float.TryParse(szBuffer, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out minX); //bool r1 = float.TryParse(szBuffer, out minX); szBuffer = oXMLReader.GetAttribute("Umax"); bool r2 = float.TryParse(szBuffer, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out maxX); //bool r2 = float.TryParse(szBuffer, out maxX); szBuffer = oXMLReader.GetAttribute("Vmin"); bool r3 = float.TryParse(szBuffer, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out minY); //bool r3 = float.TryParse(szBuffer, out minY); szBuffer = oXMLReader.GetAttribute("Vmax"); bool r4 = float.TryParse(szBuffer, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out maxY); //bool r4 = float.TryParse(szBuffer, out maxY); oUVCoords.m_v2UVMin.X = minX; oUVCoords.m_v2UVMax.X = maxX; oUVCoords.m_v2UVMin.Y = minY; oUVCoords.m_v2UVMax.Y = maxY; szBuffer = oXMLReader.GetAttribute("Char"); foreach (char c in szBuffer) { cBuffer = c; } oFontData.m_dicCharMap.Add(cBuffer, oUVCoords); if (r1 == false || r2 == false || r3 == false || r4 == false) { #if LOG4NET_ENABLED logger.Info("ResourceManager.cs Char: " + szBuffer + " Coordinates: " + oUVCoords.m_v2UVMin.X + "/" + oUVCoords.m_v2UVMin.Y + "," + oUVCoords.m_v2UVMax.X + "/" + oUVCoords.m_v2UVMax.Y + "|" + r1 + " " + r2 + " " + r3 + " " + r4); #endif } } while (oXMLReader.ReadToNextSibling("Character")); // Move to Next Charcter Element #if LOG4NET_ENABLED logger.Info("Loaded GLFont Data File " + a_szFontDataFile); #endif } catch (XmlException e) { // XML Error occured, catch and log. #if LOG4NET_ENABLED logger.Error("Error: faild to load Font Data file " + a_szFontDataFile); logger.Error("Font Exception: " + e.Message); logger.Info("You May have an unsupported Charcter in thoe font data file, inclundg <, >, &"); #endif } finally { // Close the XMl file. oXMLReader.Close(); } // load font texture. oFontData.m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(szTextureFile); // Add to list of loaded fonts: if (!m_dicGLFonts.ContainsKey(oFontData.m_szDataFile)){ m_dicGLFonts.Add(oFontData.m_szDataFile, oFontData); } return oFontData; }
public GLFontData LoadGLFont(string a_szFontDataFile) { // safty checks: if (a_szFontDataFile == null) { return(null); } else if (a_szFontDataFile == "") { return(null); } // next we see if this string has been gend already: GLFontData oFontData; if (m_dicGLFonts.TryGetValue(a_szFontDataFile, out oFontData)) { oFontData.m_uiUseCount++; return(oFontData); } oFontData = new GLFontData(); // We have not loaded the font before so, set up new one: oFontData.m_szDataFile = a_szFontDataFile; // Set Data File path. oFontData.m_uiUseCount = 1; // Create some Working Vars and Buffers: string szTextureFile = ""; string szBuffer; char cBuffer = ' '; // first load in XML file. XmlTextReader oXMLReader = new XmlTextReader(a_szFontDataFile); try { // Get Texture path: if (oXMLReader.ReadToNextSibling("Font")) // works on windows. { szTextureFile = oXMLReader.GetAttribute("texture"); } else if (oXMLReader.ReadToDescendant("Font")) // works on linux! { szTextureFile = oXMLReader.GetAttribute("texture"); } // Move to first Charecter element oXMLReader.ReadToDescendant("Character"); // Loop through all Char elements and get out UV coords for each charcter, save them to the Dic. do { GLFontData.UVCoords oUVCoords = new GLFontData.UVCoords(); szBuffer = oXMLReader.GetAttribute("Umin"); float.TryParse(szBuffer, out oUVCoords.m_v2UVMin.X); szBuffer = oXMLReader.GetAttribute("Vmin"); float.TryParse(szBuffer, out oUVCoords.m_v2UVMin.Y); szBuffer = oXMLReader.GetAttribute("Umax"); float.TryParse(szBuffer, out oUVCoords.m_v2UVMax.X); szBuffer = oXMLReader.GetAttribute("Vmax"); float.TryParse(szBuffer, out oUVCoords.m_v2UVMax.Y); szBuffer = oXMLReader.GetAttribute("Char"); foreach (char c in szBuffer) { cBuffer = c; } oFontData.m_dicCharMap.Add(cBuffer, oUVCoords); } while (oXMLReader.ReadToNextSibling("Character")); // Move to Next Charcter Element logger.Info("Loaded GLFont Data File " + a_szFontDataFile); } catch (XmlException e) { // XML Error occured, catch and log. logger.Error("Error: faild to load Font Data file " + a_szFontDataFile); logger.Error("Font Exception: " + e.Message); logger.Info("You May have an unsupported Charcter in thoe font data file, inclundg <, >, &"); } finally { // Close the XMl file. oXMLReader.Close(); } // load font texture. oFontData.m_uiTextureID = Helpers.ResourceManager.Instance.LoadTexture(szTextureFile); // Add to list of loaded fonts: m_dicGLFonts.Add(oFontData.m_szDataFile, oFontData); return(oFontData); }