diff -urN nxlib-0.45/LoadFont.c nxlib-0.45.patched/LoadFont.c --- nxlib-0.45/LoadFont.c Mon Aug 11 22:04:45 2003 +++ nxlib-0.45.patched/LoadFont.c Mon Dec 11 15:18:27 2006 @@ -1,6 +1,7 @@ #include "nxlib.h" #include #include +#include static int prefix(const char *prestr, char *allstr) @@ -13,6 +14,54 @@ return 1; } +#define DEFAULT_FONT_SIZE 12 +int +getSize(char *name) { + char *p = name; + if (p == NULL) return DEFAULT_FONT_SIZE; + while (!isdigit(*p)) ++p; + return (atoi(p)); +} + +int +isSameFont(const char *xfontname, char *font) { + int ret; + int sz = getSize(font); + char *localXfontname = NULL; + char *s; + char *d; + + if (sz) + return strcmp(xfontname, font); + + /* here the found font is 0 size: i.e, it's rescalable, + * so it works for every possible xfontname size) + */ + + localXfontname = strdup(xfontname); + if (localXfontname == NULL) + return -1; + + /* set size of localXfontname to 0 and check again */ + s = localXfontname; + d = localXfontname; + /* go to 1st digit: it's the font size */ + for (;*s && (!isdigit(*s)); ++s, ++d) *d = *s; + /* set font size to 0 */ + *d = '0'; + ++d; + /* skip other numbers of font size field */ + for (;*s && (isdigit(*s)); ++s); + /* copy the remaining string */ + for (;*s; ++s, ++d) *d = *s; + /* terminate the string */ + *d = *s; + //printf("isSameFont: %s %s %s\n", xfontname, localXfontname, font); + ret = strcmp(localXfontname, font); + free(localXfontname); + return ret; +} + char * _nxFindX11Font(const char *xfontname) { @@ -50,8 +99,8 @@ font = strchr(buffer, ' '); *font++ = '\0'; - //printf("checking '%s' '%s'\n", xfontname, font); - if (strcmp(xfontname, font) == 0) { + //printf("_nxFindX11Font: checking '%s' '%s'\n", xfontname, font); + if (isSameFont(xfontname, font) == 0) { ret = (char *) Xmalloc(strlen(_nxfontlist[f]) + strlen(file) + 2); sprintf(ret, "%s/%s", _nxfontlist[f], file); @@ -62,6 +111,7 @@ } /* not found, try */ + printf("_nxFindX11Font: not found %s\n", xfontname); fseek(fontdir, 0L, SEEK_SET); fgets(buffer, 128, fontdir); for (i = 0; i < fcount; i++) { @@ -77,7 +127,7 @@ font = strchr(buffer, ' '); *font++ = '\0'; - //printf("chk2 '%s' '%s'\n", xfontname, file); + //printf("_nxFindX11Font: chk2 '%s' '%s'\n", xfontname, file); if (prefix(xfontname, file)) { ret = (char *) Xmalloc(strlen(_nxfontlist[f]) + strlen(file) + 2); @@ -108,6 +158,7 @@ { GR_FONT_ID font = 0; char *fontname; + int sz; /* first check for wildcards*/ if (any('*', name) || any('?', name)) { @@ -123,16 +174,24 @@ /* first try to find from X11/fonts.dir file*/ fontname = _nxFindX11Font(fontname); - + /* if not found, try 6x13 for "fixed"*/ if (!fontname && !strcmp(name, "fixed")) fontname = _nxFindX11Font("6x13"); /* found font, load into server*/ - if (fontname) - font = GrCreateFont(fontname, 0, NULL); -printf("XLoadFont('%s') = '%s' [%d]\n", name, fontname, font); + // GMY 20061206: GrCreateFont needs the font size: + // I take the size from the font name and pass on + // to it. + if (fontname) { + sz = getSize(name); + font = GrCreateFont(fontname, sz, NULL); + } + +printf("XLoadFont('%s') = '%s' [%d] size=%d\n", name, fontname, font, sz); + + if (fontname) Xfree(fontname); return font;