Re: TWM: truetype support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 5 Nov 2007, Eeri Kask wrote:
So, luckily we are now a step closed to the solution:  let's not use
'fixed' as coded-in-default in twm.c if TWM_USE_XFT is defined, but
'-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*', and neither XListFonts() nor
XftFontOpenXlfd() have any further difficulties!  (Is XListFonts()
supposed to translate font alias names at all?)  This looks a good idea,
in fact this is what you suggested first: let XListFonts() resolve
'fixed' and then use it.  Now we know how to do that. :-)

(As a backside, we then remove the flexibility in twm to use the
'fixed'-alias-redirection to an arbitrary font.)

First, the X server does not even start if it cannot resolve 'fixed'.  In
that case, whether or not `twm` starts is a moot point.

Secondly, there are likely to be .twmrc's out there that specify other
aliases, such as '7x13' and so on.  Thus, it is important to fall back to a
raster font when Xft cannot resolve a font name, whether or not that name is
a default.  This makes it unnecessary to change twm's default font names.

The good news is, Xft is hardly going to fail.

One can easily put "A quick brown fox jumps over the lazy dog" for
TitleFont into .twmrc as an amusing proof.  So if XLFD loading fails, we
will in fact never enter the "fallback" branch in util.c in GetFont().

But anyways, on our adventurous path to save "fixed" I'll put up a one
more proposition.   What about the following code fragment at the
beginning for GetFont() in util.c?   Now "fixed", "variable", "7x13" et
cetera are fine as font names.   :-)

----8<----8<----

void
GetFont(MyFont *font)
{
#ifdef TWM_USE_XFT

   XFontStruct *xlfd;
   Atom  atom;
   char *atom_name;

   if (font->font != NULL) {
	XftFontClose (dpy, font->font);
	font->font = NULL;
   }

   /* test if core font: */
   xlfd = XLoadQueryFont (dpy, font->name);
   if (xlfd) {
	if (XGetFontProperty (xlfd, XA_FONT, &atom) == True) {
	    atom_name = XGetAtomName (dpy, atom);
	    if (atom_name) {
		font->font = XftFontOpenXlfd (dpy, Scr->screen, atom_name);
		XFree (atom_name);
	    }
	}
	XFreeFont (dpy, xlfd);
   }

   /* next, try Xft font: */
   if (font->font == NULL)
	font->font = XftFontOpenName (dpy, Scr->screen, font->name);

   /* fallback: */

   ....

----8<----8<----

At first, I really liked this idea, but I now realize that, because your spacing changes (as I have them integrated) are only effective for Xft fonts, "Xft'ing" bitmap fonts would change twm's default behaviour. Thus, I'd rather not call XftFontOpenXlfd(), which leaves me with a GetFont() function that looks like ...

void
GetFont(MyFont *font)
{
    if (font->fontset != NULL)
        XFreeFontSet(dpy, font->fontset);
    if (font->font != NULL)
        XFreeFont(dpy, font->font);

#ifdef TWM_USE_XFT

    if (font->xftfont != NULL)
        XftFontClose(dpy, font->xftfont);

    font->xftfont = XftFontOpenName(dpy, Scr->screen, font->name);
    if (font->xftfont != NULL) {
        font->height = font->xftfont->ascent + font->xftfont->descent;
        font->y = font->xftfont->ascent;
        font->ascent = font->xftfont->ascent;
        font->descent = font->xftfont->descent;
        return;
    }

#endif /* TWM_USE_XFT */

    if (use_fontset) {
        char **missing_charset_list_return;
        int missing_charset_count_return;
        char *def_string_return;
        XFontSetExtents *font_extents;
        XFontStruct **xfonts;
        int i, ascent, descent, fnum;
        char *basename2, **font_names;

        basename2 = (char *)malloc(strlen(font->name) + 3);
        if (basename2) {
            sprintf(basename2, "%s,*", font->name);
        } else
            basename2 = font->name;

        if( (font->fontset = XCreateFontSet(dpy, basename2,
                                            &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);
        }

        if (basename2 != font->name)
            free(basename2);

        for(i=0; i<missing_charset_count_return; i++){
            printf("%s: warning: font for charset %s is lacking.\n",
                   ProgramName, missing_charset_list_return[i]);
        }

        font_extents = XExtentsOfFontSet(font->fontset);
        fnum = XFontsOfFontSet(font->fontset, &xfonts, &font_names);
        for( i = 0, ascent = 0, descent = 0; i < fnum; i++){
            if (ascent < (*xfonts)->ascent) ascent = (*xfonts)->ascent;
            if (descent < (*xfonts)->descent) descent = (*xfonts)->descent;
            xfonts++;
        }
        font->height = font_extents->max_logical_extent.height;
        font->y = ascent;
        font->ascent = ascent;
        font->descent = descent;
        return;
    }

    if ((font->font = XLoadQueryFont(dpy, font->name)) == NULL)
    {
        char *deffontname = Scr->DefaultFont.name;

        if (deffontname == NULL)
            deffontname = "fixed";

        if ((font->font = XLoadQueryFont(dpy, deffontname)) == NULL)
        {
            fprintf (stderr, "%s:  unable to open fonts \"%s\" or \"%s\"\n",
                     ProgramName, font->name, deffontname);
            exit(1);
        }

    }

    font->height = font->font->ascent + font->font->descent;
    font->y = font->font->ascent;
    font->ascent = font->font->ascent;
    font->descent = font->font->descent;
}

This means that, to use Xft, the user would need to specify a font name that is recognized by XftFontOpenName().

In looking over your latest patch sets, I notice a fair amount of activity in the Fixes and Appearance ones. Do you now consider them as finalised? What about SloppyFocus?

I'm attaching a diff, against XFree86 CVS source, of those of your changes that I have so far integrated.

Lastly, do you intend to update twm's man page?

Thanks.

Marc.

+----------------------------------+----------------------------------+
|  Marc Aurele La France           |  work:   1-780-492-9310          |
|  Academic Information and        |  fax:    1-780-492-1729          |
|    Communications Technologies   |  email:  tsi@xxxxxxxxxxx         |
|  352 General Services Building   +----------------------------------+
|  University of Alberta           |                                  |
|  Edmonton, Alberta               |    Standard disclaimers apply    |
|  T6G 2H1                         |                                  |
|  CANADA                          |                                  |
+----------------------------------+----------------------------------+
XFree86 developer and VP.  ATI driver and X server internals.

Attachment: twm.diff.gz
Description: GNU Zip compressed data


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [X Forum]     [XFree86]     [XFree86 Newbie]     [X.Org]     [IETF Annouce]     [Security]     [Fontconfig]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]

  Powered by Linux