diff -up freewrl-1.22.13/src/lib/scenegraph/Component_Text.c.fcfontmatch-fix freewrl-1.22.13/src/lib/scenegraph/Component_Text.c
--- freewrl-1.22.13/src/lib/scenegraph/Component_Text.c.fcfontmatch-fix 2012-03-06 17:25:43.000000000 -0500
+++ freewrl-1.22.13/src/lib/scenegraph/Component_Text.c 2014-02-09 11:45:54.359080014 -0500
@@ -400,8 +400,33 @@ void FW_make_fontname(int num) {
ppComponent_Text p = (ppComponent_Text)gglobal()->Component_Text.prv;
#ifdef HAVE_FONTCONFIG
FcPattern *FW_fp=NULL;
- FcPattern *FW_fm=NULL;
FcChar8 *FW_file=NULL;
+ FcResult result;
+
+ // check whether we have a config file
+ char* configfile = (char*)FcConfigFilename(0);
+ int configexists = 0;
+ FILE*fi = fopen(configfile, "rb");
+ if(fi) {
+ configexists = 1;fclose(fi);
+ //printf("<debug> Initializing FontConfig (configfile=%s)\n", configfile);
+ } else {
+ //printf("<debug> Initializing FontConfig (no configfile)\n");
+ }
+
+ if(!FcInit()) {
+ printf("<debug> FontConfig Initialization failed.\n");
+ }
+ FcConfig * config = FcConfigGetCurrent();
+ if(!config) {
+ printf("<debug> FontConfig Config Initialization failed.\n");
+ }
+
+ FcFontSet *set = FcConfigGetFonts(config, FcSetSystem);
+ //printf("<verbose> FontConfig initialized. Found %d fonts\n", set?set->nfont:0);
+ if(!set || !set->nfont) {
+ printf("<debug> FontConfig has found zero fonts. This is probably a bad thing.\n");
+ }
#else
if (!p->font_directory) {
@@ -519,20 +544,30 @@ void FW_make_fontname(int num) {
#ifdef HAVE_FONTCONFIG
FcConfigSubstitute(0,FW_fp,FcMatchPattern);
FcDefaultSubstitute(FW_fp);
- if (!(FW_fm = FcFontMatch(0,FW_fp,0))) {
- /* do whatever is done when no match found */
- printf ("could not find font for id %x\n",num);
- } else {
- if (FcPatternGetString(FW_fm,FC_FILE,0,&FW_file) != FcResultMatch) {
- printf ("could not find font for id %x\n",num);
- } else {
- /* strcpy didn't work, use strncpy and set the null character by hand */
- strncpy(p->thisfontname,(char *)FW_file,strlen((char *)FW_file));
- p->thisfontname[strlen((char *)FW_file)] = NULL;
+ set = FcFontSort(0, FW_fp, 1, 0, &result);
+
+ /* This isn't very smart, but we just go with the first match in the set that we can find a valid file for. */
+ if(set) {
+ // printf("<debug> okay, found a set with %d fonts\n", set?set->nfont:0);
+ int t;
+ for(t=0;t<set->nfont;t++) {
+ FcPattern *match = set->fonts[t];
+ if (FcPatternGetString(match,FC_FILE,0,&FW_file) != FcResultMatch) {
+ printf("<debug> FontConfig: Couldn't get fontconfig's filename for font id %x\n", num);
+ FW_file=0;
+ } else {
+ // printf("<debug> setting p->thisfontname to %s\n", FW_file);
+ /* strcpy didn't work, use strncpy and set the null character by hand */
+ strncpy(p->thisfontname,(char *)FW_file,strlen((char *)FW_file));
+ p->thisfontname[strlen((char *)FW_file)] = NULL;
+ break;
+ }
}
- FcPatternDestroy(FW_fm);
+ } else {
+ printf("<debug> no set? wha?\n");
}
FcPatternDestroy(FW_fp);
+ FcPatternDestroy(set);
#endif
}