summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2024-08-11 21:39:59 +0200
committerLouis Burda <quent.burda@gmail.com>2024-08-11 21:39:59 +0200
commitd02ac078404fbe7b7138baee55d7a0332c544bfe (patch)
tree4beaf6f929e43736454e919d125ef1c69131eab7
parent4be51de5c252d1e6f621fcdd14de6acf9b4c43ce (diff)
downloadxnote-d02ac078404fbe7b7138baee55d7a0332c544bfe.tar.gz
xnote-d02ac078404fbe7b7138baee55d7a0332c544bfe.zip
Add fontconfig lookup
-rw-r--r--Makefile4
-rw-r--r--xnote.c21
2 files changed, 21 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 821cb9b..f400d3e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
PREFIX ?= /usr/local
BINDIR ?= /bin
-LDLIBS = -lglfw -lGL $(shell pkg-config --libs freetype2)
-CFLAGS = $(shell pkg-config --cflags freetype2)
+LDLIBS = -lglfw -lGL $(shell pkg-config --libs freetype2 fontconfig)
+CFLAGS = $(shell pkg-config --cflags freetype2 fontconfig)
ifeq ($(DEBUG),1)
CFLAGS += -Og -g
diff --git a/xnote.c b/xnote.c
index a554f42..c35193c 100644
--- a/xnote.c
+++ b/xnote.c
@@ -1,5 +1,6 @@
#include <GL/gl.h>
#include <GLFW/glfw3.h>
+#include <fontconfig/fontconfig.h>
#include <ft2build.h>
#include FT_FREETYPE_H
@@ -355,11 +356,27 @@ main(void)
push_event(EVENT_START);
+ const char *fontname = getenv("XNOTE_FONT") ?: "Arial";
+ FcConfig *config = FcInitLoadConfigAndFonts();
+ FcPattern *pattern = FcNameParse((const FcChar8 *)fontname);
+ FcConfigSubstitute(config, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+ FcResult result;
+ FcPattern *font = FcFontMatch(config, pattern, &result);
+ if (!font) die("Failed to load font: %s", fontname);
+ FcChar8 *filepath = NULL;
+ assert(FcPatternGetString(font, FC_FILE, 0, &filepath) == FcResultMatch);
+ int fontsize = 0;
+ assert(FcPatternGetInteger(font, FC_SIZE, 0, &fontsize) == FcResultMatch);
+
FT_Library freetype;
FT_Face face;
assert(!FT_Init_FreeType(&freetype));
- assert(!FT_New_Face(freetype, "NotoSansMono-Regular.ttf", 0, &face));
- assert(!FT_Set_Char_Size(face, 16 * 64, 0, 300, 300));
+ assert(!FT_New_Face(freetype, (const char *)filepath, 0, &face));
+ assert(!FT_Set_Char_Size(face, 0, fontsize * 64, 300, 300));
+
+ FcPatternDestroy(pattern);
+ FcConfigDestroy(config);
glGenTextures(128, glyphs);
for (size_t c = 0; c < 128; c++) {