// also handle an xlfd with %d for size? static char* makeFontOfSize(char *font, int size, char *fallback) { FcPattern *pattern; char *result; if (font[0]=='-') { char *fname; fname = fixXLFD(font, size); pattern = XftXlfdParse(fname, False, False); wfree(fname); } else { pattern = FcNameParse(font); } //FcPatternPrint(pattern); if (size > 0) { FcPatternDel(pattern, "pixelsize"); FcPatternAddDouble(pattern, "pixelsize", (double)size); } else if (size==0 && !hasProperty(pattern, "size") && !hasProperty(pattern, "pixelsize")) { FcPatternAddDouble(pattern, "pixelsize", (double)DEFAULT_SIZE); } if (fallback && !hasPropertyWithStringValue(pattern, "family", fallback)) { FcPatternAddString(pattern, "family", fallback); } result = FcNameUnparse(pattern); FcPatternDestroy(pattern); return result; }
TkFont * TkpGetNativeFont( Tk_Window tkwin, /* For display where font will be used. */ CONST char *name) /* Platform-specific font name. */ { UnixFtFont *fontPtr; FcPattern *pattern; #if DEBUG_FONTSEL printf("TkpGetNativeFont %s\n", name); #endif /* DEBUG_FONTSEL */ pattern = XftXlfdParse(name, FcFalse, FcFalse); if (!pattern) { return NULL; } /* * Should also try: pattern = FcNameParse(name); but generic/tkFont.c * expects TkpGetNativeFont() to only work on XLFD names under Unix. */ fontPtr = InitFont(tkwin, pattern, NULL); if (!fontPtr) { return NULL; } return &fontPtr->font; }
Bool XftCoreAddFonts (XftFontSet *set, Display *dpy, Bool ignore_scalable) { char **xlfds; int num; int i; XftPattern *font; Bool ret; xlfds = XListFonts (dpy, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*", 10000, &num); if (!xlfds) return False; ret = True; for (i = 0; ret && i < num; i++) { font = XftXlfdParse (xlfds[i], ignore_scalable, True); if (font) { if (!XftFontSetAdd (set, font)) { XftPatternDestroy (font); ret = False; } } } XFreeFontNames (xlfds); return ret; }
void load_font(FcChar8 *font_str) { FcPattern *pattern, *match; FcResult result; if (font_str[0] == '-') pattern = XftXlfdParse(font_str, False, False); else pattern = FcNameParse((FcChar8 *) font_str); if (!pattern) die("Failed to get font pattern"); match = FcFontMatch(NULL, pattern, &result); if (!match) die("Failed to get font match"); if (!(font = XftFontOpenPattern(display, match))) { FcPatternDestroy(match); die("Failed to open font"); } ascent = font->ascent; descent = font->descent; }