diff --git a/apps/krk_yutani_test.krk b/apps/krk_yutani_test.krk index 6071b09e..589041e8 100644 --- a/apps/krk_yutani_test.krk +++ b/apps/krk_yutani_test.krk @@ -7,7 +7,7 @@ from _yutani import (color, Yutani, Window, Decorator, Message, let running = True let y = Yutani() let w = Window(640,480,title="Test Window",doublebuffer=True) -let dejavu = Font("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",13) +let dejavu = Font("sans-serif",13) w.move(200,200) diff --git a/lib/kuroko/_yutani.c b/lib/kuroko/_yutani.c index 5cb24b30..2c348590 100644 --- a/lib/kuroko/_yutani.c +++ b/lib/kuroko/_yutani.c @@ -889,7 +889,13 @@ static KrkValue _font_init(int argc, KrkValue argv[], int hasKw) { if (!krk_isInstanceOf(fontColor, YutaniColor)) return krk_runtimeError(vm.exceptions->typeError, "expected color"); } - self->fontData = tt_font_from_file(AS_CSTRING(argv[1])); + /* Try to be smart about this */ + if (strstr(AS_CSTRING(argv[1]), "sans-serif") == AS_CSTRING(argv[1]) || strstr(AS_CSTRING(argv[1]), "monospace") == AS_CSTRING(argv[1])) { + self->fontData = tt_font_from_shm(AS_CSTRING(argv[1])); + } else { + self->fontData = tt_font_from_file(AS_CSTRING(argv[1])); + } + if (!self->fontData) return krk_runtimeError(vm.exceptions->typeError, "failed to load font");