summaryrefslogtreecommitdiff
path: root/sys/src/libdraw/subfontname.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libdraw/subfontname.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libdraw/subfontname.c')
-rwxr-xr-xsys/src/libdraw/subfontname.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/sys/src/libdraw/subfontname.c b/sys/src/libdraw/subfontname.c
new file mode 100755
index 000000000..8ab79408c
--- /dev/null
+++ b/sys/src/libdraw/subfontname.c
@@ -0,0 +1,52 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+
+/*
+ * Default version: convert to file name
+ */
+
+char*
+subfontname(char *cfname, char *fname, int maxdepth)
+{
+ char *t, *u, *tmp1, *tmp2;
+ int i;
+
+ t = strdup(cfname); /* t is the return string */
+ if(strcmp(cfname, "*default*") == 0)
+ return t;
+ if(t[0] != '/'){
+ tmp2 = strdup(fname);
+ u = utfrrune(tmp2, '/');
+ if(u)
+ u[0] = 0;
+ else
+ strcpy(tmp2, ".");
+ tmp1 = smprint("%s/%s", tmp2, t);
+ free(tmp2);
+ free(t);
+ t = tmp1;
+ }
+
+ if(maxdepth > 8)
+ maxdepth = 8;
+
+ for(i=3; i>=0; i--){
+ if((1<<i) > maxdepth)
+ continue;
+ /* try i-bit grey */
+ tmp2 = smprint("%s.%d", t, i);
+ if(access(tmp2, AREAD) == 0) {
+ free(t);
+ return tmp2;
+ }
+ free(tmp2);
+ }
+
+ /* try default */
+ if(access(t, AREAD) == 0)
+ return t;
+
+ free(t);
+ return nil;
+}