X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=util%2Fxftlsfonts.cc;h=d02758e28b5dfbc21012c5d42217e91785ac98c5;hb=a93f06f5b3162e59c04074a14bd3702e4bb82133;hp=1e0075edf89e7460b52ee953ff933e6332aa511c;hpb=fb7b6b37615cafa5d553560d78f931e0003fb6cc;p=chaz%2Fopenbox diff --git a/util/xftlsfonts.cc b/util/xftlsfonts.cc index 1e0075ed..d02758e2 100644 --- a/util/xftlsfonts.cc +++ b/util/xftlsfonts.cc @@ -1,3 +1,24 @@ +const char *NAME = "xftlsfonts"; +const char *VERSION = "1.0"; + +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif // HAVE_CONFIG_H + +#ifndef XFT +#include +using std::cout; +using std::endl; + +int main(int, char **) { + cout << NAME << " version " << VERSION << endl; + cout << "Copyright (c) 2002, Ben Jansens " << endl; + cout << endl; + cout << "Openbox was built without support for Xft fonts. This utility must" + << endl; + cout << "must be built with Xft support in order to function." << endl; +} +#else // XFT extern "C" { #include #include @@ -7,15 +28,12 @@ extern "C" { #include #include -const char *NAME = "xftlsfonts"; -const char *VERSION = "1.0"; - using std::string; using std::cout; using std::endl; int main(int argc, char **argv) { - if (argc > 1) { + if (argc > 1) for (int i = 1; i < argc; ++i) if (string(argv[i]) == "-help" || string(argv[i]) == "--help" || @@ -24,16 +42,52 @@ int main(int argc, char **argv) { cout << NAME << " version " << VERSION << endl; cout << "Copyright (c) 2002, Ben Jansens " << endl; cout << endl; + cout << "Usage: " << argv[0] << " [options]" << endl; + cout << " -style Show possible styles for each font" << endl; + cout << " -slant Show the slant for each font" << endl; + cout << " -weight Show the weight for each font" << endl; + cout << " -file Show which files contain each font" << endl; + cout << endl; return 1; } - } Display *display = XOpenDisplay(NULL); + if (! display) { + cout << "Failed to open connection to X display\n"; + return 2; + } + + XftObjectSet *obj = XftObjectSetCreate(); + if (! obj) { + cout << "Failed to create an XftObjectSet\n"; + return 2; + } + + XftObjectSetAdd(obj, XFT_FAMILY); - XftFontSet *set = XftListFonts(display, DefaultScreen(display), - 0, XFT_FAMILY, 0); + if (argc > 1) + for (int i = 1; i < argc; ++i) { + if (string(argv[i]) == "-style") XftObjectSetAdd(obj, XFT_STYLE); + else if (string(argv[i]) == "-file") XftObjectSetAdd(obj, XFT_FILE); + else if (string(argv[i]) == "-slant") XftObjectSetAdd(obj, XFT_SLANT); + else if (string(argv[i]) == "-weight") XftObjectSetAdd(obj, XFT_WEIGHT); + } + + XftPattern *pat = XftPatternCreate(); + if (! pat) { + cout << "Failed to create an XftPattern\n"; + exit(2); + } - cout << "Found " << set->nfont << " fonts:" << endl; + XftFontSet *set = XftListFontsPatternObjects(display, DefaultScreen(display), + pat, obj); + if (! set) { + cout << "Failed to find a matching XftFontSet\n"; + exit(2); + } + + XFree(pat); + XFree(obj); for (int i = 0; i < set->nfont; ++i) { for (int e = 0; e < set->fonts[i]->num; ++e) { @@ -74,20 +128,26 @@ int main(int argc, char **argv) { cout << val.u.b; break; +#ifdef XFT_UTF8 case XftTypeMatrix: cout << "xx(" << val.u.m->xx << ") "; cout << "xy(" << val.u.m->xy << ") "; cout << "yx(" << val.u.m->yx << ") "; cout << "yy(" << val.u.m->yy << ")"; break; +#endif } } while ((vallist = vallist->next)); cout << endl; } } + + cout << endl << "Found " << set->nfont << " matches." << endl; XFree(set); XCloseDisplay(display); return 0; } +#endif // XFT +