CreateBitmapFont
CreateBitmapFont FontIndex, Width, Height, [Format =2 ]
 
Parameters:

    FontIndex = The Index of the font you wish to initialize
    Width = The width of each character
    Height = The height of each character
    [Format =2 ] = The optional format flag. Defaults to video bitmap fonts (2)
Returns: NONE
 

      CreateBitmapFont initializes a blank bitmap font. Upon creation each character in the alphabet will be blank and have the same width and height. While this might not should that useful, it allows you to import your own hand drawn fonts.

      To import a font, you'll need to load your character set as an image, then grab individual characters from it (using GetFontChr()) to store them in their corresponding ASCII positions.

      Once imported, you can use this font like any other windows font. The benefits are not only that bitmap fonts are faster, but they vastly improve your programs visual style.


[ Format Flags ]
2= Video Bitmap Font
4= FX Bitmap Font
8= Compressed Raster Font


      The format flags allow us to prepare the type of bitmap font this should be. You can even select CRF, which will create an empty CRF for us to the grab characters into.




FACTS:


      * All characters in the font will have the same physical width and height. However you can adjust the render width using the FontChrWidth command

      * Use FontMaskColour to change the transparent colour of the font

      * To help make this process easier for new users we've included a fonts expansion library in the SLiBS folder. This library includes a function that will load an image (with your character set on it) it into a bitmap font. See the demo which is located in the Projects/Examples/Fonts folder.





Mini Tutorial #1:


      This example loads the windows true type Arial, and the builds a custom bitmap version of it. In fact this example basically replicates what the MakeBitmapFont does. But this approaches gives you the control and freedom to build or import hand drawn character sets into PlayBASIC as a custom font.


  
; --------------------------------------------------------
; For This example, were going to build a PB Bitmap font
; from the Windows Arial font as an example. Normally you'd
; load a set of pre-drawn characters in and import those...
; --------------------------------------------------------
  
; Load the Windows True Type Font Arial (50 point)
  LoadFont "Arial",2,50,1
  SetFont 2
  
; Set the Width + Height of oru custom font
  ChrWIdth=48
  ChrHeight=60
  
  
  CreateBitmapFont 10,ChrWidth,ChrHeight
  
; Manually Create the characters of our bitmap font
  For lp=Asc(" "To Asc("z")
   ; Draw a random shade box for each chr's backdrop
     ShadeBox xpos+0,0,xpos+Chrwidth,Ypos+ChrHeight,RndRGB(),RndRGB(),0,lp
     
   ; Draw the character and it's shadow
     Ink RGB(32,32,32)
     CenterText xpos+(chrwidth/2)-2,ypos-2,Chr$(lp)
     
     Ink RGB(64,64,64)
     CenterText xpos+(chrwidth/2)-1,ypos-1,Chr$(lp)
     
     Ink RGB(200,240,255)
     CenterText xpos+(chrwidth/2),ypos,Chr$(lp)
     
   ; This the section of screen at position 0x,0y for
   ; This character in font 10
     GetFontChr 10,lp,0,0
  Next
  
; Clear the Screen
  Cls RGB(0,0,0)
  
; Tell PB to use the newly created bitmap font
  SetFont 10
  
; Calc the screen center
  cw=GetScreenWidth()/2
  ch=GetScreenHeight()/2
  
; Display PLayBasic in the center of the screen
  CenterText cw,ch-(chrheight/2),">> PlayBASIC <<"
  
; refresh the screen and wait for a key press
  Sync
  WaitKey
  




This example outputs.








Mini Tutorial #2:


      This example uses the LoadBitmapFont function found in the FONTS slib, to import a bitmap image containing a hand drawn character sets into a Bitmap Font. Once loaded, you can render the text using this custom font.


  
  
  
; Include the FONT Extras library
  #Include "fonts"
  
; get PlayBASIC compiler path to guess
; location of the help file media
  path$=ProgramDir$()+"\Help\Commands/Media/"
  
  
; Build Chr/Image map conversion string for this font
  ChrMap$=" !"+Chr$(34)+"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz"
  
; Load this bitmap font in as FX bitmap font
  LoadBitmapFont(path$+"FRESH.png",10,ChrMap$,30,32,25,4)
  
  
; set our custom font as the current display font
  SetFont 10
  
; draw a message on the screen in the current ink colour
  CenterText 400,100,"hello world"
  
  
; show the screen to the user
  Sync
  WaitKey
  









Here's the bitmap font image, the test program uses to grab the font letters from.







 
Related Info: FontMaskColour | LoadFont | NewBitmapFont | SaveFont | SetFont :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com