Hi,
At Thu, 26 Apr 2001 14:42:59 +0900,
Maxime Froment <[EMAIL PROTECTED]> wrote:
> This is one possibility indeed. Another one which avoids having to
> create new resource variables is to revert to having them fixed to
> some reasonable value (like say, 3 or 4 for font0_idx and 7 for
> nfonts), and define the runtime font size range dynamically depending
> of whether resource values are specified or not for respective
> indices. Undefining resource values when there exist hard-coded
> defaults should be allowed too (so that it is also possible to
> restrict the range).
I wrote a patch to implement this and solve other problems.
1. A simple typo, from "euckr" to "kr".
2. "nfonts" is now determined automatically to include all
user-defined fonts.
3. "font0_idx" is now determined automatically by thinking
of the size of the fonts.
To achieve 3, XLoadQueryFont() is used and this may be a
"heavy" work, though "lightness" is one of most important
concepts of Rxvt. How do you think about this?
---
Tomohiro KUBOTA <[EMAIL PROTECTED]>
http://www.debian.or.jp/~kubota/
"Introduction to I18N"
http://www.debian.org/doc/manuals/intro-i18n/
diff -ruN cvs/src/defaultfont.c cvs2/src/defaultfont.c
--- cvs/src/defaultfont.c Sat Apr 28 02:27:51 2001
+++ cvs2/src/defaultfont.c Sat Apr 28 02:30:50 2001
@@ -150,7 +150,7 @@
{NFONT_LIST_GB}, {MFONT_LIST_GB} },
{ ENC_BIG5, "big5", BIG5_NFONTS, BIG5_FONT0,
{NFONT_LIST_BIG5}, {MFONT_LIST_BIG5} },
- { ENC_EUCKR, "euckr", EUCKR_NFONTS, EUCKR_FONT0,
+ { ENC_EUCKR, "kr", EUCKR_NFONTS, EUCKR_FONT0,
{NFONT_LIST_EUCKR}, {MFONT_LIST_EUCKR} },
#endif /* MULTICHAR_SET */
#if 0
@@ -184,6 +184,27 @@
#endif
/*----------------------------------------------------------------------*/
+/* INTPROTO */
+int
+set_font0(rxvt_t *r, const char *rs[])
+{
+ int j, k;
+ int size[MAX_NFONTS];
+ XFontStruct *font;
+
+ for (j=0; j < r->h->nfonts; j++) {
+ font = XLoadQueryFont(r->Xdisplay, rs[Rs_font + j]);
+ if (font == NULL) {size[j] = 0; continue;}
+ size[j] = (font->max_bounds.rbearing - font->min_bounds.lbearing)
+ * (font->max_bounds.ascent + font->max_bounds.descent);
+ XFreeFont(r->Xdisplay, font);
+ }
+ for (j=1; j < r->h->nfonts; j++) {
+ if (size[0] < size[j]) return j-1;
+ }
+ return r->h->nfonts-1;
+}
+/*----------------------------------------------------------------------*/
/* EXTPROTO */
void
rxvt_set_defaultfont(rxvt_t *r, const char *rs[])
@@ -194,6 +215,7 @@
char *p, *p2;
enum enc_label encoding = ENC_DUMMY;
int j, k;
+ int userfonts = 0;
#ifdef HAVE_NL_LANGINFO
# if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
@@ -259,6 +281,21 @@
}
/*
+ * Check number of user-defined fonts
+ * Since users have no way to specify nfonts and font0_idx directly,
+ * care has to be taken to determine these variables to respect
+ * user's font specification.
+ */
+ for (j = 0; j < MAX_NFONTS; j++) {
+ if (rs[Rs_font + j] != NULL && strlen(rs[Rs_font + j]) > 1)
+ userfonts = j + 1;
+#ifdef MULTICHAR_SET
+ if (rs[Rs_mfont + j] != NULL && strlen(rs[Rs_mfont + j]) > 1)
+ userfonts = j + 1;
+#endif
+ }
+
+/*
* Build rs[Rs_font], rs[Rs_mfont], r->encoding_method,
* and r->h->multichar_decode
*/
@@ -267,8 +304,6 @@
#ifdef MULTICHAR_SET
rxvt_set_multichar_encoding(r, defaultfont[j].encoding_method);
#endif
- r->h->nfonts = defaultfont[j].nfonts;
- r->h->fnum = r->h->font0_idx = defaultfont[j].font0_idx;
for (k = 0; k < MAX_NFONTS; k++) {
if (rs[Rs_font + k] == NULL)
rs[Rs_font + k] = defaultfont[j].font[k];
@@ -277,6 +312,9 @@
rs[Rs_mfont + k] = defaultfont[j].mfont[k];
#endif
}
+ r->h->nfonts = max(defaultfont[j].nfonts, userfonts);
+ r->h->fnum = r->h->font0_idx =
+ (userfonts ? set_font0(r, rs) : defaultfont[j].font0_idx);
return;
}
}
@@ -293,13 +331,15 @@
/* fallback for ISO-8859-* encodings */
k = encoding - ENC_ISO8859_1 + 1;
MIN_IT(k, 99999);
- r->h->nfonts = ISO8859X_NFONTS;
- r->h->fnum = r->h->font0_idx = ISO8859X_FONT0;
+ r->h->nfonts = max(ISO8859X_NFONTS, userfonts);
+ r->h->fnum = r->h->font0_idx =
+ (userfonts ? set_font0(r, rs) : ISO8859X_FONT0);
} else {
/* fallback for "C", "POSIX", and invalid locales */
k = 0;
- r->h->nfonts = DEFAULT_NFONTS;
- r->h->fnum = r->h->font0_idx = DEFAULT_FONT0;
+ r->h->nfonts = max(DEFAULT_NFONTS, userfonts);
+ r->h->fnum = r->h->font0_idx =
+ (userfonts ? set_font0(r, rs) : DEFAULT_FONT0);
}
for (j = 0; j < MAX_NFONTS; j++) {