diff --git a/WINGs/WINGs/WINGsP.h.in b/WINGs/WINGs/WINGsP.h.in index d9bb8c6..de19a63 100644 --- a/WINGs/WINGs/WINGsP.h.in +++ b/WINGs/WINGs/WINGsP.h.in @@ -748,6 +748,14 @@ void W_InitIM(WMScreen *scr); WMScreen *W_X11OpenDisplay(const char *display); void W_X11PlatformInit(W_Screen *scrPtr); +/* + * XLFD → FcPattern parser, defined in wfont.c. Replaces XftXlfdParse + * so the shared font code doesn't pull libXft / libX11. Used by + * wfont.c and wfontpanel.c. + */ +struct _FcPattern; +struct _FcPattern *W_ParseXLFDToFcPattern(const char *xlfd); + void W_CreateIC(WMView *view); void W_DestroyIC(WMView *view); diff --git a/WINGs/wfont.c b/WINGs/wfont.c index 8079706..a1af75d 100644 --- a/WINGs/wfont.c +++ b/WINGs/wfont.c @@ -8,36 +8,82 @@ #include #include -#include #include #define DEFAULT_FONT "sans serif:pixelsize=12" #define DEFAULT_SIZE WINGsConfiguration.defaultFontSize +/* + * Parse an X-style XLFD ("-foundry-family-...-pixelsize-...-...") into + * a fontconfig pattern. We used to call XftXlfdParse here; that pulls + * libXft and therefore libX11 into the shared font dispatcher, which + * is unacceptable for Wayland-only builds. + * + * The legacy XLFD format is fixed: 14 dash-separated fields. + * -foundry-family-weight-slant-setwidth-addstyle-pixelsize-pointsize + * -resolutionx-resolutiony-spacing-averagewidth-charsetregistry + * -charsetencoding + * + * We extract the family (field 2), pixelsize (field 7), weight (field 3), + * and slant (field 4). Anything we don't understand is dropped. This + * matches the practical use of XLFD names in legacy WINGs config files. + */ +FcPattern *W_ParseXLFDToFcPattern(const char *xlfd) +{ + FcPattern *pattern = FcPatternCreate(); + const char *p = xlfd; + int field = 0; + char buf[128]; + size_t buflen; + + if (!pattern) return NULL; + + if (*p == '-') p++; + while (*p) { + buflen = 0; + while (*p && *p != '-' && buflen + 1 < sizeof(buf)) + buf[buflen++] = *p++; + buf[buflen] = '\0'; + if (*p == '-') p++; + + switch (field) { + case 1: /* family */ + if (buf[0] && buf[0] != '*') + FcPatternAddString(pattern, FC_FAMILY, (FcChar8 *)buf); + break; + case 2: /* weight */ + if (strcasecmp(buf, "bold") == 0) + FcPatternAddString(pattern, FC_WEIGHT, (FcChar8 *)"bold"); + break; + case 3: /* slant */ + if (buf[0] == 'i' || buf[0] == 'I') + FcPatternAddString(pattern, FC_SLANT, (FcChar8 *)"italic"); + else if (buf[0] == 'o' || buf[0] == 'O') + FcPatternAddString(pattern, FC_SLANT, (FcChar8 *)"oblique"); + break; + case 6: /* pixelsize */ + if (buf[0] && buf[0] != '*') { + int size = atoi(buf); + if (size > 0) + FcPatternAddDouble(pattern, FC_PIXEL_SIZE, (double)size); + } + break; + } + field++; + } + + if (field < 2) { + /* Wasn't really an XLFD — bail. */ + FcPatternDestroy(pattern); + return FcNameParse((FcChar8 *)DEFAULT_FONT); + } + return pattern; +} + static FcPattern *xlfdToFcPattern(const char *xlfd) { - FcPattern *pattern; - char *fname, *ptr; - - /* Just skip old font names that contain %d in them. - * We don't support that anymore. */ - if (strchr(xlfd, '%') != NULL) - return FcNameParse((FcChar8 *) DEFAULT_FONT); - - fname = wstrdup(xlfd); - if ((ptr = strchr(fname, ','))) { - *ptr = 0; - } - pattern = XftXlfdParse(fname, False, False); - wfree(fname); - - if (!pattern) { - wwarning(_("invalid font: %s. Trying '%s'"), xlfd, DEFAULT_FONT); - pattern = FcNameParse((FcChar8 *) DEFAULT_FONT); - } - - return pattern; + return W_ParseXLFDToFcPattern(xlfd); } static char *xlfdToFcName(const char *xlfd) diff --git a/WINGs/wfontpanel.c b/WINGs/wfontpanel.c index df01ed6..cba139c 100644 --- a/WINGs/wfontpanel.c +++ b/WINGs/wfontpanel.c @@ -8,7 +8,6 @@ #include #include -#include #include /* XXX TODO */ @@ -336,9 +335,10 @@ void WMSetFontPanelFont(WMFontPanel * panel, const char *fontName) /* maybe its proper fontconfig and we can parse it */ pattern = FcNameParse((const FcChar8 *) fontName); } else { - /* maybe its proper xlfd and we can convert it to an FcPattern */ - pattern = XftXlfdParse(fontName, False, False); - /*//FcPatternPrint(pattern); */ + /* maybe its xlfd — use the WINGs native parser (was XftXlfdParse). + * Bringing the parser inline avoids pulling libXft into this file + * which would defeat the Wayland-only build constraint. */ + pattern = W_ParseXLFDToFcPattern(fontName); } if (!pattern)