Bitmap font

I use Angle Code’s BMFont tool on Windows machines. Works fine.

http://www.angelcode.com/products/bmfont [import]uid: 16734 topic_id: 6060 reply_id: 109128[/import]

Thank you so much! [import]uid: 120808 topic_id: 6060 reply_id: 111098[/import]

Just getting into BM fonts. I just purchased bmGlyph for the mac as I tried bmfont for the PC and had mixed results. bmGlyph is way better and well worth the $10. I also own Text Candy and have some crash issues when using bitmap fonts but that is for another discussion, but that led me to this thread…

I have read this thread a few times … I am really confused on how to get the latest version of BMF.lua . It seems to be posted a few times on this thread, each time with a custom tweek and there is no version history in the code. This should also be hosted on something like Github.

Am I to assume I can just use the last post of the full code ?

thanks

Ken
[import]uid: 112538 topic_id: 6060 reply_id: 113679[/import]

Hey, sorry I’ve been absent from this thread for so long (though I have been lurking via subscribed emails).
Yes, I do plan to push this onto github when I get a chance, but I would want to go back and test it with some of the newer versions of Corona first.
This thread is currently the closest thing to an authoritative “newest version” that there is, so go ahead and try the posted versions and let us know how it works for you. [import]uid: 32962 topic_id: 6060 reply_id: 113682[/import]

one year later I can say: THIS IS ONE OF THE COOLEST PIECES OF CODE I’VE GOT

Any way to center justify the text?

one year later I can say: THIS IS ONE OF THE COOLEST PIECES OF CODE I’VE GOT

Any way to center justify the text?

In case it helps anyone reading this thread, we have just added an example Corona project to our support pages that uses the latest version of bmf.lua we could fine and the latest SDK to render fonts generated in Glyph Designer.

http://tinyurl.com/ozs2lkb

Mike

i’ve updated bmGlyph in order to produce a lua font file definition, and also made some changes on the bmf.lua:

  • it now only uses the graphics engine 2.0 (you don’t need anymore the sprite.lua and v1 compatibility)

  • fully support of unicode chars

available here: https://github.com/tapouillo/bmf2—bitmap-font-for-Corona-graphics-2.0

In case it helps anyone reading this thread, we have just added an example Corona project to our support pages that uses the latest version of bmf.lua we could fine and the latest SDK to render fonts generated in Glyph Designer.

http://tinyurl.com/ozs2lkb

Mike

I’ve done my own version (free) which runs under 2.0 and works with Glyph Designer - http://coronadev.blogspot.co.uk/2014/05/think-it-can-go-out-now.html which does bendy text and animated text and so on. There’s a very simple demo at https://github.com/autismuk/Font-Demo

i’ve updated bmGlyph in order to produce a lua font file definition, and also made some changes on the bmf.lua:

  • it now only uses the graphics engine 2.0 (you don’t need anymore the sprite.lua and v1 compatibility)

  • fully support of unicode chars

available here: https://github.com/tapouillo/bmf2—bitmap-font-for-Corona-graphics-2.0

I’ve done my own version (free) which runs under 2.0 and works with Glyph Designer - http://coronadev.blogspot.co.uk/2014/05/think-it-can-go-out-now.html which does bendy text and animated text and so on. There’s a very simple demo at https://github.com/autismuk/Font-Demo

In case this would be useful for anyone else, I added the ability to tint text to any desired color. This works especially well if your bitmap font texture file consists of white letters over a transparent background:

-- Pass a font object (obtained from loadFont) and a string to render -- Return value is a DisplayObject of the rendered string -- object.font can be read/modifed -- object.text can be read/modified -- object.align can be read/modified - left/right/center (multiline not yet fully supported for non-left) -- object.tint can be read/modified - SPACEWOLF -- object.input( function(text), { filter = function(), max = 32 } ) -- turns the object into a text input. -- the callback is hit when the user presses "return" or the field losed focus. -- this code is under development - more documentation will be added soon... function newString( font, text, newsize) --local finalScale = 100/origsize \*newsize/100; local finalScale = 100/font.info.size \*newsize/100; local obj = display.newGroup() accessorize( obj ) removerize( obj ) obj.set\_font = function( t, k, v ) obj.raw\_font = v if t.text then t.text = t.text end end -- Set the alignment of the object obj.set\_align = function( t, k, v ) local w = t.textWidth if t.raw\_align == 'right' then for i = 1, t.numChildren do t[i].x = t[i].x + w end elseif t.raw\_align == 'center' then for i = 1, t.numChildren do t[i].x = t[i].x + math.floor( w \* 0.5 ) end end t.raw\_align = v if t.raw\_align == 'right' then for i = 1, t.numChildren do t[i].x = t[i].x - w end elseif t.raw\_align == 'center' then for i = 1, t.numChildren do t[i].x = t[i].x - math.floor( w \* 0.5 ) end elseif t.raw\_align ~= 'left' then t.raw\_align = 'left' end end -- Set the text for the object obj.set\_text = function( t, k, v ) if ( v == t.raw\_text ) then return end t.raw\_text = v for i = t.numChildren, 1, -1 do t[i]:removeSelf() end local oldAlign = ( t.align or 'left' ) local oldTint = ( t.tint or {0, 0, 0, 0} ) t.align = 'left' local x = 0; local y = 0 local last = ''; local xMax = 0; local yMax = 0 if t.raw\_font then for c in string.gmatch( t.raw\_text..'\n', '(.)' ) do if c == '\n' then x = 0; y = y + t.raw\_font.info.lineHeight if y \>= yMax then yMax = y end elseif t.raw\_font.chars[c] then local rfc = t.raw\_font.chars[c] if 0 + t.raw\_font.chars[c].width \> 0 and 0 + t.raw\_font.chars[c].height \> 0 then local letter = sprite.newSprite( t.raw\_font.sprites[c] ) if t.raw\_font.kernings[last .. c] then x = x + font.kernings[last .. c] end t:insert( letter ) letter.anchorX = 0 letter.anchorY = 0 letter.x = t.raw\_font.chars[c].xoffset + x letter.y = t.raw\_font.chars[c].yoffset - t.raw\_font.info.base + y last = c end --x = x + t.raw\_font.chars[c].xadvance x = x + t.raw\_font.chars[c].xadvance + (t.raw\_font.info.outline or 0) --CLF added support for outlines if x \>= xMax then xMax = x end end end obj.textWidth = xMax end t.align = oldAlign t.tint = oldTint end -- set the tint of the object obj.set\_tint = function( t, k, v ) t.raw\_tint = v for i = t.numChildren, 1, -1 do if v[4] then t[i]:setFillColor(v[1],v[2],v[3],v[4]) else t[i]:setFillColor(v[1],v[2],v[3]) end end end obj.input = function( f, args ) -- spawn the text field invisibly local field -- Handle character insertion/deletion local function char() -- check if any character has been added or deleted if field.text ~= '--' then if string.len( field.text ) \< 2 then -- backspace was pressed if string.len( obj.text ) \> 0 then obj.text = string.sub( obj.text, 1, -2 ) end else -- some other key was pressed obj.text = obj.text..string.sub( field.text, 3 ) end field.text = '--' if args.filter then obj.text = string.sub( args.filter( obj.text ), 1, (args.max or 32) ) else obj.text = string.sub( obj.text, 1, (args.max or 32) ) end end end Runtime:addEventListener( 'enterFrame', char ) -- Handle the "done" phase local function done( e ) if e.phase == 'submitted' or e.phase == 'ended' then native.setKeyboardFocus( nil ) field:removeSelf() Runtime:removeEventListener( 'enterFrame', char ) f( text ) end end field = native.newTextField( 0, 0, 240, 24, done ) field.text = '--' field.isVisible = false native.setKeyboardFocus( field ) end obj.font = font obj.align = 'left' obj.text = (text or '') obj.xScale = finalScale; obj.yScale = finalScale; return obj end

Does someone have a version of “bmf.lua” that is graphics 2.0 compatible that doesn’t have issues with character spacings and allows for font sizing and alignment (left, right, center)?

Mike, you could try my free bitmap font library https://github.com/autismuk/Font-Manager which is open on github e.g. anyone can contribute (and some people have) to improve it. It is definitely 2.0 compatible (actually, it may not work on 1.0 compatibility mode ? Must have a look at this ?) and does allow font sizing and alignment, and the kerning works if you generate kerning data.

In case this would be useful for anyone else, I added the ability to tint text to any desired color. This works especially well if your bitmap font texture file consists of white letters over a transparent background:

-- Pass a font object (obtained from loadFont) and a string to render -- Return value is a DisplayObject of the rendered string -- object.font can be read/modifed -- object.text can be read/modified -- object.align can be read/modified - left/right/center (multiline not yet fully supported for non-left) -- object.tint can be read/modified - SPACEWOLF -- object.input( function(text), { filter = function(), max = 32 } ) -- turns the object into a text input. -- the callback is hit when the user presses "return" or the field losed focus. -- this code is under development - more documentation will be added soon... function newString( font, text, newsize) --local finalScale = 100/origsize \*newsize/100; local finalScale = 100/font.info.size \*newsize/100; local obj = display.newGroup() accessorize( obj ) removerize( obj ) obj.set\_font = function( t, k, v ) obj.raw\_font = v if t.text then t.text = t.text end end -- Set the alignment of the object obj.set\_align = function( t, k, v ) local w = t.textWidth if t.raw\_align == 'right' then for i = 1, t.numChildren do t[i].x = t[i].x + w end elseif t.raw\_align == 'center' then for i = 1, t.numChildren do t[i].x = t[i].x + math.floor( w \* 0.5 ) end end t.raw\_align = v if t.raw\_align == 'right' then for i = 1, t.numChildren do t[i].x = t[i].x - w end elseif t.raw\_align == 'center' then for i = 1, t.numChildren do t[i].x = t[i].x - math.floor( w \* 0.5 ) end elseif t.raw\_align ~= 'left' then t.raw\_align = 'left' end end -- Set the text for the object obj.set\_text = function( t, k, v ) if ( v == t.raw\_text ) then return end t.raw\_text = v for i = t.numChildren, 1, -1 do t[i]:removeSelf() end local oldAlign = ( t.align or 'left' ) local oldTint = ( t.tint or {0, 0, 0, 0} ) t.align = 'left' local x = 0; local y = 0 local last = ''; local xMax = 0; local yMax = 0 if t.raw\_font then for c in string.gmatch( t.raw\_text..'\n', '(.)' ) do if c == '\n' then x = 0; y = y + t.raw\_font.info.lineHeight if y \>= yMax then yMax = y end elseif t.raw\_font.chars[c] then local rfc = t.raw\_font.chars[c] if 0 + t.raw\_font.chars[c].width \> 0 and 0 + t.raw\_font.chars[c].height \> 0 then local letter = sprite.newSprite( t.raw\_font.sprites[c] ) if t.raw\_font.kernings[last .. c] then x = x + font.kernings[last .. c] end t:insert( letter ) letter.anchorX = 0 letter.anchorY = 0 letter.x = t.raw\_font.chars[c].xoffset + x letter.y = t.raw\_font.chars[c].yoffset - t.raw\_font.info.base + y last = c end --x = x + t.raw\_font.chars[c].xadvance x = x + t.raw\_font.chars[c].xadvance + (t.raw\_font.info.outline or 0) --CLF added support for outlines if x \>= xMax then xMax = x end end end obj.textWidth = xMax end t.align = oldAlign t.tint = oldTint end -- set the tint of the object obj.set\_tint = function( t, k, v ) t.raw\_tint = v for i = t.numChildren, 1, -1 do if v[4] then t[i]:setFillColor(v[1],v[2],v[3],v[4]) else t[i]:setFillColor(v[1],v[2],v[3]) end end end obj.input = function( f, args ) -- spawn the text field invisibly local field -- Handle character insertion/deletion local function char() -- check if any character has been added or deleted if field.text ~= '--' then if string.len( field.text ) \< 2 then -- backspace was pressed if string.len( obj.text ) \> 0 then obj.text = string.sub( obj.text, 1, -2 ) end else -- some other key was pressed obj.text = obj.text..string.sub( field.text, 3 ) end field.text = '--' if args.filter then obj.text = string.sub( args.filter( obj.text ), 1, (args.max or 32) ) else obj.text = string.sub( obj.text, 1, (args.max or 32) ) end end end Runtime:addEventListener( 'enterFrame', char ) -- Handle the "done" phase local function done( e ) if e.phase == 'submitted' or e.phase == 'ended' then native.setKeyboardFocus( nil ) field:removeSelf() Runtime:removeEventListener( 'enterFrame', char ) f( text ) end end field = native.newTextField( 0, 0, 240, 24, done ) field.text = '--' field.isVisible = false native.setKeyboardFocus( field ) end obj.font = font obj.align = 'left' obj.text = (text or '') obj.xScale = finalScale; obj.yScale = finalScale; return obj end

Does someone have a version of “bmf.lua” that is graphics 2.0 compatible that doesn’t have issues with character spacings and allows for font sizing and alignment (left, right, center)?

Mike, you could try my free bitmap font library https://github.com/autismuk/Font-Manager which is open on github e.g. anyone can contribute (and some people have) to improve it. It is definitely 2.0 compatible (actually, it may not work on 1.0 compatibility mode ? Must have a look at this ?) and does allow font sizing and alignment, and the kerning works if you generate kerning data.

Hi guys,

I noticed a few of you asking about a bitmap font editor on windows and would like to mention that we have just launched a native app called Glyph Designer for Windows.

gdx-ui.png

More information can be found here

http://forums.coronalabs.com/topic/55566-new-tool-glyph-designer-for-windows-a-native-bitmap-font-generator/

Or on our web site

https://71squared.com/gdx

Hi guys,

I noticed a few of you asking about a bitmap font editor on windows and would like to mention that we have just launched a native app called Glyph Designer for Windows.

gdx-ui.png

More information can be found here

http://forums.coronalabs.com/topic/55566-new-tool-glyph-designer-for-windows-a-native-bitmap-font-generator/

Or on our web site

https://71squared.com/gdx