PLplot: impress.c Source File

PLplot 5.10.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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