feature: line spacing + characters are aligned

This commit is contained in:
0x35c 2024-12-19 19:04:43 +01:00
parent 61debdcb85
commit bab3069152
5 changed files with 159 additions and 22 deletions

View File

@ -5,5 +5,6 @@
struct font {
uint32_t height;
uint32_t width;
uint32_t yoffset;
char *bitmap;
};

View File

@ -8,641 +8,769 @@ struct font consolas_regular_13_font[] = {\
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 1,
.height = 1,
.yoffset = 12,
.bitmap = " ",
},
{
.width = 3,
.height = 13,
.yoffset = 0,
.bitmap = "## ## ## ## ## ## ## ## ## ## #########",
},
{
.width = 6,
.height = 5,
.yoffset = 0,
.bitmap = "##############################",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = " ## ## ## ## ## ## #################### ## ## ## ## #################### ## ## ## ## ## ## ",
},
{
.width = 8,
.height = 15,
.yoffset = 0,
.bitmap = " ### ## ##### ###### ## ## ## ## ##### ###### ##### ### ## ### ######### ###### ## ## ",
},
{
.width = 11,
.height = 13,
.yoffset = 0,
.bitmap = " ### ## ##### ### ## ## ## ## ## ## ######## ### ## ## ###### ####### ## ## ## ### ## ## ## ##### ## ### ",
},
{
.width = 11,
.height = 13,
.yoffset = 0,
.bitmap = " #### ###### ## ## ## ## ###### #### #### ## ###### ## ## ##### ## #### ## #### ######## #### ### ",
},
{
.width = 3,
.height = 5,
.yoffset = 0,
.bitmap = "###############",
},
{
.width = 5,
.height = 16,
.yoffset = 0,
.bitmap = " # ### ## ## ## ## ## ## ## ## ## ## ## ## ### # ",
},
{
.width = 5,
.height = 16,
.yoffset = 0,
.bitmap = " # ### ## ## ## ## ## ## ## ## ## ## ## ## ### # ",
},
{
.width = 8,
.height = 8,
.yoffset = 0,
.bitmap = " ## # ## # ######## ###### ###### ######## # ## # ## ",
},
{
.width = 8,
.height = 8,
.yoffset = 4,
.bitmap = " ## ## ## ################ ## ## ## ",
},
{
.width = 5,
.height = 6,
.yoffset = 10,
.bitmap = " ### #### ### ####### ### ",
},
{
.width = 6,
.height = 2,
.yoffset = 7,
.bitmap = "############",
},
{
.width = 4,
.height = 3,
.yoffset = 10,
.bitmap = " ## ########",
},
{
.width = 9,
.height = 15,
.yoffset = 0,
.bitmap = " ## ## ### ## ### ## ### ## ## ### ## ### ## ### ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ## ## ## ##### ###### ########## ###### ##### ## ## ## ###### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " ## #### ##### ## ## ## ## ## ## ## ## ################",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### # ## ## ## ### ## ### ### ### ################",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "##### ####### ## ## ## ##### ##### ## ## ######## ##### ",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = " ### ### #### ##### ## ## ### ## ### ## ## ## #################### ## ## ",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "###### ###### ## ## ##### ###### ## ## ## ######### ##### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ##### ## ## ###### ####### ## #### #### ##### ### ###### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "################ ### ## ### ## ### ## ### ### ### ### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ######### #### ##### ### ###### ###### ### ##### #### ######### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ### ##### #### #### ## ####### ###### ## ## ##### #### ",
},
{
.width = 3,
.height = 9,
.yoffset = 4,
.bitmap = "######### #########",
},
{
.width = 5,
.height = 12,
.yoffset = 4,
.bitmap = " ### ### ### ### #### ### ####### ### ",
},
{
.width = 7,
.height = 10,
.yoffset = 3,
.bitmap = " # ### ### #### #### #### #### ### ### # ",
},
{
.width = 8,
.height = 5,
.yoffset = 6,
.bitmap = "################ ################",
},
{
.width = 7,
.height = 10,
.yoffset = 3,
.bitmap = " # ### ### #### #### #### #### ### ### # ",
},
{
.width = 6,
.height = 13,
.yoffset = 0,
.bitmap = "### ##### ### ## ## ##### #### ## ## ## ### ### ### ",
},
{
.width = 10,
.height = 16,
.yoffset = 0,
.bitmap = " #### ####### ## ## ## ## ## ##################### ######## ######## ######## ############## ## ###### ## ## ## ####### ##### ",
},
{
.width = 12,
.height = 12,
.yoffset = 1,
.bitmap = " ### #### #### ###### ## ## ## ## ### ### ######## ######## ### ### ## ## ### ###",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "###### ########## #### #### ########## ####### ## #### #### ######### ###### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ## ### ## ## ## ## ## ## # ####### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "##### ####### ## ## ## #### #### #### #### #### ##### ## ####### ##### ",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ## ################ ## ## ##############",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ## ################ ## ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ## #### ## ## ###### ###### #### ## ## ## ####### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "## #### #### #### #### #################### #### #### #### #### ##",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ## ## ## ## ## ## ## ################",
},
{
.width = 6,
.height = 12,
.yoffset = 1,
.bitmap = "############ ## ## ## ## ## ## ### ####### ### ",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = "## ### ## ### ## ### ## ### ##### #### #### ##### ## ### ## ### ## ### ## ### ",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "## ## ## ## ## ## ## ## ## ## ##############",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = "### ####### ######## ######## ############################## ###### ## ###### ###### ###### ###### ###",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "### ##### ###### ###### ###### #### ## #### ## #### ###### ###### ###### ##### ###",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = " #### ######## ## ## ### #### #### #### #### #### ### ## ## ######## #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "###### ####### ## ##### #### #### ########## ###### ## ## ## ## ",
},
{
.width = 9,
.height = 15,
.yoffset = 1,
.bitmap = " #### ####### ## ## ## #### #### #### #### #### ## ## ## ####### ##### ## # ##### ### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "##### ####### ## ## ## ## ## ## ###### ##### ## ### ## ### ## ### ## ##### ###",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ## # ## ### ##### ##### ### #### ######### ##### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ## ## ## ## ## ## ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "## #### #### #### #### #### #### #### #### #### ### ###### #### ",
},
{
.width = 12,
.height = 12,
.yoffset = 1,
.bitmap = "### ### ### ## ### ### ## ## ### ### ### ### ## ## ###### ###### #### #### ### ",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = " ## # ## ## ## ## ## ## ## ## ## ## ## ## ######## ######## ######## ######## ### ### ### ### ",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = "### ### ## ## ### ### ###### #### #### #### #### ###### ### ### ### ### ### ###",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = "## ##### ### ## ## ## ## ###### #### #### ## ## ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ### ## ### ### ### ### ## ################",
},
{
.width = 5,
.height = 16,
.yoffset = 0,
.bitmap = "############ ## ## ## ## ## ## ## ## ## ## ## ##########",
},
{
.width = 9,
.height = 15,
.yoffset = 0,
.bitmap = "## ### ## ### ## ### ## ## ### ## ### ## ### ## ## ",
},
{
.width = 5,
.height = 16,
.yoffset = 0,
.bitmap = "########## ## ## ## ## ## ## ## ## ## ## ## ############",
},
{
.width = 10,
.height = 6,
.yoffset = 1,
.bitmap = " ## #### ###### ## ## ## ## ### ###",
},
{
.width = 10,
.height = 2,
.yoffset = 14,
.bitmap = "####################",
},
{
.width = 7,
.height = 5,
.yoffset = 0,
.bitmap = " ### ### ## ",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap = " #### ###### # ## ############## #### ########## ######",
},
{
.width = 8,
.height = 13,
.yoffset = 0,
.bitmap = "## ## ## ## ###### ####### ### #### #### #### #### ########## ##### ",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap = " #### ######### ### ## ## ### # ###### #### ",
},
{
.width = 8,
.height = 13,
.yoffset = 0,
.bitmap = " ## ## ## ## ###### ########## #### #### #### #### ### ####### ### ##",
},
{
.width = 8,
.height = 9,
.yoffset = 4,
.bitmap = " #### ###### ### #################### ### ####### ######",
},
{
.width = 9,
.height = 13,
.yoffset = 0,
.bitmap = " #### ##### ## ## ## ####### ####### ## ## ## ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 4,
.bitmap = " ################ ## ## ## ####### ###### ## ####### ########## ########## ##### ",
},
{
.width = 7,
.height = 13,
.yoffset = 0,
.bitmap = "## ## ## ## ###### ########## #### #### #### #### #### #### ##",
},
{
.width = 8,
.height = 13,
.yoffset = 0,
.bitmap = " ### ### ### ##### ##### ## ## ## ## ## ################",
},
{
.width = 7,
.height = 16,
.yoffset = 0,
.bitmap = " ### ### ### ############## ## ## ## ## ## ## ### ######## #### ",
},
{
.width = 9,
.height = 13,
.yoffset = 0,
.bitmap = "## ## ## ## ## ### ## ### ##### #### #### ##### ## ### ## ### ## ### ",
},
{
.width = 8,
.height = 13,
.yoffset = 0,
.bitmap = "##### ##### ## ## ## ## ## ## ## ## ## ################",
},
{
.width = 8,
.height = 9,
.yoffset = 4,
.bitmap = "#### ## ################## ## #### ## #### ## #### ## #### ## #### ## ##",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap = "###### ########## #### #### #### #### #### #### ##",
},
{
.width = 8,
.height = 9,
.yoffset = 4,
.bitmap = " #### ###### ### ##### #### #### ##### ### ###### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 4,
.bitmap = "###### ####### ### #### #### #### #### ########## ###### ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 4,
.bitmap = " ###### ########## #### #### #### #### ### ####### ###### ## ## ##",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap = "###### ########## #### #### ## ## ## ## ",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap = " ##### ###### ## #### ##### #### ############### ",
},
{
.width = 9,
.height = 12,
.yoffset = 1,
.bitmap = " # ## ## ################## ## ## ## ## ## ###### #####",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap = "## #### #### #### #### #### #### ########## ######",
},
{
.width = 10,
.height = 9,
.yoffset = 4,
.bitmap = "### ### ## ## ### ### ## ## ## ## ###### #### #### ## ",
},
{
.width = 10,
.height = 9,
.yoffset = 4,
.bitmap = "### ### ## ## ## ## ## ## ## ## ######## ######## ######## ### #### ### ### ",
},
{
.width = 11,
.height = 9,
.yoffset = 4,
.bitmap = " ### ### ### ### ### ### ##### #### #### ###### ###### ### ### ",
},
{
.width = 10,
.height = 12,
.yoffset = 4,
.bitmap = "### ### ### ## ### ### ## ## ###### ##### #### ### ## ### ##### #### ",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap = "############## ## ## ### ## ### ##############",
},
{
.width = 7,
.height = 16,
.yoffset = 0,
.bitmap = " ### #### ## ## ## ## ## ### #### ## ## ## ## ## ##### ####",
},
{
.width = 2,
.height = 18,
.yoffset = -2,
.bitmap = "####################################",
},
{
.width = 7,
.height = 16,
.yoffset = 0,
.bitmap = "### #### ## ## ## ## ## ### #### ## ## ## ## ## ##### #### ",
},
{
.width = 9,
.height = 4,
.yoffset = 6,
.bitmap = " ### ######## #### ######## #### ",
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
};

View File

@ -9,9 +9,10 @@
#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768
#define FONT_SIZE 13
#define VGA_WIDTH (SCREEN_WIDTH / FONT_SIZE)
#define VGA_HEIGHT (SCREEN_HEIGHT / FONT_SIZE)
#define FONT_WIDTH 13
#define FONT_HEIGHT 17
#define VGA_WIDTH (SCREEN_WIDTH / FONT_WIDTH)
#define VGA_HEIGHT (SCREEN_HEIGHT / FONT_HEIGHT)
#define TERM_COUNT 10
struct screen {
@ -19,7 +20,7 @@ struct screen {
size_t column;
uint32_t fg_color;
uint32_t bg_color;
uint16_t buffer[VGA_WIDTH * VGA_HEIGHT];
uint8_t buffer[VGA_WIDTH * VGA_HEIGHT];
uint32_t default_color;
struct icon *background;
struct font *font;

View File

@ -42,8 +42,8 @@ void terminal_remove_last_char(void)
screen->column = VGA_WIDTH - 1;
screen->row--;
}
uint32_t pos_x = (screen->column) * FONT_SIZE;
uint32_t pos_y = screen->row * FONT_SIZE;
uint32_t pos_x = (screen->column) * FONT_WIDTH;
uint32_t pos_y = screen->row * FONT_HEIGHT;
struct font node = get_font_node(
screen->buffer[screen->row * VGA_WIDTH + screen->column]);
@ -112,7 +112,8 @@ void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color,
for (size_t cy = 0; cy < node.height; cy++) {
for (size_t cx = 0; cx < node.width; cx++) {
if (glyph[cy * node.width + cx] == '#')
put_pixel(fg_color, x + cx, y + cy);
put_pixel(fg_color, x + cx,
y + cy + node.yoffset);
}
}
}
@ -127,8 +128,8 @@ static void terminal_scroll(void)
screen->row--;
memset(display.buff, 0, display.height * display.pitch);
for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) {
const uint32_t x = (i % VGA_WIDTH) * FONT_SIZE;
const uint32_t y = (i / VGA_WIDTH) * FONT_SIZE;
const uint32_t x = (i % VGA_WIDTH) * FONT_WIDTH;
const uint32_t y = (i / VGA_WIDTH) * FONT_HEIGHT;
screen->buffer[i] = screen->buffer[i + VGA_WIDTH];
terminal_putentryat(get_font_node(screen->buffer[i]),
screen->fg_color, screen->bg_color, x, y);
@ -138,7 +139,7 @@ static void terminal_scroll(void)
static void terminal_new_line(void)
{
screen->column = 0;
if (++screen->row == VGA_HEIGHT - 1)
if (++screen->row >= VGA_HEIGHT - 1)
terminal_scroll();
}
@ -203,9 +204,9 @@ int terminal_putchar(char c)
return 1;
screen->buffer[screen->column + screen->row * VGA_WIDTH] = c;
terminal_putentryat(get_font_node(c), screen->fg_color,
screen->bg_color, screen->column * FONT_SIZE,
screen->row * FONT_SIZE);
if (++screen->column == VGA_WIDTH)
screen->bg_color, screen->column * FONT_WIDTH,
screen->row * FONT_HEIGHT);
if (++screen->column >= VGA_WIDTH)
terminal_new_line();
return 1;
}

View File

@ -13,7 +13,8 @@ with open(sys.argv[1]) as f:
font_name: str = os.path.basename(sys.argv[1]).split(".")[0]
img_file_relative_path: str = re.findall(r"file=\"(\w+[^\"]+)\"", fnt_data)[0]
img_file_absolute_path: str = sys.argv[1][0:sys.argv[1].rfind("/") + 1] + img_file_relative_path
img_file_absolute_path: str = sys.argv[1][0:sys.argv[1].rfind("/") +
1] + img_file_relative_path
image = Image.open(img_file_absolute_path)
@ -23,15 +24,18 @@ pixels = [pixels[i * width:(i + 1) * width] for i in range(height)]
characteres: list[list[int]] = [None for i in range(128)]
for id, x, y, width, height, xoffset, yoffset, xadvance in re.findall(r"id=(\d+) x=(\d+) y=(\d+) width=(\d+) height=(\d+) xoffset=(-?\d+) yoffset=(-?\d+) xadvance=(\d+)", fnt_data):
id, x, y, width, height, xoffset, yoffset, xadvance = int(id), int(x), int(y), int(width), int(height), int(xoffset), int(yoffset), int(xadvance)
for id, x, y, width, height, xoffset, yoffset, xadvance in re.findall(
r"id=(\d+) x=(\d+) y=(\d+) width=(\d+) height=(\d+) xoffset=(-?\d+) yoffset=(-?\d+) xadvance=(\d+)",
fnt_data):
id, x, y, width, height, xoffset, yoffset, xadvance = int(id), int(x), int(
y), int(width), int(height), int(xoffset), int(yoffset), int(xadvance)
bitmap: list[str] = []
for line in pixels[y:y + height]:
tmp: str = ""
for r,g,b,a in line[x:x + width]:
for r, g, b, a in line[x:x + width]:
tmp += "#" if a else " "
bitmap.append(tmp)
characteres[id] = [height, width, bitmap]
characteres[id] = [height, width, yoffset, bitmap]
string: str = f"""\
#pragma once
@ -45,11 +49,12 @@ struct font {font_name}_font[] = {{\\\
for charactere in characteres:
if (charactere is not None):
height, width, bitmap = charactere
height, width, yoffset, bitmap = charactere
string += f"""
{{
.width = {width},
.height = {height},
.yoffset = {yoffset},
.bitmap = "{"".join(bitmap)}",
}},\
"""
@ -58,6 +63,7 @@ for charactere in characteres:
{{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
}},\
"""