Difference between revisions of "DSB/Fonts"
Line 1: | Line 1: | ||
− | == Font | + | == Font structure == |
DSB can only use fonts that are created in the Allegro bitmap font format[https://www.allegro.cc/manual/5/al_grab_font_from_bitmap]. You CAN'T use TrueType fonts or other standard font formats in DSB. | DSB can only use fonts that are created in the Allegro bitmap font format[https://www.allegro.cc/manual/5/al_grab_font_from_bitmap]. You CAN'T use TrueType fonts or other standard font formats in DSB. | ||
Line 8: | Line 8: | ||
An Allegro bitmap font is usually arranged on a 16 x 8 grid, which represents the standard ASCII symbols numbered 0-127[http://www.asciitable.com/]. Each position of the grid should therefore contain the correct ASCII symbol for that position. | An Allegro bitmap font is usually arranged on a 16 x 8 grid, which represents the standard ASCII symbols numbered 0-127[http://www.asciitable.com/]. Each position of the grid should therefore contain the correct ASCII symbol for that position. | ||
− | [[File: | + | Here is a sample font, created using the FontEd tool. |
+ | |||
+ | [[File:Sample_DSB_font.png]] | ||
+ | |||
+ | The font must have three colours, and 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: [http://www.dungeon-master.com/forum/viewtopic.php?f=53&t=30798#p157162] | ||
+ | |||
+ | == 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()'''. Both these functions take a font as a parameter, so you can be in complete control of which fonts to use for different parts of the screen. See [[DSB/Exposed functions]] for more details. |
Revision as of 10:46, 20 December 2018
Font structure
DSB can only use fonts that are created in the Allegro bitmap font format[1]. You CAN'T use TrueType fonts or other standard font formats 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.
The font must have three colours, and 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(). Both these functions take a font as a parameter, so you can be in complete control of which fonts to use for different parts of the screen. See DSB/Exposed functions for more details.