Term-Gnuplot
view release on metacpan or search on metacpan
gnuterm/term/x11.trm view on Meta::CPAN
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/*
* x11.trm --- inboard terminal driver for X11
*/
/* Petr Mikulik and Johannes Zellner: added mouse support (October 1999)
* Implementation and functionality is based on pm.trm
*/
/* X11 support for Petr Mikulik's pm3d
* by Johannes Zellner <johannes@zellner.org>
* (November 1999 - January 2000)
*/
#include "driver.h"
#ifdef TERM_REGISTER
register_term(x11)
#endif
#ifdef TERM_PROTO
int X11_args __PROTO((int argc, char *argv[]));
TERM_PUBLIC void X11_options __PROTO((void));
TERM_PUBLIC void X11_init __PROTO((void));
TERM_PUBLIC void X11_graphics __PROTO((void));
TERM_PUBLIC void X11_text __PROTO((void));
TERM_PUBLIC int X11_set_font __PROTO((const char * fontname));
TERM_PUBLIC void X11_reset __PROTO((void));
TERM_PUBLIC void X11_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void X11_vector __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void X11_linewidth __PROTO((double lw));
TERM_PUBLIC void X11_pointsize __PROTO((double ps));
TERM_PUBLIC void X11_linetype __PROTO((int lt));
TERM_PUBLIC void X11_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
TERM_PUBLIC int X11_text_angle __PROTO((int i));
TERM_PUBLIC int X11_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC void X11_point __PROTO((unsigned int x, unsigned int y, int number));
TERM_PUBLIC void X11_fillbox __PROTO((int style, unsigned int x, unsigned y, unsigned int width, unsigned int height));
# ifdef USE_MOUSE
TERM_PUBLIC int X11_waitforinput __PROTO((void));
TERM_PUBLIC void X11_set_ruler __PROTO((int, int));
TERM_PUBLIC void X11_set_cursor __PROTO((int, int, int));
TERM_PUBLIC void X11_put_tmptext __PROTO((int, const char str[]));
TERM_PUBLIC void X11_set_clipboard __PROTO((const char[]));
TERM_PUBLIC void X11_update_opts __PROTO((void));
# endif
# ifdef PM3D
TERM_PUBLIC int X11_make_palette __PROTO((t_sm_palette *));
TERM_PUBLIC void X11_set_color __PROTO((double));
TERM_PUBLIC void X11_filled_polygon __PROTO((int, gpiPoint *));
/* these must match the definitions in gplt_x11.c */
# define X11_GR_MAKE_PALETTE 'p'
# define X11_GR_RELEASE_PALETTE 'e'
# define X11_GR_SET_COLOR 'c'
# define X11_GR_FILLED_POLYGON 'f'
# endif
# define X11_XMAX 4096
# define X11_YMAX 4096
/* approximations for typical font/screen sizes */
# define X11_VCHAR (X11_YMAX/25)
# define X11_HCHAR (X11_XMAX/100)
# define X11_VTIC (X11_YMAX/100)
# define X11_HTIC (X11_XMAX/150)
#endif /* TERM_PROTO */
#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY
#include <ctype.h>
#ifdef PM3D
# include "getcolor.h"
#endif
/* non-zero if '-display' found on command line */
static int X11_Display = 0;
static char X11_default_font[MAX_ID_LEN+1] = {'\0'};
static void X11_atexit __PROTO((void));
static void X11_set_default_font __PROTO((void));
/* Merged the old char X11_opts[] and int X11_optarg[]
* into one array of structs.
* Loosely based on XrmOptionDescRec, the use of which
* would probably be overkill here. */
typedef enum { hasNoArg, hasArg } OptionArg;
static struct x11opt {
const char *option; /* Name of option */
OptionArg arg; /* Whether option has argument */
} X11_cmdopts[] = {
{ "-mono", hasNoArg}, { "-gray", hasNoArg}, { "-clear", hasNoArg},
{ "-tvtwm", hasNoArg}, { "-pointsize", hasArg},
{ "-iconic", hasNoArg}, { "-rv", hasNoArg},
{ "-reverse", hasNoArg}, { "+rv", hasNoArg},
{ "-synchronous", hasNoArg},
{ "-display", hasArg}, { "-geometry", hasArg}, { "-bg", hasArg},
{ "-background", hasArg}, { "-bd", hasArg},
{ "-bordercolor", hasArg}, { "-bw", hasArg},
gnuterm/term/x11.trm view on Meta::CPAN
PRINT1("J%04d\n", mode);
return (TRUE);
}
TERM_PUBLIC void
X11_point(unsigned int x, unsigned int y, int number)
{
PRINT3("P%d %d %d\n", number, x, y);
}
TERM_PUBLIC int
X11_set_font(const char *fontname)
{
PRINT1("QF%s\n", fontname?fontname:"");
return( TRUE );
}
void
X11_set_default_font()
{
PRINT1("QD%s\n",X11_default_font);
}
TERM_PUBLIC void
X11_fillbox(int style, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
{
if (X11_ipc) {
PRINT5("F%04d%04u%04u%04u%04u\n", style, x, y, w, h);
}
}
#ifdef USE_MOUSE
TERM_PUBLIC void
X11_put_tmptext(int i, const char str[])
{
if (X11_ipc) {
PRINT2("t%04d%s\n", i, str);
FFLUSH();
}
}
TERM_PUBLIC void
X11_set_ruler(int x, int y)
{
if (X11_ipc) {
PRINT2("r%04d%04d\n", x, y);
FFLUSH();
}
}
TERM_PUBLIC void
X11_set_cursor(int c, int x, int y)
{
if (X11_ipc) {
PRINT3("u%04d%04d%04d\n", c, x, y);
FFLUSH();
}
}
TERM_PUBLIC void
X11_set_clipboard(const char s[])
{
if (X11_ipc) {
PRINT1("z%s\n", s);
FFLUSH();
}
}
#endif /* USE_MOUSE */
#ifdef PM3D
static void transmit_gradient( gradient_struct *gradient, int cnt )
{
int i = 0;
fprintf( X11_ipc, "%d", cnt );
for( i=0; i<cnt; i++ ) {
/* this %50 *must* match the corresponding %50 in gplt_x11.c */
if( i%50 == 0 ) {
fputs( "\n", X11_ipc );
fflush( X11_ipc );
}
fprintf( X11_ipc, "%s", gradient_entry_to_str( &(gradient[i]) ) );
}
fputs( "\n", X11_ipc );
}
TERM_PUBLIC int
X11_make_palette(t_sm_palette *palette)
{
if( !palette ) {
return 0;
}
if( !X11_ipc ) {
fprintf(stderr, "(X11_make_palette) 0 == X11_ipc\n");
return -1;
}
fprintf( X11_ipc, "%c %c %c %c %d\n",
X11_GR_MAKE_PALETTE, (char)(palette->colorMode),
(char)(palette->positive), (char)(palette->cmodel),
palette->use_maxcolors );
switch( palette->colorMode ) {
case SMPAL_COLOR_MODE_GRAY:
fprintf( X11_ipc,"%g\n", palette->gamma );
break;
case SMPAL_COLOR_MODE_RGB:
fprintf( X11_ipc, "%d %d %d\n", palette->formulaR,
palette->formulaG, palette->formulaB );
break;
case SMPAL_COLOR_MODE_GRADIENT:
transmit_gradient( palette->gradient, palette->gradient_num );
break;
case SMPAL_COLOR_MODE_FUNCTIONS: {
int cnt=0;
gradient_struct *gradient;
gradient = approximate_palette( palette, 500, 0.01, &cnt );
transmit_gradient( gradient, cnt );
break;
gnuterm/term/x11.trm view on Meta::CPAN
fprintf( stderr, "%s:%d ooops: Unknown colorMode '%c'.\n",
__FILE__, __LINE__, (char)(palette->colorMode) );
}
fflush( X11_ipc );
return 0;
}
TERM_PUBLIC void
X11_set_color(double gray)
{
fputc(X11_GR_SET_COLOR, X11_ipc);
PRINT1("%f\n", gray);
FFLUSH();
return;
}
TERM_PUBLIC void
X11_filled_polygon(int points, gpiPoint *corners)
{
int i;
fputc(X11_GR_FILLED_POLYGON, X11_ipc);
/* FIXME HBB 20010919: this %04d format somewhat arbitrarily
* limits us to 10000 vertices in the polygon */
PRINT1("%04d", points);
for (i = 0; i < points; i++) {
PRINT2("%04d%04d", corners[i].x, corners[i].y);
/* HBB 20010919: fix for buffer overflow problem: start
* another line every 100 points, to avoid overflowing
* fixed-size buffer in gplt_x11. Number of points == -1
* signals continuation line */
if ((i % 100) == 99) {
PRINT1("xxxx\n%c-001", X11_GR_FILLED_POLYGON);
FFLUSH();
}
}
fputc('\n', X11_ipc);
FFLUSH();
return;
}
#endif /* PM3D */
#endif /* TERM_BODY */
#ifdef TERM_TABLE
TERM_TABLE_START(x11_driver)
"x11", "X11 Window System",
X11_XMAX, X11_YMAX, X11_VCHAR, X11_HCHAR,
X11_VTIC, X11_HTIC, X11_options, X11_init, X11_reset,
X11_text, null_scale, X11_graphics, X11_move, X11_vector,
X11_linetype, X11_put_text, X11_text_angle,
X11_justify_text, X11_point, do_arrow, X11_set_font,
X11_pointsize, TERM_CAN_MULTIPLOT,
X11_text /* suspend can use same routine */ , 0 /* resume */ ,
X11_fillbox, X11_linewidth
#ifdef USE_MOUSE
, X11_waitforinput, X11_put_tmptext, X11_set_ruler, X11_set_cursor, X11_set_clipboard
#endif
#ifdef PM3D
, X11_make_palette, 0 /* X11_previous_palette */ ,
X11_set_color, X11_filled_polygon
#endif
TERM_TABLE_END(x11_driver)
#undef LAST_TERM
#define LAST_TERM x11_driver
TERM_TABLE_START(X11_driver)
"X11", "X11 Window System (identical to x11)",
X11_XMAX, X11_YMAX, X11_VCHAR, X11_HCHAR,
X11_VTIC, X11_HTIC, X11_options, X11_init, X11_reset,
X11_text, null_scale, X11_graphics, X11_move, X11_vector,
X11_linetype, X11_put_text, X11_text_angle,
X11_justify_text, X11_point, do_arrow, X11_set_font,
X11_pointsize, TERM_CAN_MULTIPLOT,
X11_text /* suspend can use same routine */ , 0 /* resume */ ,
X11_fillbox, X11_linewidth
#ifdef USE_MOUSE
, X11_waitforinput, X11_put_tmptext, X11_set_ruler, X11_set_cursor, X11_set_clipboard
#endif
#ifdef PM3D
, X11_make_palette, 0 /* X11_previous_palette */ ,
X11_set_color, X11_filled_polygon
#endif
TERM_TABLE_END(X11_driver)
#undef LAST_TERM
#define LAST_TERM x11_driver
#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */
#ifdef TERM_HELP
START_HELP(x11)
"1 x11",
"?commands set terminal x11",
"?set terminal x11",
"?set term x11",
"?terminal x11",
"?term x11",
"?x11",
"?X11",
" `gnuplot` provides the `x11` terminal type for use with X servers. This",
" terminal type is set automatically at startup if the `DISPLAY` environment",
" variable is set, if the `TERM` environment variable is set to `xterm`, or",
" if the `-display` command line option is used.",
"",
" Syntax:",
#ifdef USE_X11_DRIVER /* HBB 20020214: Disabled X11_DRIVER */
" set terminal x11 [reset] [<n>] [driver <path>] [[no]persist] [[no]raise]",
#else
" set terminal x11 [reset] [<n>] [[no]persist] [[no]raise] [font <fontspec>]",
#endif
"",
" Multiple plot windows are supported: `set terminal x11 <n>` directs the",
" output to plot window number n. If n>0, the terminal number will be",
" appended to the window title and the icon will be labeled `gplt <n>`.",
" The active window may distinguished by a change in cursor (from default",
" to crosshair.)",
"",
" X11 fonts:",
" A preferred default font may be specified to the x11 driver using",
" `set term x11 font \"<fontspec>\"`",
" The driver first queries the X-server for a font of the exact name given,",
" for example `set term x11 font \"lucidasans-10\"`. If this query fails, then",
" the driver tries to interpret <fontspec> as \"<font>,<size>,<slant>\" ",
" and to construct a full X11 font name of the form",
" -*-<font>-*-<s>-*-*-<size>-*-*-*-*-*-<encoding>",
" <font> is the base name of the font (e.g. Times or Symbol)",
" <size> is the point size (defaults to 12 if not specified)",
" <s> is `i` if <slant>==\"italic\" `o` if <slant>==\"oblique\" `r` otherwise",
" <encoding> is set based on the current character set (help set encoding)",
" So `set term x11 font \"arial,15,italic\"` will be translated to",
" -*-arial-*-i-*-*-15-*-*-*-*-*-iso8859-1 (assuming default encoding).",
" The driver also recognizes some common PostScript font names and",
" replaces them with possible X11 or TrueType equivalents.",
" This same sequence is used to process font requests from `set label`.",
"",
( run in 0.653 second using v1.01-cache-2.11-cpan-2398b32b56e )