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