Alpha Bitmap Font Example

Started by kevin, August 07, 2008, 01:37:44 PM

Previous topic - Next topic

kevin


Alpha Bitmap Font Library/Example

       
    This little library example loads a bitmap font with alpha channel via (FreeImage).  Once loaded there's a trimming function which will try and clip the characters with kerning based upon the alpha channel.  So soft edges can be ignored and characters can overlap.  You can of course set these yourself.

    The library is written in PB1.63w beta 13 (or whatever version i have currently installed :) ), but should also work in order versions with a few modifications.  



Bitmap Fonts


   The example includes a few fonts from  http://www.thecodebrewers.com/Fonts.html.  Lots of nice ones  




Functions


  • LoadBitmapFont(ThisFont.tAlphaBitmapFont,Filename$, TileWidth,TileHeight)    ; Load font into a previously dimmed TYpe.  

  • DeleteBitmapFont(ThisFont.tAlphaBitmapFont)  ; Delete a font from memory


  • TrimBitmapFontCHRS(ThisFont.tAlphaBitmapFont,MinAlpha)    ; trim the char widths in this font


  • SetBitmapFONT(ThisFont.tAlphaBitmapFont)    ; set the current bitmap


  • GetBitmapFontTExtWidth(Message$)   ; get the width of this text in the current font

  • GetBitmapFontHeight()   ; get the height of the current font

  • DrawBitmapFontTExt(Message$,Xpos,Ypos)  ; draw a message in the current bitmap font

 


DownLoad


    Alpha BitMap Fonts (login required)



thaaks

Super duper!
Automatic trimming of bitmap fonts!  :o
That's a great feature and I will give it a try with Font Candy Studio after my vacation!

Thanks a lot!

Cheers,
Tommy

thaaks

Couldn't resist and gave it a quick try  ;)

Not working yet (must have messed up the alpha channel) but during testing I detected some requirement:
It would be cool if I could specify a string as last parameter of LoadBitmapFont() which lists the characters contained in the bitmap in their order of appearance like "ABCDEFGHIJKLMNOPQRSTUVWXYZ !$%1234..."

And looking at the output I'd say the space character is always too wide as it is the default width of the characters in the font I guess. Make it 2/3 of the width or something like that...

Cheers,
Tommy

kevin

#3
Reorder Font

This function (untested) should allow users to change the fonts ASCII mapping.  Just pass it the ASCII sequence the chr's appears in (on the bitmap font) and it'll remap the characters.

PlayBASIC Code: [Select]
Function ReorderBitmapFont(ThisFont.tAlphaBitmapFont,AlphabetSequence$)
if ThisFont.status
Dim BackupBitMapFont as tALphaBitMapFont

BackupBitMapFont.tAlphaBitmapFont=ThisFont()
Dim TempChrMap(255)
ClearArray TempChrMap(),-1

For lp=1 to len(AlphabetSequence$)
ThisChr=mid(AlphabetSequence$,lp)
TempChrMap(ThisChr)=(lp-1)+ThisFont.BaseChr
Next

For chr=0 to 255
ThisFont.Image(chr) =0
ThisFont.Width(chr) =0
ThisFont.Height(chr) =0
ThisFont.UnderHang(chr) =0
ThisFont.OverHang(chr) =0
next

for ThisChr =0 to 255
NewPosition=TempChrMap(ThisChr)
if NewPosition>-1
#print "remap"
#print Chr$(ThisChr)+"="+str$(newposition)
SrcPosition=ThisChr
ThisFont.Image(NewPosition) =BackupBitMapFont.Image(SrcPosition)
ThisFont.Width(NewPosition) =BackupBitMapFont.Width(SrcPosition)
ThisFont.Height(NewPosition) =BackupBitMapFont.Height(SrcPosition)
ThisFont.UnderHang(NewPosition) =BackupBitMapFont.UnderHang(SrcPosition)
ThisFont.OverHang(NewPosition) =BackupBitMapFont.OverHang(SrcPosition)
BackupBitMapFont.Image(SrcPosition)=0
endif
next

DeleteBitmapFont(BackupBitmapFont())
SetBitmapFont(ThisFont())

Endif

endfunction




Adaz

Doesn't work here with the included freeimage.dll
FontIMage=FreeImage_LoadImage(Filename$,1) cannot load Alien.dds so PrepareAfxImage FontIMage crashes.
If I change this dll (Time stamp 2004.01.26., size 277 KB) to a newer one (Time stamp 2007.11.19., size 1.84 MB), it loads everything, but upside down (this is a feature in the later versions).
But how does that old dll work there? It doesn't know the dds format at all.

Thanks,

Ádáz

Hungary