Bill Nottingham (notting@xxxxxxxxxx) said:
> So, maybe I'm insane, but if all you want is a sans bold, etc. font - that
> can't be more than about 20 lines of fontconfig code to look for a match
> for the 'sans' pattern and get a filename. That way:
>
> - you don't have to hardcode any files
> - you don't have to hardcode any requirements
OK, *somewhat* more than 20 lines. But still...
[notting@nostromo: ~]$ ./font-fu arial:style=bold
Found /usr/share/fonts/liberation/LiberationSans-Bold.ttf for arial:style=bold
[notting@nostromo: ~]$ ./font-fu serif
Found /usr/share/fonts/dejavu/DejaVuSerif.ttf for serif
Bill
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fontconfig/fontconfig.h>
char *find_me_a_font(char *style) {
FcPattern *pat, *match;
FcResult result;
FcChar8 *file;
if (!FcInit()) return NULL;
pat = FcNameParse((FcChar8 *)style);
if (!pat) return NULL;
FcConfigSubstitute(0, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
match = FcFontMatch(0, pat, &result);
if (match)
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch)
return (char *)file;
return NULL;
}
int main(int argc, char **argv) {
char *fontname;
if (argc < 2) {
printf("usage: font-fu <style>\n");
return 1;
}
fontname = find_me_a_font(argv[1]);
if (fontname)
printf("Found %s for %s\n",fontname, argv[1]);
else
printf("Couldn't find a font for %s\n", argv[1]);
return 0;
}
--
fedora-devel-list mailing list
fedora-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/fedora-devel-list