gterm: Implement TERMINAL_FONT_SPACING and default it to 1
This commit is contained in:
parent
f9fe2f96ed
commit
cefc4a76ca
@ -58,10 +58,12 @@ Some keys take *URIs* as values; these are described in the next section.
|
||||
* `MENU_BRANDING` - A string that will be displayed on top of the Limine menu.
|
||||
* `MENU_FONT` - URI path to a font file to be used instead of the default one for the menu and terminal. The font file must be a code page 437 character set comprised of 256 consecutive glyph bitmaps. Each glyph's bitmap must be expressed left to right (1 byte per row), and top to bottom (16 bytes per whole glyph by default; see `MENU_FONT_SIZE`). See e.g. the [VGA text mode font collection](https://github.com/viler-int10h/vga-text-mode-fonts) for fonts.
|
||||
* `TERMINAL_FONT` - Alias of `MENU_FONT`.
|
||||
* `MENU_FONT_SIZE` - The size of the font in dots, which must correspond to the font file or the display will be garbled. Note that glyphs are always one byte wide, and columns over 8 are empty. Many fonts may be used in both 8- and 9-dot wide variants. Defaults to `8x16`.
|
||||
* `MENU_FONT_SIZE` - The size of the font in dots, which must correspond to the font file or the display will be garbled. Note that glyphs are always one byte wide, and columns over 8 are empty. Many fonts may be used in both 8- and 9-dot wide variants. Defaults to `8x16`. Ignored if `MENU_FONT` or `TERMINAL_FONT` not set or if the font fails to load.
|
||||
* `TERMINAL_FONT_SIZE` - Alias of `MENU_FONT_SIZE`.
|
||||
* `MENU_FONT_SCALE` - Scaling for the font in the x and y directions. `2x2` would display the font in double size, which is useful on high-DPI displays at native resolution. `2x1` only makes the font twice as wide, similar to the VGA 40 column mode. `4x2` might be good for a narrow font on a high resolution display. Values over 8 are disallowed. Default is no scaling, i.e. `1x1`.
|
||||
* `TERMINAL_FONT_SCALE` - Alias of `MENU_FONT_SCALE`.
|
||||
* `MENU_FONT_SPACING` - Horizontal spacing, in pixels, between glyphs on screen. It is equivalent to setting a font width of `<specified width>+<this value>`, except this value is preserved even in case font loading fails, and it also applies to the built-in Limine font. Defaults to 1. 0 is allowed.
|
||||
* `TERMINAL_FONT_SPACING` - Alias of `MENU_FONT_SPACING`.
|
||||
* `THEME_COLOURS` - Specifies the colour palette used by the terminal (AARRGGBB). It is a `;` separated array of 10 colours: black, red, green, brown, blue, magenta, cyan, gray, background, and foreground respectively. While an alpha transparency value can be specified for every colour, it is ignored for all but background. Ignored if `GRAPHICS` is not `yes`.
|
||||
* `THEME_COLORS` - Alias of `THEME_COLOURS`.
|
||||
* `THEME_BACKGROUND` - Alias of the background value in `THEME_COLOURS`.
|
||||
|
@ -16,8 +16,11 @@
|
||||
#define VGA_FONT_MAX 16384
|
||||
#define VGA_FONT_GLYPHS 256
|
||||
|
||||
static size_t vga_font_width = 8;
|
||||
static size_t vga_font_height = 16;
|
||||
#define DEFAULT_FONT_WIDTH 8
|
||||
#define DEFAULT_FONT_HEIGHT 16
|
||||
|
||||
static size_t vga_font_width;
|
||||
static size_t vga_font_height;
|
||||
static size_t glyph_width = 8;
|
||||
static size_t glyph_height = 16;
|
||||
|
||||
@ -658,15 +661,19 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
|
||||
gterm_bpp = fbinfo.framebuffer_bpp;
|
||||
gterm_pitch = fbinfo.framebuffer_pitch;
|
||||
|
||||
vga_font_width = DEFAULT_FONT_WIDTH, vga_font_height = DEFAULT_FONT_HEIGHT;
|
||||
|
||||
size_t font_width = DEFAULT_FONT_WIDTH, font_height = DEFAULT_FONT_HEIGHT;
|
||||
|
||||
char *menu_font_size = config_get_value(NULL, 0, "MENU_FONT_SIZE");
|
||||
if (menu_font_size == NULL) {
|
||||
menu_font_size = config_get_value(NULL, 0, "TERMINAL_FONT_SIZE");
|
||||
}
|
||||
if (menu_font_size != NULL) {
|
||||
parse_resolution(&vga_font_width, &vga_font_height, NULL, menu_font_size);
|
||||
parse_resolution(&font_width, &font_height, NULL, menu_font_size);
|
||||
}
|
||||
|
||||
size_t font_bytes = (vga_font_width * vga_font_height * VGA_FONT_GLYPHS) / 8;
|
||||
size_t font_bytes = (font_width * font_height * VGA_FONT_GLYPHS) / 8;
|
||||
|
||||
if (vga_font_bits == NULL) {
|
||||
vga_font_bits = ext_mem_alloc(VGA_FONT_MAX);
|
||||
@ -689,9 +696,23 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
|
||||
if (!uri_open(&f, menu_font)) {
|
||||
print("menu: Could not open font file.\n");
|
||||
} else {
|
||||
fread(&f, vga_font_bits, 0, font_bytes);
|
||||
if (fread(&f, vga_font_bits, 0, font_bytes) == 0) {
|
||||
vga_font_width = font_width;
|
||||
vga_font_height = font_height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t font_spacing = 1;
|
||||
char *font_spacing_str = config_get_value(NULL, 0, "MENU_FONT_SPACING");
|
||||
if (font_spacing_str == NULL) {
|
||||
font_spacing_str = config_get_value(NULL, 0, "TERMINAL_FONT_SPACING");
|
||||
}
|
||||
if (font_spacing_str != NULL) {
|
||||
font_spacing = strtoui(font_spacing_str, NULL, 10);
|
||||
}
|
||||
|
||||
vga_font_width += font_spacing;
|
||||
|
||||
// if not loaded (stage2) or custom font (stage3), load font
|
||||
if (vga_font_bool == NULL || menu_font != NULL) {
|
||||
|
@ -81,9 +81,11 @@ static const char *VALID_KEYS[] = {
|
||||
"MENU_FONT",
|
||||
"MENU_FONT_SIZE",
|
||||
"MENU_FONT_SCALE",
|
||||
"MENU_FONT_SPACING",
|
||||
"TERMINAL_FONT",
|
||||
"TERMINAL_FONT_SIZE",
|
||||
"TERMINAL_FONT_SCALE",
|
||||
"TERMINAL_FONT_SPACING",
|
||||
"THEME_COLOURS",
|
||||
"THEME_COLORS",
|
||||
"THEME_BRIGHT_COLOURS",
|
||||
|
@ -3,8 +3,6 @@ TIMEOUT=3
|
||||
GRAPHICS=yes
|
||||
MENU_FONT=boot:///boot/font.bin
|
||||
VERBOSE=yes
|
||||
TERMINAL_FONT_SIZE=9x16
|
||||
TERMINAL_FONT_SCALE=1x1
|
||||
|
||||
THEME_BACKGROUND=50000000
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user