Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:07 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Font format

Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:20am 21 Sep 2020
Copy link to clipboard 
Print this post

I was asked to provide details about fonts to enable producing fonts on the CMM2.
This program should give enough to get you started.
It uses a large font to print something then reads the pixels to reassemble the first character.

I would advise sticking to font sizes where the width by height is an exact multiple of 8.
It will make life a lot easier.

The output from this program is an exact copy of the included font first character. A good test to see if we have things working.

 CLS
 pixX = 100
 pixY = 100
 ' print something to play with
 TEXT pixX+1,pixY,CHR$(48),lt,9
 PRINT @(10,150), "" ' move the cursor to somewhere safe
 
 charCount  = 10
 charStart  = 48
 charHeight = 50
 charWidth  = 32
 ' print the header
 txt$ = HEX$(charCount,2)+HEX$(charStart,2)+HEX$(charHeight,2)+HEX$(charWidth,2)
 PRINT txt$
 txt$ = ""
 
 FOR y = 0 TO charHeight-1
   FOR x = 0 TO charWidth -1
     IF PIXEL(pixX+x,pixY+y)= 0 THEN pxl = 0 ELSE pxl = 1
     outBuffer% = (outbuffer%<<1)+ pxl '<<7)
     IF b MOD 8 = 0 AND b <> 0  THEN ' we have filled the first output group
       chunk% = (chunk%>>8) + (outbuffer%<<24)
       outBuffer% = 0
     ENDIF
     IF b MOD 32 = 0 AND b <> 0 THEN ' we have a 'word'
       txt$ = txt$+ HEX$(chunk%,8)+" " ' fill the output line
       IF LEN(txt$) > 70 THEN
         PRINT txt$
         txt$ = ""
       ENDIF
       chunk% = 0
     ENDIF
     b = b + 1
   NEXT x
 NEXT y
 txt$ = txt$+ HEX$(chunk%,8)+" "
 PRINT txt$
 
END
 
DEFINEFONT #9
 0A303220
 00000000 00000000 00FEFF00 00FFFF01 80FFFF03 60FFFF01 F0FEFF0C F801001E
 F801003F F801003F F801003F F801003F F801003F F801003F F801003F F801003F
 F801003F F801003F F801003F F801003F F801003F 7800003E 18000038 08000020
 00000000 00000020 18000038 7800003E F801003F F801003F F801003F F801003F
 F801003F F801003F F801003F F801003F F801003F F801003F F801003F F801003F
 F801003F F801003F F000001E 60FEFF0C 00FFFF01 80FFFF03 00FFFF01 00FEFF00
 00000000 00000000 00000000 00000000 00000000 00000000 00000000 60000000
 F0000000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 78000000
 18000000 08000000 00000000 00000000 18000000 78000000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F0000000 60000000 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 00000000 00FEFF00 00FFFF01
 80FFFF03 60FFFF01 F0FEFF00 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 78000000 18FEFF01 88FFFF03 E0FFFF0F C0FFFF27 00FFFF39 0000003E
 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F
 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F 0000001E 00FEFF0C
 00FFFF01 80FFFF03 00FFFF01 00FEFF00 00000000 00000000 00000000 00000000
 00FEFF00 00FFFF01 80FFFF03 60FFFF01 F0FEFF00 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 78000000 18FEFF01 88FFFF03 E0FFFF0F C0FFFF07
 18FFFF01 78000000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F0000000 60FEFF00 00FFFF01 80FFFF03 00FFFF01 00FEFF00 00000000 00000000
 00000000 00000000 00000000 00000000 00000000 60000000 F000000C F801001E
 F801003F F801003F F801003F F801003F F801003F F801003F F801003F F801003F
 F801003F F801003F F801003F F801003F F801003F 7800003E 18FEFF39 88FFFF23
 E0FFFF0F C0FFFF07 18FFFF01 78000000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F0000000 60000000 00000000 00000000 00000000 00000000
 00000000 00000000 00000000 00000000 00FEFF00 00FFFF01 80FFFF03 00FFFF01
 00FEFF0C 0000001E 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F
 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F 0000003E
 00FEFF39 80FFFF23 E0FFFF0F C0FFFF07 18FFFF01 78000000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F0000000 60FEFF00 00FFFF01 80FFFF03
 00FFFF01 00FEFF00 00000000 00000000 00000000 00000000 00FEFF00 00FFFF01
 80FFFF03 00FFFF01 00FEFF0C 0000001E 0000003F 0000003F 0000003F 0000003F
 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F 0000003F
 0000003F 0000003E 00FEFF39 80FFFF23 E0FFFF0F C0FFFF27 18FFFF39 7800003E
 F801003F F801003F F801003F F801003F F801003F F801003F F801003F F801003F
 F801003F F801003F F801003F F801003F F801003F F801003F F000001E 60FEFF0C
 00FFFF01 80FFFF03 00FFFF01 00FEFF00 00000000 00000000 00000000 00000000
 00FEFF00 00FFFF01 80FFFF03 60FFFF01 F0FEFF00 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 78000000 18000000 08000000 00000000 00000000
 18000000 78000000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F0000000 60000000 00000000 00000000 00000000 00000000 00000000 00000000
 00000000 00000000 00FEFF00 00FFFF01 80FFFF03 60FFFF01 F0FEFF0C F801001E
 F801003F F801003F F801003F F801003F F801003F F801003F F801003F F801003F
 F801003F F801003F F801003F F801003F F801003F 7800003E 18FEFF39 88FFFF23
 E0FFFF0F C0FFFF27 18FFFF39 7800003E F801003F F801003F F801003F F801003F
 F801003F F801003F F801003F F801003F F801003F F801003F F801003F F801003F
 F801003F F801003F F000001E 60FEFF0C 00FFFF01 80FFFF03 00FFFF01 00FEFF00
 00000000 00000000 00000000 00000000 00FEFF00 00FFFF01 80FFFF03 60FFFF01
 F0FEFF0C F801001E F801003F F801003F F801003F F801003F F801003F F801003F
 F801003F F801003F F801003F F801003F F801003F F801003F F801003F 7800003E
 18FEFF39 88FFFF23 E0FFFF0F C0FFFF07 18FFFF01 78000000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000 F8010000
 F8010000 F8010000 F8010000 F8010000 F0000000 60FEFF00 00FFFF01 80FFFF03
 00FFFF01 00FEFF00 00000000 00000000 00000000
END DEFINEFONT


Jim
VK7JH
MMedit
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 01:24am 22 Sep 2020
Copy link to clipboard 
Print this post

Thanks. I think it could be useful to have a description of the format, so I had a go at documenting the format of the hex numbers based on reading your code. My description could probably use some more work but I'm posting it in case it's useful either for understanding or for making better documentation.

  Quote  
Pixels in the font character are ordered top to bottom, and within a row, left to right.
Take 8 pixels at a time, treat as binary with set pixels being a 1, blank pixels being a 0, and the first/leftmost pixel being the high bit. This gets you a sequence of bytes.

For example, if you have a 16x16 character and the top left pixel is the only one set, the sequence of binary bytes are &b10000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000, &b00000000

In hex this would be written
&h80,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,
&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00,&h00

From the sequence of bytes, take four at a time. The one with the first/leftmost pixels is the low byte this time. This is the reverse of how numbers are written, so it will appear out of order when written.
For example, if you have a 16x16 character and the top left pixel is the only one set, the sequence of binary 4-byte words are &b00000000000000000000000010000000, &b00000000000000000000000000000000, &b00000000000000000000000000000000, &b00000000000000000000000000000000, &b00000000000000000000000000000000, &b00000000000000000000000000000000, &b00000000000000000000000000000000, &b00000000000000000000000000000000

In hex this would be written
&h00000080, &h00000000, &h00000000, &h00000000, &h00000000, &h00000000, &h00000000, &h00000000

Now another example. Say you have a 6x8 font, and all the leftmost pixels are set, and on the top row the second pixel from the left is also set.

Bits in a grid:

110000
100000
100000
100000
100000
100000
100000
100000

Bits, not in a grid: 110000100000100000100000100000100000100000100000
Bytes: &b11000010, &b00001000, &b00100000, &b10000010, &b00001000, &b00100000
Hex bytes: &hc2, &h08, &h20, &h82, &h08, &h20
Hex words: &hc2200882, ???

In the font file, the hex words are written with digits from A-F usually being in uppercase, and no comma in between, just spaces or going to the next indented line
Hex words for font file: C2200882 ???


Also, these were my notes on the header word:
  Quote  
https://www.thebackshed.com/forum/ViewTopic.php?TID=12451&PID=151451#151451
Here TassyJim explained some information from the font format.
In the example 01203C30
Each two hex digits are one number.
"1 character, Chr$(32), 60 pixels high and 48 pixels wide"
01 is number of characters, 1
20 is the hex code for the first character, decimal 32, the space character.
3C hex is 60 in decimal.
30 hex is 48 in decimal.
 
berighteous
Senior Member

Joined: 18/07/2020
Location: United States
Posts: 110
Posted: 06:33am 22 Sep 2020
Copy link to clipboard 
Print this post

I just make my own font in any size and color(s) I want in photoshop, load the image on a spare page, and use my own font subroutine to read an array of strings and blit the letter images to the screen.

I can add a constant value to the letter coordinates to change colors from my font page.

in the snippet below I'm printing each line in black for a drop shadow and then in whatever color on top of it. This particular font is 6x6 and is good at 320x200.
I'm loading it on page 9 in mode 3.  This font is upper case only.





dim ozmessage1$(19)
ozmessage1$(0)= "           ABOUT OIDZONE          "
ozmessage1$(1)= "                                  "
ozmessage1$(2)= " HOW TO PLAY:                     "
ozmessage1$(3)= " YOUR JOB IS TO CLEAR THE OIDZONE "
ozmessage1$(4)= " OF ASTEROIDS AND OTHER HAZARDOUS "
ozmessage1$(5)= " OBJECTS.  YOU HAVE A FAST SHIP   "
ozmessage1$(6)= " AND A PULSE-CANON TO BLAST AWAY  "
ozmessage1$(7)= " AT ANYTHING IN YOUR PATH.        "
ozmessage1$(8)= "                                  "
ozmessage1$(9)= " TO CLEAR THE OIDZONE, YOU MUST   "
ozmessage1$(10)= " FIRST BLAST THE ASTEROIDS INTO   "
ozmessage1$(11)= " MANY SMALL PIECES, THEN DESTROY  "
ozmessage1$(12)= " EACH PIECE INDIVIDUALLY.  YOU    "
ozmessage1$(13)= " MUST BE VERY CAREFUL, AS ANY OF  "
ozmessage1$(14)= " THE SMALLER ASTEROIDS CAN EASILY "
ozmessage1$(15)= " DESTROY YOUR SMALL SHIP.  ONCE   "
ozmessage1$(16)= " YOU CLEAR YOUR ZONE, YOU WILL GO "
ozmessage1$(17)= " TO ANOTHER, MORE DIFFICULT ZONE. "
ozmessage1$(18)= "                                  "
ozmessage1$(19)= "   PRESS ANY KEY TO CONTINUE:"

vtab=25
htab=6
fwidth=6
fheight=6
vspace=7

dim myfont(12)=(0,12,24,36,48,60,72,84,96,108,120,132,144)
dim letterx(58)=(0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96,102,108,114,120,126,132,138,144,150,156,162,168,0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96,102,108,114,120,126,132,138,144,150,156,162,168,174)
dim lettery(58)=(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6)
dim fcolors(21)=(0,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,12)

page write 0:cls

for q = 0 to 19
printline ozmessage1$(q),htab+1,vtab+1+q*vspace,fcolors(1)
printline ozmessage1$(q),htab,vtab+q*vspace,fcolors(q+2)
next


sub printline f$,htab,vtab,fcolor
colorfont=color*fheight
for i = 1 to len(f$)
a = asc(mid$(f$,i,1))-32
h=htab+i*fwidth
v=vtab
blit letterx(a),lettery(a)+1+myfont(fcolor),htab+fwidth*i,vtab,fwidth,fheight,9,&b100
next i
end sub







sorry for the lousy phone photos, my video capture thing I ordered is lost in the mail.
Edited 2020-09-22 16:58 by berighteous
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025