ref: 6acb1876c6aff7dc67dabc11c353bdda967a3504
parent: 7e690483be7c21cdd869f9686f9c2ff5ccc3c3fe
author: telephil9 <telephil9@gmail.com>
date: Tue Oct 27 09:49:26 EDT 2020
Added draw.openfont() and draw.buildfont() It is now possible to load and use different fonts
--- a/draw.c
+++ b/draw.c
@@ -1,4 +1,5 @@
#include <u.h>
+#include <lib9.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -443,6 +444,48 @@
pushpoint(L, rp);
return 1;
}
+
+static int
+lopenfont(lua_State *L)
+{
+ Display *d;
+ Font *f;
+ char *n;
+ char err[128];
+
+ d = checkdisplay(L, 1);
+ n = luaL_checkstring(L, 2);
+ f = openfont(d, n);
+ if(f == nil){
+ errstr(err, sizeof err);
+ lua_pushfstring(L, "cannot open font '%s': %s", n, err);
+ return lua_error(L);
+ }
+ pushfont(L, f);
+ return 1;
+}
+
+static int
+lbuildfont(lua_State *L)
+{
+ Display *d;
+ Font *f;
+ char *n, *m;
+ char err[128];
+
+ d = checkdisplay(L, 1);
+ n = luaL_checkstring(L, 2);
+ m = luaL_checkstring(L, 3);
+ f = buildfont(d, n, m);
+ if(f == nil){
+ errstr(err, sizeof err);
+ lua_pushfstring(L, "cannot build font '%s': %s", n, err);
+ return lua_error(L);
+ }
+ pushfont(L, f);
+ return 1;
+}
+
static int
lallocimage(lua_State *L)
@@ -502,6 +545,8 @@
{ "stringn", lstringn },
{ "stringbg", lstringbg },
{ "stringnbg", lstringnbg },
+ { "openfont", lopenfont },
+ { "buildfont", lbuildfont },
{ "allocimage", lallocimage },
{ "allocimagemix", lallocimagemix },
{ NULL, NULL }