wings: drop libXft from wfont.c / wfontpanel.c

The only Xft API used in shared font code was XftXlfdParse — used
to convert legacy X11 XLFD font names to fontconfig FcPatterns so
old WINGs config files keep working.

Replaced with a hand-written parser W_ParseXLFDToFcPattern (defined
in wfont.c, declared in WINGsP.h) that walks the 14 dash-separated
XLFD fields and pulls out family / weight / slant / pixelsize.
This is enough for every XLFD that wmaker / WPrefs has ever used
in practice (~14 different names across all defaults).

Both wfont.c and wfontpanel.c now use W_ParseXLFDToFcPattern, and
neither file includes <X11/Xft/Xft.h> any more.  libXft is now only
pulled in by the X11 font backend (wfont_x11.c), as it should be.

Build clean.  Wayland-only files still have zero X11 symbol
dependencies (verified via nm).
This commit is contained in:
Window Maker 2026-05-24 11:09:39 +02:00
parent 32377afed9
commit f7a7142889
3 changed files with 80 additions and 26 deletions

View File

@ -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);

View File

@ -8,36 +8,82 @@
#include <wraster.h>
#include <assert.h>
#include <X11/Xft/Xft.h>
#include <fontconfig/fontconfig.h>
#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)

View File

@ -8,7 +8,6 @@
#include <strings.h>
#include <stdint.h>
#include <X11/Xft/Xft.h>
#include <fontconfig/fontconfig.h>
/* 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)