/* Hello, Emacs, this is -*-C-*- */
/* $Id: tgif.trm,v 1.55 2014/01/30 05:50:53 sfeam Exp $ */

/* GNUPLOT - tgif.trm */

/*[
 * Copyright 1990 - 1993, 1998, 2004
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the complete modified source code.  Modifications are to
 * be distributed as patches to the released version.  Permission to
 * distribute binaries produced by compiling modified sources is granted,
 * provided you
 *   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.
]*/

/*                                       */
/* This file is included by ../term.c.                                     */
/*                                                                         */
/* This terminal driver supports:                                          */
/*     TGIF                                                                */
/*                                                                         */
/* AUTHORS:                                                                */
/*  Werner Geppert and Andreas Kuhlewind                                   */
/*  March, 21st 1995                                                       */
/*                                                                         */
/* send your comments or suggestions to werner@mez.ruhr-uni-bochum.de      */
/*                                                                         */
/*                                                                         */
/* MODIFIED May, 11st 1997 by NOVÁK Levente (novakl@tigris.klte.hu):       */
/*                                                                         */
/*          - Modified the default linewidth for borders from 3 to 2       */
/*          - Modified the default size of markers' bounding box           */
/*            to allow nicer shapes                                        */
/*          - Slightly modified the markers and added several new ones,    */
/*            now we have 64 different pointtypes, the same as for the     */
/*            PostScript terminal                                          */
/*          - I left the %.1f format for pixel positions, but I think      */
/*            Tgif does only calculate with integer positions              */
/*                                                                         */
/* Modified  07 July 2000 by Ian MacPhedran                                */
/*          - added PM3D support                                           */
/*                                                                         */
/* Modified  04 February 2002 by Levente Novák                             */
/*          - break long "polygon()" directives into lines, as it made     */
/*            Tgif fail polygons had >8 sides                              */
/*            (e.g. when using "filledcurves")                             */
/*                                                                         */
/* Modified  29 November 2004  Shigeharu TAKENO <shige@iee.niit.ac.jp>     */
/*          - add linewidth and monochrome options                         */
/*            update option parsing to be order-independent                */
/*                                                                         */
/***************************************************************************/

/*}}}  */
/***************************************************************************/
#include "driver.h"

#ifdef TERM_REGISTER
register_term(tgif)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void TGIF_options __PROTO((void));
TERM_PUBLIC void TGIF_init __PROTO((void));
TERM_PUBLIC void TGIF_reset __PROTO((void));
TERM_PUBLIC void TGIF_text __PROTO((void));
TERM_PUBLIC void TGIF_graphics __PROTO((void));
TERM_PUBLIC void TGIF_move __PROTO((unsigned int ux, unsigned int uy));
TERM_PUBLIC void TGIF_vector __PROTO((unsigned int ux, unsigned int uy));
TERM_PUBLIC void TGIF_linetype __PROTO((int linetype));
TERM_PUBLIC void TGIF_put_text __PROTO((unsigned int ux, unsigned int uy, const char *str));	/* ref point and text */
TERM_PUBLIC int TGIF_text_angle __PROTO((int ang));
TERM_PUBLIC int TGIF_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC void TGIF_point __PROTO((unsigned int ux, unsigned int uy, int number));
TERM_PUBLIC int TGIF_set_font __PROTO((const char *font));
TERM_PUBLIC void TGIF_set_pointsize __PROTO((double size));
TERM_PUBLIC void TGIF_set_linewidth __PROTO((double size));
TERM_PUBLIC int TGIF_make_palette (t_sm_palette *);
TERM_PUBLIC void TGIF_previous_palette (void);
TERM_PUBLIC void TGIF_set_color (t_colorspec *);
TERM_PUBLIC void TGIF_fillbox(int style, unsigned int x1, unsigned int y1, 
			      unsigned int width, unsigned int height);
TERM_PUBLIC void TGIF_FillSolid(char *curcolor,int fillpar);
TERM_PUBLIC void TGIF_filled_polygon (int, gpiPoint *);
/*}}}  */
/* default length for static strings */
#define TGIF_STRLEN_MAX 255

/* standard x/y plot size in portrait mode */
#define TGIF_XMAX 950
#define TGIF_YMAX 634

/* total available plotting area */
#define TGIF_XTOT 950
#define TGIF_YTOT 1400

/* Offset  */
#define TGIF_XOFF 50
#define TGIF_YOFF 50

#define TGIF_XSHIFT 1030	/* 80 points skip */
#define TGIF_YSHIFT 714

#define TGIF_VCHAR 18		/* default is 18 pt       */
#define TGIF_HCHAR (18*6/10)

#define TGIF_VTIC (TGIF_YMAX/80)
#define TGIF_HTIC (TGIF_YMAX/80)

#define TGIF_MAXPOLY 100
/*}}}  */
#define GOT_TGIF_PROTO
#endif

#ifndef TERM_PROTO_ONLY

#ifdef TERM_BODY
/* tgif driver by Werner Geppert, werner@mez.ruhr-uni-bochum.de */
/***************************************************************************/
/* Variables:                                                              */
static unsigned int uLastTgifX, uLastTgifY;	/* last Coordinate         */

static unsigned int uActNr;	/* current elementnumber                   */
static unsigned int uActPage;	/* current pagenumber                      */
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                    */
static double uActPointSize = 1;	/* point size                      */
static unsigned int uActStyle;	/* actual linestyle                        */
static unsigned int uActJust;	/* actual textjustification                */
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=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]         */

static double dActThick_factor=1.0;  /* linewidth factor */
static double dActThick_default=1.0; /* default linewidth factor */
static TBOOLEAN TgifUseColor = TRUE;

static char sActColor[TGIF_STRLEN_MAX];		/* current color         */
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;
static TBOOLEAN TgifPortrait = TRUE;

static unsigned int uTgifPlotsPerPage = 1;

/*
 * 10 different pointtypes need 10 different linetypes
 */

/* NL: Modified first value to 2 from 3 */
static unsigned int uLineThick[] = { 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
static unsigned int uLineStyle[] = { 0, 5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0 };
static const char *psColors[] = {
    "black", "black",		/* border and x/y-zero-axes       */
    "red", "green", "blue", "magenta", "cyan", "yellow",
    "DarkSeaGreen", "HotPink", "black", "coral"
};
/* for color density */
static const rgb255_color psColorcomp[] = {
    {0,0,0}, {0,0,0},
    {255,0,0}, {0,255,0}, {0,0,255}, {255,0,255}, {0,255,255}, {255,255,0},
    {143,188,143}, {255,105,180}, {0,0,0}, {255,127,80}
};
static rgb255_color rgbActColor;

static unsigned int uFillPattern[] = { 2, 3, 5, 1, 20, 26, 21, 27, 14, 15 };
#define TGIF_fillpatterns 10

static int iTgifPolyCount;
static unsigned int uBuffX[TGIF_MAXPOLY], uBuffY[TGIF_MAXPOLY];

enum eState {
    NEWPOLY = 100, INPOLY
};
static enum eState eTgifState = NEWPOLY;

static void TGIF_flush_poly __PROTO((void));



/*}}}  */
/***************************************************************************/
static void
TGIF_flush_poly()
{
    int i;


    if (eTgifState == INPOLY) {
	fprintf(gpoutfile, "poly('%s',%d,[\n\t", sActColor, iTgifPolyCount);

	for (i = 0; i < iTgifPolyCount - 1; i++) {
	    fprintf(gpoutfile, "%u,%u,", uBuffX[i], uBuffY[i]);
	    if ((i + 1) % 8 == 0)
		fputs("\n\t", gpoutfile);
	}

	fprintf(gpoutfile, "%u,%u],0,%u,1,%u,0,0,%u,0,8,3,0,[\n]).\n",
		uBuffX[iTgifPolyCount - 1], uBuffY[iTgifPolyCount - 1],
		uActThick, uActNr, uActStyle);

	uActNr++;

	eTgifState = NEWPOLY;
	iTgifPolyCount = 0;
	if (gpoutfile != (FILE *) NULL)
	    fflush(gpoutfile);
    }
}				/* 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()
{

    struct value a, b;
    double dscaleH, dscaleV;
    int option;

    while (!END_OF_COMMAND) {
	option = lookup_table(&TGIF_opts[0],c_token);
	switch(option) {
	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);

	    TgifPortrait = TRUE;
	    TgifUseColor = TRUE;
	    term->flags &= ~TERM_MONOCHROME;
	    TgifSolid = FALSE;
	    uTgifPlotsPerPage = 1;
	    uTgifPlotRow = 1;
	    uTgifPlotCol = 1;
	    uTgif_win_horiz = 1;
	    uTgif_win_verti = 1;
	    uActResolution = 100;
	    dActThick_factor = 1.0;
	    dActThick_default = 1.0;
	    c_token++;
	    break;
	case TGIF_MONOCHROME:
	    TgifUseColor = FALSE;
	    term->flags |= TERM_MONOCHROME;
	    c_token++;
	    break;
	case TGIF_COLOR:
	    TgifUseColor = TRUE;
	    term->flags &= ~TERM_MONOCHROME;
	    c_token++;
	    break;
	case TGIF_LINEWIDTH:
	    c_token++;
	    if (END_OF_COMMAND) {
		int_error(c_token, "linewidth: width is not specified.");
	    } else {
		if((dActThick_default = real(const_express(&a)))<=0.0){
		    int_error(c_token-1,"linewidth: out of range");
		    dActThick_default = 1.0;
		}
	    }
	    break;
	case TGIF_PORTRAIT:
	    TgifPortrait = TRUE;
	    c_token++;
	    break;
	case TGIF_LANDSCAPE:
	    TgifPortrait = FALSE;
	    /* uActResolution = 140;
	    */
	    c_token++;
	    break;
	case TGIF_GRAPHS:
	    c_token++;
	    if (END_OF_COMMAND) {
		int_error(c_token, "no. windows: [horizontal,vertical] expected");
	    } else if (!equals(c_token, ",")) {
		uTgif_win_horiz = (int) real(const_express(&a));
	    }
	    if (!equals(c_token, ","))
		int_error(c_token, "',' expected");
	    c_token++;
	    if (!equals(c_token, "]")) {
		uTgif_win_verti = (int) real(const_express(&a));
	    }
	    if (!equals(c_token, "]"))
		int_error(c_token, "expecting ']'");
	    c_token++;
	    uTgifPlotsPerPage = uTgif_win_verti * uTgif_win_horiz;
	    break;
	case TGIF_SOLID:
	    TgifSolid = TRUE;
	    c_token++;
	    break;
	case TGIF_DASHED:
	    TgifSolid = FALSE;
	    c_token++;
	    break;
	case TGIF_FONT:
	    c_token++;
	    /* Fall through */
	case TGIF_OTHER:
	default:
	{
	    char *s;
	    if ((s = try_to_get_string())) {
		double fontsize;
		int sep = strcspn(s,",");
		if (s[sep] == ',' && (1 == sscanf(&s[sep+1],"%lf",&fontsize)))
		    uActFontSize =  (int)(fontsize+0.5);
		if (sep > 0) {
		    strncpy(sActFont, s, sizeof(sActFont));
		    sActFont[sep] = NUL;
		}
		strcpy(sDefaultFont, sActFont);
		free(s);
	    } else if (option == TGIF_FONT) {
		int_error(c_token,"Expecting font name ");
	    } 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 (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));
	uActResolution = (int) GPMIN(dscaleH, dscaleV);
	switch (uTgif_win_verti) {
	case 1:
	    uActZoom = 0;
	    break;

	case 2:
	    uActZoom = 1;
	    break;
	default:
	    uActZoom = 2;
	    break;

	}
    } else {
	dscaleH = (double) 100.0 *(TGIF_YTOT) / (xsize * (TGIF_XMAX + (uTgif_win_horiz - 1) * TGIF_XSHIFT));
	dscaleV = (double) 100.0 *(TGIF_XTOT) / (ysize * (TGIF_YMAX + (uTgif_win_verti - 1) * TGIF_YSHIFT));
	uActResolution = (unsigned int) GPMIN(dscaleH, dscaleV);

	switch (uTgif_win_verti) {
	case 1:
	    uActZoom = 0;
	    break;

	case 2:
	    uActZoom = 1;
	    break;
	default:
	    uActZoom = 2;
	    break;

	}
    }

    sprintf(&(term_options[strlen(term_options)]), "%s [%u,%u]",
	    TgifPortrait ? "portrait" : "landscape",
	    uTgif_win_horiz, uTgif_win_verti);

    strcat(term_options, TgifUseColor ? " color" : " monochrome");
    sprintf(&(term_options[strlen(term_options)]), " linewidth %f", 
	    dActThick_default);
    sprintf(&(term_options[strlen(term_options)]), " %s font \"%s,%u\"",
	    TgifSolid ? "solid" : "dashed",
	    sActFont, uActFontSize);
}
/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_init()
{

    if (multiplot) {
	/* uActResolution= TgifPortrait ? (unsigned int)100 : (unsigned int)145 ; */
	uActResolution = (unsigned int) 100;

	if (uTgifPlotsPerPage > 1) {
	    fputs("warning: using standard multiplot\n", stderr);
	    uTgifPlotsPerPage = 1;
	}
	uActZoom = 1;
    }
    fprintf(gpoutfile, "\
%%TGIF 2.15-p7\n\
state(%d,30,%u,0,0,%u,16,1,9,1,1,0,0,0,0,1,0,'%s',0,%u,0,0,1,10,0,0,1,1,0,16,0,0,1,1,1).\n\
%%\n\
%% @(#)Creator: gnuplot %s patchlevel %s\n\
%% %%W%%\n\
%%\n\
page(1,\"\").\n",
	    TgifPortrait ? 0 : 1, uActResolution, uActZoom, sActFont, uActFontSize,
	    gnuplot_version, gnuplot_patchlevel);
    eTgifState = NEWPOLY;
    iTgifPolyCount = 0;
    uTgifPlotCount = 0;
    uActPage = 1;
}				/* TGIF_init */
/*}}}  */

/***************************************************************************/
TERM_PUBLIC void
TGIF_graphics()
{

    TGIF_flush_poly();

    if (multiplot) {

	term->xmax = (TgifPortrait) ? TGIF_XTOT : TGIF_YTOT;
	term->ymax = (TgifPortrait) ? TGIF_YTOT : TGIF_XTOT;
	uLastTgifX = (TgifPortrait) ? TGIF_XOFF : TGIF_YOFF;
	uLastTgifY = (TgifPortrait) ? TGIF_YTOT + TGIF_YOFF : TGIF_XTOT + TGIF_XOFF;

	uYshift = uLastTgifY;
	uXshift = uLastTgifX;

    } else {
	if (uTgifPlotCount < uTgifPlotsPerPage)
	    uTgifPlotCount++;
	else {
	    fputs("error: number of plots > plots per page\n", stderr);
	    return;
	}

	uXshift = (unsigned int) TGIF_XOFF *100 / uActResolution + (xsize * (uTgifPlotCol - 1) * TGIF_XSHIFT);
	uYshift = (unsigned int) TGIF_YOFF *100 / uActResolution + (ysize * (TGIF_YMAX +
									     (uTgifPlotRow - 1) * TGIF_YSHIFT));

	if (uTgifPlotCount % uTgif_win_horiz == 0) {
	    uTgifPlotCol = 1;
	    uTgifPlotRow++;
	} else {
	    uTgifPlotCol++;
	}

	uLastTgifX = uXshift;
	uLastTgifY = uYshift;

    }





/* default settings for each plot */
    iTgifPolyCount = 0;
    uActNr = 0;
    uActAngle = 0;
    uActThick = 1;
    uActStyle = 0;
    uActJust = LEFT;
    strcpy(sActColor,psColors[0]); /* black */
    rgbActColor = psColorcomp[0];

}				/* TGIF_graphics */
/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_text()
{
    TGIF_flush_poly();


}				/* TGIF_text */

/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_reset()
{
    TGIF_flush_poly();
    iTgifPolyCount = 0;
    uTgifPlotCount = 0;
    uTgifPlotRow = 1;
    uTgifPlotCol = 1;


    if (gpoutfile != (FILE *) NULL)
	fflush(gpoutfile);

}				/* TGIF_reset */
/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_linetype(int linetype)
{
    unsigned int ult;


    TGIF_flush_poly();


    if (linetype >= 0)
	ult = 2 + linetype % 10;
    else if (linetype < -2)
	ult = 0;
    else
	ult = linetype + 2;

    if (TgifUseColor == FALSE) {
	strcpy(sActColor,"black");
	rgbActColor = psColorcomp[0];
    }
    else{
	strcpy(sActColor, psColors[ult]);
	rgbActColor = psColorcomp[ult];
    }
    uActThick = dActThick_factor * dActThick_default * uLineThick[ult]+0.5;
    if (!TgifSolid)
	uActStyle = uLineStyle[ult];
    else {
	if (ult == 1)		/* grid */
	    uActStyle = uLineStyle[ult];
	else
	    uActStyle = uLineStyle[2];

    }

}				/* TGIF_linetype */
/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_move(unsigned int ux, unsigned int uy)
{

    uLastTgifX = ux + uXshift;
    uLastTgifY = uYshift - uy;

    if (eTgifState == INPOLY)
	TGIF_flush_poly();



}				/* TGIF_move */
/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_vector(unsigned int ux, unsigned int uy)
{

    ux = ux + uXshift;
    uy = uYshift - uy;



    if (eTgifState == NEWPOLY) {
	uBuffX[0] = uLastTgifX;
	uBuffY[0] = uLastTgifY;
	iTgifPolyCount = 1;
	eTgifState = INPOLY;
    }
    uBuffX[iTgifPolyCount] = ux;
    uBuffY[iTgifPolyCount] = uy;
    uLastTgifX = ux;
    uLastTgifY = uy;
    iTgifPolyCount++;
    eTgifState = INPOLY;

    if (iTgifPolyCount == TGIF_MAXPOLY) {
	TGIF_flush_poly();

    }
}				/* TGIF_vector */
/*}}}  */
#if (0) /* Not used any more */
/***************************************************************************/
TERM_PUBLIC void
TGIF_arrow(
    unsigned int sx, unsigned int sy,
    unsigned int ex, unsigned int ey,
    int head)
{

    TGIF_flush_poly();

    sx = sx + uXshift;
    ex = ex + uXshift;
    sy = uYshift - sy;
    ey = uYshift - ey;


    if (head) {
	fprintf(gpoutfile, "\
poly('%s',%d,[\n\
\t%u,%u,%u,%u],1,%u,1,%u,0,0,%u,0,8,3,0,[\n]).\n",
		sActColor, 2, sx, sy, ex, ey, uActThick, uActNr, uActStyle);
    } else {
	fprintf(gpoutfile, "\
poly('%s',%d,[\n\
\t%u,%u,%u,%u],1,%u,1,%u,0,0,%u,0,8,3,0,[\n]).\n",
		sActColor, 2, sx, sy, ex, ey, uActThick, uActNr, uActStyle);
    }

    uActNr++;



    uLastTgifX = ex;
    uLastTgifY = ey;

}				/* TGIF_arrow */
#endif

/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_put_text(unsigned int ux, unsigned int uy, const char *str)
{

    unsigned int x, y;
    struct termentry *t = term;

    TGIF_flush_poly();

    x = ux + uXshift;
    y = uYshift - uy - t->v_char / 2;

    if (strlen(str) == 0)
	return;

    fprintf(gpoutfile, "\
text('%s',%u,%u,'%s',0,%u,1,%u,%u,1,55,119,%u,0,15,4,0,0,0,0,[\n\t\"%s\"]).\n",
	    sActColor, x, y, sActFont, uActFontSize,
	    (uActAngle ? CENTRE : uActJust), uActAngle,
	    uActNr, str);

    uActNr += 2;


}				/* TGIF_put_text */
/*}}}  */
/***************************************************************************/
TERM_PUBLIC int
TGIF_text_angle(int ang)
{
    switch (ang) {
	case -270:
	case   90:	uActAngle = 3; break;
	case  180:
	case -180:	uActAngle = 2; break;
	case  -90:
	case  270:	uActAngle = 1; break;
	default:	uActAngle = 0; break;
    }
    return (TRUE);
}				/* TGIF_text_angle */

/*}}}  */
/***************************************************************************/
TERM_PUBLIC int
TGIF_justify_text(enum JUSTIFY mode)
{
    uActJust = mode;
    return (TRUE);
}				/* TGIF_justify_text */

/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_point(unsigned int ux, unsigned int uy, int number)
{
    double p;		/* all pointtypes fit in a (x +/-p)x(y +/-p) box */

    double x, y;



    x = (double) (ux + uXshift);
    y = (double) (uYshift - uy);

    p = 4.0 * uActPointSize;
    if (p == (double) 0.0)
	p = 0.1;

    TGIF_flush_poly();

    if (number != -1)
	number = number % 63;
    switch (number) {
    case -1:
	/* HBB: corrected format string, shuts up gcc -Wall */
	fprintf(gpoutfile, "\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,1,1,%u,0,0,0,0,8,3,0,[\n]).\n",
		sActColor, x, y, x + 1, y + 1, uActNr++);
	break;
    case 0:
	/* plus */
	/* taking thickness 2 for cross & plus & star */
	fprintf(gpoutfile, "\
group([\n\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,2,1,%u,0,0,0,0,8,3,0,[\n]),\n\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,2,1,%u,0,0,0,0,8,3,0,[\n])\n",
		sActColor, x, y - p - 1, x, y + p + 1, uActNr+1,
		sActColor, x - p - 1, y, x + p + 1, y, uActNr+2);
	uActNr += 4;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 1:
	/* cross */
	/* taking thickness 2 for cross & plus & star */
	fprintf(gpoutfile, "\
group([\n\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,2,1,%u,0,0,0,0,8,3,0,[\n]).\n\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,2,1,%u,0,0,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr+1,
		sActColor, x - p, y + p, x + p, y - p, uActNr+2);
	uActNr += 4;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 2:
	/* star */
	/* taking thickness 2 for cross & plus & star */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,2,1,%u,0,0,0,0,8,3,0,[\n]),\n",
		sActColor, x, y - p - 1, x, y + p + 1, uActNr++);
	fprintf(gpoutfile, "\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,2,1,%u,0,0,0,0,8,3,0,[\n])\n",
		sActColor, x - p - 1, y, x + p + 1, y, uActNr++);
	fprintf(gpoutfile, "\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,2,1,%u,0,0,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
poly('%s',2,[\n\t%.1f,%.1f,%.1f,%.1f],0,2,1,%u,0,0,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y + p, x + p, y - p, uActNr++);
	uActNr += 4;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 3:
	/* box */
	fprintf(gpoutfile, "\
box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 4:
	/* filled box */
	fprintf(gpoutfile, "\
box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 5:
	/* circle */
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 6:
	/* filled circle */
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 7:
	/* triangle up */
	fprintf(gpoutfile, "\
polygon('%s',4,[\n\
%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y - p, x + p, y + 0.75 * p, x - p, y + 0.75 * p,
		x, y - p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 8:
	/* filled triangle up */
	fprintf(gpoutfile, "\
polygon('%s',4,[\n\
%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y - p, x + p, y + 0.75 * p, x - p, y + 0.75 * p,
		x, y - p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 9:
	/* triangle down */
	fprintf(gpoutfile, "\
polygon('%s',4,[\n\
%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x - p, y - 0.75 * p, x + p, y - 0.75 * p,
		x, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 10:
	/* filled triangle down */
	fprintf(gpoutfile, "\
polygon('%s',4,[\n\
%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x - p, y - 0.75 * p, x + p, y - 0.75 * p,
		x, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 11:
	/* diamond */
	fprintf(gpoutfile, "\
polygon('%s',5,[\n\
%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n\
]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p,
		uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 12:
	/* filled diamond */
	fprintf(gpoutfile, "\
polygon('%s',5,[\n\
%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n\
]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p,
		uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 13:
	/* pentagon */
	fprintf(gpoutfile, "\
polygon('%s',6,[\n\
%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y - p, x + p, y - p / 4, x + 0.625 * p, y + p,
		x - 0.625 * p, y + p, x - p, y - p / 4, x, y - p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 14:
	/* filled pentagon */
	fprintf(gpoutfile, "\
polygon('%s',6,[\n\
%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y - p, x + p, y - p / 4, x + 0.625 * p, y + p,
		x - 0.625 * p, y + p, x - p, y - p / 4, x, y - p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 15:
	/* circle1 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n\
]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,4480,2560,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x + p * 0.342, y - p * 0.94,
		x - p * 0.342, y - p * 0.94, 2 * p, 2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 16:
	/* circle2 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,0,5760,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x + p, y, x, y - p, 2 * p,
		2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 17:
	/* circle3 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,5760,5760,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x, y - p, x - p, y, 2 * p,
		2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 18:
	/* circle4 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,0,11520,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x + p, y, x - p, y, 2 * p,
		2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 19:
	/* circle5 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,11520,5760,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x - p, y, x, y + p, 2 * p,
		2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 20:
	/* circle6 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,0,5760,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x + p, y, x, y - p, 2 * p,
		2 * p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,11520,5760,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x - p, y, x, y + p, 2 * p,
		2 * p, uActNr++);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 21:
	/* circle7 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,5760,11520,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x, y - p, x, y + p, 2 * p,
		2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 22:
	/* circle8 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,0,17280,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x + p, y, x, y + p, 2 * p,
		2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 23:
	/* circle9 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,17280,5760,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x, y + p, x + p, y, 2 * p,
		2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 24:
	/* circle10 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,17280,11520,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x, y + p, x, y - p, 2 * p,
		2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 25:
	/* circle11 */
	fputs("group([\n", gpoutfile);
	fprintf(gpoutfile, "\
oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,5760,5760,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x, y - p, x - p, y, 2 * p,
		2 * p, uActNr++);
	fprintf(gpoutfile, "\
arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,17280,5760,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x, y + p, x + p, y, 2 * p,
		2 * p, uActNr++);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 26:
	/* circle12 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile,
		"arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,17280,17280,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x, y + p, x - p, y, 2 * p, 2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 27:
	/* circle13 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile,
		"arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,11520,11520,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x - p, y, x + p, y, 2 * p, 2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 28:
	/* circle14 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile,
		"arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,11520,17280,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x - p, y, x, y - p, 2 * p, 2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 29:
	/* circle15 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "oval('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile,
		"arc('%s',1,1,1,0,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,0,%.1f,%.1f,5760,17280,%u,0,0,8,3,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, x, y - p, x + p, y, 2 * p, 2 * p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 30:
	/* circle16 */
	fprintf(gpoutfile, "oval('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 31:
	/* box1 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p / 4, y - p, x + p / 4, y, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 32:
	/* box2 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x, y - p, x + p, y, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 33:
	/* box3 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 34:
	/* box4 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 35:
	/* box5 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y, x, y + p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 36:
	/* box6 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x, y - p, x + p, y, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y, x, y + p, uActNr++);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 37:
	/* box7 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x, y + p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 38:
	/* box8 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y, x, y + p, uActNr++);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 39:
	/* box9 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x, y, x + p, y + p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 40:
	/* box10 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x, y - p, x + p, y + p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 41:
	/* box11 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x, y, x + p, y + p, uActNr++);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 42:
	/* box12 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x, y, x + p, y + p, uActNr++);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 43:
	/* box13 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y, x + p, y + p, uActNr++);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 44:
	/* box14 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x, y - p, x + p, y, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y, x + p, y + p, uActNr++);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 45:
	/* box15 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,2,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x, y, uActNr++);
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y, x + p, y + p, uActNr++);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 46:
	/* box16 */
	fprintf(gpoutfile, "box('%s',%.1f,%.1f,%.1f,%.1f,1,1,1,%u,0,0,0,[\n]).\n",
		sActColor, x - p, y - p, x + p, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */
    case 47:
	/* diamond1 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - 0.625 * p, y - 0.375 * p, x - 0.375 * p, y - 0.625 * p, x + p / 8,
		y - p / 8, x - p / 8, y + p / 8, x - 0.625 * p, y - 0.375 * p, uActNr);
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	uActNr += 2;
	break;
	/*}}}  */
    case 48:
	/* diamond2 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p / 2, y - p / 2, x, y - p, x + p / 2, y - p / 2, x, y, x - p / 2,
		y - p / 2, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 49:
	/* diamond3 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p, y, x - p / 2, y - p / 2, x, y, x - p / 2, y + p / 2, x - p, y, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 50:
	/* diamond4 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p, y, x, y - p, x + p / 2, y - p / 2, x - p / 2, y + p / 2, x - p,
		y, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 51:
	/* diamond5 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p / 2, y + p / 2, x, y, x + p / 2, y + p / 2, x, y + p, x - p / 2,
		y + p / 2, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 52:
	/* diamond6 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p / 2, y - p / 2, x, y - p, x + p / 2, y - p / 2, x, y, x - p / 2,
		y - p / 2, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p / 2, y + p / 2, x, y, x + p / 2, y + p / 2, x, y + p, x - p / 2,
		y + p / 2, uActNr);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 53:
	/* diamond7 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p, y, x - p / 2, y - p / 2, x + p / 2, y + p / 2, x, y + p, x - p,
		y, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 54:
	/* diamond8 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',7,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p, y, x, y - p, x + p / 2, y - p / 2, x, y, x + p / 2, y + p / 2,
		x, y + p, x - p, y, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 55:
	/* diamond9 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y, x + p / 2, y - p / 2, x + p, y, x + p / 2, y + p / 2, x, y, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 56:
	/* diamond10 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p / 2, y - p / 2, x, y - p, x + p, y, x + p / 2, y + p / 2, x - p /
		2, y - p / 2, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 57:
	/* diamond11 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p, y, x - p / 2, y - p / 2, x, y, x - p / 2, y + p / 2, x - p, y, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y, x + p / 2, y - p / 2, x + p, y, x + p / 2, y + p / 2, x, y, uActNr);
	uActNr += 3;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 58:
	/* diamond12 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',7,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p, y, x, y - p, x + p, y, x + p / 2, y + p / 2, x, y, x - p / 2, y
		+ p / 2, x - p, y, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 59:
	/* diamond13 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p / 2, y + p / 2, x + p / 2, y - p / 2, x + p, y, x, y + p, x - p /
		2, y + p / 2, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 60:
	/* diamond14 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',7,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p / 2, y - p / 2, x, y - p, x + p, y, x, y + p, x - p / 2, y + p /
		2, x, y, x - p / 2, y - p / 2, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 61:
	/* diamond15 */
	fprintf(gpoutfile, "group([\n");
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],0,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	fprintf(gpoutfile,
		"polygon('%s',7,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x - p, y, x - p / 2, y - p / 2, x, y, x + p / 2, y - p / 2, x + p, y,
		x, y + p, x - p, y, uActNr);
	uActNr += 2;
	fprintf(gpoutfile, "],\n%u,0,[\n]).\n", uActNr++);
	break;
	/*}}}  */
    case 62:
	/* diamond16 */
	fprintf(gpoutfile,
		"polygon('%s',5,[\n%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f],1,1,1,0,%u,0,0,0,0,0,[\n]).\n",
		sActColor, x, y + p, x + p, y, x, y - p, x - p, y, x, y + p, uActNr);
	uActNr++;
	break;
	/*}}}  */

    }				/* switch */
}				/* TGIF_point */

/*}}}  */
/***************************************************************************/
TERM_PUBLIC void
TGIF_set_pointsize(double size)
{
    uActPointSize = size < 0. ? 1. : size;
}

TERM_PUBLIC void
TGIF_set_linewidth(double size)
{
    dActThick_factor = size < 0. ? 1. : size;
}

/*}}}  */
/***************************************************************************/
TERM_PUBLIC int
TGIF_set_font(const char *font)
{
    int sep;

    if (!font || !(*font))
        font = sDefaultFont;
    sep = strcspn(font, ",");
    if (sep > 0) {
	strncpy(sActFont, font, sep);
	sActFont[sep] = NUL;
    }
    sscanf(&(font[sep + 1]), "%d", &uActFontSize);
    return TRUE;
}

TERM_PUBLIC int
TGIF_make_palette(t_sm_palette *palette)
{
    return 0; 
    /* can do continuous colors */
}

TERM_PUBLIC void 
TGIF_previous_palette(void)
{
    /* do nothing */
}

TERM_PUBLIC void
TGIF_set_color(t_colorspec *colorspec)
{
    if (colorspec->type == TC_LT) {
	TGIF_linetype(colorspec->lt);
    } else if (colorspec->type == TC_FRAC) {
	rgb255maxcolors_from_gray(colorspec->value, &rgbActColor);
	sprintf(sActColor, "#%.2x%.2x%.2x", 
		rgbActColor.r, rgbActColor.g, rgbActColor.b);
    } else if (colorspec->type == TC_RGB) {
	rgbActColor.r = colorspec->lt >> 16 & 0xff;
	rgbActColor.g = colorspec->lt >> 8 & 0xff;
	rgbActColor.b = colorspec->lt & 0xff;
	sprintf(sActColor, "#%.2x%.2x%.2x", 
		rgbActColor.r, rgbActColor.g, rgbActColor.b);
    }
}

TERM_PUBLIC void
TGIF_fillbox(int style, unsigned int x1, unsigned int y1, 
	     unsigned int width, unsigned int height)
{
    gpiPoint corner[4];

	corner[0].x = x1;        corner[0].y = y1;
	corner[1].x = x1+width;  corner[1].y = y1;
	corner[2].x = x1+width;  corner[2].y = y1+height;
	corner[3].x = x1;        corner[3].y = y1+height;
	corner->style = style;

	TGIF_filled_polygon(4, corner);
}

TERM_PUBLIC void
TGIF_FillSolid(char *curcolor,int fillpar)
{
    int red, green, blue;
    double fact = (double)(100 - fillpar) * 0.01;

    if (fact < 0.0) fact = 0.0;
    else if (fact > 1.0) fact = 1.0;
    red   = rgbActColor.r + (0xff - rgbActColor.r) * fact;
    green = rgbActColor.g + (0xff - rgbActColor.g) * fact;
    blue  = rgbActColor.b + (0xff - rgbActColor.b) * fact;
    sprintf(curcolor,"#%.2x%.2x%.2x", red, green, blue);
}

TERM_PUBLIC void
TGIF_filled_polygon(int points, gpiPoint *corners)
{
    int i,pattern;
    int fillpar = corners->style >> 4;
    int style = corners->style & 0xf;
    char curcolor[TGIF_STRLEN_MAX];

    if (eTgifState == INPOLY)
	TGIF_flush_poly(); /* Clean up current data */

    switch (style) {
    case FS_EMPTY:
	pattern=uFillPattern[0];
	strcpy(curcolor,"white");
	break;
    case FS_TRANSPARENT_PATTERN:
    case FS_PATTERN:
	pattern=uFillPattern[fillpar % TGIF_fillpatterns];
	strcpy(curcolor,sActColor);
	break;
    case FS_TRANSPARENT_SOLID:
    case FS_SOLID:
	pattern=1;
	TGIF_FillSolid(curcolor,fillpar);
	break;
    default:
	pattern=1;
	strcpy(curcolor,sActColor);
    }

    fprintf(gpoutfile, "polygon('%s',%d,[\n\t",curcolor,points+1);
    /* loop through points, do the first one last as well as first */
    fprintf(gpoutfile,"%u,%u,", corners[0].x+uXshift, uYshift-corners[0].y);
    for (i = 1; i < points; i++) {
	fprintf(gpoutfile, "%u,%u,",
		corners[i].x+uXshift, uYshift-corners[i].y);
	/* LN: Break long lines as Tgif is rather picky about them */
        if ((i + 1) % 8 == 0)
	    fputs("\n\t", gpoutfile);
    }
    fprintf(gpoutfile, "%u,%u", corners[0].x+uXshift, uYshift-corners[0].y);
    fprintf(gpoutfile, "],%d,1,0,0,%u,0,0,0,0,[\n]).\n", pattern, uActNr);
    uActNr++;
}

/*}}}  */
/***************************************************************************/

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(tgif_driver)
    "tgif",
    "TGIF X11 [mode] [x,y] [dashed] [\042font\042 [fontsize]]",
    TGIF_XMAX, TGIF_YMAX, TGIF_VCHAR, TGIF_HCHAR,
    TGIF_VTIC, TGIF_HTIC, TGIF_options, TGIF_init, TGIF_reset,
    TGIF_text, null_scale, TGIF_graphics, TGIF_move, TGIF_vector,
    TGIF_linetype, TGIF_put_text, TGIF_text_angle,
    TGIF_justify_text, TGIF_point, do_arrow, TGIF_set_font,
    TGIF_set_pointsize, 
    TERM_CAN_MULTIPLOT|TERM_CAN_DASH|TERM_LINEWIDTH, 
    0, 0, TGIF_fillbox,
    TGIF_set_linewidth
#ifdef USE_MOUSE
    ,0, 0, 0, 0, 0 /* no mouse support for the tgif terminal */
#endif
    , TGIF_make_palette, TGIF_previous_palette, TGIF_set_color, 
    TGIF_filled_polygon
TERM_TABLE_END(tgif_driver)

#undef LAST_TERM
#define LAST_TERM tgif_driver

#endif /* TERM_TABLE */

#endif /* TERM_PROTO_ONLY */

#ifdef TERM_HELP
START_HELP(tgif)
"1 tgif",
"?commands set terminal tgif",
"?set terminal tgif",
"?set term tgif",
"?terminal tgif",
"?term tgif",
"?tgif",
" Tgif is an X11-based drawing tool---it has nothing to do with GIF.",
"",
" The `tgif` driver supports a choice of font and font size and multiple",
" graphs on the page.  The proportions of the axes are not changed.",
"",
" Syntax:",
"       set terminal tgif {portrait | landscape | default} {<[x,y]>}",
"                         {monochrome | color}",
"                         {{linewidth | lw} <LW>}",
"                         {solid | dashed}",
"                         {font \"<fontname>{,<fontsize>}\"}",
"",
" where <[x,y]> specifies the number of graphs in the x and y directions on the",
" 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`,",
" `linewidth 1.0`, `dashed`, `\"Helvetica,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",
" chosen for that.",
"",
" Multiplot is implemented in two different ways.",
"",
" The first multiplot implementation is the standard gnuplot multiplot feature:",
"",
"       set terminal tgif",
"       set output \"file.obj\"",
"       set multiplot",
"       set origin x01,y01",
"       set size  xs,ys",
"       plot ...",
"            ...",
"       set origin x02,y02",
"       plot ...",
"       unset multiplot",
"",
" See `set multiplot` for further information.",
"",
" The second version is the [x,y] option for the driver itself.  The advantage",
" of this implementation is that everything is scaled and placed automatically",
" without the need for setting origins and sizes; the graphs keep their natural",
" x/y proportions of 3/2 (or whatever is fixed by `set size`).",
"",
" If both multiplot methods are selected, the standard method is chosen and a",
" warning message is given.",
"",
" Examples of single plots (or standard multiplot):",
"       set terminal tgif                  # defaults",
"       set terminal tgif \"Times-Roman,24\"",
"       set terminal tgif landscape",
"       set terminal tgif landscape solid",
"",
" Examples using the built-in multiplot mechanism:",
"       set terminal tgif portrait [2,4]  # portrait; 2 plots in the x-",
"                                         # and 4 in the y-direction",
"       set terminal tgif [1,2]           # portrait; 1 plot in the x-",
"                                         # and 2 in the y-direction",
"       set terminal tgif landscape [3,3] # landscape; 3 plots in both",
"                                         # directions"
END_HELP(tgif)
#endif
/*{{{}}}*/
