From: "Martin Kajdas" To: "Greg Haerr" Cc: "Peter Barada" Subject: RE: [nanogui] Font usage/setup Date: Wednesday, January 18, 2006 2:19 PM The fix for the problem #1 is at: ftp://microwindows.censoft.com/pub/microwindows/patch-0.92/font_pcf-patch.tar.bz2 but it is not included in CVS and needs to be. The fix for problem #3 (needs better way of specifying mask): --- Text.c.org 2002-09-23 03:23:25.000000000 +0000 +++ Text.c 2006-01-18 12:44:01.941722456 +0000 @@ -4,9 +4,24 @@ XDrawString(Display *dpy, Drawable d, GC gc, int x, int y, _Xconst char *string, int length) { - if (length > 0) + if (length > 0) { + /* the mask needs to match the color's valid bits, + * i.e. 0x0000FFFF for 5:6:5 16 bit RGB mode + */ + unsigned long mask = 0x0000FFFF; /* 0xFFFFFFFF >> (32 - 8*sizeof(MWPIXELVAL)); */ + XGCValues *vp = (XGCValues *)gc->ext_data; + /* this test is to fix a problem where: + * if foreground color == background color, + * it will print transparent and nothing will show up. + * In such a case, change foreground color. + */ + if (((vp->background ^ vp->foreground) & mask) == 0) { + vp->foreground += (vp->foreground == mask) ? -1 : 1; + XSetForeground(dpy, gc, vp->foreground); + } GrText(d, gc->gid, x, y, (char *)string, length, GR_TFASCII|GR_TFBASELINE); + } return 0; } The fix for problem #4: --- LoadFont.c.org 2003-08-11 20:04:45.000000000 +0000 +++ LoadFont.c 2006-01-17 15:52:17.000000000 +0000 @@ -2,6 +2,10 @@ #include #include +#undef MIN +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +static int ttfSize; + static int prefix(const char *prestr, char *allstr) { @@ -20,6 +24,8 @@ char *ret; char buffer[128]; +ttfSize = 0; + if (!_nxfontcount) _nxSetDefaultFontDir(); @@ -52,6 +58,7 @@ //printf("checking '%s' '%s'\n", xfontname, font); if (strcmp(xfontname, font) == 0) { +found: ret = (char *) Xmalloc(strlen(_nxfontlist[f]) + strlen(file) + 2); sprintf(ret, "%s/%s", _nxfontlist[f], file); @@ -59,6 +66,30 @@ fclose(fontdir); return ret; } + else { + /* the code to test for TTF fonts that match in the following manner: + * fontname-0-0-0-0-0-... with + * fontname-12-0-0-0-0-... + * where the only difference is the size + * which for TTF fonts is not specified in the name + */ + int idx; + int len = MIN(strlen(font), strlen(xfontname)); + + for (idx = 0; idx < len; idx++) { + if (xfontname[idx] != font[idx]) { + int idx1 = idx; + while (xfontname[idx] >= '0' && xfontname[idx] <= '9') { + ttfSize = ttfSize * 10 + (xfontname[idx++] - '0'); + } + //if (ttfSize >= 64) ttfSize = 63; + if (font[idx1] == '0' && strcmp(&xfontname[idx], &font[++idx1]) == 0) + goto found; + ttfSize = 0; + break; + } + } + } } /* not found, try */ @@ -130,7 +161,7 @@ /* found font, load into server*/ if (fontname) - font = GrCreateFont(fontname, 0, NULL); + font = GrCreateFont(fontname, ttfSize, NULL); printf("XLoadFont('%s') = '%s' [%d]\n", name, fontname, font); if (fontname) --end of patches-- Of course, the patch for Text.c would not be necessary if the drawing algorithm worked properly: when foreground == background, background is transparent and foreground is used for text color. I will try to come up with a sample code. Martin -----Original Message----- From: Greg Haerr [mailto:greg@censoft.com] Sent: Wednesday, January 18, 2006 12:02 PM To: Martin Kajdas Subject: Re: [nanogui] Font usage/setup Hi Martin - Thanks for your reports and debugging lately. I looked into the source and didn't realize that the fg == bg statement as _already_ commented out, so I need to dig into this obvious bug further. I'm definitely interested in your patches for 1,3 & 4 below. For the text display bug, is there any simple program you can point me to (your own, or one of FLTK's demos?) that shows this problem? I need to get an easy-to-reproduce program that shows the bug so I can fix it. In looking at my comments, its obvious there's some issues, with two FIXME statements in the area ;-) Regards, Greg I got my fonts working and I would like to summarize my findings/fixes for others to use. Because, my application is FLTK based and uses nxlib to communicate with nano-X, many problems are mostly nxlib based and FLTK + X11 specific and will not show up with other applications. That is why I tried to put my fixes into nxlib when possible instead of nano-X so not to break other people's code which is working. Summary of what I found: 1. font_pcf.c in nano-X (engine) needs to be updated with patched file from microwindows web site which is still not included in CVS. This was necessary in order to use X11 fonts without GrCreateFont() hanging up. 2. font_freetype.c and font_t1lib.c in nano-X (engine) need to be fixed to work properly with gr_foreground == gr_background. The recommended fix (commented out) will not work as block outlines of letters are only printed. The background color must stay transparent and it does not with the fix. 3. Text.c in nxlib (XDrawString()) I modified to check foreground and background colors of the string and if they are the same, I increase the foreground color by 1. I did it here instead of modifying font_freetype.c and font_t1lib.c in nano-X. 4. LoadFont.c in nxlib needs to be fixed (_nxFindX11Font()) to properly match TTF font names (i.e. ...12-0-0...==...0-0-0... and size=12) and call GrCreateFont() with proper font size. Once, the fonts are properly created, the main problem is with nano-X's Area draw function. When foreground==background color, it is assumed that the background is already drawn and the foreground need not be. This is a problem when the background is transparent and is not drawn and so is the foreground, resulting in nothing being drawn. The nano-X's drawing algorithm needs to be fixed so this case is handled properly. I will get into this next because I am having some problems with some images not being drawn (which I believe it is related to this) but I will start a separate email thread. Martin