Hi,

I previously managed to create a Java program that would convert a TTF font 
into a Palm font (NFNT).  I wanted to make another Java program that would make 
an extended font (nfnt) with only a hi res font, no low resolution or 1.5 
density font.

It took me a while to figure out, but here are some things that I found. I 
wished I could have found them online instead of by trial and error, so I 
thought I would share.


This is info about the structure of an extended font (nfnt) that ONLY includes 
a double density font (no low density, no 1.5 density).

Let's assume that there are k characters in your font.  Once you include the 
obligatory Missing Character, it becomes k+1.
So if you have a font with 256 characters, k=256, and with the Missing 
Character, k+1=257.

This is what I have figured out based on the documentation for fonts, plus 
trial and error.  Some of it is not entirely clear in the documentation.

The font record is constructed as follows:

FontTypeV2 Struct  [15 words | 30 bytes]
FontDensityType Struct [3 words | 6 bytes]
Bitmap Location Table [k+2 words | (k+2)*2 bytes]
Offset/Width Table [k+2 words | (k+2)*2 bytes]
Font Image (double density) [size varies]

(Note that IF you had more than one font density in the font, the 
FontDensityType would be bigger: 6 words for two densities, 9 words for 3 
densities.  But I'm only talking about one density in the font, remember?)

The trickiest parts of this are:

In FontTypeV2:
Int16 fontType = 0x9200
or
Int16 fontType = 0x9000 | fntExtendedFormatMask
because
fntExtendedFormatMask == 0x0200


In FontTypeV2:
Int16 owTLoc = 9 + (k+2)
or
Int16 owTLoc = (12 + 6)/2 + (k+2)
here,
* 12 if for the 12 following bytes in FontTypeV2 Struct,
* 6 is for the 6 bytes in FontDensityType Struct
* divide that by 2 to change from bytes to words
* add (k+2) which will be the size in words of the Bitmap Location Table

Some of the other values in FontTypeV2 can be tricky to calculate, but you have 
to figure them out on a font by font basis, and I think the documenation is 
sufficient for figuring them out.


FontDensityType:
Int16 density = 0x90
* 0x90 is for double density (Supposedly 144 dpi?  0x90 = 144-decimal)
* (for low density, you would use 0x48, = 72-decimal)


UInt32 glyphBitsOffset
This one was really hard.  The docs only say:

"Offset in bytes from the beginning of the font data to the start of the font 
image for this density."

The problem is, it doesn't define what "font data" refers to exactly, so you 
don't know where to start from.

The equation that seems to work for this, however, is:

glyphBitsOffset = (k+2)

To me, this means the documentation for this was in error and should either 
state:
1. Offset in WORDS from the beginning of the Offset/Width Table
2. Offset in UInt32's from the beginning of the Bitmap Location Table
3. Offset in UInt32's starting right after glyphBitsOffset
(Note: If you want to make a font with more than one density in it, you'll need 
to figure out which of these three options is really true.  Otherwise, just use 
glyphBitsOffset = k+2)


This information seemed to work for me, so hopefully it is accurate.  I hope it 
can help someone else out there.

Jeremy
-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to