DEFont *de_load_font(const char *fontname) { DEFont *fnt; XFontSet fontset=NULL; XFontStruct *fontstruct=NULL; assert(fontname!=NULL); /* There shouldn't be that many fonts... */ for(fnt=fonts; fnt!=NULL; fnt=fnt->next){ if(strcmp(fnt->pattern, fontname)==0){ fnt->refcount++; return fnt; } } if(ioncore_g.use_mb && !(ioncore_g.enc_utf8 && iso10646_font(fontname))){ fontset=de_create_font_set(fontname); if(fontset!=NULL){ if(XContextDependentDrawing(fontset)){ warn(TR("Fontset for font pattern '%s' implements context " "dependent drawing, which is unsupported. Expect " "clutter."), fontname); } } }else{ fontstruct=XLoadQueryFont(ioncore_g.dpy, fontname); } if(fontstruct==NULL && fontset==NULL){ if(strcmp(fontname, CF_FALLBACK_FONT_NAME)!=0){ DEFont *fnt; warn(TR("Could not load font \"%s\", trying \"%s\""), fontname, CF_FALLBACK_FONT_NAME); fnt=de_load_font(CF_FALLBACK_FONT_NAME); if(fnt==NULL) warn(TR("Failed to load fallback font.")); return fnt; } return NULL; } fnt=ALLOC(DEFont); if(fnt==NULL) return NULL; fnt->fontset=fontset; fnt->fontstruct=fontstruct; fnt->pattern=scopy(fontname); fnt->next=NULL; fnt->prev=NULL; fnt->refcount=1; LINK_ITEM(fonts, fnt, next, prev); return fnt; }
DEFont *de_load_font(const char *fontname) { DEFont *fnt; const char *default_fontname=de_default_fontname(); #ifdef HAVE_X11_XFT XftFont *font=NULL; #endif #ifdef HAVE_X11_BMF XFontSet fontset=NULL; XFontStruct *fontstruct=NULL; #endif assert(fontname!=NULL); /* There shouldn't be that many fonts... */ for(fnt=fonts; fnt!=NULL; fnt=fnt->next){ if(strcmp(fnt->pattern, fontname)==0){ fnt->refcount++; return fnt; } } #ifdef HAVE_X11_XFT LOG(DEBUG, FONT, "Loading font %s via XFT", fontname); if(strncmp(fontname, "xft:", 4)==0){ font=XftFontOpenName(ioncore_g.dpy, DefaultScreen(ioncore_g.dpy), fontname+4); }else{ #ifdef HAVE_X11_BMF goto bitmap_font; #else font=XftFontOpenXlfd(ioncore_g.dpy, DefaultScreen(ioncore_g.dpy), fontname); #endif } if(font==NULL){ if(strcmp(fontname, default_fontname)!=0){ warn(TR("Could not load font \"%s\", trying \"%s\""), fontname, default_fontname); fnt=de_load_font(default_fontname); if(fnt==NULL) LOG(WARN, FONT, TR("Failed to load fallback font.")); return fnt; } return NULL; }else{ FcPatternPrint(font->pattern); } #endif /* HAVE_X11_XFT */ #ifdef HAVE_X11_BMF #ifdef HAVE_X11_XFT bitmap_font: #endif if(ioncore_g.use_mb && !(ioncore_g.enc_utf8 && iso10646_font(fontname))){ LOG(DEBUG, FONT, "Loading fontset %s", fontname); fontset=de_create_font_set(fontname); if(fontset!=NULL){ if(XContextDependentDrawing(fontset)){ warn(TR("Fontset for font pattern '%s' implements context " "dependent drawing, which is unsupported. Expect " "clutter."), fontname); } } }else{ LOG(DEBUG, FONT, "Loading fontstruct %s", fontname); fontstruct=XLoadQueryFont(ioncore_g.dpy, fontname); } if(fontstruct==NULL && fontset==NULL){ if(strcmp(fontname, default_fontname)!=0){ DEFont *fnt; LOG(WARN, FONT, TR("Could not load font \"%s\", trying \"%s\""), fontname, default_fontname); fnt=de_load_font(default_fontname); if(fnt==NULL) LOG(WARN, FONT, TR("Failed to load fallback font.")); return fnt; } return NULL; } #endif /* HAVE_X11_BMF */ fnt=ALLOC(DEFont); if(fnt==NULL) return NULL; #ifdef HAVE_X11_XFT fnt->font=font; #endif #ifdef HAVE_X11_BMF fnt->fontset=fontset; fnt->fontstruct=fontstruct; #endif fnt->pattern=scopy(fontname); fnt->next=NULL; fnt->prev=NULL; fnt->refcount=1; LINK_ITEM(fonts, fnt, next, prev); return fnt; }