summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2019-07-15 17:14:59 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2019-07-15 17:14:59 -0400
commitf7a9ead69089a862fbd9aab6995980d3ecd290bf (patch)
treeb7b8be2285adbd8676576cf8572c26b13909b0a4 /src/util.c
parent55a26c49c8a976abb0ead8bd58da6260de61b739 (diff)
issue 7: check if there are no fonts found for the fontset, and fallback to fixed in that case.
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/src/util.c b/src/util.c
index acc8769..303ccbf 100644
--- a/src/util.c
+++ b/src/util.c
@@ -566,20 +566,9 @@ GetColorValue(int kind, XColor *what, const char *name)
}
}
-/*
- * The following functions are sensible to 'use_fontset'.
- * When 'use_fontset' is True,
- * - XFontSet-related internationalized functions are used
- * so as multibyte languages can be displayed.
- * When 'use_fontset' is False,
- * - XFontStruct-related conventional functions are used
- * so as 8-bit characters can be displayed even when
- * locale is not set properly.
- */
-void
-GetFont(MyFont *font)
+static Boolean
+FindFontSet(MyFont *font, const char *fontname)
{
- const char *deffontname = "fixed";
char **missing_charset_list_return;
int missing_charset_count_return;
char *def_string_return;
@@ -596,13 +585,11 @@ GetFont(MyFont *font)
XFreeFontSet(dpy, font->fontset);
}
- if( (font->fontset = XCreateFontSet(dpy, font->name,
+ if( (font->fontset = XCreateFontSet(dpy, fontname,
&missing_charset_list_return,
&missing_charset_count_return,
&def_string_return)) == NULL) {
- fprintf (stderr, "%s: unable to open fontset \"%s\"\n",
- ProgramName, font->name);
- exit(1);
+ return False;
}
for(i=0; i<missing_charset_count_return; i++){
printf("%s: warning: font for charset %s is lacking.\n",
@@ -620,29 +607,52 @@ GetFont(MyFont *font)
font->y = ascent;
font->ascent = ascent;
font->descent = descent;
- return;
+ return True;
}
if (font->font != NULL)
XFreeFont(dpy, font->font);
- if ((font->font = XLoadQueryFont(dpy, font->name)) == NULL)
+ if ((font->font = XLoadQueryFont(dpy, fontname)) == NULL)
{
- if (Scr->DefaultFont.name) {
- deffontname = Scr->DefaultFont.name;
- }
- if ((font->font = XLoadQueryFont(dpy, deffontname)) == NULL)
- {
- fprintf (stderr, "%s: unable to open fonts \"%s\" or \"%s\"\n",
- ProgramName, font->name, deffontname);
- exit(1);
- }
-
+ return False;
}
font->height = font->font->ascent + font->font->descent;
font->y = font->font->ascent;
font->ascent = font->font->ascent;
font->descent = font->font->descent;
+ return True;
+}
+
+/*
+ * The following functions are sensible to 'use_fontset'.
+ * When 'use_fontset' is True,
+ * - XFontSet-related internationalized functions are used
+ * so as multibyte languages can be displayed.
+ * When 'use_fontset' is False,
+ * - XFontStruct-related conventional functions are used
+ * so as 8-bit characters can be displayed even when
+ * locale is not set properly.
+ */
+void
+GetFont(MyFont *font)
+{
+ const char *deffontname = "fixed";
+
+ if (!FindFontSet(font, font->name)) {
+ const char *what = "fonts";
+
+ if (use_fontset) {
+ what = "fontsets";
+ } else if (Scr->DefaultFont.name) {
+ deffontname = Scr->DefaultFont.name;
+ }
+ if (!FindFontSet(font, deffontname)) {
+ fprintf (stderr, "%s: unable to open %s \"%s\" or \"%s\"\n",
+ ProgramName, what, font->name, deffontname);
+ exit(1);
+ }
+ }
}
int