Subject: Font loading and Draw String API

From: Olivier Chapuis <[email-masked]>
Date: Mon, 4 Feb 2002 08:35:14 +0100

Hello,

Here a proposal for an "API" for font loading and for displaying
string. Any comments welcome before I start the changes.

Before two questions:

The menus code use only XTextWidth and never XmbTextEscapement.
Are there good reasons to do not use XmbTextEscapement (via some ifdef)?

Does a font cache will be useful?

Olivier

------------
/* As it is now but font loading logic will change */
typedef struct FvwmFont
{
  XFontStruct *font;		/* font structure */
#ifdef I18N_MB
  XFontSet fontset;		/* font set */
#endif
  int height;			/* height of the font */
  int y;			/* Y coordinate to draw characters */
} FvwmFont;

/*
 * Load fontname into ret_font. For I18N_MB:
 * 1) first try to load fontname with XCreateFontSet
 * 2) If this fail try to load fontname with XLoadQueryFont
 * 3) If this fail try to load
 * -*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*,\
 * -*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*
 * with XCreateFontSet
 * 4) If this fail try to load "fixed" with XLoadQueryFont
 *
 * For !I18N_MB just do 2) and 4) as now but if a "," separated list
 * of fonts is given try to load each.                    
 */
Bool LoadFvwmFont(
  Display *dpy, char *fontname, FvwmFont *ret_font);

typedef struct FvwmWinString
{
  char *str;
  GC gc;
  Window win;
  int x;
  int y;
  /* may add more elements in the future */
} FvwmWinString;

/*
 *  Draw string fstr->str at position fstr->x, fstr->y on window fstr->win
 *  by using either XmbDrawString if ff.fonset != None (and I18N_MB) or
 *  XDrawString. flags: may be used in the future.
 */
void FDrawString(Display *dpy, FvwmFont ff, FvwmWinString *fstr,
		 unsigned long flags);

/* 
 * Simple wapper to XmbTextEscapement (used if ff.fontset != None and I18_MB)
 * and XTextWidth
 */
int FTextWidth(FvwmFont ff, char *str, int sl);

/* 
 * Create a FvwmWinString structure initialized to 0
 */
Bool AllocateFvwmWinString(FvwmWinString **pfws);

/* maybe other warrper as FTextPropertyToTextList */
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Mon, 4 Feb 2002 12:18:47 +0100

> Does a font cache will be useful?

The X server already caches fonts, so an fvwm font cache needs to
cache only the information about the fonts that would have to be
queried from the server.  To me, it seems to be a good idea to do
this in order to reduce network traffic.

>   Display *dpy, char *fontname, FvwmFont *ret_font);

Looks good this far.  But let's rename I18N_MB to something that
makes more sense.  Also, I'd use "FFontStruct" instead of
"FvwmFont" to indicate that it's our replacement for XFontStruct.

> void FDrawString(Display *dpy, FvwmFont ff, FvwmWinString *fstr,

Again, I'd use a different name since it is *not* an exact
replacement for XDrawString (the parameters are different).  The
idea I had in mind with the F... names was to replace 'X' with 'F'
if - and only if - the object is our own replacement for
functionally identical object in X.  If the parameter list is
different, I'd indicate that by giving it a different name.

> int FTextWidth(FvwmFont ff, char *str, int sl);

Ok.

> /* maybe other warrper as FTextPropertyToTextList */

In addition, I'd prefix all the names from Flocale.h with
"Flocale" (only those that don't have an X->F name of course)

  FlocaleWinString
  FlocaleAllocateWinString
  FlocaleFont
  FlocaleLoadFont
  ...

BTW, the font handling functions should probably be moved into
Flocale.

Bye

Dominik ^_^  ^_^

-- 
Dominik Vogt, email: [email-masked]
LifeBits Aktiengesellschaft, Albrechtstr. 9, D-72072 Tuebingen
fon: ++49 (0) 7071/7965-0, fax: ++49 (0) 7071/7965-20
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Alexander Kotelnikov <[email-masked]>
Date: Mon, 04 Feb 2002 15:01:56 +0300

>>>>> On Mon, 4 Feb 2002 08:35:14 +0100
>>>>> "Olivier" == Olivier Chapuis <[email-masked]> wrote:
Olivier> 
Olivier> The menus code use only XTextWidth and never XmbTextEscapement.
Olivier> Are there good reasons to do not use XmbTextEscapement (via some ifdef)?

menus.c includes misc.h where XTextWidth is defined as
XmbTextEscapement fo I18N_MB.

Olivier> Does a font cache will be useful?

Francly speaking, I do not understand, what are you about. May be you
do not want to keep mmultiple XFontStructs for, e.g., "fixed"? I am
very sure xlibs gives you the same XFontStruct for second and
successive queries of already loaded fonts.

Olivier> /* As it is now but font loading logic will change */
Olivier> typedef struct FvwmFont
Olivier> {
Olivier>   XFontStruct *font;		/* font structure */
Olivier> #ifdef I18N_MB
Olivier>   XFontSet fontset;		/* font set */
Olivier> #endif
Olivier>   int height;			/* height of the font */
Olivier>   int y;			/* Y coordinate to draw characters */
Olivier> } FvwmFont;

I have already proposed 

# ifndef I18N_MB
  XFontStruct *font;
# endif

and I insist on this.

Olivier> 
Olivier> /*
Olivier>  * Load fontname into ret_font. For I18N_MB:
Olivier>  * 1) first try to load fontname with XCreateFontSet
Olivier>  * 2) If this fail try to load fontname with XLoadQueryFont

great, and you'll get  font absolutely unusable for user, but having
ASCII glyphs similar to ones he wanted.

Olivier>  * 3) If this fail try to load
Olivier>  * -*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*,\
Olivier>  * -*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*
Olivier>  * with XCreateFontSet

should be second and the last.

Olivier>  * 4) If this fail try to load "fixed" with XLoadQueryFont
Olivier>  *
Olivier>  * For !I18N_MB just do 2) and 4) as now but if a "," separated list
Olivier>  * of fonts is given try to load each.                    
Olivier>  */

Olivier> void FDrawString(Display *dpy, FvwmFont ff, FvwmWinString *fstr,

probably, FvwmFont *ff

Olivier> 		 unsigned long flags);

-- 
Alexander Kotelnikov
Saint-Petersburg, Russia

---

From: Olivier Chapuis <[email-masked]>
Date: Mon, 4 Feb 2002 17:26:00 +0100

> XmbTextEscapement fo I18N_MB.

Ah yes.
 
> successive queries of already loaded fonts.

As Dominik say this font cache can be useful to prevent  unuseful
multiple call to  XCreateFontSet/XLoadQueryFont. Also, in my machine
(with I18N_MB) each use of
  Style * -*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*
add memory to fvwm2 (around 10kb with a few xterm only) and really I
do not think that the problem is a pure fvwm problem (it just seems
that XFreeFontSet does not do its job).

> Olivier>   int y;			/* Y coordinate to draw characters */

One of my idea is that when fvwm will load a font either font or
fontset should be 0 at the end of the loading (font will never
be the XFontsOfFontSet of fontset). If fontset is not null the Xmb*
functions will be used and if font is not NULL XDrawString/TextWidth
will be used (the gc's will be set as needed). I do not see why a line
as

    Style "an-app" -a-funny-font-that-my-locale-dont-have-iso8859-1  

should give the "fixed" locale font. If a user add a charset
to its font I do not see why we should reject its query
(BTW, KDE app bother me because they never use the fonts
I specify). Maybe this will does not work, if it is the case
this will be easy to change.
 
Olivier

---

From: Alexander Kotelnikov <[email-masked]>
Date: Mon, 04 Feb 2002 21:27:32 +0300

>>>>> On Mon, 4 Feb 2002 17:26:00 +0100
Olivier> 
Olivier> 

Your motivations are rather obvious, but I thing before implementation
of mixed Xmb- and X- DrawString it will be good to get version where
only one Xmb-, or X- works, and then think if we need mixed one.

Olivier> One of my idea is that when fvwm will load a font either font or
Olivier> fontset should be 0 at the end of the loading (font will never
Olivier> be the XFontsOfFontSet of fontset). If fontset is not null the Xmb*
Olivier> functions will be used and if font is not NULL XDrawString/TextWidth
Olivier> will be used (the gc's will be set as needed). I do not see why a line
Olivier> as
Olivier> 
Olivier>     Style "an-app" -a-funny-font-that-my-locale-dont-have-iso8859-1  
Olivier> 
Olivier> should give the "fixed" locale font. If a user add a charset
Olivier> to its font I do not see why we should reject its query