]> Dogcows Code - chaz/openbox/blob - util/xftlsfonts.cc
build something when theres no xft support
[chaz/openbox] / util / xftlsfonts.cc
1 const char *NAME = "xftlsfonts";
2 const char *VERSION = "1.0";
3
4 #ifndef XFT
5 #include <iostream>
6
7 int main(int, char **) {
8 cout << NAME << " version " << VERSION << endl;
9 cout << "Copyright (c) 2002, Ben Jansens <ben@orodu.net>" << endl;
10 cout << endl;
11 cout << "Openbox was built without support for Xft fonts. This utility must"
12 << endl;
13 cout << "must be built with Xft support in order to function." << endl;
14 }
15 #else // XFT
16 extern "C" {
17 #include <X11/Xlib.h>
18 #include <X11/Xft/Xft.h>
19 }
20
21 #include <iostream>
22 #include <string>
23 #include <vector>
24
25 using std::string;
26 using std::cout;
27 using std::endl;
28
29 int main(int argc, char **argv) {
30 if (argc > 1)
31 for (int i = 1; i < argc; ++i)
32 if (string(argv[i]) == "-help" ||
33 string(argv[i]) == "--help" ||
34 string(argv[i]) == "-version" ||
35 string(argv[i]) == "--version") {
36 cout << NAME << " version " << VERSION << endl;
37 cout << "Copyright (c) 2002, Ben Jansens <ben@orodu.net>" << endl;
38 cout << endl;
39 cout << "Usage: " << argv[0] << " [options]" << endl;
40 cout << " -style Show possible styles for each font" << endl;
41 cout << " -slant Show the slant for each font" << endl;
42 cout << " -weight Show the weight for each font" << endl;
43 cout << " -file Show which files contain each font" << endl;
44 cout << endl;
45 return 1;
46 }
47
48 Display *display = XOpenDisplay(NULL);
49 if (! display) {
50 cout << "Failed to open connection to X display\n";
51 return 2;
52 }
53
54 XftObjectSet *obj = XftObjectSetCreate();
55 if (! obj) {
56 cout << "Failed to create an XftObjectSet\n";
57 return 2;
58 }
59
60 XftObjectSetAdd(obj, XFT_FAMILY);
61
62 if (argc > 1)
63 for (int i = 1; i < argc; ++i) {
64 if (string(argv[i]) == "-style") XftObjectSetAdd(obj, XFT_STYLE);
65 else if (string(argv[i]) == "-file") XftObjectSetAdd(obj, XFT_FILE);
66 else if (string(argv[i]) == "-slant") XftObjectSetAdd(obj, XFT_SLANT);
67 else if (string(argv[i]) == "-weight") XftObjectSetAdd(obj, XFT_WEIGHT);
68 }
69
70 XftPattern *pat = XftPatternCreate();
71 if (! pat) {
72 cout << "Failed to create an XftPattern\n";
73 exit(2);
74 }
75
76 XftFontSet *set = XftListFontsPatternObjects(display, DefaultScreen(display),
77 pat, obj);
78 if (! set) {
79 cout << "Failed to find a matching XftFontSet\n";
80 exit(2);
81 }
82
83 XFree(pat);
84 XFree(obj);
85
86 for (int i = 0; i < set->nfont; ++i) {
87 for (int e = 0; e < set->fonts[i]->num; ++e) {
88 // if (string(set->fonts[i]->elts[e].object) != "family")
89 // continue; // i just want font family names
90
91 if (e > 0)
92 cout << " "; // indent after the first element
93 cout << set->fonts[i]->elts[e].object << ": ";
94
95 XftValueList *vallist = set->fonts[i]->elts[e].values;
96 bool f = true;
97 do {
98 if (f)
99 f = false;
100 else
101 cout << ", ";
102
103 XftValue val = vallist->value;
104 switch (val.type) {
105 case XftTypeVoid:
106 cout << "(void)";
107 break;
108
109 case XftTypeInteger:
110 cout << val.u.i;
111 break;
112
113 case XftTypeDouble:
114 cout << val.u.d;
115 break;
116
117 case XftTypeString:
118 cout << val.u.s;
119 break;
120
121 case XftTypeBool:
122 cout << val.u.b;
123 break;
124
125 case XftTypeMatrix:
126 cout << "xx(" << val.u.m->xx << ") ";
127 cout << "xy(" << val.u.m->xy << ") ";
128 cout << "yx(" << val.u.m->yx << ") ";
129 cout << "yy(" << val.u.m->yy << ")";
130 break;
131 }
132 } while ((vallist = vallist->next));
133 cout << endl;
134 }
135 }
136
137 cout << endl << "Found " << set->nfont << " matches." << endl;
138
139 XFree(set);
140
141 XCloseDisplay(display);
142 return 0;
143 }
144 #endif // XFT
145
This page took 0.044086 seconds and 5 git commands to generate.