1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
Description: WINGs: wfont fallback to default font when font is not found
This patch is fixing the issue reported
at https://github.com/window-maker/wmaker/issues/62
where wmaker is crashing if the font specified in WMGLOBAL is not found.
Now by default it will failsafe to DEFAULT_FONT.
Origin: https://repo.or.cz/wmaker-crm.git/commitdiff/b662d08
Author: David Maciejak <david.maciejak@gmail.com>
Bug: https://github.com/window-maker/wmaker/issues/62
Bug-Debian: https://bugs.debian.org/1126087
Last-Update: 2026-01-23
--- a/WINGs/wfont.c
+++ b/WINGs/wfont.c
@@ -70,37 +70,30 @@
return False;
}
-static Bool hasPropertyWithStringValue(FcPattern * pattern, const char *object, const char *value)
-{
- FcChar8 *str;
- int id;
-
- if (!value || value[0] == 0)
- return True;
-
- id = 0;
- while (FcPatternGetString(pattern, object, id, &str) == FcResultMatch) {
- if (strcasecmp(value, (char *)str) == 0) {
- return True;
- }
- id++;
- }
-
- return False;
-}
-
static char *makeFontOfSize(const char *font, int size, const char *fallback)
{
- FcPattern *pattern;
+ FcPattern *pattern = NULL;
char *result;
- if (font[0] == '-') {
+ if (font && font[0] == '-') {
pattern = xlfdToFcPattern(font);
} else {
pattern = FcNameParse((const FcChar8 *) font);
}
- /*FcPatternPrint(pattern); */
+ if (!pattern) {
+ wwarning(_("could not load font spec: %s."), font);
+ if (!fallback)
+ return NULL;
+ pattern = FcPatternCreate();
+ if (!pattern)
+ return NULL;
+ if (!FcPatternAddString(pattern, FC_FAMILY, (const FcChar8 *) fallback)) {
+ wfatal(_("could not load default font spec: %s."), fallback);
+ FcPatternDestroy(pattern);
+ return NULL;
+ }
+ }
if (size > 0) {
FcPatternDel(pattern, FC_PIXEL_SIZE);
@@ -109,12 +102,6 @@
FcPatternAddDouble(pattern, FC_PIXEL_SIZE, (double)DEFAULT_SIZE);
}
- if (fallback && !hasPropertyWithStringValue(pattern, FC_FAMILY, fallback)) {
- FcPatternAddString(pattern, FC_FAMILY, (const FcChar8 *) fallback);
- }
-
- /*FcPatternPrint(pattern); */
-
result = (char *)FcNameUnparse(pattern);
FcPatternDestroy(pattern);
@@ -135,7 +122,7 @@
double size;
#endif
- if (fontName[0] == '-') {
+ if (fontName && fontName[0] == '-') {
fname = xlfdToFcName(fontName);
} else {
fname = wstrdup(fontName);
@@ -262,7 +249,11 @@
WMFont *font;
char *fontSpec;
- fontSpec = makeFontOfSize(WINGsConfiguration.systemFont, size, NULL);
+ fontSpec = makeFontOfSize(WINGsConfiguration.systemFont, size, DEFAULT_FONT);
+
+ if (!fontSpec) {
+ return NULL;
+ }
font = WMCreateFont(scrPtr, fontSpec);
@@ -280,7 +271,11 @@
WMFont *font;
char *fontSpec;
- fontSpec = makeFontOfSize(WINGsConfiguration.boldSystemFont, size, NULL);
+ fontSpec = makeFontOfSize(WINGsConfiguration.boldSystemFont, size, DEFAULT_FONT);
+
+ if (!fontSpec) {
+ return NULL;
+ }
font = WMCreateFont(scrPtr, fontSpec);
|