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