GEM Font

From ModdingWiki
Jump to navigation Jump to search

GEM Font is a bitmap font format used in GEM, the Atari ST operating environment. It typically has a *.gft or *.fnt file extension when used in DOS projects. It was incorporated in the Genus Microprogramming graphics library which was used for various DOS games. The DOS version of NeoPaint uses the format for drawing text into bitmaps.

GEM Font Header

SoftType font format description taken from official Genus GX Development Series TXLIB.H header file.

Data Type Name Description
INT16LE fid Font ID.
INT16LE psize Point size.
char[32] fntname Font name.
INT16LE minch Minimum character in [0..255] range.
INT16LE maxch Maximum character in [0..255] range.
INT16LE topline Top line distance.
INT16LE ascent Ascent distance.
INT16LE halfline Half line distance.
INT16LE descent Descent distance.
INT16LE botline Bottom line distance.
INT16LE maxwidth Maximum character width.
INT16LE cellsize Maximum cell size.
INT16LE leftofs Left offset.
INT16LE rightofs Right offset.
INT16LE thicken Thicken pixels, for bolding.
INT16LE ulwidth Underline width.
INT16LE lightmask Lightening and...
INT16LE skewmask ...Skew masks.
INT16LE flags Font flags.
INT32LE hotptr Horiz Offset Table pointer.
INT32LE cotptr Char Offset Table pointer.
INT32LE bufptr Data Buffer pointer.
INT16LE fwidth Sum of all character widths.
INT16LE fheight Number of character rows.

To check if specified file is a correct file the following code can be used:

/* from official TXLIB.H header file */

/* GEM Font Header */
#pragma pack(push, 1)
typedef struct gemheader {
  int16_t fid;       /* Font ID                     */
  int16_t psize;     /* Point size                  */
  char fntname[32];  /* Font name                   */
  int16_t minch;     /* Minimum character           */
  int16_t maxch;     /* Maximum character           */
  int16_t topline;   /* Top line distance           */
  int16_t ascent;    /* Ascent distance             */
  int16_t halfline;  /* Half line distance          */
  int16_t descent;   /* Descent distance            */
  int16_t botline;   /* Bottom line distance        */
  int16_t maxwidth;  /* Maximum character width     */
  int16_t cellsize;  /* Maximum cell size           */
  int16_t leftofs;   /* Left offset                 */
  int16_t rightofs;  /* Right offset                */
  int16_t thicken;   /* Thicken pixels, for bolding */
  int16_t ulwidth;   /* Underline width             */
  int16_t lightmask; /* Lightening and              */
  int16_t skewmask;  /* Skew masks                  */
  int16_t flags;     /* Font flags                  */
  int32_t hotptr;    /* Horiz Offset Table pointer  */
  int32_t cotptr;    /* Char Offset Table pointer   */
  int32_t bufptr;    /* Data Buffer pointer         */
  int16_t fwidth;    /* Sum of all character widths */
  int16_t fheight;   /* Number of character rows    */
} GEMHEADER; /* sizeof(GEMHEADER) == 84 bytes */
#pragma pack(pop)

int txVerifyBuffer(GEMHEADER *gh) {
  if (
    (gh == NULL) ||
    /* from disassembled TX_??.LIB library code */
    (gh->fheight == 0) ||
    (gh->fheight < gh->ascent) || (gh->ascent < 0) ||
    (gh->ascent < gh->descent) || (gh->descent < 0) ||
    ((gh->ascent + gh->descent) > gh->fheight) ||
    (gh->cellsize == 0) ||
    (gh->maxch < gh->minch) ||
    (gh->maxch >= 256)
  ) {
    return(0);
  }
  return(1);
}

Credits

This format was researched by TheAlmightyGuru and CTPAX-X Team. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)

Links