I wrote a custom font code i wanted some feed back on
before i past it, i need to make some info clear on how it works
first I use a simple bitmap (.BMP) to hold the characters along with a little data in the bitmap about the font
at point 0,0 in the bitmap is a pixil representation of the width in pixils the space character is(it would be silly to have this value over 10), and at point 1,0 (there should be at most 70-90 characters in a full alpha-numeric list, inlcuding punctuations and mathmatic symbols) is the number of characters that are in the font +1 (I know theres a flaw in the codes somewhere or this number would just be a count of characters)
now there needs to be a support file that also has all characters used in the font surrounded by double perentheses ("), such as " ABC" in the order that it appears in the bitmap...
now that I've explained the setup here are the subs and what they do
SUBS
setfontfile( file as string)- this will change the fontlist to what is placed in file
load(file as string)- loads the font bitmap for file
fontcolor( r as integer, g as integer, b as integer)- sets color to rgb
fontcolor( c as integer) - makes font color of c
txt( t as string, x as single,y as single) - puts t at x,y on screen
screen 19,,,1
DIM as fonts font
font.setfontfile( <FONTLIST> )
font.load( <BITMAP> )
font.txt( "Your text goes here", 0,100)
-----------"FONT.FNT"-------------------
" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.!?,':-+*/=()"
----------TO MAKE A QUICK FONT BITMAP---------
I use a paint program called ultimate paint which has a palette function on it and saves in 8 bit formats using the palette chart which makes this really easy, I type the characters down first in note pad and then in the paint editor using palette color 255 (the color i've reserved for font) on a black (0) background, then i figure out howmany pixils are from the start of the bitmap to the first character and place the color of that value (10 pixiles= color 10) at coor(0,0) followed by the number of characters+1 at coor(1,0), i save the note pad file as "FONT.FNT" and save the bitmap as "FONT.BMP"
well here's the code, I know there's probably better codes somewhere but
I prefer to write my own personal include files for what i code so dont bother telling me otherwise...
![Smile :)](./images/smilies/icon_smile.gif)
-----------START OF "font.bi"------------
TYPE fint
DIM AS INTEGER wide,offset
DIM AS BYTE ascii
END TYPE
TYPE fonts
PRIVATE:
DIM AS STRING fontfile
DIM AS ANY PTR gph
DIM AS STRING fontlist
DIM AS fint PTR list
DIM AS INTEGER count,tall
PUBLIC:
DECLARE constructor
DECLARE SUB LOAD(file AS STRING)
DECLARE SUB txt(l AS STRING,x AS SINGLE,y AS SINGLE)
DECLARE SUB setfontfile(file AS STRING)
DECLARE SUB fontcolor(c AS INTEGER)
DECLARE SUB fontcolor(r AS INTEGER,g AS INTEGER,b AS INTEGER)
END TYPE
constructor fonts
this.fontfile="font.wdu"
END constructor
SUB fonts.fontcolor(c AS INTEGER)
DIM AS INTEGER r,g,b
PALETTE GET 255,r,g,b
PALETTE 255,r,g,b
END SUB
SUB fonts.fontcolor(r AS INTEGER,g AS INTEGER,b AS INTEGER)
PALETTE 255,r,g,b
END SUB
SUB fonts.setfontfile(file AS STRING)
this.fontfile=file
END SUB
SUB fonts.txt(l AS STRING,x AS SINGLE,y AS SINGLE)
l=ucase(l)
DIM AS INTEGER scan,s2
DIM AS INTEGER c
FOR scan=1 TO LEN(l)
c=ASC(MID(l,scan,1))
FOR s2=0 TO LEN(this.fontlist)-1
IF c=this.list[s2].ascii THEN EXIT FOR
NEXT
PUT(x,y),this.gph,(this.list[s2].offset,0)-STEP(this.list[s2].wide,this.tall),TRANS
x+=this.list[s2].wide+1
NEXT
'PUT (15,15),this.gph,(this.list[curchar].offset,0)-STEP(this.list[curchar].wide,ysize),TRANS
END SUB
SUB fonts.LOAD(file AS STRING)
'set screen mode if not currently set
LOCATE 1,1
PRINT "LOADING FONT FROM: ";file
SLEEP 2500
DIM AS STRING drive
SCREENINFO ,,,,,,drive
IF drive="" THEN SCREEN 19,,,1
'load list of characters in font
DIM AS INTEGER h = FREEFILE
OPEN this.fontfile FOR INPUT AS #h
INPUT #h,this.fontlist
CLOSE h
'open bitmap as a file and get sizeof picture
DIM AS INTEGER xsize,ysize
OPEN file FOR BINARY AS #h
GET #h,19,xsize
GET #h,23,ysize
CLOSE #h
'load file into a bitmap pointer,extract startpoint,and number of characters
this.gph=IMAGECREATE(xsize,ysize)
DIM AS INTEGER sp,nc
BLOAD file,this.gph
sp=POINT(0,0,this.gph):nc=POINT(1,0,this.gph)
'allocate enough memory to hold fontinfo for all characters for width,offset,asciicode
this.list=CALLOCATE(nc,SIZEOF(fint))
'begin setting info into list array...
DIM AS INTEGER curchar,xpos,yscan,scan,wide,offset
DIM AS BYTE flag,ischar
'scanning graphics...
curchar=1
wide=1
offset=sp
FOR xpos=sp TO xsize-1
FOR yscan=0 TO ysize-1
ischar=0
IF POINT(xpos,yscan,this.gph) THEN
ischar=1:EXIT FOR
END IF
NEXT
LOCATE 1,1
IF ischar=1 AND flag=0 THEN
curchar+=1:flag=1
wide=0:offset=xpos
END IF
IF ischar=1 AND flag=1 THEN
wide+=1:
END IF
IF ischar=0 THEN
this.list[curchar].wide=wide
this.list[curchar].ascii=ASC(MID(this.fontlist,curchar,1))
this.list[curchar].offset=offset
flag=0
END IF
'
NEXT
this.list[0].wide=sp-3
this.list[0].ascii=ASC(" ")
this.list[0].offset=2
this.tall=ysize
PALETTE 255,255,255,255
END SUB
well that's it, go ahead and check it out and get back to me with any advice/pointers/or comments you have, I don't mind criticism but unless you can say it in a way that can get me to laugh, try to be polite
thank you.