Load custom PNG fonts without the pipeline.

As charles said a font is basically a spritesheet aka a texture and a array or list of rectangles that describe were thing in it are like characters in that case you need a list of characters that match the rectangle indexes ect. So those are the things you need spritebatch also has kerning information.

You might find this helpful as a starting point.

This goes a step beyond and takes a regular spritefont you loaded thru the pipeline tears it down into its component parts into arrays of description data that also includes the image which it tears down into a byte array.

Then instead of writing that info to disk as a texture and description file. It writes it to disk in the format of c# class file but one that not only holds the data but the methods to reconstruct it into a spritefont, As if that resulting class was also a instruction class on how to make the spritefont from the data it also held onto. The writer sticks a .cs extension on the end of the text file and viola its a c# class.

However before you write it to disk everything is in its component parts and all the steps neccessary to take apart a spritefont and put one together are obviously there.

The only part that maybe a bit confusing is when i wrote the data to a class i sort of do a naive run length compression on the png byte array so there isn’t a page full of numbers.

The result is that the class file in the link at the bottom will actually create a sprite font from nothing as the class file is the instructions itself to create a spritefont and you just use it.

For example from the above this .cs is generated in this post.

I actually use this quite a bit cause i can just drag and drop it right into a project and call the below in loadcontent which is actually slightly quicker then going thru the pipeline tool.

myfont = new SpriteFontAsClassFile_TheSpriteFont_Tahoma().LoadHardCodeSpriteFont(GraphicsDevice);