[comp.windows.x] variable width fonts..

shamash@LASALLE.CS.COLUMBIA.EDU (Ari Shamash) (06/30/89)

Is there a way of determining whether a font has variable or fixed
width?  The only way I could think of is by comparing the maximum and
minimum widths provided by the XFontStruc for the particular font.  Is
there a better way?

Thanks in advance,
Ari

shamash@cs.columbia.edu
shamash@gollum.cs.columbia.edu
...!rutgers!columbia!gollum!shamash
------------------------

Here is my program..

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

main (argc, argv)
int argc;
char **argv;
{
  Display *display;
  XFontStruct *font;

  if (argc < 2) {
    fprintf(stderr, "usage:  %s fontname.\n", argv[0]);
    exit(1);
  }

  if ((display = XOpenDisplay (NULL)) == NULL) {
    fprintf(stderr, "Can't open X display connection.\n");
    exit(1);
  }

  if ((font = XLoadQueryFont(display, argv[1])) == (XFontStruct *) NULL) {
    fprintf(stderr, "The font %s is not available.\n", argv[1]);
    XCloseDisplay(display);
    exit(1);
  }

  if (font ->min_bounds.width == font ->max_bounds.width)
    printf("%s is fixed width.\n", argv[1]);
  else
    printf("%s is not fixed width.\n", argv[1]);
    
  XFreeFont(display,font);
  XCloseDisplay(display);
  exit(0);
}

jim@EXPO.LCS.MIT.EDU (Jim Fulton) (07/01/89)

> Is there a way of determining whether a font has variable or fixed
> width?  The only way I could think of is by comparing the maximum and
> minimum widths provided by the XFontStruc for the particular font.  Is
> there a better way?

That is one way to tell whether or not the font is Monospaced (as defined by in
section 3.1.2.11 of X Logical Font Description, available from the xstuff mail
server on expo).  But, that doesn't guarantee that the font can be used to draw
ImageText (usually used for terminal emulators or other things in which you
wish to have the "background" of the text drawn).  For that you need stricter
class of fonts called Character Cell fonts:

             "C"    CharCell         - a monospaced font which follows
                                     the standard typewriter character
                                     cell model, i.e. the glyphs of the
                                     font can be modeled by X clients as
                                     "boxes" of the same width and height
                                     which are imaged side by side to
                                     form text strings, or top to bottom
                                     to form text lines. By definition,
                                     all glyphs have the same logical
                                     character width, and no glyphs have
                                     "ink" outside of the character cell-
                                     there is no kerning (i.e., on a per
                                     char basis with positive metrics: 0
                                     <= left-bearing <= right-bearing <=
                                     width; with negative metrics: width
                                     <= left-bearing <= right-bearing
                                     <= 0)-and the vertical extents of
                                     the font do not exceed the vertical
                                     spacing (i.e. on a per char basis:
                                     ascent <= font-ascent & descent <=
                                     font-descent). The cell height =
                                     font-descent + font-ascent, and width
                                     = AVERAGE_WIDTH.


The distinction between Monospaced and Character Cell fonts can be seen by
displaying accented characters in an xterm using a Courier font.  The accents
don't get erased if you backspace over the character.

You can get the XLFD from the following sources:

    o  anonymous ftp from expo.lcs.mit.edu in pub/XLFD/{README,xlfd.{ps,text}}

    o  xstuff mail server:

	%  mail xstuff@expo.lcs.mit.edu
	Subject:  send etc xlfd.text.1
	path electronic-mail-path-back-to-you-from-expo
	^D

	%  mail xstuff@expo.lcs.mit.edu
	Subject:  send etc xlfd.text.2
	path electronic-mail-path-back-to-you-from-expo
	^D


		[PostScript for the XLFD can be requested by asking for the
		 files xlfd.ps.1 through xlfd.ps.4 separately.]