shige 11/29 2004
----------------
| From: Ethan Merritt <merritt@...>
| To: Shigeharu TAKENO <shige@...>
| Subject: Re: tgif.trm patch for linewidth and monochrome mode
| Date: Sun, 28 Nov 2004 14:31:56 -0800
| Cc: gnuplot-beta@...
=====
| It looks OK.
|
| But I wonder if you want to also add a terminal option,
| as in the some other terminals (post pdf svg ...), that sets
| a constant multiplier for all line widths?
|
| set term tgif linewidth 2.0
Thank you for your suggestion. To accepts it I widely rewrite
TGIF_options() to some modern form. I send new unified diff file
of tgif.trm (rev. 1.28).
----- From here -----
--- term/tgif.trm.ORG Thu Oct 28 16:12:12 2004
+++ term/tgif.trm Mon Nov 29 19:59:42 2004
@@ -74,6 +74,9 @@
register_term(tgif)
#endif
+#define USE_LINEWIDTH
+#define USE_MONO_MODE
+
#ifdef TERM_PROTO
TERM_PUBLIC void TGIF_options __PROTO((void));
TERM_PUBLIC void TGIF_init __PROTO((void));
@@ -90,6 +93,9 @@
TERM_PUBLIC void TGIF_arrow __PROTO((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, int head));
TERM_PUBLIC int TGIF_set_font __PROTO((const char *font));
TERM_PUBLIC void TGIF_set_pointsize __PROTO((double size));
+#ifdef USE_LINEWIDTH
+TERM_PUBLIC void TGIF_set_linewidth __PROTO((double size));
+#endif
#ifdef PM3D
TERM_PUBLIC int TGIF_make_palette (t_sm_palette *);
/* TERM_PUBLIC void TGIF_previous_palette (void); */
@@ -147,7 +153,7 @@
static unsigned int uActNr; /* current elementnumber */
static unsigned int uActPage; /* current pagenumber */
-static unsigned int uActResolution; /* resolution in percent */
+static unsigned int uActResolution=100; /* resolution in percent */
static unsigned int uActZoom; /* zoom factor */
static unsigned int uActAngle; /* current textangle */
static unsigned int uActThick; /* actual linethickness */
@@ -157,16 +163,24 @@
static unsigned int uXshift; /* actual shift x */
static unsigned int uYshift; /* actual shift y */
static unsigned int uTgifPlotCount; /* counts number of plots */
-static unsigned int uTgifPlotRow, uTgifPlotCol; /* actual plot row and col */
-static unsigned int uTgif_win_horiz, /* number of plots in x and */ uTgif_win_verti; /* y direction [x,y] */
+static unsigned int uTgifPlotRow=1, uTgifPlotCol=1; /* actual plot row and col */
+static unsigned int uTgif_win_horiz=1, /* number of plots in x and */
+ uTgif_win_verti=1; /* y direction [x,y] */
+#ifdef USE_LINEWIDTH
+static double uActThick_factor=1.0;
+static double uActThick_default=1.0;
+#endif
+#ifdef USE_MONO_MODE
+static TBOOLEAN TgifUseColor = TRUE;
+#endif
static char sActColor[TGIF_STRLEN_MAX]; /* current color */
-static unsigned int uDefaultFontSize; /* default font size */
-static unsigned int uActFontSize; /* current font size */
-static char sDefaultFont[TGIF_STRLEN_MAX]; /* default font */
-static char sActFont[TGIF_STRLEN_MAX]; /* current font */
+static unsigned int uDefaultFontSize = 18; /* default font size */
+static unsigned int uActFontSize = 18; /* current font size */
+static char sDefaultFont[TGIF_STRLEN_MAX] = "Helvetica"; /* default font */
+static char sActFont[TGIF_STRLEN_MAX] = "Helvetica"; /* current font */
/* static char sActPointString[TGIF_STRLEN_MAX]; HBB: unused */
static TBOOLEAN TgifSolid = FALSE;
@@ -241,6 +255,35 @@
} /* TGIF_flush_poly */
/*}}} */
/***************************************************************************/
+
+enum TGIF_id {
+ TGIF_MONOCHROME, TGIF_COLOR,
+ TGIF_LINEWIDTH,
+ TGIF_PORTRAIT, TGIF_LANDSCAPE,
+ TGIF_GRAPHS,
+ TGIF_SOLID, TGIF_DASHED,
+ TGIF_FONT,
+ TGIF_OTHER,
+ TGIF_DEFAULT
+};
+
+static struct gen_table TGIF_opts[] =
+{
+ {"mo$nochrome", TGIF_MONOCHROME},
+ {"c$olor", TGIF_COLOR},
+ {"c$olour", TGIF_COLOR},
+ {"linew$idth", TGIF_LINEWIDTH},
+ {"lw", TGIF_LINEWIDTH},
+ {"p$ortrait", TGIF_PORTRAIT},
+ {"l$andscape", TGIF_LANDSCAPE},
+ {"[", TGIF_GRAPHS},
+ {"s$olid", TGIF_SOLID},
+ {"d$ashed", TGIF_DASHED},
+ {"font", TGIF_FONT},
+ {"default", TGIF_DEFAULT},
+ {NULL, TGIF_OTHER}
+};
+
TERM_PUBLIC void
TGIF_options()
{
@@ -248,39 +291,67 @@
struct value a, b;
double dscaleH, dscaleV;
+ while (!END_OF_COMMAND) {
+ switch(lookup_table(&TGIF_opts[0],c_token)) {
+ case TGIF_DEFAULT:
+ strcpy(sActFont, "Helvetica");
+ strcpy(sDefaultFont, "Helvetica");
+ uActFontSize = 18;
+ uDefaultFontSize = 18;
+ term->v_char = (unsigned int) (uActFontSize);
+ term->h_char = (unsigned int) (uActFontSize * 6 / 10);
- strcpy(sActFont, "Helvetica");
- strcpy(sDefaultFont, "Helvetica");
- uActFontSize = 18;
- uDefaultFontSize = 18;
- term->v_char = (unsigned int) (uActFontSize);
- term->h_char = (unsigned int) (uActFontSize * 6 / 10);
-
- TgifPortrait = TRUE;
- uTgifPlotsPerPage = 1;
- uTgifPlotRow = 1;
- uTgifPlotCol = 1;
- uTgif_win_horiz = 1;
- uTgif_win_verti = 1;
- uActResolution = 100;
-
-
-/*}}} */
-
- if (!END_OF_COMMAND) {
- if (almost_equals(c_token, "p$ortrait")) {
TgifPortrait = TRUE;
+#ifdef USE_MONO_MODE
+ TgifUseColor = TRUE;
+#endif
+ TgifSolid = FALSE;
+ uTgifPlotsPerPage = 1;
+ uTgifPlotRow = 1;
+ uTgifPlotCol = 1;
+ uTgif_win_horiz = 1;
+ uTgif_win_verti = 1;
+ uActResolution = 100;
+#ifdef USE_LINEWIDTH
+ uActThick_factor = 1.0;
+ uActThick_default = 1.0;
+#endif
+ c_token++;
+ break;
+#ifdef USE_MONO_MODE
+ case TGIF_MONOCHROME:
+ TgifUseColor = FALSE;
+ c_token++;
+ break;
+ case TGIF_COLOR:
+ TgifUseColor = TRUE;
c_token++;
- } else if (almost_equals(c_token, "l$andscape")) {
+ break;
+#endif
+#ifdef USE_LINEWIDTH
+ case TGIF_LINEWIDTH:
+ c_token++;
+ if (END_OF_COMMAND) {
+ int_error(c_token, "linewidth: width is not specified.");
+ } else {
+ if((uActThick_default = real(const_express(&a)))<=0.0){
+ int_error(c_token-1,"linewidth: out of range");
+ uActThick_default = 1.0;
+ }
+ }
+ break;
+#endif
+ case TGIF_PORTRAIT:
+ TgifPortrait = TRUE;
+ c_token++;
+ break;
+ case TGIF_LANDSCAPE:
TgifPortrait = FALSE;
- uActResolution = 140;
+ /* uActResolution = 140;
+ */
c_token++;
- }
- }
-/*}}} */
-
- if (!END_OF_COMMAND) {
- if (equals(c_token, "[")) { /* windows specified */
+ break;
+ case TGIF_GRAPHS:
c_token++;
if (END_OF_COMMAND) {
int_error(c_token, "no. windows: [horizontal,vertical] expected");
@@ -296,39 +367,33 @@
if (!equals(c_token, "]"))
int_error(c_token, "expecting ']'");
c_token++;
-
uTgifPlotsPerPage = uTgif_win_verti * uTgif_win_horiz;
-
-
- }
- }
-/*}}} */
-
- if (!END_OF_COMMAND) {
- if (almost_equals(c_token, "s$olid")) {
+ break;
+ case TGIF_SOLID:
TgifSolid = TRUE;
c_token++;
- } else if (almost_equals(c_token, "d$ashed")) {
+ break;
+ case TGIF_DASHED:
TgifSolid = FALSE;
c_token++;
+ break;
+ case TGIF_FONT:
+ case TGIF_OTHER:
+ default:
+ if (isstring(c_token)) {
+ quote_str(sActFont, c_token, MAX_LINE_LEN);
+ strcpy(sDefaultFont, sActFont);
+ c_token++;
+ } else {
+ /* We have font size specified */
+ uActFontSize = (unsigned int) real(const_express(&b));
+ uDefaultFontSize = uActFontSize;
+ term->v_char = (unsigned int) (uActFontSize);
+ term->h_char = (unsigned int) (uActFontSize * 6 / 10);
+ }
+ break;
}
}
-/*}}} */
-
- if (!END_OF_COMMAND && isstring(c_token)) {
- quote_str(sActFont, c_token, MAX_LINE_LEN);
- strcpy(sDefaultFont, sActFont);
- c_token++;
- }
- if (!END_OF_COMMAND) {
- /* We have font size specified */
- uActFontSize = (unsigned int) real(const_express(&b));
- uDefaultFontSize = uActFontSize;
- term->v_char = (unsigned int) (uActFontSize);
- term->h_char = (unsigned int) (uActFontSize * 6 / 10);
- }
-/*}}} */
-
if (TgifPortrait) {
dscaleH = (double) 100.0 *(TGIF_XTOT) / (xsize * (TGIF_XMAX + (uTgif_win_horiz - 1) * TGIF_XSHIFT));
dscaleV = (double) 100.0 *(TGIF_YTOT) / (ysize * (TGIF_YMAX + (uTgif_win_verti - 1) * TGIF_YSHIFT));
@@ -366,11 +431,22 @@
}
}
-/*}}} */
-
- sprintf(term_options, "%s [%u,%u] %s \"%s\" %u",
+ sprintf(term_options, "%s%s%s [%u,%u]",
+ term_options, term_options[0]!='\0' ? " ":"",
TgifPortrait ? "portrait" : "landscape",
- uTgif_win_horiz, uTgif_win_verti,
+ uTgif_win_horiz, uTgif_win_verti);
+#ifdef USE_MONO_MODE
+ sprintf(term_options, "%s%s%s",
+ term_options, term_options[0]!='\0' ? " ":"",
+ TgifUseColor ? "color" : "monochrome");
+#endif
+#ifdef USE_LINEWIDTH
+ sprintf(term_options, "%s%s%s %f",
+ term_options, term_options[0]!='\0' ? " ":"",
+ "linewidth",uActThick_default);
+#endif
+ sprintf(term_options, "%s%s%s \"%s\" %u",
+ term_options, term_options[0]!='\0' ? " ":"",
TgifSolid ? "solid" : "dashed",
sActFont, uActFontSize);
}
@@ -461,8 +537,12 @@
uActThick = 1;
uActStyle = 0;
uActJust = LEFT;
+#ifndef USE_MONO_MODE
strcpy(sActColor, psColors[0]);
-
+#else
+ if(TgifUseColor == FALSE) strcpy(sActColor,"black");
+ else strcpy(sActColor, psColors[0]);
+#endif
} /* TGIF_graphics */
/*}}} */
@@ -507,8 +587,17 @@
else
ult = linetype + 2;
+#ifndef USE_MONO_MODE
strcpy(sActColor, psColors[ult]);
+#else
+ if(TgifUseColor == FALSE) strcpy(sActColor,"black");
+ else strcpy(sActColor, psColors[ult]);
+#endif
+#ifndef USE_LINEWIDTH
uActThick = uLineThick[ult];
+#else
+ uActThick = uActThick_factor * uActThick_default * uLineThick[ult]+0.5;
+#endif
if (!TgifSolid)
uActStyle = uLineStyle[ult];
else {
@@ -1481,6 +1570,14 @@
uActPointSize = size < 0. ? 1. : size;
}
+#ifdef USE_LINEWIDTH
+TERM_PUBLIC void
+TGIF_set_linewidth(double size)
+{
+ uActThick_factor = size < 0. ? 1. : size;
+}
+#endif
+
/*}}} */
/***************************************************************************/
TERM_PUBLIC int
@@ -1509,6 +1606,21 @@
TGIF_flush_poly(); /* Clean up current data */
if (TGIF_palette_set == FALSE) {
+#ifdef USE_MONO_MODE
+ if (TgifUseColor == FALSE
+ || sm_palette.colorMode == SMPAL_COLOR_MODE_GRAY) {
+ /* Gray palette */
+ if (TgifUseColor == FALSE
+ && sm_palette.colorMode == SMPAL_COLOR_MODE_RGB){
+ fprintf(stderr, "Monochrome Tgif file: ");
+ fprintf(stderr, "using gray palette instead of color\n");
+ }
+ for (i = 0; i < sm_palette.colors; i++) {
+ int j = (int)(i * 255.0 / (sm_palette.colors-1) + 0.5);
+ sprintf(TGIF_colours[i],"#%.2x%.2x%.2x",j,j,j);
+ }
+ } else {
+#endif
/* Create new palette */
for (i = 0; i < sm_palette.colors; i++) {
sprintf(TGIF_colours[i],"#%.2x%.2x%.2x",
@@ -1516,6 +1628,9 @@
(int)( palette->color[i].g * 255 + 0.5 ),
(int)( palette->color[i].b * 255 + 0.5 ) );
}
+#ifdef USE_MONO_MODE
+ }
+#endif
TGIF_palette_set = TRUE;
} else {
fprintf(stderr, "Attempt to set palette twice\n");
@@ -1578,7 +1693,11 @@
TGIF_text, null_scale, TGIF_graphics, TGIF_move, TGIF_vector,
TGIF_linetype, TGIF_put_text, TGIF_text_angle,
TGIF_justify_text, TGIF_point, TGIF_arrow, TGIF_set_font,
+#ifndef USE_LINEWIDTH
TGIF_set_pointsize, TERM_CAN_MULTIPLOT, 0, 0, 0, 0
+#else
+ TGIF_set_pointsize, TERM_CAN_MULTIPLOT, 0, 0, 0, TGIF_set_linewidth
+#endif
#ifdef USE_MOUSE
,0, 0, 0, 0, 0 /* no mouse support for the tgif terminal */
#endif
@@ -1611,14 +1730,18 @@
" axes are not changed.",
"",
" Syntax:",
-" set terminal tgif {portrait | landscape} {<[x,y]>}",
+" set terminal tgif {portrait | landscape | default} {<[x,y]>}",
+" {monochrome | color}",
+" {{linewidth | lw} <LW>}",
" {solid | dashed}",
" {\"<fontname>\"} {<fontsize>}",
"",
" where <[x,y]> specifies the number of graphs in the x and y directions on the",
-" page, \"<fontname>\" is the name of a valid PostScript font, and <fontsize>",
-" specifies the size of the PostScript font. Defaults are `portrait`, `[1,1]`,",
-" `dashed`, `\"Helvetica\"`, and `18`.",
+" page, `color` enables color, `linewidth` scales all linewidths by <LW>,",
+" \"<fontname>\" is the name of a valid PostScript font, and <fontsize>",
+" specifies the size of the PostScript font.",
+" `defaults` sets all options to their defaults: `portrait`, `[1,1]`, `color`,",
+" `linwidth 1.0`, `dashed`, `\"Helvetica\"`, and `18`.",
"",
" The `solid` option is usually prefered if lines are colored, as they often",
" are in the editor. Hardcopy will be black-and-white, so `dashed` should be",
----- To here -----
+========================================================+
Shigeharu TAKENO NIigata Institute of Technology
kashiwazaki,Niigata 945-1195 JAPAN
shige@... TEL(&FAX): +81-257-22-8161
+========================================================+
|