]> Dogcows Code - chaz/openbox/blob - util/xftlsfonts.cc
build epist normally, dont link in stuff it doenst need to yet
[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 cout << "Usage: " << argv[0] << " [options]" << endl;
28 cout << " -style Show possible styles for each font" << endl;
29 cout << " -slant Show the slant for each font" << endl;
30 cout << " -weight Show the weight for each font" << endl;
31 cout << " -file Show which files contain each font" << endl;
32 cout << endl;
33 return 1;
34 }
35
36 Display *display = XOpenDisplay(NULL);
37 if (! display) {
38 cout << "Failed to open connection to X display\n";
39 return 2;
40 }
41
42 XftObjectSet *obj = XftObjectSetCreate();
43 if (! obj) {
44 cout << "Failed to create an XftObjectSet\n";
45 return 2;
46 }
47
48 XftObjectSetAdd(obj, XFT_FAMILY);
49
50 if (argc > 1)
51 for (int i = 1; i < argc; ++i) {
52 if (string(argv[i]) == "-style") XftObjectSetAdd(obj, XFT_STYLE);
53 else if (string(argv[i]) == "-file") XftObjectSetAdd(obj, XFT_FILE);
54 else if (string(argv[i]) == "-slant") XftObjectSetAdd(obj, XFT_SLANT);
55 else if (string(argv[i]) == "-weight") XftObjectSetAdd(obj, XFT_WEIGHT);
56 }
57
58 XftPattern *pat = XftPatternCreate();
59 if (! pat) {
60 cout << "Failed to create an XftPattern\n";
61 exit(2);
62 }
63
64 XftFontSet *set = XftListFontsPatternObjects(display, DefaultScreen(display),
65 pat, obj);
66 if (! set) {
67 cout << "Failed to find a matching XftFontSet\n";
68 exit(2);
69 }
70
71 XFree(pat);
72 XFree(obj);
73
74 for (int i = 0; i < set->nfont; ++i) {
75 for (int e = 0; e < set->fonts[i]->num; ++e) {
76 // if (string(set->fonts[i]->elts[e].object) != "family")
77 // continue; // i just want font family names
78
79 if (e > 0)
80 cout << " "; // indent after the first element
81 cout << set->fonts[i]->elts[e].object << ": ";
82
83 XftValueList *vallist = set->fonts[i]->elts[e].values;
84 bool f = true;
85 do {
86 if (f)
87 f = false;
88 else
89 cout << ", ";
90
91 XftValue val = vallist->value;
92 switch (val.type) {
93 case XftTypeVoid:
94 cout << "(void)";
95 break;
96
97 case XftTypeInteger:
98 cout << val.u.i;
99 break;
100
101 case XftTypeDouble:
102 cout << val.u.d;
103 break;
104
105 case XftTypeString:
106 cout << val.u.s;
107 break;
108
109 case XftTypeBool:
110 cout << val.u.b;
111 break;
112
113 case XftTypeMatrix:
114 cout << "xx(" << val.u.m->xx << ") ";
115 cout << "xy(" << val.u.m->xy << ") ";
116 cout << "yx(" << val.u.m->yx << ") ";
117 cout << "yy(" << val.u.m->yy << ")";
118 break;
119 }
120 } while ((vallist = vallist->next));
121 cout << endl;
122 }
123 }
124
125 cout << endl << "Found " << set->nfont << " matches." << endl;
126
127 XFree(set);
128
129 XCloseDisplay(display);
130 return 0;
131 }
This page took 0.039599 seconds and 4 git commands to generate.