[comp.windows.x] Finding name of installed font

denio@beno.CSS.GOV (Dennis O'Neill) (02/09/90)

How does one determine the name of the currently-loaded font?  

Specifically, what I'm trying to do is set up a sequence of Xw widgets
as follows:  statictext statictext valuator, all inside a rowcol.  The width
of each statictext is to be determined by the length of certain strings.
To do this, it looks like I have to:

    o  specify the widths of the statictext widgets, for which I must

    o  determine the width in pixels of a certain string to be displayed.
       This seems to be doable using
           width = XTextWidth (fontstruct, string, string_length)
       for which I need to

    o  find out the fontstruct using
           fontstruct = XLoadQueryFont (display, fontname)
       for which I need to

    o  learn the name of the installed font.

How do I do this last (the last shall be first ...) thing?  I know how to
do this if I've installed the font myself first; my problem is to have the
procedure find the name of the installed font for itself.

Is there an easier way around all this?

Dennis O'Neill
denio@seismo.css.gov, denio@s3reston.scubed.com  703-476-5197

mouse@LARRY.MCRCIM.MCGILL.EDU (der Mouse) (02/11/90)

> How does one determine the name of the currently-loaded font?

There is no "the" currently-loaded font.  My server at the moment, for
example, has (at least) four fonts loaded; I've got that many different
fonts in use in various windows.

> Specifically, what I'm trying to do is set up a sequence of Xw
> widgets as follows:  statictext statictext valuator, all inside a
> rowcol.  The width of each statictext is to be determined by the
> length of certain strings.

A string has a length (in pixels) only when associated with a font.
The string "foo", for example, does not have a length in pixels,
whereas the thing <"foo" in font "fixed"> does (18 pixels, I think it
is, on the system I'm using to type this).

> To do this, it looks like I have to:

> [...]
>     o  find out the fontstruct using
>            fontstruct = XLoadQueryFont (display, fontname)
>        for which I need to

>     o  learn the name of the installed font.

You can get an XFontStruct that way, yes.  However, you can also use
XQueryFont, for which you need only the font ID, or even a graphics
context ID (obtainable from the GC with XGContextFromGC).

I don't know enough about widgets (of any sort) to more than guess what
font your statictext widget is going to use, but if you can get it to
tell you the graphics context it will use for drawing, you can use
that.  If all else fails, you might be able to get away with using the
default GC for the screen, but I doubt that'd work properly.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu