Setting the font size
In XWIndows how do I set the font size to draw with? There's probably something simple I'm missing on this.
I know you can get a font's size with something like this:
But how can I tell it I want to use font size 18 when I output text?
int FontSize(Display Disp, char *FontName)
FontInfo = XLoadQueryFont(Disp, "fixed");
Height = FontInfo.ascent + FontInfo.descent
Maybe an answer?
This is a crude way of setting the font size, its by no means very thorough though. If you read the font.alias file (not sure what its default location is, I found mine at /usr/X11R6/lib/X11/fonts/misc/fonts.alias) it has a list of alias names for fonts. Among the aliases you see things like 5x7, 5x8, 6x9 and so on. Those appear to be average character sizes, width x height.
You can load fonts based on these aliases. Like this:
Any text drawing done with that GC (XDrawText() function calls) will write using the font aliased by 6x9. This also permits wildcards, so you can do stuff like this:
font = XLoadFont(cdisDisplay, "6x9");
gc = XCreateGC(/*Code Omitted*/);
XSetFont(cdisDisplay, Context, font);
And it will load any font with x9 in the name. By using that it seems you can choose a font height (which is pretty close to selecting a font size) and it will look for a matching name or alias.
font = XLoadFont(cdisDisplay, "*x9");
This is obviously not the best way of doing this, since not all sizes will have a convenient alias and I don't know how well you can predict what aliases will be available from one system to the next. The other thing it doesn't permit is selecting a font and size, since you are tied to the fonts that are aliases (which appear to be all fixed width fonts).
As a side note, you can take a look at fonts.dir files (do a search for then, their appears to be multiple) to get a full listing of the available fonts. No aliases, but you can load them by name, and wildcards are still permitted in loading them. So you can load "*helvetica*" to get the helvetica font, but no size. Not sure how to get a size and font together though.
Theres a number of functions that allow you to enumerate the fonts set in those files. But it appears that loading fonts is tied to what is set in these files.
Its not perfect, but its a pretty decent method of setting the size of a font.
Although you seem to have worked out a solution for yourself , I thought you might still be interested in this page (ie. Appendix A of Xlib Programming Manual ) which seems to provide a more formal approach to enumerating and using fonts with xlib.
Thanks, that clears up a lot of the questions I had left.