forked from vixus0/xftwidth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxftwidth.c
42 lines (32 loc) · 843 Bytes
/
xftwidth.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <X11/Xft/Xft.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
#include <fontconfig/fontconfig.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
if (argc < 3)
{
printf("xftwidth font string\n");
return 1;
}
char *name = argv[1];
size_t len = strlen(argv[2]);
Display *dpy;
XftFont *fn;
XGlyphInfo ext;
FcChar8 str[len];
memcpy(str, argv[2], len);
dpy = XOpenDisplay(NULL);
fn = XftFontOpenName(dpy, 0, name);
if (fn == NULL)
{
puts("Font not found.");
return 1;
}
XftTextExtents8(dpy, fn, str, (int)len, &ext);
printf("%d\n", ext.width);
XCloseDisplay(dpy);
return 0;
}