From b065c29aa6c95e3342612867ca160c9c43a6f364 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 25 Jul 2002 05:15:45 +0000 Subject: [PATCH] make what is output optional --- util/xftlsfonts.cc | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/util/xftlsfonts.cc b/util/xftlsfonts.cc index 1e0075ed..0651065b 100644 --- a/util/xftlsfonts.cc +++ b/util/xftlsfonts.cc @@ -15,7 +15,7 @@ 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 +24,48 @@ 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); - XftFontSet *set = XftListFonts(display, DefaultScreen(display), - 0, XFT_FAMILY, 0); + XftObjectSet *obj = XftObjectSetCreate(); + if (! obj) { + cout << "Failed to create an XftObjectSet\n"; + exit(2); + } + + XftObjectSetAdd(obj, XFT_FAMILY); + + 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); + } - cout << "Found " << set->nfont << " fonts:" << endl; + XftPattern *pat = XftPatternCreate(); + if (! pat) { + cout << "Failed to create an XftPattern\n"; + exit(2); + } + + 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) { @@ -85,6 +117,8 @@ int main(int argc, char **argv) { cout << endl; } } + + cout << endl << "Found " << set->nfont << " matches." << endl; XFree(set); -- 2.45.2