A program using the xvertext routines will invariably start with a call to XRotLoadFont, since this loads and rotates a font. For example:
Display *dpy;
XRotFontStruct *rotfont;
char *fontname=
"lucidasans-bolditalic-10";
/* dpy obtained by calling XOpenDisplay() elsewhere in program */
rotfont=XRotLoadFont(dpy, fontname, 90.);
if(rotfont==NULL) {
if(xv_errno==XV_NOFONT)
rotfont=XRotLoadFont(dpy, "fixed", 90.);
else {
if(xv_errno==XV_NOMEM)
fprintf(stderr, "malloc problem - can't continue");
else
fprintf(stderr, "XImage problem - can't continue");
exit(1);
}
}
This code segment attempts to load the font "lucidasans-bolditalic-10" rotated at 90 degrees anticlockwise. If this fails, xv_errno is checked to find the reason. A value of XV_NOFONT indicates "lucidasans-bolditalic-10" isn't around, and the sure-bet font "fixed" is loaded instead. The other two errors, XV_NOMEM and XV_NOXIMAGE, indicate memory or XImage failures (and are unlikely to happen).
The other calls a user is most likely to make are to XRotDrawAlignedString or XRotDrawAlignedImageString. These are the most general purpose text drawing functions in the package, allowing the painting of strings containing newlines and specification of alignment. Typical usage might be:
Display *dpy;
XRotFontStruct *rotfont;
Window window;
GC gc;
char *message="This\nis\nno\nordinary\ntest";
/* dpy obtained by calling XOpenDisplay() elsewhere in program */
/* window already opened */
/* rotfont obtained as described above */
gc=XCreateGC(dpy, window, NULL, 0);
XSetForeground(dpy, gc, WhitePixel(dpy, DefaultScreen(dpy)));
XSetBackground(dpy, gc, BlackPixel(dpy, DefaultScreen(dpy)));
XRotDrawAlignedImageString(dpy, rotfont, window,
gc, 200, 200,
message, MLEFT);
This example paints a five line message in white, filling the background in black. The reference point is (200, 200) and with an alignment of MLEFT the output for a horizontal font would be (crosshairs mark (200, 200)):
|This
|is
---------+no-------
|ordinary
|test
Alignments of MCENTER and MRIGHT would result in:
| |
This This |
is is |
--------no-------- -no------+---------
ordinary ordinary|
test test |
| |
The lower level functions XRotDrawString and XRotDrawImageString do not handle newline characters or apply any alignment. They draw a one line string with the lower left hand corner at a specified position. They are called by XRotDrawAlignedString and XRotDrawAlignedImageString.
The function XRotTextWidth is provided to enable the width of strings painted in a certain rotated font to be found. It is called by the XRotDrawAlignedString and XRotDrawAlignedImageString functions.
Once a rotated font has been finished with it may be freed by calling XRotUnloadFont. This frees the bitmaps representing each rotated character, or the XFontStruct structure held for `right way up' fonts.