1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
/* $Id: impress.c,v 1.4 2010/10/06 16:02:49 rice Exp $
PLplot ImPress device driver.
*/
#include "plDevs.h"
#ifdef PLD_imp
#include "plplotP.h"
#include "drivers.h"
/* Device info */
const char* plD_DEVICE_INFO_impress = "imp:Impress File:0:impress:37:imp";
/* Function prototypes */
/* pmr: defined in drivers.h */
/*void plD_dispatch_init_imp ( PLDispatchTable *pdt );*/
void plD_init_imp (PLStream *);
void plD_line_imp (PLStream *, short, short, short, short);
void plD_polyline_imp (PLStream *, short *, short *, PLINT);
void plD_eop_imp (PLStream *);
void plD_bop_imp (PLStream *);
void plD_tidy_imp (PLStream *);
void plD_state_imp (PLStream *, PLINT);
void plD_esc_imp (PLStream *, PLINT, void *);
static void flushline(PLStream *);
/* top level declarations */
#define IMPX 2999
#define IMPY 2249
#define BUFFPTS 50
#define BUFFLENG 2*BUFFPTS
/* Graphics control characters. */
#define SET_HV_SYSTEM 0315
#define OPBYTE1 031
#define OPBYTE2 0140
#define SET_ABS_H 0207
#define SET_ABS_V 0211
#define OPWORDH1 0
#define OPWORDH2 150
#define OPWORDV1 0
#define OPWORDV2 150
#define ENDPAGE 0333
#define SET_PEN 0350
#define CREATE_PATH 0346
#define DRAW_PATH 0352
#define OPTYPE 017
static short *LineBuff;
static short FirstLine;
static int penchange = 0, penwidth = 1;
static short count;
void plD_dispatch_init_imp( PLDispatchTable *pdt )
{
#ifndef ENABLE_DYNDRIVERS
pdt->pl_MenuStr = "Impress File";
pdt->pl_DevName = "imp";
#endif
pdt->pl_type = plDevType_FileOriented;
pdt->pl_seq = 37;
pdt->pl_init = (plD_init_fp) plD_init_imp;
pdt->pl_line = (plD_line_fp) plD_line_imp;
pdt->pl_polyline = (plD_polyline_fp) plD_polyline_imp;
pdt->pl_eop = (plD_eop_fp) plD_eop_imp;
pdt->pl_bop = (plD_bop_fp) plD_bop_imp;
pdt->pl_tidy = (plD_tidy_fp) plD_tidy_imp;
pdt->pl_state = (plD_state_fp) plD_state_imp;
pdt->pl_esc = (plD_esc_fp) plD_esc_imp;
}
/*--------------------------------------------------------------------------*\
* plD_init_imp()
*
* Initialize device (terminal).
\*--------------------------------------------------------------------------*/
void
plD_init_imp(PLStream *pls)
{
PLDev *dev;
/* Initialize family file info */
plFamInit(pls);
/* Prompt for a file name if not already set */
plOpenFile(pls);
/* Allocate and initialize device-specific data */
dev = plAllocDev(pls);
dev->xold = PL_UNDEFINED;
dev->yold = PL_UNDEFINED;
dev->xmin = 0;
dev->ymin = 0;
dev->xmax = IMPX;
dev->ymax = IMPY;
dev->xlen = dev->xmax - dev->xmin;
dev->ylen = dev->ymax - dev->ymin;
plP_setpxl((PLFLT) 11.81, (PLFLT) 11.81);
plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax);
LineBuff = (short *) malloc(BUFFLENG * sizeof(short));
if (LineBuff == NULL) {
plexit("Error in memory alloc in plD_init_imp().");
}
fprintf(pls->OutFile, "@Document(Language ImPress, jobheader off)");
fprintf(pls->OutFile, "%c%c", SET_HV_SYSTEM, OPBYTE1);
fprintf(pls->OutFile, "%c%c%c", SET_ABS_H, OPWORDH1, OPWORDH2);
fprintf(pls->OutFile, "%c%c%c", SET_ABS_V, OPWORDV1, OPWORDV2);
fprintf(pls->OutFile, "%c%c", SET_HV_SYSTEM, OPBYTE2);
}
/*--------------------------------------------------------------------------*\
* plD_line_imp()
*
* Draw a line in the current color from (x1,y1) to (x2,y2).
\*--------------------------------------------------------------------------*/
void
plD_line_imp(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
{
PLDev *dev = (PLDev *) pls->dev;
int xx1 = x1a, yy1 = y1a, xx2 = x2a, yy2 = y2a;
int iw;
if (FirstLine) {
if (penchange) {
fprintf(pls->OutFile, "%c%c", SET_PEN, (char) penwidth);
penchange = 0;
}
/* Add both points to path */
count = 0;
FirstLine = 0;
*(LineBuff + count++) = (short) xx1;
*(LineBuff + count++) = (short) yy1;
*(LineBuff + count++) = (short) xx2;
*(LineBuff + count++) = (short) yy2;
}
else if ((count + 2) < BUFFLENG && xx1 == dev->xold && yy1 == dev->yold) {
/* Add new point to path */
*(LineBuff + count++) = (short) xx2;
*(LineBuff + count++) = (short) yy2;
}
else {
/* Write out old path */
count /= 2;
fprintf(pls->OutFile, "%c%c%c", CREATE_PATH, (char) count / 256, (char) count % 256);
iw = fwrite((char *) LineBuff, sizeof(short), 2 * count, pls->OutFile);
fprintf(pls->OutFile, "%c%c", DRAW_PATH, OPTYPE);
/* And start a new path */
if (penchange) {
fprintf(pls->OutFile, "%c%c", SET_PEN, (char) penwidth);
penchange = 0;
}
count = 0;
*(LineBuff + count++) = (short) xx1;
*(LineBuff + count++) = (short) yy1;
*(LineBuff + count++) = (short) xx2;
*(LineBuff + count++) = (short) yy2;
}
dev->xold = xx2;
dev->yold = yy2;
}
/*--------------------------------------------------------------------------*\
* plD_polyline_imp()
*
* Draw a polyline in the current color.
\*--------------------------------------------------------------------------*/
void
plD_polyline_imp(PLStream *pls, short *xa, short *ya, PLINT npts)
{
PLINT i;
for (i = 0; i < npts - 1; i++)
plD_line_imp(pls, xa[i], ya[i], xa[i + 1], ya[i + 1]);
}
/*--------------------------------------------------------------------------*\
* plD_eop_imp()
*
* End of page.
\*--------------------------------------------------------------------------*/
void
plD_eop_imp(PLStream *pls)
{
flushline(pls);
fprintf(pls->OutFile, "%c", ENDPAGE);
}
/*--------------------------------------------------------------------------*\
* plD_bop_imp()
*
* Set up for the next page.
\*--------------------------------------------------------------------------*/
void
plD_bop_imp(PLStream *pls)
{
PLDev *dev = (PLDev *) pls->dev;
FirstLine = 1;
dev->xold = PL_UNDEFINED;
dev->yold = PL_UNDEFINED;
if (!pls->termin)
plGetFam(pls);
pls->page++;
}
/*--------------------------------------------------------------------------*\
* plD_tidy_imp()
*
* Close graphics file or otherwise clean up.
\*--------------------------------------------------------------------------*/
void
plD_tidy_imp(PLStream *pls)
{
free((void *) LineBuff);
fclose(pls->OutFile);
}
/*--------------------------------------------------------------------------*\
* plD_state_imp()
*
* Handle change in PLStream state (color, pen width, fill attribute, etc).
\*--------------------------------------------------------------------------*/
void
plD_state_imp(PLStream *pls, PLINT op)
{
switch (op) {
case PLSTATE_WIDTH:
if (pls->width > 0 && pls->width <= 20) {
penwidth = pls->width;
penchange = 1;
}
break;
case PLSTATE_COLOR0:
break;
case PLSTATE_COLOR1:
break;
}
}
/*--------------------------------------------------------------------------*\
* plD_esc_imp()
*
* Escape function.
\*--------------------------------------------------------------------------*/
void
plD_esc_imp(PLStream *pls, PLINT op, void *ptr)
{
(void) pls; /* pmr: make these used */
(void) op;
(void) ptr;
}
/*--------------------------------------------------------------------------*\
* flushline()
*
* Spits out the line buffer.
\*--------------------------------------------------------------------------*/
static void
flushline(PLStream *pls)
{
int iw;
count /= 2;
fprintf(pls->OutFile, "%c%c%c", CREATE_PATH, (char) count / 256, (char) count % 256);
iw = fwrite((char *) LineBuff, sizeof(short), 2 * count, pls->OutFile);
fprintf(pls->OutFile, "%c%c", DRAW_PATH, OPTYPE);
FirstLine = 1;
}
#else
int
pldummy_impress(void)
{
return 0;
}
#endif /* PLD_imp */
|