bmGlyph Fonts & AngelFont

I recently decided to use AngelFont for font rendering duties in Monkey projects. One of the bitmap font creation tools recommended is bmGlyph so I was a bit miffed to find that it doesn't actually seem to export to any formats that AngelFont can just read.

Anyway, comparing some of the example font definitions that came with AngelFont with some of the exports from bmGlyph made it clear that the formats even more similar than you would expect – right down to the order of the various bits of information! Hence it wasn't too difficult to hack a bit of code together that takes a Cocos2D / BMFont / Coronna format *.fnt export from bmGlyph and spits out a *.txt file that AngelFont can load with LoadFont().

Note that it's written in BlitzMax, not Monkey. Hope it's useful!

' CoronnaToAngel ' ============ ' Converts Coronna/Cocos2D/BMFont *.fnt exports from bmGlyph to a *.txt format that AngelFont ' can parse with LoadFont(). Framework BRL.System Import BRL.Retro SuperStrict Const DEBUG_LOG:Int = False Local fileName:String = "" If AppArgs.length = 2 fileName = AppArgs[1] Else fileName = RequestFile("CoronnaToAngel: Select fnt file","Fnt Files:fnt",False,AppDir$) EndIf If (fileName="") Or (Not(Right$(fileName,4)=".fnt")) End Local bank:TBank = LoadBank(fileName) Local stream:TStream = CreateBankStream(bank) While Not Eof(stream) Local currentLine:String = ReadLine(stream) If Left$(currentLine,7) = "char id" currentLine = Right$(currentLine,Len(currentLine)-5) DLog ("Adding: "+currentLine) AddLine(currentLine) EndIf Wend For Local currentLine:TLine = EachIn Tline.lineList currentLine.components = currentLine.text.Split(" ") Local index:Int = 0 For Local currentComponent:String = EachIn currentLine.components Local pair:String[] = currentComponent.Split("=") currentLine.components[index] = pair[1] index = index+1 DLog (currentComponent) Next Next Local file:TStream=WriteFile( Left(fileName,Len(fileName)-4) + ".txt" ) WriteLine file,"id,x,y,width,height,xoffset,yoffset,xadvance,page,chnl" For Local currentLine:TLine = EachIn Tline.lineList Local output:String = "" For Local currentComponent:String = EachIn currentLine.components output = output+currentComponent+"," Next output = Left$(output,Len(output)-1) WriteLine file,output Next Type TLine Global lineList:TList = CreateList() Field text:String Field components:String[] Function AddLine(text_arg:String) Local newLine:TLine = New TLine newLine.text = text_arg ListAddLast lineList,newLine End Function End Type Function AddLine(text_arg:String) TLine.AddLine(text_arg) End Function Function DLog(text_arg:String) If DEBUG_LOG Print text_arg End Function

EDIT (12/01/14): When I mentioned this over at the Monkey community forums Nobuyuki, who maintains a fork of AngelFont, leapt into action and added the ability to load BMFont format exports from bmGlyph with his fork's LoadPlain() method. He's added a couple of other fixes too so give it a look:

<< Go back to the previous page