Implement fc-list --verbose (#13015)
A private FcObjectGetSet() is implemented that provides an FcObjectSet of all registered elements. FcFontSetList() is then modified to use the object set from FcObjectGetSet() if provided object-set is NULL. Alternatively FcObjectGetSet() can be made public. In that case fc-list can use that as a base if --verbose is included, and also add any elements provided by the user (though that has no effect, as all elements from the cache are already registered). Currently fc-list ignores user-provided elements if --verbose is specified.
This commit is contained in:
parent
77c0d8bce8
commit
2987409853
|
@ -71,11 +71,11 @@ static void usage (char *program)
|
||||||
fprintf (stderr, "List fonts matching [pattern]\n");
|
fprintf (stderr, "List fonts matching [pattern]\n");
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
#if HAVE_GETOPT_LONG
|
#if HAVE_GETOPT_LONG
|
||||||
fprintf (stderr, " -v, --verbose display status information while busy\n");
|
fprintf (stderr, " -v, --verbose display entire font pattern\n");
|
||||||
fprintf (stderr, " -V, --version display font config version and exit\n");
|
fprintf (stderr, " -V, --version display font config version and exit\n");
|
||||||
fprintf (stderr, " -?, --help display this help and exit\n");
|
fprintf (stderr, " -?, --help display this help and exit\n");
|
||||||
#else
|
#else
|
||||||
fprintf (stderr, " -v (verbose) display status information while busy\n");
|
fprintf (stderr, " -v (verbose) display entire font pattern\n");
|
||||||
fprintf (stderr, " -V (version) display font config version and exit\n");
|
fprintf (stderr, " -V (version) display font config version and exit\n");
|
||||||
fprintf (stderr, " -? (help) display this help and exit\n");
|
fprintf (stderr, " -? (help) display this help and exit\n");
|
||||||
#endif
|
#endif
|
||||||
|
@ -85,7 +85,7 @@ static void usage (char *program)
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
/*int verbose = 0;*/
|
int verbose = 0;
|
||||||
int i;
|
int i;
|
||||||
FcObjectSet *os = 0;
|
FcObjectSet *os = 0;
|
||||||
FcFontSet *fs;
|
FcFontSet *fs;
|
||||||
|
@ -105,7 +105,7 @@ main (int argc, char **argv)
|
||||||
FC_MAJOR, FC_MINOR, FC_REVISION);
|
FC_MAJOR, FC_MINOR, FC_REVISION);
|
||||||
exit (0);
|
exit (0);
|
||||||
case 'v':
|
case 'v':
|
||||||
/* verbose = 1; */
|
verbose = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage (argv[0]);
|
usage (argv[0]);
|
||||||
|
@ -124,20 +124,22 @@ main (int argc, char **argv)
|
||||||
if (argv[i])
|
if (argv[i])
|
||||||
{
|
{
|
||||||
pat = FcNameParse ((FcChar8 *) argv[i]);
|
pat = FcNameParse ((FcChar8 *) argv[i]);
|
||||||
while (argv[++i])
|
if (!verbose)
|
||||||
{
|
while (argv[++i])
|
||||||
if (!os)
|
{
|
||||||
os = FcObjectSetCreate ();
|
if (!os)
|
||||||
FcObjectSetAdd (os, argv[i]);
|
os = FcObjectSetCreate ();
|
||||||
}
|
FcObjectSetAdd (os, argv[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pat = FcPatternCreate ();
|
pat = FcPatternCreate ();
|
||||||
|
|
||||||
if (!os)
|
if (!verbose && !os)
|
||||||
os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
|
os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
|
||||||
fs = FcFontList (0, pat, os);
|
fs = FcFontList (0, pat, os);
|
||||||
FcObjectSetDestroy (os);
|
if (os)
|
||||||
|
FcObjectSetDestroy (os);
|
||||||
if (pat)
|
if (pat)
|
||||||
FcPatternDestroy (pat);
|
FcPatternDestroy (pat);
|
||||||
|
|
||||||
|
@ -150,11 +152,16 @@ main (int argc, char **argv)
|
||||||
FcChar8 *font;
|
FcChar8 *font;
|
||||||
FcChar8 *file;
|
FcChar8 *file;
|
||||||
|
|
||||||
font = FcNameUnparse (fs->fonts[j]);
|
if (verbose)
|
||||||
if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
|
FcPatternPrint (fs->fonts[j]);
|
||||||
printf ("%s: ", file);
|
else
|
||||||
printf ("%s\n", font);
|
{
|
||||||
free (font);
|
font = FcNameUnparse (fs->fonts[j]);
|
||||||
|
if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
|
||||||
|
printf ("%s: ", file);
|
||||||
|
printf ("%s\n", font);
|
||||||
|
free (font);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FcFontSetDestroy (fs);
|
FcFontSetDestroy (fs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,8 +76,10 @@ manpage.1: manpage.sgml
|
||||||
<title>DESCRIPTION</title>
|
<title>DESCRIPTION</title>
|
||||||
|
|
||||||
<para><command>&dhpackage;</command> lists fonts and styles
|
<para><command>&dhpackage;</command> lists fonts and styles
|
||||||
available on the system for applications using fontconfig.</para>
|
available on the system for applications using fontconfig.
|
||||||
|
With <option>--verbose</option>, the whole font pattern
|
||||||
|
for each font is printed, otherwise only the elements requested
|
||||||
|
are printed (family and style if none provided).</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
<refsect1>
|
<refsect1>
|
||||||
<title>OPTIONS</title>
|
<title>OPTIONS</title>
|
||||||
|
@ -92,7 +94,9 @@ manpage.1: manpage.sgml
|
||||||
<option>--verbose</option>
|
<option>--verbose</option>
|
||||||
</term>
|
</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Display status information while busy.</para>
|
<para>Print whole font pattern for each match. Provided
|
||||||
|
<replaceable>element</replaceable>s are ignored in this
|
||||||
|
case.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
|
|
@ -863,6 +863,9 @@ FcObjectFromName (const char * name);
|
||||||
FcPrivate const char *
|
FcPrivate const char *
|
||||||
FcObjectName (FcObject object);
|
FcObjectName (FcObject object);
|
||||||
|
|
||||||
|
FcPrivate FcObjectSet *
|
||||||
|
FcObjectGetSet (void);
|
||||||
|
|
||||||
FcPrivate FcBool
|
FcPrivate FcBool
|
||||||
FcObjectInit (void);
|
FcObjectInit (void);
|
||||||
|
|
||||||
|
|
10
src/fclist.c
10
src/fclist.c
|
@ -457,6 +457,7 @@ FcFontSetList (FcConfig *config,
|
||||||
FcListHashTable table;
|
FcListHashTable table;
|
||||||
int i;
|
int i;
|
||||||
FcListBucket *bucket;
|
FcListBucket *bucket;
|
||||||
|
int destroy_os = 0;
|
||||||
|
|
||||||
if (!config)
|
if (!config)
|
||||||
{
|
{
|
||||||
|
@ -468,6 +469,13 @@ FcFontSetList (FcConfig *config,
|
||||||
goto bail0;
|
goto bail0;
|
||||||
}
|
}
|
||||||
FcListHashTableInit (&table);
|
FcListHashTableInit (&table);
|
||||||
|
|
||||||
|
if (!os)
|
||||||
|
{
|
||||||
|
os = FcObjectGetSet ();
|
||||||
|
destroy_os = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Walk all available fonts adding those that
|
* Walk all available fonts adding those that
|
||||||
* match to the hash table
|
* match to the hash table
|
||||||
|
@ -532,6 +540,8 @@ bail2:
|
||||||
bail1:
|
bail1:
|
||||||
FcListHashTableCleanup (&table);
|
FcListHashTableCleanup (&table);
|
||||||
bail0:
|
bail0:
|
||||||
|
if (destroy_os)
|
||||||
|
FcObjectSetDestroy (os);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
src/fcname.c
14
src/fcname.c
|
@ -327,6 +327,20 @@ FcObjectFromName (const char * name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FcObjectSet *
|
||||||
|
FcObjectGetSet (void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
FcObjectSet *os = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
os = FcObjectSetCreate ();
|
||||||
|
for (i = 0; i < FcObjectsNumber; i++)
|
||||||
|
FcObjectSetAdd (os, FcObjects[i].object);
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
FcBool
|
FcBool
|
||||||
FcObjectInit (void)
|
FcObjectInit (void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue