/* * $Id$ */ /* * File: vidtext.c * * Author: John Clyne * National Center for Atmospheric Research * PO 3000, Boulder, Colorado * * Date: Mon Sep 9 11:49:12 MDT 1991 * * Description: Translate lines of text into metacode by way of * NCAR Graphics utility 'plotchar'. * * '-l' specifies the number of lines per frame. This * is the maximum number that may be displayed. It is * used to determine font size. The default is * $DEFAULT_LINES * * '-o' specifies the output metafile. * */ #include #include #define DEFAULT_METAFILE "gmeta" /* output file */ #define DEFAULT_LINES 12 /* lines per frame */ #define NCARG_ENV "NCARG_GKS_OUTPUT" static char *progName; usage() { (void) fprintf(stderr, "Usage: %s [-l <#lines>] [-o ]\n", progName); exit(1); } main(argc, argv) int argc; char **argv; { int c; extern int opterr, optind; extern char *optarg; char buf[BUFSIZ]; char *metafile = DEFAULT_METAFILE; /* output metafile */ int lines = DEFAULT_LINES; /* lines per frame */ float vert_space, /* space between lines of text */ char_width; /* width of a capitol letter */ float x,y; int i; progName = (progName = strrchr(argv[0], '/')) ? ++progName : *argv; opterr = 0; while((c = getopt(argc, argv, "l:o:m:")) != -1) { switch(c) { case 'l': if (sscanf(optarg, "%d", &lines) != 1) { usage(); } break; case 'o': metafile = optarg; break; case '?': usage(); break; } } if ((argc - optind) != 0) usage(); /* * init the gks package */ init_text(metafile, lines); /* * calculate spacing based on number of lines of text per frame */ vert_space = 1.0 / (lines + 1); char_width = vert_space * 0.5; /* * translate text to metacode */ x = 0.5; y = 1 - vert_space; for (i=0; i < lines && gets(buf); i++) { if (! strcmp(buf, "\f")) { advance_frame(); y = 1 - vert_space; } else { text(x,y,buf,char_width); y -= vert_space; } } close_text(); } /* * init_text() * * open gks package */ static init_text(metafile, lines) char *metafile; int lines; { char *s; extern char *malloc(); float line_width = 3.0; char *fc = "FC"; char control_char = '\001'; int wkid = 1; /* gks workstation id */ int c_index = 1; /* color index */ #ifdef DEAD float red = 0.60; float green = 0.60; float blue = 0.94; #endif /* DEAD */ float red = 1.00; float green = 1.00; float blue = 1.00; s = malloc(strlen(NCARG_ENV) + strlen("=") + strlen(metafile) + 1); if (!s) { perror(progName); exit(1); } (void) strcpy(s, NCARG_ENV); (void) strcat(s, "="); (void) strcat(s, metafile); /* * redirect GKS output to $metafile */ if (putenv(s) != 0) { perror(progName); exit(1); } /* * open gks */ opngks_(); /* * Try and come up with a somewhat reasonable text line width based * on the maximum number of lines of text per frame. */ line_width = 30.0 / (float) lines; /* * set text line width. */ gslwsc_(&line_width); /* * tell plchhq to treat ':' as a normal character */ pcsetc_(fc, &control_char, strlen(fc)); /* * put an entry in the color table */ gscr_(&wkid, &c_index, &red, &green, &blue); /* * set the (line) text color */ gsplci_(&c_index); } close_text() { clsgks_(); } /* * text() * * render text. */ text(x,y,string,char_width) float x,y; char *string; float char_width; { float angle = 0.0; #ifdef DEAD float center = -1.0; #endif float center = 0.0; float x_ = x; float y_ = y; float char_width_ = char_width; plchhq_(&x_,&y_, string, &char_width_, &angle, ¢er, strlen(string)); } advance_frame() { frame_(); }