[fc-match] Accept list of elements like fc-list (bug #13017)

Also make --verbose not ignore list of elements and only print those.
Update docs.
This commit is contained in:
Behdad Esfahbod 2009-01-15 19:12:37 -05:00
parent 263f16ced2
commit 41af588f54
4 changed files with 77 additions and 41 deletions

View File

@ -76,13 +76,13 @@ usage (char *program, int error)
fprintf (file, "List fonts matching [pattern]\n"); fprintf (file, "List fonts matching [pattern]\n");
fprintf (file, "\n"); fprintf (file, "\n");
#if HAVE_GETOPT_LONG #if HAVE_GETOPT_LONG
fprintf (file, " -v, --verbose display entire font pattern\n"); fprintf (file, " -v, --verbose display entire font pattern verbosely\n");
fprintf (file, " -f, --format=FORMAT use the given output format\n"); fprintf (file, " -f, --format=FORMAT use the given output format\n");
fprintf (file, " -q, --quiet suppress all normal output, exit 1 if no fonts matched\n"); fprintf (file, " -q, --quiet suppress all normal output, exit 1 if no fonts matched\n");
fprintf (file, " -V, --version display font config version and exit\n"); fprintf (file, " -V, --version display font config version and exit\n");
fprintf (file, " -h, --help display this help and exit\n"); fprintf (file, " -h, --help display this help and exit\n");
#else #else
fprintf (file, " -v (verbose) display entire font pattern\n"); fprintf (file, " -v (verbose) display entire font pattern verbosely\n");
fprintf (file, " -f FORMAT (format) use the given output format\n"); fprintf (file, " -f FORMAT (format) use the given output format\n");
fprintf (file, " -q, (quiet) suppress all normal output, exit 1 if no fonts matched\n"); fprintf (file, " -q, (quiet) suppress all normal output, exit 1 if no fonts matched\n");
fprintf (file, " -V (version) display font config version and exit\n"); fprintf (file, " -V (version) display font config version and exit\n");
@ -144,13 +144,12 @@ main (int argc, char **argv)
if (argv[i]) if (argv[i])
{ {
pat = FcNameParse ((FcChar8 *) argv[i]); pat = FcNameParse ((FcChar8 *) argv[i]);
if (!verbose) while (argv[++i])
while (argv[++i]) {
{ if (!os)
if (!os) os = FcObjectSetCreate ();
os = FcObjectSetCreate (); FcObjectSetAdd (os, argv[i]);
FcObjectSetAdd (os, argv[i]); }
}
} }
else else
pat = FcPatternCreate (); pat = FcPatternCreate ();
@ -170,9 +169,6 @@ main (int argc, char **argv)
for (j = 0; j < fs->nfont; j++) for (j = 0; j < fs->nfont; j++)
{ {
FcChar8 *font;
FcChar8 *file;
if (verbose) if (verbose)
{ {
FcPatternPrint (fs->fonts[j]); FcPatternPrint (fs->fonts[j]);
@ -187,11 +183,14 @@ main (int argc, char **argv)
} }
else else
{ {
font = FcNameUnparse (fs->fonts[j]); FcChar8 *str;
FcChar8 *file;
str = FcNameUnparse (fs->fonts[j]);
if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
printf ("%s: ", file); printf ("%s: ", file);
printf ("%s\n", font); printf ("%s\n", str);
free (font); free (str);
} }
} }
} }

View File

@ -81,9 +81,9 @@ manpage.1: manpage.sgml
<para><command>&dhpackage;</command> lists fonts and styles <para><command>&dhpackage;</command> lists fonts and styles
available on the system for applications using fontconfig. available on the system for applications using fontconfig.
With <option>--verbose</option>, the whole font pattern If any elements are specified, only those are printed.
for each font is printed, otherwise only the elements requested Otherwise family and style are printed, unless verbose
are printed (family and style if none provided).</para> output is requested.</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
<title>OPTIONS</title> <title>OPTIONS</title>
@ -98,9 +98,9 @@ manpage.1: manpage.sgml
<option>--verbose</option> <option>--verbose</option>
</term> </term>
<listitem> <listitem>
<para>Print whole font pattern for each match. Provided <para>Print verbose output of the whole font pattern for each match,
<replaceable>element</replaceable>s are ignored in this or <replaceable>element</replaceable>s if any is
case.</para> provided.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -69,25 +69,25 @@ usage (char *program, int error)
{ {
FILE *file = error ? stderr : stdout; FILE *file = error ? stderr : stdout;
#if HAVE_GETOPT_LONG #if HAVE_GETOPT_LONG
fprintf (file, "usage: %s [-savVh] [-f FORMAT] [--sort] [--all] [--verbose] [--format=FORMAT] [--version] [--help] [pattern]\n", fprintf (file, "usage: %s [-savVh] [-f FORMAT] [--sort] [--all] [--verbose] [--format=FORMAT] [--version] [--help] [pattern] {element...}\n",
program); program);
#else #else
fprintf (file, "usage: %s [-savVh] [-f FORMAT] [pattern]\n", fprintf (file, "usage: %s [-savVh] [-f FORMAT] [pattern] {element...}\n",
program); program);
#endif #endif
fprintf (file, "List fonts matching [pattern]\n"); fprintf (file, "List best font matching [pattern]\n");
fprintf (file, "\n"); fprintf (file, "\n");
#if HAVE_GETOPT_LONG #if HAVE_GETOPT_LONG
fprintf (file, " -s, --sort display sorted list of matches\n"); fprintf (file, " -s, --sort display sorted list of matches\n");
fprintf (file, " -a, --all display unpruned sorted list of matches\n"); fprintf (file, " -a, --all display unpruned sorted list of matches\n");
fprintf (file, " -v, --verbose display entire font pattern\n"); fprintf (file, " -v, --verbose display entire font pattern verbosely\n");
fprintf (file, " -f, --format=FORMAT use the given output format\n"); fprintf (file, " -f, --format=FORMAT use the given output format\n");
fprintf (file, " -V, --version display font config version and exit\n"); fprintf (file, " -V, --version display font config version and exit\n");
fprintf (file, " -h, --help display this help and exit\n"); fprintf (file, " -h, --help display this help and exit\n");
#else #else
fprintf (file, " -s, (sort) display sorted list of matches\n"); fprintf (file, " -s, (sort) display sorted list of matches\n");
fprintf (file, " -a (all) display unpruned sorted list of matches\n"); fprintf (file, " -a (all) display unpruned sorted list of matches\n");
fprintf (file, " -v (verbose) display entire font pattern\n"); fprintf (file, " -v (verbose) display entire font pattern verbosely\n");
fprintf (file, " -f FORMAT (format) use the given output format\n"); fprintf (file, " -f FORMAT (format) use the given output format\n");
fprintf (file, " -V (version) display font config version and exit\n"); fprintf (file, " -V (version) display font config version and exit\n");
fprintf (file, " -h (help) display this help and exit\n"); fprintf (file, " -h (help) display this help and exit\n");
@ -102,6 +102,7 @@ main (int argc, char **argv)
int sort = 0, all = 0; int sort = 0, all = 0;
FcChar8 *format = NULL; FcChar8 *format = NULL;
int i; int i;
FcObjectSet *os = 0;
FcFontSet *fs; FcFontSet *fs;
FcPattern *pat; FcPattern *pat;
FcResult result; FcResult result;
@ -148,7 +149,15 @@ main (int argc, char **argv)
return 1; return 1;
} }
if (argv[i]) if (argv[i])
{
pat = FcNameParse ((FcChar8 *) argv[i]); pat = FcNameParse ((FcChar8 *) argv[i]);
while (argv[++i])
{
if (!os)
os = FcObjectSetCreate ();
FcObjectSetAdd (os, argv[i]);
}
}
else else
pat = FcPatternCreate (); pat = FcPatternCreate ();
@ -192,25 +201,35 @@ main (int argc, char **argv)
for (j = 0; j < fs->nfont; j++) for (j = 0; j < fs->nfont; j++)
{ {
FcPattern *font;
font = FcPatternFilter (fs->fonts[j], os);
if (verbose) if (verbose)
{ {
FcPatternPrint (fs->fonts[j]); FcPatternPrint (font);
} }
else if (format) else if (format)
{ {
FcChar8 *s; FcChar8 *s;
s = FcPatternFormat (fs->fonts[j], format); s = FcPatternFormat (font, format);
printf ("%s", s);
free (s); free (s);
} }
else if (os)
{
FcChar8 *str;
str = FcNameUnparse (font);
printf ("%s\n", str);
free (str);
}
else else
{ {
FcChar8 *family; FcChar8 *family;
FcChar8 *style; FcChar8 *style;
FcChar8 *file; FcChar8 *file;
if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) != FcResultMatch) if (FcPatternGetString (font, FC_FILE, 0, &file) != FcResultMatch)
file = (FcChar8 *) "<unknown filename>"; file = (FcChar8 *) "<unknown filename>";
else else
{ {
@ -218,16 +237,23 @@ main (int argc, char **argv)
if (slash) if (slash)
file = slash+1; file = slash+1;
} }
if (FcPatternGetString (fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch) if (FcPatternGetString (font, FC_FAMILY, 0, &family) != FcResultMatch)
family = (FcChar8 *) "<unknown family>"; family = (FcChar8 *) "<unknown family>";
if (FcPatternGetString (fs->fonts[j], FC_STYLE, 0, &style) != FcResultMatch) if (FcPatternGetString (font, FC_STYLE, 0, &style) != FcResultMatch)
style = (FcChar8 *) "<unknown style>"; style = (FcChar8 *) "<unknown style>";
printf ("%s: \"%s\" \"%s\"\n", file, family, style); printf ("%s: \"%s\" \"%s\"\n", file, family, style);
} }
FcPatternDestroy (font);
} }
FcFontSetDestroy (fs); FcFontSetDestroy (fs);
} }
if (os)
FcObjectSetDestroy (os);
FcFini (); FcFini ();
return 0; return 0;
} }

View File

@ -73,7 +73,8 @@ manpage.1: manpage.sgml
</group> </group>
<arg><option>--version</option></arg> <arg><option>--version</option></arg>
<arg><option>--help</option></arg> <arg><option>--help</option></arg>
<arg><option><replaceable>font-pattern</replaceable></option></arg> <sbr>
<arg><option><replaceable>pattern</replaceable></option> <arg rep="repeat"><option><replaceable>element</replaceable></option></arg> </arg>
</cmdsynopsis> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
@ -81,14 +82,15 @@ manpage.1: manpage.sgml
<title>DESCRIPTION</title> <title>DESCRIPTION</title>
<para><command>&dhpackage;</command> matches <para><command>&dhpackage;</command> matches
<replaceable>font-pattern</replaceable> (empty <replaceable>pattern</replaceable> (empty
pattern by default) using the normal fontconfig matching rules to find pattern by default) using the normal fontconfig matching rules to find
the best font available. If <option>--sort</option> is given, the sorted list of best the best font available. If <option>--sort</option> is given, the sorted list of best
matching fonts is displayed. With <option>--verbose</option>, the whole font pattern matching fonts is displayed.
for each match is printed, otherwise only the file, family and style The <option>--all</option> option works like
are printed. The <option>--all</option> option works like
<option>--sort</option> except that no pruning is done on the list of fonts.</para> <option>--sort</option> except that no pruning is done on the list of fonts.</para>
If any elements are specified, only those are printed.
Otherwise short file name, family, and style are printed, unless verbose
output is requested.</para>
</refsect1> </refsect1>
<refsect1> <refsect1>
<title>OPTIONS</title> <title>OPTIONS</title>
@ -120,7 +122,9 @@ are printed. The <option>--all</option> option works like
<option>--verbose</option> <option>--verbose</option>
</term> </term>
<listitem> <listitem>
<para>Print whole font pattern for each match.</para> <para>Print verbose output of the whole font pattern for each match,
or <replaceable>element</replaceable>s if any is
provided.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -150,13 +154,20 @@ are printed. The <option>--all</option> option works like
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><option><replaceable>font-pattern</replaceable></option> <term><option><replaceable>pattern</replaceable></option>
</term> </term>
<listitem> <listitem>
<para>Displays fonts matching <para>Displays fonts matching
<replaceable>font-pattern</replaceable> (uses empty pattern by default).</para> <replaceable>pattern</replaceable> (uses empty pattern by default).</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option><replaceable>element</replaceable></option>
</term>
<listitem>
<para>If set, the <replaceable>element</replaceable> property
is displayed for matching fonts.</para>
</listitem>
</variablelist> </variablelist>
</refsect1> </refsect1>