/********** SplitBMfont(fn$) ************************** Description: Uses a text file to determine how to split a bitmap font sheet The text file should have the same name as the font and be in the same folder Parameters: fn$ - The full RAW PATH file name of the text file that holds the data for the split NOT including any file extension Returns: Returns nothing but CREATES a subimages.txt file to use for the bitmap font sheet Notes: The text file should be in the following format 100 A:M N:Z 0:9 And saved with the same filename as the bitmap font The above example demonstrates how the file should be formatted 100 = The Height of each row of text Each subsequent row is the range characters on each line which must be in correct ASCII order */ function SplitBMfont(fn$) fn$ = "raw:" + fn$ OpenToRead(1, fn$+".txt") height = val(ReadLine(1)) imgFont = LoadImage(fn$+".png") mbFont = CreateMemblockFromImage(imgFont) y = 0 OpenToWrite(2, fn$ + " subimages.txt") avg = 0 avgCount = 0 repeat ln$ = ReadLine(1) startASC = asc(left(ln$, 1)) endASC = asc(right(ln$, 1)) ascii = startASC startX = 0 while ascii <= endASC inc avgCount repeat test = ColumnIsAllAlpha(mbFont, startX, y, y+height-1) if test = TRUE inc startX endif until test = FALSE endX = startX+1 repeat test = ColumnHasNonAlpha(mbFont, endX, y, y+height-1) if test = TRUE inc endX endif until test = FALSE WriteLine(2, str(ascii) + ":" + str(startX) + ":" + str(y)+":"+str(endX-startX)+":"+str(height)) inc ascii inc avg, endX-startX startX = endX+1 endwhile inc y, height until FileEOF(1) //Create Space that is half the width of the average of all characters //And place it at the begining of the file WriteLine(2, "32:0:0:"+str(avg/avgCount)+":"+str(height)) CloseFile(2) CloseFile(1) endfunction function GetMemblockImageOffset(mb, x, y) w = GetMemblockInt(mb, 0) h = GetMemblockInt(mb, 4) yy = 12 + (4*w*y) xx = 4*x ret = xx+yy endfunction ret function ColumnIsAllAlpha(mb, x, startY, endY) for y = startY to endY pix = GetMemblockImageOffset(mb, x, y) if GetMemblockByte(mb, pix+3) > 0 exitfunction FALSE endif next y endfunction TRUE function ColumnHasNonAlpha(mb, x, startY, endY) for y = startY to endY pix = GetMemblockImageOffset(mb, x, y) if GetMemblockByte(mb, pix+3) > 0 exitfunction TRUE endif next y endfunction FALSE