ref: 9561401327db61b80702e2744881b428e093cd79
parent: 3c77420b78c6c828c66a5a31bf4d685e289a21e1
author: telephil9 <telephil9@gmail.com>
date: Wed Oct 28 18:24:22 EDT 2020
Added font size computation functions to draw module Added functions are stringsize, stringwidth and stringnwidth
--- a/draw.c
+++ b/draw.c
@@ -486,8 +486,50 @@
return 1;
}
-
static int
+lstringsize(lua_State *L)
+{
+ Font *f;
+ char *s;
+ Point p;
+
+ f = checkfont(L, 1);
+ s = luaL_checkstring(L, 2);
+ p = stringsize(f, s);
+ pushpoint(L, p);
+ return 1;
+}
+
+static int
+lstringwidth(lua_State *L)
+{
+ Font *f;
+ char *s;
+ int w;
+
+ f = checkfont(L, 1);
+ s = luaL_checkstring(L, 2);
+ w = stringwidth(f, s);
+ lua_pushinteger(L, w);
+ return 1;
+}
+
+static int
+lstringnwidth(lua_State *L)
+{
+ Font *f;
+ char *s;
+ int n, w;
+
+ f = checkfont(L, 1);
+ s = luaL_checkstring(L, 2);
+ n = luaL_checkinteger(L, 3);
+ w = stringnwidth(f, s, n);
+ lua_pushinteger(L, w);
+ return 1;
+}
+
+static int
lallocimage(lua_State *L)
{
Display *d;
@@ -547,6 +589,9 @@
{ "stringnbg", lstringnbg },
{ "openfont", lopenfont },
{ "buildfont", lbuildfont },
+ { "stringsize", lstringsize },
+ { "stringwidth", lstringwidth },
+ { "stringnwidth", lstringnwidth },
{ "allocimage", lallocimage },
{ "allocimagemix", lallocimagemix },
{ NULL, NULL }