I am trying to use the following example: http://www.faqstackoverflow.com/answered/using-a-bmp-image-as-font-in-monogame
The concept seems sound. I'm using a .fnt generated by the suggested tool. It looks properly formatted and makes sense based on the [Serialization] used in the classes.
However, Every time I run the code I get this error: "An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
Additional information: There is an error in XML document (1, 1)."
I have looked feverishly around StackExchange and google, and tried many things before coming here and posting my question. I have many of the messy leavings of those attempts still in the comments posted below inside the FontLoader class I am modifying to try to fix the issue. No matter how it is sliced, it gives the same error, or worse.
public class FontLoader
{
public static FontFile Load(String filename)
{
/* XmlSerializer deserializer = new XmlSerializer(typeof(FontFile));
TextReader textReader = new StreamReader(Encoding.UTF8.GetBytes(filename).ToString());
FontFile file = (FontFile)deserializer.Deserialize(textReader);
textReader.Close();
return file;*/
byte[] bytes = Encoding.UTF8.GetBytes(System.IO.File.ReadAllText(filename));
FontFile myInstance = null;
using (MemoryStream memStream = new MemoryStream(bytes))
{
XmlSerializer tokenSerializer = new XmlSerializer(typeof(FontFile));
myInstance = (FontFile)tokenSerializer.Deserialize(memStream);
Console.WriteLine(myInstance);
return myInstance;
}
/*
XmlSerializer deserializer = new XmlSerializer(typeof(FontFile));
TextReader textReader = new StreamReader(filename);
FontFile file = (FontFile)deserializer.Deserialize(textReader);
textReader.Close();
return file;*/
/* var xml = System.IO.File.ReadAllText(filename);
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
{
XmlSerializer serializer = new XmlSerializer(typeof(FontFile));
FontFile file = (FontFile)serializer.Deserialize(stream);
return file;
}*/
/* var writer = new StringWriter();
var serializer = new XmlSerializer((filename.GetType()));
serializer.Serialize(writer, filename);
string xml = writer.ToString();
return xml;*/
}
}
The font I'm using is Arial, as a test, so it should be ok to use. It starts out with these lines:
info face="Arial" size=32 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1 outline=0
common lineHeight=32 base=26 scaleW=256 scaleH=256 pages=1 packed=0 alphaChnl=1 redChnl=0 greenChnl=0 blueChnl=0
page id=0 file="arial_0.png"
chars count=191
char id=32 x=155 y=75 width=3 height=1 xoffset=-1 yoffset=31 xadvance=8 page=0 chnl=15
And then contineus with many "char" lines that have identical structure, followed by the kernings line, and then a bunce of "kerning" lines as below with identical structure to one another:
kernings count=91
kerning first=32 second=65 amount=-2
If it ends up being something wrong with the serialization, I apologize for positing, but I am not seeing it. Please let me know if anyone has a solution. Thank you.