summaryrefslogtreecommitdiff
path: root/draw/initfont.c
diff options
context:
space:
mode:
authorConnor Lane Smith <cls@lubutu.com>2010-06-24 17:44:35 +0100
committerConnor Lane Smith <cls@lubutu.com>2010-06-24 17:44:35 +0100
commit4508fd2c4ee3171bdc1bffb7e53ecda8290292ef (patch)
treee86bbdfc4e1cc93fe5906ef204bf970d389c3df2 /draw/initfont.c
parent723361fa124aa666d637e3fc9f5df1210a9e02b4 (diff)
moved draw.c to libdraw.a
Diffstat (limited to 'draw/initfont.c')
-rw-r--r--draw/initfont.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/draw/initfont.c b/draw/initfont.c
new file mode 100644
index 0000000..77d3182
--- /dev/null
+++ b/draw/initfont.c
@@ -0,0 +1,36 @@
+/* See LICENSE file for copyright and license details. */
+#include <X11/Xlib.h>
+#include "draw.h"
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+void
+initfont(DC *dc, const char *fontstr) {
+ char *def, **missing = NULL;
+ int i, n;
+
+ if(!fontstr || !*fontstr)
+ eprint("cannot load null font\n");
+ dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def);
+ if(missing)
+ XFreeStringList(missing);
+ if(dc->font.set) {
+ XFontStruct **xfonts;
+ char **font_names;
+ dc->font.ascent = dc->font.descent = 0;
+ n = XFontsOfFontSet(dc->font.set, &xfonts, &font_names);
+ for(i = 0; i < n; i++) {
+ dc->font.ascent = MAX(dc->font.ascent, (*xfonts)->ascent);
+ dc->font.descent = MAX(dc->font.descent, (*xfonts)->descent);
+ xfonts++;
+ }
+ }
+ else {
+ if(!(dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))
+ && !(dc->font.xfont = XLoadQueryFont(dc->dpy, "fixed")))
+ eprint("cannot load font '%s'\n", fontstr);
+ dc->font.ascent = dc->font.xfont->ascent;
+ dc->font.descent = dc->font.xfont->descent;
+ }
+ dc->font.height = dc->font.ascent + dc->font.descent;
+}