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