From DmWiki
Jump to navigationJump to search

Font structure

DSB uses fonts in the Allegro bitmap font format[1]. TrueType fonts or other standard font formats can't be used directly in DSB.

Fonts can be created by hand in your graphics package of choice, or you can use a tool like FontEd[2] which allows you to generate the correct format from a TrueType font.

An Allegro bitmap font is usually arranged on a 16 x 8 grid, which represents the standard ASCII symbols numbered 0-127[3]. Each position of the grid should therefore contain the correct ASCII symbol for that position.

Here is a sample font, created using the FontEd tool.

Sample DSB font.png

The font must be arranged in a specific way:

  • A single, solid background colour that starts at 0,0 and wraps the entire image
  • A second, solid color behind each character. There must be at least 1 pixel space between characters, both horizontally and vertically.
  • A third color for the characters themselves. Typically this is black or white.

Font format

DSB only recognises fonts in PCX or BMP format, in either 8-bit (256 colours) or 24-bit (millions of colours). Regardless of bit depth, the fonts must always be structured as above.

DSB can use its own text-writing functions to re-colour any 8-bit font. But it can't re-color a 24-bit font. So if you want your font to be re-coloured by DSB at runtime (such as for messages in the champion's colours), then make sure your font is an 8-bit font. DSB expects 8-bit fonts to have color indexes setup correctly:

  • Index 0: The background colour (yellow in this example)
  • Index 1: The character color (white in this example)
  • Index 255: The background color of each character (pink in this example)

Your graphics package should be able to create an 8-bit image, see this forum message for how to do it in PhotoShop: [4]

Default fonts

By default, DSB uses just three fonts:

  • sys_font which is used for all parts of the standard interface and is the chunky 5x5 font (including spell runes assigned to the lower case letters)
  • gfx.scroll_font which is only used when displaying text on scrolls in the champion's active hand
  • gfx.wall_font which is the chiselled text used on wall-writing throughout the dungeon

Loading fonts

Fonts are loaded in the same way as graphics. In your custom graphics.lua file, you can add them like this:

gfx.font_main = dsb_get_font("FONT_MAIN", "path/to/font/0403.pcx")

You can override default fonts by re-declaring the original, for example:

gfx.scroll_font = dsb_get_font("SCROLLFONT", "path/to/font/myscrollfont.bmp")
sys_font = dsb_get_font("AAASYSFONT", "path/to/font/mysysfont.bmp")

Using fonts

DSB has two functions for creating text on screen: dsb_write() and dsb_bitmap_textout().

  • dsb_write() renders text in the console/message area at the bottom of the screen. It always uses the system font (sys_font) and this can't be changed.
  • dsb_bitmap_textout() is used to add text to all the other parts of the interface. You can override any of DSBs original rendering functions if you want to change the fonts that are used, as this function takes a font as a parameter.

See DSB/Exposed functions for more details.