home *** CD-ROM | disk | FTP | other *** search
- /* ************************************************************************ */
-
-
- /* This is an example program designed to utilise and manipulate the
- `xvertext' routines.
-
- Copyright (c) 1992 Alan Richardson (mppa3@uk.ac.sussex.syma) */
-
-
- /* ************************************************************************ */
-
-
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <stdio.h>
- #include <signal.h>
- #include "rotated.h"
-
-
- /* ---------------------------------------------------------------------- */
-
-
- extern char *getenv();
-
- long AllocNamedColor();
- void ShowFontName();
- void PaintMessage();
- void Advance();
-
-
- /* ---------------------------------------------------------------------- */
-
-
- #define INFO_FONT \
- "-adobe-helvetica-bold-o-normal--14-140-75-75-p-82-iso8859-1"
-
- #define NFONTS 18
-
- char *fonts[]={
- "-adobe-helvetica-medium-r-normal--18-180-75-75-p-98-iso8859-1",
- "-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1",
- "-adobe-helvetica-medium-r-normal--10-100-75-75-p-56-iso8859-1",
- "-adobe-courier-bold-o-normal--18-180-75-75-m-110-iso8859-1",
- "-adobe-courier-medium-o-normal--12-120-75-75-m-70-iso8859-1",
- "-adobe-courier-bold-o-normal--10-100-75-75-m-60-iso8859-1",
- "-adobe-times-medium-r-normal--18-180-75-75-p-94-iso8859-1",
- "-adobe-times-bold-r-normal--12-120-75-75-p-67-iso8859-1",
- "-adobe-times-medium-r-normal--10-100-75-75-p-54-iso8859-1",
- "-adobe-helvetica-bold-o-normal--18-180-75-75-p-98-iso8859-1",
- "-adobe-helvetica-medium-o-normal--12-120-75-75-p-67-iso8859-1",
- "-adobe-helvetica-bold-o-normal--10-100-75-75-p-57-iso8859-1",
- "-adobe-courier-medium-r-normal--18-180-75-75-m-110-iso8859-1",
- "-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1",
- "-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1",
- "-adobe-times-bold-i-normal--18-180-75-75-p-94-iso8859-1",
- "-adobe-times-medium-i-normal--12-120-75-75-p-63-iso8859-1",
- "-adobe-times-bold-i-normal--10-100-75-75-p-52-iso8859-1"
- };
-
- char *message={"\
- This is a system for doing\n\
- (fairly) fast vertical and\n\
- upside down text\n\
- in an X Window.\n\
- It handles\n\
- both fixed width and\n\
- proportional fonts.\n\n\
- But it will cry\n\
- if you shout at it."
- };
-
-
- /* ---------------------------------------------------------------------- */
-
-
- GC info_gc, message_gc;
- Display *dpy;
- Window window;
- int depth, screen;
- XRotFontStruct *font1=NULL, *font2=NULL;
- int ifont, ipos;
-
-
- /* ---------------------------------------------------------------------- */
-
-
- /* *** Allocates a colour from the default colour map *** */
-
- long AllocNamedColor(colname)
- char *colname;
- {
- XColor scrncol, excol;
-
- if(depth==1)
- return WhitePixel(dpy, screen);
-
- if(XAllocNamedColor(dpy, DefaultColormap(dpy, screen), colname,
- &scrncol, &excol))
- return scrncol.pixel;
-
- else
- return WhitePixel(dpy, screen);
- }
-
-
- /* ---------------------------------------------------------------------- */
-
-
- /* *** Main routine *** */
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- XEvent ev;
- char *host;
- char buf[1];
- float version;
- char copyright[100];
-
- version=XRotVersion(copyright, 100);
- fprintf(stderr, "%s - version %.1f\n", copyright, version);
-
- /* establish connection to display ... */
- if((host=getenv("DISPLAY"))==NULL) {
- fprintf(stderr,"%s : Error : Can't connect to host\n", argv[0]);
- exit();
- }
-
- /* open connection to display ... */
- if((dpy=XOpenDisplay(host))==NULL) {
- fprintf(stderr,"%s : Error : Can't open display\n", argv[0]);
- exit();
- }
-
- screen=DefaultScreen(dpy);
- depth=DefaultDepth(dpy, screen);
-
- /* create a window ... */
- window=XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, 700, 700,
- 0, depth, InputOutput, DefaultVisual(dpy, screen),
- 0, NULL);
-
- XSelectInput(dpy, window, ExposureMask|KeyPressMask);
- XSetWindowBackground(dpy, window, BlackPixel(dpy, screen));
- XMapWindow(dpy, window);
-
- info_gc=XCreateGC(dpy, window, NULL, 0);
- XSetBackground(dpy, info_gc, BlackPixel(dpy, screen));
- XSetForeground(dpy, info_gc, AllocNamedColor("cyan"));
-
- message_gc=XCreateGC(dpy, window, NULL, 0);
- if(depth>1)
- XSetBackground(dpy, message_gc, AllocNamedColor("red"));
- else
- XSetBackground(dpy, message_gc, BlackPixel(dpy, screen));
- XSetForeground(dpy, message_gc, AllocNamedColor("yellow"));
-
- /* load a font for showing the current font name ... */
- font2=XRotLoadFont(dpy, INFO_FONT, 0.);
- if(font2==NULL) {
- if(xv_errno==XV_NOFONT) {
- fprintf(stderr,"no font `%s'\n", INFO_FONT);
- font2=XRotLoadFont(dpy, "fixed", 0.);
- }
- else {
- if(xv_errno==XV_NOMEM)
- fprintf(stderr, "malloc problem - can't continue\n");
- else
- fprintf(stderr, "XImage problem - can't continue\n");
- exit(1);
- }
- }
-
- /* set the alarm for the first time ... */
- ifont=-1;
- ipos=8;
- Advance(0, 0, (struct sigcontext *)NULL);
-
- /* simple event loop ... */
- for(;;) {
- XNextEvent(dpy, &ev);
-
- switch(ev.type) {
- case Expose:
- if(ev.xexpose.count==0) {
- ShowFontName(False);
- PaintMessage();
- }
- break;
-
- case KeyPress:
- XLookupString(&ev.xkey, buf, 1, NULL, NULL);
- if(buf[0]=='q' || buf[0]=='Q')
- exit(0);
- break;
-
- default:
- break;
- }
- }
- }
-
-
- /* ---------------------------------------------------------------------- */
-
-
- /* *** Display the current font name in the top left corner *** */
-
- void ShowFontName(loading)
- Bool loading;
- {
- char str[300];
-
- if(loading)
- sprintf(str, "FONT: %s ... loading", fonts[ifont]);
- else
- sprintf(str, "FONT: %s ", fonts[ifont]);
- XRotDrawAlignedImageString(dpy, font2, window, info_gc, 0, 0, str, TLEFT);
-
- XFlush(dpy);
- }
-
-
- /* ---------------------------------------------------------------------- */
-
-
- /* *** Paint the message in the appropriate place *** */
-
- void PaintMessage()
- {
- static int alignment[]={
- TLEFT, TCENTRE, TRIGHT, MLEFT, MCENTRE, MRIGHT, BLEFT, BCENTRE, BRIGHT
- };
-
- /* draw some centered crosshairs ... */
- XDrawLine(dpy, window, info_gc, 350, 200, 350, 500);
- XDrawLine(dpy, window, info_gc, 200, 350, 500, 350);
-
- /* draw the message ... */
- if(ifont%2==0)
- XRotDrawAlignedString(dpy, font1, window, message_gc, 350, 350,
- message, alignment[ipos]);
- else
- XRotDrawAlignedImageString(dpy, font1, window, message_gc, 350, 350,
- message, alignment[ipos]);
-
- XFlush(dpy);
- }
-
-
- /* ---------------------------------------------------------------------- */
-
-
- /* *** Change the font, position and/or rotation *** */
-
- void Advance(sig, code, scp)
- int sig, code;
- struct sigcontext * scp;
- {
- /* advance position ... */
- if((ipos+=2)>=9) {
- if(++ifont==NFONTS) ifont=0;
-
- ipos=(ifont%2);
-
- /* finished with this font ... */
- if(font1!=NULL)
- XRotUnloadFont(dpy, font1);
-
- /* load a new font ... */
- ShowFontName(True);
-
- font1=XRotLoadFont(dpy, fonts[ifont], (float)(ifont%4)*90.);
- if(font1==NULL) {
- if(xv_errno==XV_NOFONT) {
- fprintf(stderr,"no font `%s'\n", fonts[ifont]);
- font1=XRotLoadFont(dpy, "fixed", (float)(ifont%4)*90.);
- }
- else {
- if(xv_errno==XV_NOMEM)
- fprintf(stderr, "malloc problem - can't continue\n");
- else
- fprintf(stderr, "XImage problem - can't continue\n");
- exit(1);
- }
- }
- ShowFontName(False);
- }
-
- /* delete old message and draw new ... */
- XClearArea(dpy, window, 0, font2->height+1, 700, 700-font2->height, False);
- PaintMessage();
-
- /* reset alarm ... */
- signal(SIGALRM, Advance);
- alarm(1);
- }
-
-