7 #define STB_TRUETYPE_IMPLEMENTATION
8 #include "3rdparty/stb_truetype.h"
10 #include "lib/stdio.h"
11 #include "io/screen.h"
14 void ttf_init(
ttf_font_t* font,
const char* path) {
21 fseek(fp, 0, SEEK_END);
25 fseek(fp, 0, SEEK_SET);
30 stbtt_InitFont(&font->info, font->data, 0);
32 stbtt_GetFontVMetrics(&font->info, &font->ascent, &font->descent, &font->linegap);
36 qemu_log(
"ASCENT: %d; DESCENT: %d", font->ascent, font->descent);
41 void ttf_draw_char(
ttf_font_t *font,
char *buffer,
int bwidth,
int bheight,
int sx,
int sy,
int character) {
44 float scale = stbtt_ScaleForPixelHeight(&font->info, font->user_size);
49 stbtt_GetCodepointHMetrics(&font->info, character, &ax, &lsb);
51 int c_x1, c_y1, c_x2, c_y2;
52 stbtt_GetCodepointBitmapBox(&font->info, character, scale, scale, &c_x1, &c_y1, &c_x2, &c_y2);
53 qemu_log(
"==> C_X1: %d, C_Y1: %d, C_X2: %d, C_Y2: %d", c_x1, c_y1, c_x2, c_y2);
55 char* bitmap = calloc(100 * 100, 1);
59 stbtt_MakeCodepointBitmap(&font->info, bitmap, c_x2 - c_x1, font->user_size,
60 font->user_size, scale, scale, character);
62 for(
int y = 0; y < font->user_size; y++) {
63 for(
int x = 0; x < c_x2; x++) {
64 if(bitmap[y * font->user_size + x] != 0) {
65 set_pixel(sx + x, sy + y + ((font->user_size / 2) + 5 + c_y1), 0xFFFFFF);
74 void ttf_draw_string(
ttf_font_t* font,
char* buffer,
int bwidth,
int bheight,
int sx,
int sy,
const char*
string) {
78 float scale = stbtt_ScaleForPixelHeight(&font->info, font->user_size);
83 stbtt_GetCodepointHMetrics(&font->info, *
string, &ax, &lsb);
88 qemu_log(
"AX: %d; LSB: %d", ax, lsb);
91 ttf_draw_char(font, buffer, bwidth, bheight, sx, sy, *
string);
94 sx += (int)(scale * ax);
size_t filesize(const char *Path)
[FileIO] Возвращает размер указанного файла
ssize_t fseek(FILE *stream, ssize_t offset, uint8_t whence)
Установка позиции в потоке данных относительно текущей позиции
void fclose(FILE *stream)
Закончить работу с файлом
FILE * fopen(const char *filename, const char *_mode)
Открывает файл
int ftell(FILE *stream)
Текущая позиция считывания в файле
int fread(FILE *stream, size_t count, size_t size, void *buffer)
Чтение файла
Структура файла. Требуется для работы с VFS.