aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiley Beckett <rbeckettvt@gmail.com>2025-10-12 00:35:52 -0400
committerRiley Beckett <rbeckettvt@gmail.com>2025-10-12 01:53:54 -0400
commit91759767b0c7793060f447fd545b639cf91b7ae3 (patch)
tree352721239f5fccde336aec48d6ff6acdb3fbd6ed
parentd58f2e870b8f998262609b98f91d290b65ab80d3 (diff)
freetype/fontconfig base
-rw-r--r--Makefile2
-rw-r--r--font.c64
-rw-r--r--font.h8
-rw-r--r--keyboard.c1
-rw-r--r--main.c8
-rw-r--r--state.h7
6 files changed, 88 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 24e62bb..0b1ba9b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
BIN=swenu
CC=gcc
OBJDIR=objs
-LIBS=egl wayland-client gl wayland-egl xkbcommon
+LIBS=egl wayland-client gl wayland-egl xkbcommon freetype2 fontconfig
CFLAGS=-Wall -g $(shell pkg-config --cflags $(LIBS)) -I$(OBJDIR)
LDFLAGS=$(shell pkg-config --libs $(LIBS))
VPATH=/usr/share/wayland-protocols/staging/cursor-shape/:/usr/share/wayland-protocols/stable/tablet/:/usr/share/wayland-protocols/stable/xdg-shell/:$(OBJDIR)
diff --git a/font.c b/font.c
new file mode 100644
index 0000000..9198b3a
--- /dev/null
+++ b/font.c
@@ -0,0 +1,64 @@
+#include <fontconfig/fontconfig.h>
+#include "font.h"
+
+char* get_font(const char* font_name) {
+ FcPattern* pattern = FcNameParse((const FcChar8*)font_name);
+ if (!pattern) {
+ fprintf(stderr, "Failed to create font pattern\n");
+ return NULL;
+ }
+
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+
+ FcResult result = 0;
+ FcFontSet* font_patterns = FcFontSort(0, pattern, FcTrue, 0, &result);
+ if (!font_patterns || !font_patterns->nfont) {
+ fprintf(stderr, "No fonts installed on system\n");
+ return NULL;
+ }
+
+ FcFontSet* fs = FcFontSetCreate();
+ FcPattern* font_pattern = FcFontRenderPrepare(0, pattern, font_patterns->fonts[0]);
+ if (!font_pattern) {
+ fprintf(stderr, "Could not prepare matched font for loading\n");
+ return NULL;
+ }
+ FcFontSetAdd(fs, font_pattern);
+
+ FcFontSetSortDestroy(font_patterns);
+ FcPatternDestroy(pattern);
+
+ if (!fs || !font_patterns->nfont) {
+ fprintf(stderr, "Could not prepare font set\n");
+ }
+ FcObjectSet* os = FcObjectSetBuild(FC_FILE, (char*)0);
+ FcValue v = { 0 };
+
+ FcPattern* fontp = FcPatternFilter(fs->fonts[0], os);
+ FcPatternGet(fontp, FC_FILE, 0, &v);
+ char* font = strdup((char*)v.u.f);
+
+ FcPatternDestroy(fontp);
+ FcFontSetDestroy(fs);
+ FcObjectSetDestroy(os);
+
+ return font;
+}
+
+bool init_freetype(client_state* state, const char* file) {
+ if (FT_Init_FreeType(&state->ft_library)) {
+ fprintf(stderr, "Failed to intalize FreeType Library\n");
+ return false;
+ }
+ if (FT_New_Face(state->ft_library, file, 0, &state->ft_face)) {
+ fprintf(stderr, "Failed to create font\n");
+ return false;
+ }
+ if (FT_Set_Char_Size(state->ft_face, 0, 12 << 6, 0, 0)) {
+ fprintf(stderr, "Failed to set font size\n");
+ return false;
+ }
+
+ return true;
+}
diff --git a/font.h b/font.h
new file mode 100644
index 0000000..ecb4a01
--- /dev/null
+++ b/font.h
@@ -0,0 +1,8 @@
+#ifndef FONT_H_
+#define FONT_H_
+#include "state.h"
+
+char* get_font(const char* font_name);
+bool init_freetype(client_state* state, const char* font);
+
+#endif // FONT_H_
diff --git a/keyboard.c b/keyboard.c
index 5460570..4929dcf 100644
--- a/keyboard.c
+++ b/keyboard.c
@@ -117,7 +117,6 @@ void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
client_state* state = data;
state->key_repeat_rate = rate;
state->key_repeat_delay = delay;
- printf("repeat info\n");
}
struct wl_keyboard_listener keyboard_listener = {
diff --git a/main.c b/main.c
index bf27838..4489928 100644
--- a/main.c
+++ b/main.c
@@ -6,6 +6,7 @@
#include "wayland.h"
#include "graphics.h"
#include "input_field.h"
+#include "font.h"
void poll_events(client_state* state);
@@ -34,6 +35,13 @@ int main() {
return 1;
}
+ char* font = get_font("Monospace");
+ printf("font: %s\n", font);
+ if (!init_freetype(&state, font)) {
+ fprintf(stderr, "Failed to Initalize FreeType\n");
+ }
+ free(font);
+
// event loop
while (state.running) {
poll_events(&state);
diff --git a/state.h b/state.h
index 352236d..465e9b6 100644
--- a/state.h
+++ b/state.h
@@ -11,6 +11,9 @@
#include <cursor-shape-v1.h>
#include <sys/timerfd.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
#include "./glad/glad.h"
typedef struct {
@@ -46,6 +49,10 @@ typedef struct {
// state
char* input_buffer;
uint32_t width, height;
+
+ FT_Library ft_library;
+ FT_Face ft_face;
+
bool running;
} client_state;