Definition of the font-format used in GrafX2
Draft revision 0.91

The XFN-Format is free for everyone. The only restriction is not to copy
my own routines, but to write yourself your loaders/displayers etc.

The format shown here could be more or less the final format. I revised it
again and think, that it's now good enough to be used. Of course any ideas
are welcome.

  tfont = record
    id                    : array[0..3] of char;  { 'Fnt2'              }
    version               : word;                 { 0101h               }
    name                  : array[0..31] of char; { Name of the font - #0-terminated }
    copyright             : array[0..31] of char; { #0-terminated       }
    fonttype              : array[0..3] of char;  { 'BMP1','VECL'...    }
    numofsubfonts         : word;     { Number of different subfonts    }
    data                  : word;
    space                 : array[0..1] of byte;
    size                  : longint;  { Size in memory                  }
    flags                 : longint;  { See fontfmt.txt                 }

    fontstart             : longint;
    bpp                   : byte;     { bits per pixel                  }
    bpl                   : word;     { BMP-fonts; bytes per line       }
    sizex,sizey           : word;     { Size of largest character       }
    baseline              : word;
    descender             : word;
    startchar,endchar     : word;     { Yea, we support more than 255!  }
    distance              : byte;     { Distance between characters     }
    randomx,randomy       : byte;     { Only <> 0 if flag anipos on     }
    usedcolors            : longint;  { Only really needed for BMP8 yet }
    spacer                : longint;  { Distance for non-existing chars }
    reserved              : array[0..9] of byte;
  end;

.FONTTYPE

 This character-array can have currently following shortcuts:
 BMP1 : simple 1-Bit-font
 BMP8 : 7-Bit colored font (bit 7 transparency bit)
 CHN8 : 8 bit Alphachannel font
 RGBD : RGB-Bitmap font
 RGBA : RGB-Bitmap font with alphachannel
 VECF : Vectorized font (similar to Borland's ones)
 More to come...

.BMP1

 The data is built up this way:
 offsets : array[0..numofsubchars] of
           array[startchar..endchar]*numofsubchars of longint;

 data : array[startchar..endchar] of record
          width : byte;
          height: byte;
          data  : array[0..sizey-1] of byte*(sizex+7) div 8;
        end;

 If fnfixed bit (Bit 0) is setted:
 WIDTH and HEIGHT must be equal to tfont.sizex respectively tfont.sizey.

 If fnfixed bit (Bit 0) is NOT setted:
 WIDTH and HEIGHT should normally represent the character's really used
 pixels from pixel 0 until the last x- and y-pixel of the character.
 Only the lines from 0..HEIGHT-1 are saved! WIDTH doesn't influence
 anything than the correct positioning when putting the font. It also
 influences the maximum drawn x-pixel of the character.


.BMP8

 Data is built up like this:
 tbmp4 = record
   offsets : array[0..numofsubchars] of
             array[startchar..endchar]*numofsubchars of longint;
   data : record end;
 end;
 The transparent color bit is 80h. So we can use the full 128 color range.
 Please note that the transparency bit should be only set if the other
 bits are zero. This is a reservement for future extensions.

 WARNING: the bpp-field in the tfont-record MUST NOT contain the color
 depth 8 bpp, but the REAL used colors. This can vary between 2 and 7!
 This is needed for the right recognition of the font and the right
 color settings if they are calculated automatically.

 Each character begins with 4 doublewords:
 addx,addy   : longint
 sizex,sizey : longint
 Addx and addy are needed to use really only the necessary space and not a
 bit more. This gives also a bit speed improvement. Officially, each
 characer has the sizex:sizey of the header, but most of the letters won't
 fill all that space. So all unused lines (which do only include transparent
 pixels) are eliminated. Little example:
 This is a letter (1), using 8:7 pixels:
 ........
 ....oo..
 ...ooo..
 ....oo..
 ....oo..
 ...oooo.
 ........
 Like you see, on the left side there are 3 unused columns, on the right
 there's 1 unused column and at the top and the bottom there is 1 unused
 line.
 This is the same letter, using specific addx,addy/sizex,sizey:
 .oo.
 ooo.
 .oo.
 .oo.
 oooo
 addx=3
 addy=1
 sizex=4
 sizey=5
 We save more than 60% space!


.RGBD

 The RGBD-font works similar to the BMP8-font. The only difference is, that
 we use 4 bytes instead of one byte for each pixel. Also you are not able
 anymore to set your specific colors. The D stands for 'dummy'. In this
 dummy byte, bit 7 indicates a transparent color.


.RGBA

 The RGBA-font works similar to the RGBD-font. Here the additional byte
 is used for an alphachannel. Allows very well looking fonts.


.VECF

 Data is built up this way:

 offsets : array[startchar..endchar] of longint;

 {Lookuptable contains offset to the equivalent char}
 Each character is written this way:

 tvecchar = record
   sizex,sizey : byte;
   numoflines  : word;
   coordinates : array[0..numoflines-1] of record
     code,x,y : byte;
   end;
 end;

 The code within the coordinates-rec is currently defined like here:
 0 = undefined
 1 = Move to (x,y)
 2 = Line to (x,y)

 More is possible but currently not defined.

.FLAGS

 Bit  Property, if set                         must not appear with
 ----+-----------------------------------------+--------------------------
  0   The font size is fixed, this means each 
      character has got sizex                 
      GX2 flag name: fnfixed                  
  1   The font contains different sizes or    
      types of the letter                     
      GX2 flag name: fnmulti                  
  2   The font is animated, means that the     BMP1-Fonts
      font manager will use the different     
      characters randomly                     
      GX2 flag name: fnanimate                
  3   The font is position animated, means     BMP1-Fonts
      the font manager will vary the position 
      of each character by randomx:randomy    
      GX2 flag name: fnanipos                 
  4   Scaling allowed (set, if scaling        
      doesn't look ugly)                      
      GX2 flag name: fnscaleable              
  5   Font is vector font                      Bits 1,2,3

 WARNING: If the fnanimate-flag is set, the font should be a fixed size
          font! Or at least EVERY subcharacter of a character should have
          the same width and height! If this is not the case, it is
          IMPOSSIBLE for GrafX to calculate the right font width and/or
          height, which makes alot trouble!



.NUMOFSUBCHARS

 This value is normally zero. Other values are only allowed with BMP1, BMP8
 and RGBx type fonts yet.


.USEDCOLORS

 Usedcolors represents the largest used color value in a font. It's needed
 to calculate the color values. In any other font format than BMP8, this
 value is ignored, you can set it there to zero.

.SPACER

 This is a variable which declares the space for a character for displayment,
 which isn't available in the font. For fixed size fonts, use the font width
 for this value, in non-fixed fonts, it's preferable to use 1/2 of the width
 of the largest character of the smallest font (subfont spacers are
 calculated by (subfont+1)*spacer). Of course you can use other sizes.
 Choose that value which looks best.


.Saving fonts

 GrafX 2 is able to load fonts with the format shown here. The extension of
 these  files  needs to  be 'XFN'. This new kind of TFont allows without
 any problems to load fonts unless the memory gets weak ;). Theoretically no
 limit.

Copyright (c) 1998-2000 by Stefan Goehler, Germany
