home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_02 / imagen.trm < prev    next >
Text File  |  1991-02-05  |  8KB  |  339 lines

  1. /* GNUPLOT - imagen.trm */
  2. /*
  3.  * Copyright (C) 1990   
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *   Imagen laser printers
  21.  *
  22.  * AUTHORS
  23.  *   Paul E. McKenney, David Kotz
  24.  * 
  25.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  26.  * 
  27.  */
  28.  
  29. /*
  30.  * Original for direct Imagen output (but retaining many of the
  31.  * LaTeX extensions) by Paul E. McKenney, 1989.
  32.  * Further modified by David Kotz to fit into gnuplot 2.0.
  33.  * Information Science and Technology Division, SRI International,
  34.  * 333 Ravenswood Ave, Menlo Park, CA 94025.
  35.  * Mail to mckenney@sri.com.
  36.  */
  37.  
  38. #include "imPcodes.h"
  39.  
  40. #define IMAGEN_PTS_PER_INCH (300)
  41.  
  42. #define IMAGEN_XMAX (IMAGEN_PTS_PER_INCH * 10) /* 10.0 inches */
  43. #define IMAGEN_YMAX (IMAGEN_PTS_PER_INCH * 75 / 10) /* 7.5 inches */
  44.  
  45. #define IMAGEN_FONTSIZE 12
  46.  
  47. #define IMAGEN_HTIC (20)
  48. #define IMAGEN_VTIC (20)
  49. #define IMAGEN_VCHAR (IMAGEN_FONTSIZE*5)
  50. #define IMAGEN_HCHAR (IMAGEN_VCHAR/2)
  51.  
  52. static int IMAGEN_orgx;        /* absolute-pixel-ORIgin of graph.    */
  53. static int IMAGEN_orgy;
  54. static int IMAGEN_posx;        /* current drawing position (lines).    */
  55. static int IMAGEN_posy;
  56. static int IMAGEN_inplot;
  57. static int IMAGEN_xmax;        /* width of graph in pixels.        */
  58. static int IMAGEN_ymax;        /* height of graph in pixels.        */
  59. static int IMAGEN_hchar;        /* Height of CHAR in current font.    */
  60. static int IMAGEN_wchar;        /* Width of CHAR in current font.    */
  61. static int IMAGEN_blofs;        /* BaseLine OFfSet from bounding box.    */
  62. static int IMAGEN_angle = -1;    /* 0 for horizontal text, 1 for vertical */
  63. static enum JUSTIFY IMAGEN_justify = LEFT; /* left/center/right */
  64.  
  65. static IMAGEN_seq_pos;        /* position in sequence */
  66.  
  67. static void IMAGEN_putwd();
  68. static void IMAGEN_createfamily();
  69. static void IMAGEN_setfont();
  70. static void IMAGEN_setpos();
  71. static char *IMAGEN_cvts();
  72.  
  73. IMAGEN_init()
  74. {
  75.     char font[10];            /* font name */
  76.  
  77.     IMAGEN_posx = IMAGEN_posy = 0;
  78.  
  79.     IMAGEN_orgx = (11.0 * IMAGEN_PTS_PER_INCH - IMAGEN_XMAX) / 2;
  80.     IMAGEN_orgy = (8.5 * IMAGEN_PTS_PER_INCH - IMAGEN_YMAX)/ 2;
  81.  
  82.     fputs("@document(language impress)", outfile);
  83.  
  84.     putc(imP_SET_HV_SYSTEM, outfile);
  85.     putc((3<<3)|5, outfile);
  86.  
  87.     sprintf(font, "cour%02d", IMAGEN_FONTSIZE);
  88.     IMAGEN_createfamily(font, IMAGEN_FONTSIZE);
  89.     IMAGEN_setfont(IMAGEN_FONTSIZE);
  90.  
  91.     IMAGEN_text_angle(0);
  92.  
  93.     putc(imP_SET_ABS_H, outfile);
  94.     IMAGEN_putwd(0);
  95.     putc(imP_SET_ABS_V, outfile);
  96.     IMAGEN_putwd(0);
  97.  
  98.     IMAGEN_linetype(-1);
  99. }
  100.  
  101. IMAGEN_graphics()
  102. {
  103.     static BOOLEAN first = TRUE;
  104.  
  105.     if (!first)
  106.      putc(imP_ENDPAGE, outfile);
  107.     first = FALSE;
  108.  
  109.     IMAGEN_move(0, 0);
  110. }
  111.  
  112. IMAGEN_text()
  113. {
  114. }
  115.  
  116.  
  117. IMAGEN_linetype(linetype)
  118. int linetype;
  119. {
  120.     static int lastlinetype = -10;
  121.  
  122.     if (linetype < 0)
  123.      linetype = -linetype;
  124.     else
  125.      linetype *= 2;
  126.  
  127.     if (lastlinetype == linetype)
  128.      return;
  129.  
  130.     lastlinetype = linetype;    /* now >= 0 */
  131.  
  132.     putc(imP_SET_PEN, outfile);
  133.     putc(linetype, outfile);
  134. }
  135.  
  136.  
  137. IMAGEN_move(x,y)
  138.     unsigned int x,y;
  139. {
  140.     IMAGEN_posx = x;
  141.     IMAGEN_posy = y;
  142. }
  143.  
  144. IMAGEN_vector(ux,uy)
  145.     unsigned int ux,uy;
  146. {
  147.     /* Create path. */
  148.  
  149.     putc(imP_CREATE_PATH, outfile);
  150.     IMAGEN_putwd(2);
  151.     IMAGEN_putwd(IMAGEN_posx + IMAGEN_orgx);
  152.     IMAGEN_putwd(IMAGEN_posy + IMAGEN_orgy);
  153.     IMAGEN_putwd(ux + IMAGEN_orgx);
  154.     IMAGEN_putwd(uy + IMAGEN_orgy);
  155.  
  156.     /* Draw path with black pen. */
  157.  
  158.     putc(imP_DRAW_PATH, outfile);
  159.     putc(15, outfile);
  160.  
  161.     /* Set current position to end of line. */
  162.  
  163.     IMAGEN_move(ux, uy);
  164. }
  165.  
  166. static void
  167. IMAGEN_setpos(ux, uy)
  168.     int ux,uy;
  169. {
  170.     /* Set x and y position (for text), also set beginning-of-line. */
  171.  
  172.     putc(imP_SET_ABS_H, outfile);
  173.     IMAGEN_putwd(ux + IMAGEN_orgx);
  174.     putc(imP_SET_ABS_V, outfile);
  175.     IMAGEN_putwd(uy + IMAGEN_orgy);
  176.     putc(imP_SET_BOL, outfile);
  177.     if (IMAGEN_angle == 1)
  178.      IMAGEN_putwd(uy + IMAGEN_orgx); /* vertical */
  179.     else
  180.      IMAGEN_putwd(ux + IMAGEN_orgx); /* horizontal */
  181. }
  182.  
  183. IMAGEN_text_angle(angle)
  184.     int angle;
  185. {
  186.     if (IMAGEN_angle != angle) {
  187.        IMAGEN_angle = angle;    /* record for later use */
  188.        putc(imP_SET_ADV_DIRS, outfile);
  189.        putc(angle == 0 ? 0 : 7, outfile); /* 0=>horiz : 7=>vert */
  190.     }
  191.  
  192.     return(TRUE);
  193. }
  194.  
  195. IMAGEN_justify_text(mode)
  196.     enum JUSTIFY mode;
  197. {
  198.     IMAGEN_justify = mode;
  199.     return(TRUE);
  200. }
  201.  
  202. static char *
  203. IMAGEN_cvts(str, width, height)
  204.     char        *str;
  205.     int        *width;
  206.     int        *height;
  207. {
  208.     char        *cp1;
  209.     char        *cp2;
  210.     static char    *buf = NULL;
  211.     int        h;
  212.     int        maxw;
  213.     int        w;
  214.  
  215.     /* Free up old buffer, if there is one, get a new one.  Since    */
  216.     /* all transformations shorten the string, get a buffer that is    */
  217.     /* the same size as the input string.                */
  218.  
  219.     if (buf != NULL)
  220.      (void) free(buf);
  221.     buf = (char *) alloc(strlen(str), "converted label string");
  222.  
  223.     /* Do the transformations. */
  224.  
  225.     cp1 = str;
  226.     cp2 = buf;
  227.     h = 1;
  228.     maxw = 0;
  229.     w = 0;
  230.     while (*cp1 != NULL) {
  231.        switch (*cp1) {
  232.           case ' ' :        /* Space character. */
  233.             *cp2++ = imP_SP;
  234.             w++;
  235.             break;
  236.             
  237.             case  '\\' :    /* Escape sequence. */
  238.              if (*++cp1 == '\\') {
  239.                 /* Begin new line. */
  240.                 h++;
  241.                 if (w > maxw)
  242.                   maxw = w;
  243.                 w = 0;
  244.                 *cp2++ = imP_CRLF;
  245.                 break;
  246.              }
  247.             
  248.             /* Fall through to just copy next char out.    */
  249.             
  250.             default :
  251.              *cp2++ = *cp1;
  252.             w++;
  253.             break;
  254.         }
  255.        cp1++;
  256.     }
  257.     
  258.     *cp2 = '\0';
  259.     if (w > maxw)
  260.      maxw = w;
  261.     
  262.     if (height != NULL)
  263.      *height = IMAGEN_angle ?
  264.        IMAGEN_wchar * maxw :
  265.         IMAGEN_hchar * h;
  266.     if (width != NULL)
  267.      *width = IMAGEN_angle ?
  268.        IMAGEN_hchar * h :
  269.         IMAGEN_wchar * maxw;
  270.     return (buf);
  271. }
  272.  
  273. IMAGEN_put_text(x, y, str)
  274.     int x,y;                /* reference point of string */
  275.     char str[];            /* the text */
  276. {
  277.     char *cvstr;
  278.     int height;
  279.     int width;
  280.     
  281.     cvstr = IMAGEN_cvts(str, &width, &height);
  282.  
  283.     switch (IMAGEN_justify) {
  284.        case LEFT: break;
  285.        case CENTRE: x -= width/2; break;
  286.        case RIGHT: x -= width; break;
  287.     }
  288.  
  289.     if (IMAGEN_angle) {        /* vertical */
  290.        x += IMAGEN_hchar;
  291.        y -= height/2;
  292.     } else                /* horizontal */
  293.      y += height/2 - IMAGEN_hchar;
  294.  
  295.     IMAGEN_setpos(x, y + IMAGEN_blofs);
  296.     fputs(cvstr, outfile);
  297. }
  298.  
  299.  
  300. IMAGEN_reset()
  301. {
  302.     putc(imP_EOF, outfile);
  303. }
  304.  
  305. static void
  306. IMAGEN_putwd(w)
  307. {
  308.     putc(w>>8, outfile);
  309.     putc(w, outfile);
  310. }
  311.  
  312. static void
  313. IMAGEN_createfamily(c, sz)
  314.     char        *c;
  315.     int        sz;
  316. {
  317.     putc(imP_CREATE_FAMILY_TABLE, outfile);
  318.     putc(sz, outfile);
  319.     putc(1, outfile);
  320.     putc(0, outfile);
  321.     fputs(c, outfile);
  322.     putc(0, outfile);
  323. }
  324.  
  325. static void
  326. IMAGEN_setfont(sz) 
  327.     int sz;
  328. {
  329.     IMAGEN_hchar = sz * 5;
  330.     IMAGEN_wchar = IMAGEN_hchar / 2;
  331.     IMAGEN_blofs = IMAGEN_hchar / 3;
  332.     putc(imP_SET_FAMILY, outfile);
  333.     putc(sz, outfile);
  334.     putc(imP_SET_SP, outfile);
  335.     IMAGEN_putwd(IMAGEN_wchar);
  336.     putc(imP_SET_IL, outfile);
  337.     IMAGEN_putwd(IMAGEN_hchar);
  338. }
  339.