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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
|
DOCUMENTATION FOR GNUPLOT TERMINAL DRIVER WRITERS
By Russell Lang 1/90
Updated for new file layout by drd 4/95
Paragraphs about inclusion of TERM_HELP added by rcc 1/96
No change to the interface between gnuplot and the terminal drivers,
but we would like to make the terminal drivers standalone
1) in order move the support for the terminal drivers outside of the
support for the main program, thereby encouraging a library of
contributed drivers
2) To make it easy for users to add contributed drivers, by adding
a single #include line to term.h
Whole of terminal driver should be contained in one <driver>.trm file,
with a fairly strict layout as detailed below - this allows the
gnuplot maintainers to change the way the terminal drivers are
compiled without having to change the drivers themselves.
A few routines shared by multiple terminal drivers are given their
own C file, for example .../term/write_png_image.c.
term.h, and therefore each file.trm file, may be loaded more than once,
with different sections selected by macros.
Each driver provides all the functions it needs, and a table of
function pointers and other data to interface to gnuplot.
The table entry is currently defined as follows in term_api.h:
struct TERMENTRY {
/* required entries */
const char *name;
const char *description;
unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
void (*options)(void);
void (*init)(void);
void (*reset)(void);
void (*text)(void);
int (*scale)(double, double); /* DEPRECATED */
void (*graphics)(void);
void (*move)(unsigned int, unsigned int);
void (*vector)(unsigned int, unsigned int);
void (*linetype)(int);
void (*put_text)(unsigned int, unsigned int, const char*);
/* optional entries */
int (*text_angle)(float); /* Changed from (int) to (double) in 2021 (v5.5) */
int (*justify_text)(enum JUSTIFY);
void (*point)(unsigned int, unsigned int,int);
void (*arrow)(unsigned int, unsigned int, unsigned int, unsigned int, int);
int (*set_font)(const char *font); /* "font,size" */
void (*pointsize)(double pointsize);
int flags; /* various flags */
void (*suspend)(void); /* after one plot of multiplot */
void (*resume)(void); /* before subsequent plot of multiplot */
void (*fillbox)(int style, unsigned int x1, unsigned int y1, unsigned int width, unsigned int height); /* clear part of multiplot */
void (*linewidth)(double linewidth);
#ifdef USE_MOUSE
int (*waitforinput)(int);
void (*put_tmptext)(int i, const char str[]);
void (*set_ruler)(int x, int y);
void (*set_cursor)(int c, int x, int y);
void (*set_clipboard)(const char s[]);
#endif
int (*make_palette)t_sm_palette *palette);
void (*previous_palette)();
void (*set_color)(t_colorspec *colorspec);
void (*filled_polygon)(int points, gpiPoint *corners);
void (*image)(unsigned, unsigned, coordval *, gpiPoint *, t_imagecolor);
/* Enhanced text mode driver call-backs */
void (*enhanced_open)(char * fontname, double fontsize,
double base, TBOOLEAN widthflag, TBOOLEAN showflag,
int overprint);
void (*enhanced_flush)(void);
void (*enhanced_writec)(int c);
/* Driver-specific synchronization or other layering commands */
void (*layer)(t_termlayer syncpoint);
/* Path control for end-joins of closed polygons on PostScript-like devices */
void (*path)(int p);
/* Scale factor for converting terminal coordinates to output pixels */
double tscale;
/* Hypertext support */
void (*hypertext)(int type, const char *text);
void (*boxed_text)unsigned int x, unsigned int y, int option);
void (*modify_plots)(unsigned int operations, int plotno);
void (*dashtype)(int type, t_dashtype *custom_dash_pattern);
};
One consequence of (1) is that we would like drivers to be backwards
compatible - drivers in the correct form below should work in future
versions of gnuplot without change. ISO C guarantees to fill uninitialised
members of a static structure to zero, so gnuplot can detect old drivers,
in which fields have not been initialised, and can point new interface entry
pointers to dummy functions.
We can add fields to the terminal structure, but only at the end of the list.
If you design a terminal that can't work without a new interface being defined,
and consequent changes to the main gnuplot source, please contact
gnuplot-beta@lists.sourceforge.net simply to ensure that you have the most
up to date definition of the terminal structure. Also, please ensure that
the 'set term' command checks for 0 values in added fields when an
old driver is selected, and a pointer to a suitable 'can't do' function
is provided. It is therefore not required (and in fact not possible)
to add padding fields to the end of all drivers.
Similarly, if you add an optional field to an old driver, take care
to ensure that all intervening fields are padded with zeros.
Some of the above fields are required - this should not be a problem,
since they were all required in earlier releases of gnuplot.
The later fields are interfaces to capabilities that not all devices
can do, or for which the generic routines provided should be adequate.
There are several null ('can't do') functions provided by term.c which
a driver can reference in the table. Similarly, for bitmap devices, there
are generic routines for lines and text provided by bitmap.c
Here's a brief description of each variable:
The char *name is a pointer to a string containing the name
of the terminal. This name is used by the 'set terminal' and
'show terminal' commands.
The name must be unique and must not be confused with an abbreviation
of another name. For example if the name "postscript" exists, it is not
possible to have another name "postscript2".
Keep the name under 15 characters.
The char *description is a pointer to a string containing a
description of the terminal, which is displayed in response
to the 'set terminal' command.
Keep the description under 60 characters.
xmax is the maximum number of points in the x direction.
The range of points used by gnuplot is 0 to xmax-1.
ymax is the maximum number of points in the y direction.
The range of points used by gnuplot is 0 to ymax-1.
v_char is the height of characters, in the same units as xmax and ymax.
v_char is used as the vertical line spacing for characters.
v_char and h_char should be updated by set_font() since they are
needed for the core routines to estimate how much space will be
required for a text element.
h_char is the width of characters, in the same units as xmax and ymax.
The border for labelling at the left and right of the plot is
calculated using h_char, for example.
If the _justify_text function returns FALSE, h_char is used to justify
text right or centre. If characters are not fixed width, then the
_justify_text function must correctly justify the text.
v_tic is the vertical size of tics along the x axis,
in the same units as ymax.
h_tic is the horizontal size of tics along the y axis,
in the same units as xmax.
v_tic and h_tic should give tics of the same physical size on the
output. The ratio of these two quantities is used by gnuplot to set the
aspect ratio to 1 so that circles appear circular when 'set size square'
is active.
All the above values need not be static - values can be substituted
into the table during terminal initialisation, based on options for
example.
Here's a brief description of what each term.c function does:
_options() Called when terminal type is selected. Also called by
'set termoption'. The two cases can be distinguished because on entry
the value of c_token is either 3 or 2, respectively.
This procedure should parse options on the command line. A list of the
currently selected options should be stored in term_options[] in a form
suitable for use with the set term command. term_options[] is used by
the save command. Use options_null() if no options are available.
_options() and _waitforinput() are the only terminal functions that may
be called prior to _init(), so they must take care not to perform actions
that require previous initialisation.
_init() Called once, when the device is first selected. This procedure
should set up things that only need to be set once, like handshaking and
character sets etc...
There is a global variable 'pointsize' which you might want to use here.
If set pointsize is issued after init has been called, the pointsize()
function is called.
_reset() Called when gnuplot is exited, the output device changed or
the terminal type changed. This procedure should reset the device,
possibly flushing a buffer somewhere or generating a form feed.
_scale(xs,ys) Deprecated. PLEASE DO NOT USE THIS INTERFACE.
_graphics() Called just before a plot is going to be displayed. This
procedure should set the device into graphics mode. Devices which can't
be used as terminals (like plotters) will probably be in graphics mode
always and therefore won't need this.
_text() Called immediately after a plot is displayed. This procedure
should set the device back into text mode if it is also a terminal, so
that commands can be seen as they're typed. Again, this will probably
do nothing if the device can't be used as a terminal. This call can
be used to trigger conversion and output for bitmap devices.
_move(x,y) Called at the start of a line. The cursor should move to the
(x,y) position without drawing.
_vector(x,y) Called when a line is to be drawn. This should display a line
from the last (x,y) position given by _move() or _vector() to this new (x,y)
position.
_linetype(lt) Called to set the line type before text is displayed or
line(s) plotted. This procedure should select a pen color or line
style if the device has these capabilities.
Non-negative lt values correspond to a "real" linetype.
Negative lt values correspond to special values as defined in term_api.h
#define LT_AXIS (-1) /* Used to draw X and Y axes */
#define LT_BLACK (-2)
#define LT_NODRAW (-3)
#define LT_BACKGROUND (-4)
#define LT_UNDEFINED (-5)
#define LT_COLORFROMCOLUMN (-6) /* Used by hidden3d code */
#define LT_DEFAULT (-7)
#define LT_SINGLECOLOR (-8) /* Used by hidden3d code */
If _linetype() is called with lt greater than the available line types,
it should map it to one of the available line types.
_put_text(x,y,str) Called to display text at the (x,y) position,
while in graphics mode. The text should be vertically (with respect
to the text) justified about (x,y). The text is rotated according
to _text_angle and then horizontally (with respect to the text)
justified according to _justify_text.
The following are optional
_text_angle(ang) Called to rotate the text angle when placing the y label.
Ang is the rotation angle in degrees. If ang = 0 then text is horizontal.
Returns TRUE if text can be rotated, FALSE otherwise.
[But you must return TRUE if called with ang=0]
Mar 2021 (development version 5.5): ang is now (float) rather than (int).
_justify_text(mode) Called to justify text left, right or centre.
If mode = LEFT then text placed by _put_text is flushed left against (x,y).
If mode = CENTRE then centre of text is at (x,y).
If mode = RIGHT then text is placed flushed right against (x,y).
Returns TRUE if text can be justified
Returns FALSE otherwise and then _put_text assumes text is flushed left;
justification of text is then performed by calculating the text width
using strlen(text) * h_char.
_point(x,y,point) Called to place a point at position (x,y).
point is -1 or an integer from 0 upwards.
At least 6 point types (numbered 0 to 5) are normally provided.
Point type -1 is a dot. 'point' corresponds to (pointtype - 1),
e.g. 'plot x with points pointtype 2' will call _point(x, y, 1).
If possible, the driver should support the following 13 point types
in the given order:
point pointtype
0 1 plus
1 2 X
2 3 star
3 4 box
4 5 box filled
5 6 circle
6 7 circle (disk) filled
7 8 triangle
8 9 triangle filled
9 10 upside down triangle
10 11 upside down triangle filled
11 12 diamond
12 13 diamond filled
If point is more than the available point types then it should
be mapped back to one of the available points.
Two _point() functions called do_point() and line_and_point() are
provided in term.c and should be suitable for most drivers.
do_point() draws the points in the current line type.
If your driver uses dotted line types (generally because it is
monochrome), you should use line_and_point() which changes to
line type 0 before drawing the point. line type 0 should be solid.
There is a global variable 'pointsize' which is controlled by the
set pointsize command. If possible, use that. pointsize should be
examined at terminal init. If it is subsequently changed, the
pointsize() function will be called.
_arrow(sx,sy,ex,ey,head) Called to draw an arrow from (sx,sy) to (ex,ey).
"head" is a bitfield controlling where/if arrowheads are drawn:
END_HEAD | BACKHEAD | BOTH_HEADS | HEADS_ONLY
An _arrow() function called do_arrow() is provided in term.c which will
draw arrows using the _move() and _vector() functions.
Drivers should use do_arrow unless it causes problems.
_set_font() is called to set the font of labels, etc.
- fonts are selected as strings "name,size".
- _set_font("") restores the terminal's default font.
- FIXME >> Return value is never used! <<
- FIXME >> Should tolerate being passed a NULL font <<
_pointsize() is used to set the pointsize for subsequent points
_flags stores various flags describing driver capabilities.
- TERM_CAN_MULTIPLOT - driver can do multiplot in interactive mode,
- TERM_CANNOT_MULTIPLOT - driver cannot multiplot, even if output
is redirected. (not used by any current driver)
- TERM_BINARY - output file must be opened in binary mode
- TERM_ENHANCED_TEXT - terminal is currently in enhanced text mode
- TERM_NO_OUTPUTFILE - terminal does not use gpoutfile
See other flags defined in term_api.h
_suspend() - Called before gnuplot issues a prompt in multiplot mode.
Called only in interactive mode, and only for drivers that have set the
flag TERM_CAN_MULTIPLOT. Some of these must flip between text/graphics
mode (e.g. linuxvga). X11 driver will take this opportunity to paint
the window on the display.
_resume() - called after suspend(), before subsequent plots of a multiplot.
Called only in interactive mode, and only for drivers that have set the
flag TERM_CAN_MULTIPLOT.
_fillbox() - draws a filled axis-aligned rectangular box. The first
argument controls the type of fill-in: either a solid color at some
percentage of full intensity, or a hatch pattern. Used by plot style
"with filledboxes" and by the "clear" command (with background as
fill colour) to do inset plots via multiplot.
_linewidth() - sets the linewidth
The next five functions are used for mouse support, and should be
conditioned on USE_MOUSE:
_waitforinput(int options) - multiplexes mouse and hotkey input with
reading from the terminal. Returns the next character read from stdin.
In the mean time, process any mouse events. If the terminal has not yet
been initialised, this routine should return getc(stdin).
_put_tmptext(int i, const char str[]) - Display temporary text, after
erasing any temporary text displayed previously at this location.
The int determines where: 0=statusline, 1,2: at corners of zoom
box, with \r separating text above and below the point.
_set_ruler(int x, int y) - Draw a ruler (crosshairs) centered at the
indicated screen coordinates. If x<0, switch ruler off.
_set_cursor(int c, int x, int y) - Set cursor style and corner of
rubber band rectangle. c selects the action: -2=warp the cursor to
the given point, -1=start zooming, 0=standard cross-hair cursor,
1=cursor during rotation, 2=cursor during scaling, 3=cursor during
zooming, -3=draw line between ruler and current mouse position,
-4=don't draw (erase) line between ruler and current mouse position.
_set_clipboard(const char s[]) - Write a string to the clipboard.
The following four functions support PM3D and RGB colors.
_make_palette(t_sm_palette *palette) - If argument is NULL, return
number of colors available. If the number of colors is not limited
(continuously shaded colors can be generated), return 0.
Otherwise, allocate the palette. (t_sm_palette is defined in
src/color.h.)
_set_color(t_colorspec *colorspec) - EAM November 2004 ***CHANGED***
This routine used to accept a single double value, which was
interpreted as a fractional index into the current color palette.
Changing the parameter to a colorspec allows terminals to support
other methods of specifying a color. If a given driver can not
support a particular color request mechanism, it ignores it.
If (colorspec->type == TC_FRAC) (this was the old behavior):
Set current color according to colorspec->value, where 0 <= value <= 1.
If using a palette, first map value to an integer i in the interval
[0...num_colors-1], then set to the ith color in the palette.
If (colorspec->type == TC_RGB):
Set current color to the rgb triple given in colorspec->lt.
_filled_polygon(int points, gpiPoint *corners) - Draw a polygon with
the fill color set by set_color, and no border. (gpiPoint is
defined in src/color.h.)
_previous_palette() - Release the palette that the above routine
allocated and get back the palette that was active before. Some
terminals, like displays, may draw parts of the figure using their
own palette. Terminals that use only one palette for the whole plot
don't need this routine.
The following 3 functions are required for drivers that support enhanced
text mode. They are called only by the term.c routine enhanced_recursion().
_enhanced_open() - initialize state variables to process an enhanced text
fragment
_enhanced_writec() - write (or buffer) a single character of the text fragment
being constructed
_enhanced_flush() - finish processing of previous fragment and write it to
the output stream
_image(unsigned M, unsigned N, coordval *image, gpiPoint *corner, t_imagecolor color_mode)
Plot a pixel-based image on the display device.
'M' is the number of pixels along the y-dimension of the image and
'N' is the number of pixels along the x-dimension of the image. The
coordval pointer 'image' is the pixel values normalized to the range
[0:1]. These values should be scaled appropriately for the output
device. The 'image' data starts in the upper left corner and scans
along rows finishing in the lower right corner. If 'color_mode' is
IC_PALETTE, the terminal is to use palette lookup to generate color
information. In this scenario the size of 'image' is M*N. If
'color_mode' is IC_RGB, successive bytes of the data structure are
interpreted as RGB components of a single pixel. In this scenario
the size of 'image' is 3*M*N. The data appears in RGB triples, i.e.,
image[0] = R(1,1), image[1] = G(1,1), image[2] = B(1,1),
image[3] = R(1,2), image[4] = G(1,2), ..., image[3*M*N-1] = B(M,N).
The mode IC_RGBA is similar except that four values red, green, blue,
alpha per pixel are passed to the terminal in the image structure.
The 'image' is actually an "input" image in the sense that
it must also be properly resampled for the output device. Many output
media, e.g., PostScript, do this work via various driver functions.
To determine the appropriate rescaling, the 'corner' information
should be used. There are four entries in the gpiPoint data array.
'corner[0]' is the upper left corner (in terms of plot location) of
the outer edge of the image. Similarly, 'corner[1]' is the lower
right corner of the outer edge of the image. (Outer edge means the
outer extent of the corner pixels, not the middle of the corner
pixels.) 'corner[2]' is the upper left corner of the visible part
of the image, and 'corner[3]' is the lower right corner of the visible
part of the image. The information is provided in this way because
often it is necessary to clip a portion of the outer pixels of the
image.
There is a single entry point associated with support for boxed text.
This option is independent of enhanced text mode.
_boxed_text() - Called first with option==0 (TEXTBOX_INIT) to initiate
a new text box; subsequent calls to put_text() and/or internal enhanced text
routines including enhanced_flush() accumulate bounding-box limits for this box;
then boxed_text() is called again with option>0 to actually draw
the text box. The option parameter values are
TEXTBOX_INIT: initialize a new text box
TEXTBOX_OUTLINE: stroke the bounding box of the text box
TEXTBOX_BACKGROUNDFILL: fill the text box with background color
TEXTBOX_MARGINS: adjust whitespace around text to x,y percent of default
It is the responsibility of the term->put_text and term->enhanced_XXX routines
to update the text box if one is active.
_layer(t_termlayer syncpoint)
Driver-specific synchronization or other layering commands.
For example, the BEGIN_KEY_SAMPLE/END_KEY_SAMPLE sync points allow
a driver to respond differently to mouse-clicks on the key sample
than to mouse clicks elsewhere.
See term_api.h for defined synchronization points. Any driver that
implements term->layer() must silently ignore unrecognized syncpoints.
_path(int p)
PostScript-like devices make a distinction between the end of a
line segment that is internal to a polyline and one that has no
line-join to another segment. In order to treat the endpoints of
a closed polygon as "internal" line-joins, one must bracket the
polygon segments with "newpath ... closepath".
term->path(0) triggers a "newpath"
term->path(1) triggers a "closepath"
These calls are optional, and only required by a few drivers.
_hypertext(int type, const char *text)
Associates a text string with a subsequent graphics object.
The effect of this association is controlled by type.
Currently the only type supported is a tooltips-like text popup
triggered by mousing over the object. Possible future extensions
include treating the text as a URL activated by mouse click.
_modify_plots(unsigned int operations, int plotno) - used for interactive terminals.
Apply operations to a single plot or to every plot in the graph.
Bit definitions in the operations bitmask are given in term_api.h
and include SET_VISIBLE and SET_INVISIBLE.
_dashtype(int type, t_dashtype *custom_dash_pattern) - set dash/dot
pattern independently from linetype. The integer parameter,
if non-negative, may refer to the Nth dash/dot pattern pre-defined by
the specific terminal. The terminal must handle values larger than
the number pre-defined patterns (e.g. by wrapping around).
Negative values have special meaning, as defined in term_api.h.
The t_dashtype parameter can be used to set explicitly defined patterns.
Alternating numbers in the pattern field of this parameter specify
dash lengths and spaces between them, in units of the terminal's
dashlength.
The following should illustrate the order in which calls to these
routines are made:
_options()
_waitforinput() /* If present, may be called before init() */
_init()
_graphics()
_linewidth(lw)
_linetype(lt)
_dashtype(dt)
_path(0)
_move(x,y)
_vector(x,y)
_path(1)
_pointsize(size)
_point(x,y,point)
_text_angle(angle)
_justify_text(mode)
_set_font(font)
_put_text(x,y,text)
_enhanced_open(fontname,fontsize,base,width,show,overprint)
_enhanced_writec(char)
_enhanced_flush()
_arrow(sx,sy,ex,ey, head)
_image(M,N,image,corner,color_mode)
_text()
_graphics()
.
_suspend()
_set_pointsize()
_resume()
.
_text()
_reset()
------------------------------------
BITMAP DEVICES
A file bitmap.c is provided, implementing a generic set of bitmap
routines. It provides all the routines required to generate a
bitmap in memory, drawing lines and writing text. A simple driver
need provide only a text() entry point, which converts and outputs
the stored bitmap in the format required by the device.
As of version 4.5, inclusion of bitmap.c and the terminal drivers
that depend on it is controlled by ./configure --with-bitmap-terminals.
This may be desirable because the terminals it supports are mostly
obsolete.
Internally, the bitmap is built of one or more planes of 1
bit per pixel. In fact, I think the library would be easier to
use if it offered one or more planes of pixels with 1,2,4 or 8
bits per pixel, since not all bitmap devices are based on planes,
and the planes have to be recombined at the end at present.
In general, a device would use either planes or bits-per-pixel,
though I guess a 24-bit bitmap could use 3 planes of 8 bits
per pixel..?
The pixels are currently organised horizontally packed into bytes.
i.e.
********%%%%%%%%$$$$$$$$!!!!!!!! etc
^^^^^^^^@@@@@@@@########++++++++ etc
where like symbols are stored in one byte. Vertical packing can be
arranged by reversing x and y dimensions and setting the global
b_rastermode to TRUE. (e.g. Epson 8-pin dot-matrix printer)
Functions provided are
(internal functions ? - should probably be static, not external ?)
b_setpixel(x,y,value)
b_setmaskpixel(x,y,value)
b_putc(x,y,char,angle)
b_setvalue(size)
setting up stuff
b_makebitmap(x,y,planes) - make a bitmap of size x * y
b_freebitmap() - free bitmap
b_charsize(size)
gnuplot driver interface functions (can go straight into gnuplot structure)
b_setlinetype(linetype)
b_move(x,y)
b_vector(x,y)
b_put_text(x,y,*str)
b_text_angle(ang)
I think that the library could be made easier to use if we defined
a structure which described the bitmap (raster mode, planes, bits-per-pixel,
colours, etc) and then added to the gnuplot term struct a pointer to
this structure. Then we could have b_graphics() routine which did all
the initialisation that presently has to be done by the driver graphics()
entry point. Also, one day I would like to have parsing, including
terminal driver options, table-driven, but I'm getting ahead of myself
here.
------------------------------------
FILE LAYOUT
-----------
I think a file layout like the following will leave most flexibility
to the gnuplot maintainers. I use REGIS for example.
#include "driver.h"
#ifdef TERM_REGISTER
register_term(regis) /* no ; */
#endif
#ifdef TERM_PROTO
TERM_PUBLIC void REGISinit(void);
TERM_PUBLIC void REGISgraphics(void);
/* etc */
#define GOT_REGIS_PROTO
#endif
#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY
TERM_PUBLIC void REGISinit()
{
/* etc */
}
/* etc */
#endif
#ifdef TERM_TABLE
TERM_TABLE_START(regis_driver)
/* no { */
"regis", "REGIS graphics language",
REGISXMAX, /* etc */
/* no } */
TERM_TABLE_END(regis_driver)
#undef LAST_TERM
#define LAST_TERM regis_driver
#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */
#ifdef TERM_HELP
START_HELP(regis)
"1 regis",
"?set terminal regis",
"?regis",
" The `regis` terminal device generates output in the REGIS graphics language.",
" It has the option of using 4 (the default) or 16 colors.",
"",
" Syntax:",
" set term regis {4 | 16}"
END_HELP(regis)
#endif
--------------
The first three lines in the TERM_HELP section must contain the same
name as that specified by register_term, since this is the name that
will be entered into the list of available terminals. If more than
one name is registered, the additional names should have their own
two "?" lines, but not the "1" line.
Each record is enclosed in double-quotes and (except for the last
record) followed by a comma. The text is copied as a single string
into gnuplot.doc, so the syntax must obey the rules of that entity.
If the text includes double-quotes or backslashes, these must be
escaped by preceding each occurrence with a backslash.
--------------
Rationale:
We may want to compile all drivers into term.c or one driver at a time
this layout should support both
TERM_PUBLIC will be static if all modules are in term.c, or blank
otherwise.
Please make private support functions static if possible.
We may include term.h, and therefore all these files, one or more times.
If just once (all modules compiled into term.c) putting the four
parts in this order should make it work.
We may compile the table entries into either an array or a linked list.
This organisation should support both.
For separate compilation, we may write a program which
defines TERM_REGISTER and #include term.h to find out which drivers are
selected in term.h and thereby generate a makefile.
For a driver which depends on another (e.g. enhpost and pslatex on post)
the driver can do something like
#ifndef GOT_POST_PROTO
#define TERM_PROTO_ONLY
#include "post.trm"
#undef TERM_PROTO_ONLY
#endif
this is probably needed only in the TERM_TABLE section, but may
also be used in the body. The TERM_PROTO_ONLY means that we pick up
only the prototypes from post.trm, even if current driver is being compiled
with TERM_BODY or TERM_TABLE
If we do it the linked-list way, the argument to TERM_TABLE_START will be
the name of the variable, so any valid, unique name is fine.
The TERM_TABLE_START macro will do all the work of linking the entries
together, probably using LAST_TERM
The inclusion of the TERM_HELP section (and removal of terminal documentation
from the master gnuplot.doc file) means that the online help will include
discussions of only those terminals available to the user. For generation
of the printed manual, all can be included.
Please make as many things as possible static, but do still try to use unique
names since all drivers may be compiled into term.o
The bit in the PROTO section is basically what you would put into a .h
file if we had them - everything that is needed by the TABLE_ENTRY
should be defined in this part. In particular, don't forget all the maxes
and character sizes and things for the table entry.
Don't forget to put TERM_PUBLIC in the definitions of the functions as
well as the prototypes. It will probably always expand to 'static'
except for PCs.
|