]> Dogcows Code - chaz/openbox/blob - util/xftlsfonts.cc
add the xftlsfonts utility
[chaz/openbox] / util / xftlsfonts.cc
1 extern "C" {
2 #include <X11/Xlib.h>
3 #include <X11/Xft/Xft.h>
4 }
5
6 #include <iostream>
7 #include <string>
8 #include <vector>
9
10 const char *NAME = "xftlsfonts";
11 const char *VERSION = "1.0";
12
13 using std::string;
14 using std::cout;
15 using std::endl;
16
17 int main(int argc, char **argv) {
18 if (argc > 1) {
19 for (int i = 1; i < argc; ++i)
20 if (string(argv[i]) == "-help" ||
21 string(argv[i]) == "--help" ||
22 string(argv[i]) == "-version" ||
23 string(argv[i]) == "--version") {
24 cout << NAME << " version " << VERSION << endl;
25 cout << "Copyright (c) 2002, Ben Jansens <ben@orodu.net>" << endl;
26 cout << endl;
27 return 1;
28 }
29 }
30
31 Display *display = XOpenDisplay(NULL);
32
33 XftFontSet *set = XftListFonts(display, DefaultScreen(display),
34 0, XFT_FAMILY, 0);
35
36 cout << "Found " << set->nfont << " fonts:" << endl;
37
38 for (int i = 0; i < set->nfont; ++i) {
39 for (int e = 0; e < set->fonts[i]->num; ++e) {
40 // if (string(set->fonts[i]->elts[e].object) != "family")
41 // continue; // i just want font family names
42
43 if (e > 0)
44 cout << " "; // indent after the first element
45 cout << set->fonts[i]->elts[e].object << ": ";
46
47 XftValueList *vallist = set->fonts[i]->elts[e].values;
48 bool f = true;
49 do {
50 if (f)
51 f = false;
52 else
53 cout << ", ";
54
55 XftValue val = vallist->value;
56 switch (val.type) {
57 case XftTypeVoid:
58 cout << "(void)";
59 break;
60
61 case XftTypeInteger:
62 cout << val.u.i;
63 break;
64
65 case XftTypeDouble:
66 cout << val.u.d;
67 break;
68
69 case XftTypeString:
70 cout << val.u.s;
71 break;
72
73 case XftTypeBool:
74 cout << val.u.b;
75 break;
76
77 case XftTypeMatrix:
78 cout << "xx(" << val.u.m->xx << ") ";
79 cout << "xy(" << val.u.m->xy << ") ";
80 cout << "yx(" << val.u.m->yx << ") ";
81 cout << "yy(" << val.u.m->yy << ")";
82 break;
83 }
84 } while ((vallist = vallist->next));
85 cout << endl;
86 }
87 }
88
89 XFree(set);
90
91 XCloseDisplay(display);
92 return 0;
93 }
This page took 0.042697 seconds and 5 git commands to generate.