summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-11 12:48:08 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-11 12:48:08 +0100
commitcf3e6ac4c968b09b4e431b111162aea6041f47a6 (patch)
tree98d57d3006c71fe2bb1f4d0e3480981d8be0fdeb /src
parent3b2636cbc666159f0962f7b6024d6a85743d6594 (diff)
load font manually
Diffstat (limited to 'src')
-rw-r--r--src/text.cc23
-rw-r--r--src/text.h5
2 files changed, 25 insertions, 3 deletions
diff --git a/src/text.cc b/src/text.cc
index 600220e..43ee74e 100644
--- a/src/text.cc
+++ b/src/text.cc
@@ -1,5 +1,10 @@
#include "text.h"
+#include <fcntl.h>
+#include <mimalloc.h>
+#include <unistd.h>
+#include <utils.h>
+
#include "utils.h"
enum font_context_error_e wayc_font_context_init(struct font_context_s* ctx) {
@@ -22,12 +27,26 @@ enum font_error_e wayc_font_init(struct font_s* font,
wayc_notnull(ctx);
wayc_notnull(path);
- FT_Error err = FT_New_Face(ctx->library, path, 0, &font->face);
- if (err) return FONT_ERROR_LOAD;
+ i32 fd = open(path, O_RDONLY);
+ if (fd < 0) return FONT_ERROR_FILE_LOAD;
+ wayc_defer(close(fd));
+
+ usize size = lseek(fd, 0, SEEK_END);
+ if (size < 0) return FONT_ERROR_FILE_LOAD;
+ lseek(fd, 0, SEEK_SET);
+
+ font->data = (u8*)mi_malloc(size);
+ usize _read = read(fd, font->data, size);
+ if (_read != size) return FONT_ERROR_FILE_LOAD;
+
+ FT_Error err = FT_New_Memory_Face(ctx->library, (const FT_Byte*)font->data,
+ size, 0, &font->face);
+ if (err) return FONT_ERROR_FONT_LOAD;
return FONT_ERROR_NONE;
}
void wayc_font_deinit(struct font_s* font) {
wayc_notnull(font);
FT_Done_Face(font->face);
+ mi_free(font->data);
}
diff --git a/src/text.h b/src/text.h
index ec0b4fe..cfd7a00 100644
--- a/src/text.h
+++ b/src/text.h
@@ -1,6 +1,7 @@
#pragma once
#include "freetype/freetype.h"
+#include "utils.h"
enum font_context_error_e {
FONT_CONTEXT_ERROR_NONE,
@@ -16,10 +17,12 @@ void wayc_font_context_deinit(struct font_context_s* ctx);
enum font_error_e {
FONT_ERROR_NONE,
- FONT_ERROR_LOAD,
+ FONT_ERROR_FILE_LOAD,
+ FONT_ERROR_FONT_LOAD,
};
struct font_s {
+ u8* data;
FT_Face face;
};