1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: mif.trm,v 1.33 2006/07/21 02:35:47 sfeam Exp $
5 /* GNUPLOT -- mif.trm */
8 * Copyright 1992, 1993, 1998, 2004
10 * Permission to use, copy, and distribute this software and its
11 * documentation for any purpose with or without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and
13 * that both that copyright notice and this permission notice appear
14 * in supporting documentation.
16 * Permission to modify the software is granted, but not the right to
17 * distribute the complete modified source code. Modifications are to
18 * be distributed as patches to the released version. Permission to
19 * distribute binaries produced by compiling modified sources is granted,
21 * 1. distribute the corresponding source modifications from the
22 * released version in the form of a patch file along with the binaries,
23 * 2. add special version identification to distinguish your version
24 * in addition to the base release version number,
25 * 3. provide your name and address as the primary contact for the
26 * support of your modified version, and
27 * 4. retain our contact information in regard to use of the base
29 * Permission to distribute the released version of the source code along
30 * with corresponding source modifications in the form of a patch file is
31 * granted with same provisions 2 through 4 for binary distributions.
33 * This software is provided "as is" without express or implied warranty
34 * to the extent permitted by applicable law.
38 * This file is included by ../term.c.
40 * This terminal driver was developed for
41 * gnuplot for unix version 3.0 (patchlevel 1)
42 * gnuplot for unix version 3.2 (patchlevel 2)
44 * This terminal driver supports:
45 * Frame Maker MIF format version 3.00
47 * Options for this terminal driver (set terminal mif [options]):
48 * colour / Draw primitives with line types >= 0 in colour (sep. 2-7)
49 * monochrome Draw primitives in black (sep. 0)
51 * polyline / Draw lines as continuous curves
52 * vectors Draw lines as collections of vectors
54 * help / ? Print short usage description on stderr
56 * Properties for this terminal driver:
57 * -Gnuplot size of worksheet: MIF_XMAX * MIF_YMAX
58 * -Unit in MIF output: cm
59 * -Plot primitives with the same pen will
60 * be grouped in the same MIF group.
61 * -Plot primitives with line types >= 0
62 * will as default be drawn in colour.
63 * -Lines are plotted as collections of
64 * vectors, or as continuous lines (default)
65 * -Plot primitives in a plot will be in a
66 * Frame in MIF. Several plot Frames will
67 * be collected in one large Frame.
68 * -Point size of MIF output characters: MIF_PSIZE
69 * -Used font for MIF output characters: Times
70 * -Supports vertical text
71 * -points and dots as characters
72 * -character formats for TextLines
75 * Olof Franksson, Physics IV, KTH, S-100 44 Stockholm, Sweden
77 * NEW TERMINAL FORMAT: David C. Schooley
80 * Send comments and/or suggestions to olof@fysik4.kth.se
83 * Changed to new terminal format 9/29/95 schooley@ee.gatech.edu
84 * Changed order of routine declarations. olof@fysik4.kth.se
85 * Changed mechanism for pen pattern selection. kssingvo@immd4.informatik.uni-erlangen.de
86 * Support for vertical text. kssingvo@immd4.informatik.uni-erlangen.de
87 * Fixed plot bug for "set size XS,YS", XS/YS > 1. olof@fysik4.kth.se
88 * Support colored text merritt@u.washington.edu
89 * Support box fill and pattern fill merritt@u.washington.edu
102 TERM_PUBLIC void MIF_init __PROTO((void));
103 TERM_PUBLIC void MIF_graphics __PROTO((void));
104 TERM_PUBLIC void MIF_text __PROTO((void));
105 TERM_PUBLIC void MIF_linetype __PROTO((int linetype));
106 TERM_PUBLIC void MIF_move __PROTO((unsigned int x, unsigned int y));
107 TERM_PUBLIC void MIF_vector __PROTO((unsigned int x, unsigned int y));
108 TERM_PUBLIC void MIF_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
109 TERM_PUBLIC int MIF_text_angle __PROTO((int ang));
110 TERM_PUBLIC void MIF_reset __PROTO((void));
111 TERM_PUBLIC void MIF_options __PROTO((void));
112 TERM_PUBLIC int MIF_justify_text __PROTO((enum JUSTIFY mode));
113 TERM_PUBLIC void MIF_point __PROTO((unsigned int x, unsigned int y, int number));
114 TERM_PUBLIC void MIF_boxfill __PROTO((int style, unsigned int x1, unsigned int y1,
115 unsigned int width, unsigned int height));
116 TERM_PUBLIC void MIF_filled_polygon __PROTO((int points, gpiPoint* corners));
119 /* The cast to float is not necessary because we are dividing by a float */
120 /* On OSK the cast to a float is not allowed in a constant expression wich */
121 /* is used by the declaration and initialization of mif_line */
122 /* Converts gnuplot units to MIF units */
123 #define GNP_TO_MIF(P) ((P) / 1000.0)
124 /* Basic unit: 0.01 mm (15cm -> 15*10*100=15000) */
125 #define MIF_XMAX 15000
126 /* Basic unit: 0.01 mm (10cm -> 10*10*100=10000) */
127 #define MIF_YMAX 10000
129 #define MIF_XLAST (MIF_XMAX - 1)
130 #define MIF_YLAST (MIF_YMAX - 1)
132 static int insert_mif_line __PROTO((double fx, double fy));
133 static int proc_group_id __PROTO((int group_id));
134 static void free_mif_line __PROTO((void));
135 static void put_mif_line __PROTO((void));
136 static void MIF_set_font __PROTO((const char *));
137 static void mif_put_point __PROTO((unsigned int x, unsigned int y, int np));
141 #ifndef TERM_PROTO_ONLY
148 static struct mif_line { /* Line point structure specification */
149 float fpos_x; /* Line point X coordinate */
150 float fpos_y; /* Y coordinate */
151 struct mif_line *next; /* Pointer to next line point */
152 struct mif_line *prev; /* Pointer to previous line point */
154 { /* Current position structure. Adjust for orign. Local for this file. */
156 GNP_TO_MIF(MIF_YLAST),
162 #define MIF_PSIZE 9 /* Point size of used characters */
164 #define MIF_VCHAR (MIF_YMAX/31) /* Distance between rows (a guess) */
165 #define MIF_HCHAR (MIF_XMAX/95) /* Distance between characters (a guess) */
168 #define MIF_VTIC (MIF_YMAX/150) /* Size of scale mark (vert) */
169 #define MIF_HTIC (MIF_XMAX/225) /* Size of scale mark (hor) */
171 /** Drawing properties **/
172 static char mif_justify[64]; /* How to justify the used text */
173 static char mif_pen[64], mif_pen_width[64], mif_separation[64]; /* How to plot */
174 static char mif_textcolor[64]; /* EAM parallels separation */
176 static int mif_text_ang = 0; /* Rotation angle of text */
178 static int mif_fill_patterns[] = {7,12,3,0,9,8,14,13};
179 #define MIF_FILL_SOLID 0
180 #define MIF_FILL_NONE 15
182 #define MIF_NPENS 16 /* Number of MIF pen types */
183 static int mif_pentype = 0; /* Pen type to use. Also used to create groups for graphics */
184 #define MIF_PEN_TO_GROUP(P) ( 1 + (P) ) /* Map pen type to group number. Must be >= 1 */
186 static int mif_pattern_table[MIF_NPENS] =
187 { /* Table, which pattern should be used for drawing */
190 2, 3, 4, 8, 12, 13, /* other lines: functions, data, ... (5 is used for grid; 6,7 is (nearly) invisible) */
192 9, 10, 11, 12, 13, 14, 15 /* not used */
195 /** MIF groups administration **/
196 #define MIF_NGROUP_ID 20
197 static struct mif_group_id {
199 /* This group id should generate a MIF group */
200 #define MIF_GROUP_EXISTS 1
201 /* This group id should not generate a MIF group */
202 #define MIF_GROUP_NOT_EXISTS 0
205 #define MIF_INVALID_GROUP_ID 0 /* An invalid MIF group ID */
207 } mif_group_id[MIF_NGROUP_ID]; /* List of used group ID:s and corresponding MIF groups existance */
210 static int mif_initialized = 0; /* != 0 when output is active */
211 static int mif_in_frame = 0; /* != 0 when inside a plot frame */
212 static int mif_frameno = -1; /* Current frame number */
213 static int mif_colour = TRUE; /* == TRUE when colour should be used */
214 static int mif_polyline = TRUE; /* == TRUE when lines are drawn as continuous curves */
216 struct mpt { /* point definition structure */
217 int chr; /* character for point */
218 float x_offset, y_offset; /* offset for vertical positioning */
219 char *font; /* font */
222 static char zgnuplot[] = "ZGnuplot"; /* character formats */
223 static char zgnuplotp[] = "ZGnuplotP";
224 static char zgnuplotd[] = "ZGnuplotD";
225 static const char *mif_font = NULL; /* actual character format */
227 static struct mpt mpt[POINT_TYPES + 1] =
228 { /* point definition data */
229 {'.', 0.000, 0.005, zgnuplotd, /* dot */ },
231 {'G', 0.002, 0.084, zgnuplotp, /* diamond */ },
232 {';', 0.002, 0.084, zgnuplotp, /* plus */ },
233 {'n', 0.002, 0.084, zgnuplotp, /* box */ },
234 {'5', 0.002, 0.084, zgnuplotp, /* X */ },
235 {'s', 0.002, 0.062, zgnuplotp, /* triangle */ },
236 {'K', 0.005, 0.075, zgnuplotp, /* star */ },
239 /* diamond is offset 0, dot is offset -1 */
240 static struct mpt *mif_point = &(mpt[1]);
243 /** Declaration of routine/s for internal use **/
244 static int insert_mif_line __PROTO((double fx, double fy));
245 static int proc_group_id __PROTO((int group_id));
248 MIF_MONOCHROME, MIF_COLOR, MIF_VECTORS, MIF_POLYLINE, MIF_HELP,
252 static struct gen_table MIF_opts[] =
254 { "m$onochrome", MIF_MONOCHROME },
255 { "c$olor", MIF_COLOR },
256 { "c$olour", MIF_COLOR },
257 { "v$ectors", MIF_VECTORS },
258 { "p$olyline", MIF_POLYLINE },
259 { "h$elp", MIF_HELP },
266 /* Called when this terminal type is set in order to parse options */
270 while (!END_OF_COMMAND) {
271 switch(lookup_table(&MIF_opts[0],c_token)) {
283 mif_polyline = FALSE;
295 Usage: set terminal mif [options]\n\
297 \t\tcolour / Draw primitives with line types >= 0 in colour (sep. 2-7)\n\
298 \t\tmonochrome Draw primitives in black (sep. 0)\n\n\
299 \t\tpolyline / Draw lines as continuous curves\n\
300 \t\tvectors Draw lines as collections of vectors\n\n\
301 \t\thelp / ? Print short usage description on stderr\n");
306 sprintf(term_options, "%s %s",
307 (mif_colour == TRUE) ? "colour" : "monochrome",
308 (mif_polyline == TRUE) ? "polyline" : "vectors");
311 /* Deallocate the used line structure elements */
315 struct mif_line *tline;
317 while (mif_line.prev != &mif_line) {
319 tline = mif_line.prev;
320 mif_line.prev = mif_line.prev->prev;
321 mif_line.prev->next = &mif_line;
327 /* Make sure that the list will be empty */
328 mif_line.prev = &mif_line;
329 mif_line.next = &mif_line;
332 /* Draw the pending line. Change current position. */
337 struct mif_line *tline;
339 /* Process if inside a Frame */
340 if (mif_initialized != 0 && mif_in_frame != 0) {
342 /* Count the number of available points */
343 for (tline = mif_line.next, np = 1; tline != &mif_line; tline = tline->next, np++);
345 /* Draw line (at least two points) */
349 fprintf(gpoutfile, "\t<PolyLine <GroupID %d> %s %s %s <Fill 15>\n",
350 MIF_PEN_TO_GROUP(mif_pentype), mif_pen, mif_pen_width, mif_separation);
352 /* Draw the line elements */
353 fprintf(gpoutfile, "\t\t<NumPoints %d> ", np);
354 for (i = 0, tline = &mif_line; i < np; i++, tline = tline->next) {
356 fputs("\n\t\t", gpoutfile);
357 fprintf(gpoutfile, "<Point %.3f %.3f> ",
358 tline->fpos_x, tline->fpos_y);
361 /* Line post amble */
362 fputs("\n\t>\n", gpoutfile);
364 /* Register the used group ID */
365 proc_group_id(MIF_PEN_TO_GROUP(mif_pentype));
367 /* Avoid to redraw this. The MIF system should remember it. */
369 mif_pen_width[0] = '\0';
370 mif_separation[0] = '\0';
372 /* Move current position to end of line */
373 mif_line.fpos_x = mif_line.prev->fpos_x;
374 mif_line.fpos_y = mif_line.prev->fpos_y;
376 /* Restore the line */
379 } /* Line processed */
382 /* Filled box support - Ethan Merritt <merritt@u.washington.edu> */
384 MIF_boxfill(int style, unsigned int x1, unsigned int y1,
385 unsigned int width, unsigned int height)
389 int fillpar = style >> 4;
393 case FS_EMPTY: fill_pattern = 7;
395 case FS_SOLID: fill_pattern = MIF_FILL_SOLID;
397 case FS_PATTERN:fill_pattern = mif_fill_patterns[fillpar % 8];
401 /* Object preamble */
402 fprintf(gpoutfile, "\t<Rectangle <GroupID %d> %s\n",
403 MIF_PEN_TO_GROUP(mif_pentype), mif_separation);
406 fprintf(gpoutfile, "\t\t<Fill %d>\n", fill_pattern);
409 fprintf(gpoutfile, "\t\t<ShapeRect %.3f %.3f %.3f %.3f>\n",
410 GNP_TO_MIF(x1), GNP_TO_MIF(MIF_YLAST - (y1+height)),
411 GNP_TO_MIF(width), GNP_TO_MIF(height));
414 fputs("\n\t>\n", gpoutfile);
416 /* Register the used group ID */
417 proc_group_id(MIF_PEN_TO_GROUP(mif_pentype));
421 /* Filled polygon. Ethan Merritt <merritt@u.washington.edu> */
423 MIF_filled_polygon(int points, gpiPoint* corners)
427 /* Object preamble */
428 fprintf(gpoutfile, "\t<Polygon <GroupID %d>\n",
429 MIF_PEN_TO_GROUP(mif_pentype));
432 fprintf(gpoutfile, "\t\t<Fill %d>\n", MIF_FILL_SOLID);
434 /* Draw the line elements */
435 fprintf(gpoutfile, "\t\t<NumPoints %d> ", points);
436 for (i=0; i<points; i++) {
437 fprintf(gpoutfile, "<Point %.3f %.3f> ",
438 GNP_TO_MIF(corners[i].x),
439 GNP_TO_MIF(MIF_YLAST - corners[i].y));
443 fputs("\n\t>\n", gpoutfile);
445 /* Register the used group ID */
446 proc_group_id(MIF_PEN_TO_GROUP(mif_pentype));
452 mif_put_point(unsigned int x, unsigned int y, int np)
454 /* Process if inside a Frame */
455 if (mif_initialized != 0 && mif_in_frame != 0) {
457 /* Draw pending line */
458 if (mif_polyline == TRUE)
461 /* Adjust current position for text-graphics alignment */
465 MIF_justify_text(CENTRE);
468 fprintf(gpoutfile, "\t<TextLine <GroupID %d> %s\n",
469 MIF_PEN_TO_GROUP(mif_pentype),
472 MIF_set_font(mif_point[np].font);
474 fprintf(gpoutfile, "\t\t<TLOrigin %.3f %.3f> %s <String `%c'>\n",
475 mif_line.fpos_x + mif_point[np].x_offset,
476 mif_line.fpos_y + mif_point[np].y_offset,
479 fputs("\t>\n", gpoutfile);
481 /* Register the used group ID */
482 proc_group_id(MIF_PEN_TO_GROUP(mif_pentype));
484 /* Avoid to redraw this. The MIF system should remember it. */
485 mif_justify[0] = '\0';
487 } /* Point processed */
495 MIF_point(unsigned int x, unsigned int y, int number)
497 if (number < 0) { /* dot */
500 number %= POINT_TYPES;
502 mif_put_point(x, y, number);
506 /* Set up a MIF output file */
512 /* Process if not inside a MIF file and Frame */
513 if (mif_initialized == 0 && mif_in_frame == 0) {
514 /* Tell this terminal driver that the output is initialized and
515 * no current frames are processed */
519 /* Reset internal position */
521 mif_line.fpos_x = GNP_TO_MIF(0);
522 mif_line.fpos_y = GNP_TO_MIF(MIF_YLAST);
524 /* Reset drawing properties strings */
526 mif_pen_width[0] = '\0';
527 mif_separation[0] = '\0';
529 MIF_justify_text(LEFT);
531 /* Reset group ID generator */
532 for (i = 0; i < MIF_NGROUP_ID; i++) {
533 mif_group_id[i].group_id = MIF_INVALID_GROUP_ID;
534 mif_group_id[i].group_existance = MIF_GROUP_NOT_EXISTS;
537 /* Identify ourselves */
539 /* Setup a default environment to use */
540 fprintf(gpoutfile, "\
541 <MIFFile 3.00> # Generated by gnuplot version %s patchlevel %s; identifies this as a MIF file\n\
544 <Document\n<DBordersOn Yes>\n>\n\
545 # Set a default pen pattern, pen width, unit and font for subsequent objects\n\
552 \t<Font <FTag `%s'><FFamily `Times'><FSize %d><FPlain Yes>>\n\
553 \t<Font <FTag `%s'><FFamily `ZapfDingbats'><FSize 7.0 pt><FPlain Yes>>\n\
554 \t<Font <FTag `%s'><FFamily `Symbol'><FSize 5.0 pt><FPlain Yes>>\n\
557 gnuplot_version, gnuplot_patchlevel,
561 } /* MIF file created */
564 /* Finish of a MIF output file */
568 /* Process if inside a MIF file and not inside a Frame */
569 if (mif_initialized != 0 && mif_in_frame == 0) {
570 /* Finish off the MIF file */
573 # End of MIFFile\n", gpoutfile);
575 /* Tell this terminal driver that the output is finished */
578 /* bs: reset frame number */
581 } /* MIF file finished */
584 /* Start plotting a Frame (-> graphics mode) */
590 /* Process if not inside a Frame */
591 if (mif_initialized != 0 && mif_in_frame == 0) {
592 /* Tell that this terminal driver is working with a plot frame */
595 /* Update frame number */
598 /* Set current position */
600 mif_line.fpos_x = GNP_TO_MIF(0);
601 mif_line.fpos_y = GNP_TO_MIF(MIF_YLAST);
603 /* Set drawing properties */
605 mif_pen_width[0] = '\0';
606 mif_separation[0] = '\0';
608 MIF_justify_text(LEFT);
610 /* Reset group ID generator */
611 for (i = 0; i < MIF_NGROUP_ID; i++) {
612 mif_group_id[i].group_id = MIF_INVALID_GROUP_ID;
613 mif_group_id[i].group_existance = MIF_GROUP_NOT_EXISTS;
617 fprintf(gpoutfile, "\
619 # Frame number %d with plot of graphics\n\
623 \t<PenWidth 0.5 pt>\n\
625 \t<BRect 2.000 %.3f %.3f %.3f>\n\
626 \t<NSOffset 0.000>\n\
627 \t<BLOffset 0.000>\n",
629 ((float) mif_frameno) * GNP_TO_MIF(MIF_YMAX + 100),
630 GNP_TO_MIF(MIF_XMAX), GNP_TO_MIF(MIF_YMAX));
631 } /* Frame created */
634 /* Stop plotting a Frame (-> text mode) */
640 /* Process if inside a Frame */
641 if (mif_initialized != 0 && mif_in_frame != 0) {
643 /* Draw pending line */
644 if (mif_polyline == TRUE)
647 /* Group the used plot primitives */
650 \t# Group the the objects in groups to make the chart easier to manipulate\n\
651 \t# after it's imported into FrameMaker.\n", gpoutfile);
653 for (i = 0; i < MIF_NGROUP_ID; i++) {
654 if (mif_group_id[i].group_id != MIF_INVALID_GROUP_ID &&
655 mif_group_id[i].group_existance == MIF_GROUP_EXISTS) {
656 fprintf(gpoutfile, "\
659 \t>\n", mif_group_id[i].group_id);
663 /* Frame post amble */
664 fprintf(gpoutfile, "\
666 # End of Frame number %d\n\
670 /* Tell that this terminal driver is not working with a plot frame */
672 } /* Frame finshed */
675 /* Select type of line in grapics */
676 /* NOTE: actually written to output the first time a primitive
677 * is drawn AFTER this call */
678 /* -2=border, -1=X/Y-axis, 0-13=lines, and 14-=mapped back */
680 MIF_linetype(int linetype)
682 /* Process if inside a Frame */
683 if (mif_initialized != 0 && mif_in_frame != 0) {
685 /* Draw pending line */
686 if (mif_polyline == TRUE)
689 /* Translate gnuplot pen types to MIF pen types */
690 if (linetype < 0) { /* Special lines */
691 if (linetype == LT_AXIS) {
692 mif_pentype = 8 + MIF_NPENS; /* -1 */
693 if (mif_colour == TRUE)
694 sprintf(mif_separation, " <Separation 0> ");
696 mif_pentype = 0 + MIF_NPENS; /* -2 or less */
697 if (mif_colour == TRUE)
698 sprintf(mif_separation, " <Separation 0> ");
700 sprintf(mif_pen_width, " <PenWidth 1.0 pt> ");
701 /* EAM - set text color to black */
702 sprintf(mif_textcolor, " <Font <FSeparation 0>> ");
703 } else { /* Normal lines */
704 mif_pentype = (linetype) % MIF_NPENS; /* 0-(MIF_NPENS-1) */
705 sprintf(mif_pen_width, " <PenWidth 0.1 pt> ");
706 if (mif_colour == TRUE)
707 sprintf(mif_separation, " <Separation %d> ",
708 2 + (mif_pentype % 6)); /* 2-7 */
709 /* EAM - set text color also */
710 if (mif_colour == TRUE)
711 sprintf(mif_textcolor, " <Font <FSeparation %d>> ",
712 2 + (mif_pentype % 6)); /* 2-7 */
716 sprintf(mif_pen, " <Pen %d> ",
717 mif_pattern_table[mif_pentype % MIF_NPENS]);
719 } /* Primitive processed */
722 /* Allow arbitrary text rotation */
724 MIF_text_angle(int ang)
730 /* Justify following text lines (MIF_put_text()) relative to the
732 * NOTE: actually written to output in text primitives which are
733 * drawn AFTER this call */
735 MIF_justify_text(enum JUSTIFY mode)
739 /* Process if inside a Frame */
740 if (mif_initialized != 0 && mif_in_frame != 0) {
743 sprintf(mif_justify, " <TLAlignment Left> ");
746 sprintf(mif_justify, " <TLAlignment Center> ");
749 sprintf(mif_justify, " <TLAlignment Right> ");
757 /* Primitive processed */
765 /* Draw a vector from current position to (x, y) and change current position.
766 * NOTE: actually written to output the first time another primitive
767 * is called AFTER this call */
769 MIF_vector(unsigned int x, unsigned int y)
771 /* Process if inside a Frame */
772 if (mif_initialized != 0 && mif_in_frame != 0) {
774 /* Setup the vector as a part of the line */
775 insert_mif_line(GNP_TO_MIF(x), GNP_TO_MIF(MIF_YLAST - (int) y));
777 /* Draw pending line -> vector */
778 if (mif_polyline == FALSE)
781 } /* Vector processed */
784 /* Move current position */
786 MIF_move(unsigned int x, unsigned int y)
788 /* Process if inside a Frame */
789 if (mif_initialized != 0 && mif_in_frame != 0) {
791 /* Draw pending line */
792 if (mif_polyline == TRUE)
795 mif_line.fpos_x = GNP_TO_MIF(x);
796 mif_line.fpos_y = GNP_TO_MIF(MIF_YLAST - (int) y);
803 MIF_set_font(const char *font)
805 if (font != mif_font) {
806 fprintf(gpoutfile, "\t\t<Font\n\t\t\t<FTag `%s'>\n\t\t>\n", font);
812 /* Draw the text string str at (x, y). Adjust according to MIF_justify_text().
813 * Change current position. */
815 MIF_put_text(unsigned int x, unsigned int y, const char str[])
817 /* Process if inside a Frame */
818 if (mif_initialized != 0 && mif_in_frame != 0) {
820 /* Draw pending line */
821 if (mif_polyline == TRUE)
824 /* Adjust current position for text-graphics alignment */
825 MIF_move(x, y - MIF_VCHAR / 5);
827 if (strlen(str) > 0) {
830 fprintf(gpoutfile, "\t<TextLine <GroupID %d> %s %s %s %s\n",
831 MIF_PEN_TO_GROUP(mif_pentype), mif_pen,
832 mif_pen_width, mif_separation, mif_textcolor);
834 MIF_set_font(zgnuplot);
836 fprintf(gpoutfile, "\
837 \t\t<TLOrigin %.3f %.3f> %s <Angle %d> <String `%s'>\n\
839 mif_line.fpos_x, mif_line.fpos_y, mif_justify,
842 /* Register the used group ID */
843 proc_group_id(MIF_PEN_TO_GROUP(mif_pentype));
845 /* Avoid to redraw this. The MIF system should remember it. */
847 mif_pen_width[0] = '\0';
848 mif_separation[0] = '\0';
850 mif_justify[0] = '\0'; /* Independent of linetype */
852 } /* Text processed */
856 /* Insert one point in the line */
858 insert_mif_line(double fx, double fy)
862 if ((mif_line.prev->next = (struct mif_line *) gp_alloc(sizeof(struct mif_line),
863 "MIF driver")) != (struct mif_line *) NULL) {
865 mif_line.prev->next->next = &mif_line;
866 mif_line.prev->next->prev = mif_line.prev;
867 mif_line.prev = mif_line.prev->next;
870 mif_line.prev->fpos_x = fx;
871 mif_line.prev->fpos_y = fy;
874 } else { /* Failed to allocate */
876 mif_line.prev->next = &mif_line;
884 /* Register group ID. Update group ID existance. */
885 /* Returns: 1 group_id belongs to a MIF group
886 0 group_id does not belong to a MIF group
887 -1 not inside a Frame
888 -2 group ID list is full
891 proc_group_id(int group_id)
895 /* Process if inside a Frame */
896 if (mif_initialized != 0 && mif_in_frame != 0) {
898 /* Find out the group ID, or a free group ID slot index. */
899 for (i = 0; i < MIF_NGROUP_ID &&
900 mif_group_id[i].group_id != MIF_INVALID_GROUP_ID &&
901 mif_group_id[i].group_id != group_id;
903 /* Don't check the group_existance variable */
906 if (i < MIF_NGROUP_ID) {
907 if (mif_group_id[i].group_id == MIF_INVALID_GROUP_ID) {
908 /* Register as new group ID for eventual use as MIF group */
909 mif_group_id[i].group_id = group_id;
910 mif_group_id[i].group_existance = MIF_GROUP_NOT_EXISTS;
912 /* If second use of this group ID -> create a new MIF group */
913 if (mif_group_id[i].group_id == group_id) {
914 mif_group_id[i].group_existance = MIF_GROUP_EXISTS;
915 /* NOTE: a group MUST have at least two members. */
920 rval = -2; /* No place for this group ID in the list */
924 /* Group ID processed */
926 rval = -1; /* Not inside a Frame */
929 /* Return MIF group status */
939 TERM_TABLE_START(mif_driver)
940 "mif", "Frame maker MIF 3.00 format",
941 MIF_XMAX, MIF_YMAX, MIF_VCHAR, MIF_HCHAR,
942 MIF_VTIC, MIF_HTIC, MIF_options, MIF_init, MIF_reset,
943 MIF_text, null_scale, MIF_graphics, MIF_move, MIF_vector,
944 MIF_linetype, MIF_put_text, MIF_text_angle,
945 MIF_justify_text, MIF_point, do_arrow, set_font_null,
948 0, 0, /* suspend, resume */
954 ,0 /* make_palette */
955 ,0 /* previous_palette */
957 ,MIF_filled_polygon /* filled_polygon */
958 TERM_TABLE_END(mif_driver)
961 #define LAST_TERM mif_driver
964 #endif /* TERM_PROTO_ONLY */
969 "?commands set terminal mif",
975 " The `mif` terminal driver produces Frame Maker MIF format version 3.00. It",
976 " plots in MIF Frames with the size 15*10 cm, and plot primitives with the same",
977 " pen will be grouped in the same MIF group. Plot primitives in a `gnuplot`",
978 " page will be plotted in a MIF Frame, and several MIF Frames are collected in",
979 " one large MIF Frame. The MIF font used for text is \"Times\".",
981 " Several options may be set in the MIF 3.00 driver.",
984 " set terminal mif {color | colour | monochrome} {polyline | vectors}",
987 " `colour` plots lines with line types >= 0 in colour (MIF sep. 2--7) and",
988 " `monochrome` plots all line types in black (MIF sep. 0).",
989 " `polyline` plots curves as continuous curves and `vectors` plots curves as",
990 " collections of vectors.",
991 " `help` and `?` print online help on standard error output---both print a",
992 " short description of the usage; `help` also lists the options.",
995 " set term mif colour polylines # defaults",
996 " set term mif # defaults",
997 " set term mif vectors",
1000 #endif /* TERM_HELP */