Ejemplo n.º 1
0
void GrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrColor c)
{
    int (*pnts)[2];
    setup_ALLOC();
    pnts = ALLOC(sizeof(int) * 2 * (GR_MAX_ELLIPSE_POINTS + 1));
    if (pnts != NULL)
    {
	GrFillArg fval;
	int npts  = GrGenerateEllipseArc(xc,yc,xa,ya,start,end,pnts);
	int close = FALSE;
	switch(style) {
	  case GR_ARC_STYLE_CLOSE2:
	    pnts[npts][0] = xc;
	    pnts[npts][1] = yc;
	    npts++;
	  case GR_ARC_STYLE_CLOSE1:
	    close = TRUE;
	    break;
	}
	fval.color = c;
	_GrDrawPolygon(npts,pnts,&_GrSolidFiller,fval,close);
	FREE(pnts);
    }
    reset_ALLOC();
}
Ejemplo n.º 2
0
void GrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrLinePattern *lp)
{
    int (*points)[2];
    setup_ALLOC();
    points = ALLOC(sizeof(int) * 2 * (GR_MAX_ELLIPSE_POINTS + 2));
    if (points != NULL)
    {
	int numpts = GrGenerateEllipseArc(xc,yc,xa,ya,start,end,points);
	GrFillArg fval;
	int close;

	close = FALSE;
	if (style == GR_ARC_STYLE_CLOSE2) {
		points[numpts][0] = xc;
		points[numpts][1] = yc;
		numpts++;
		points[numpts][0] = points[0][0];
		points[numpts][1] = points[0][1];
		numpts++;
		close = TRUE;
	}
	if (style == GR_ARC_STYLE_CLOSE1) {
		points[numpts][0] = points[0][0];
		points[numpts][1] = points[0][1];
		numpts++;
		close = TRUE;
	}
	fval.p = lp->lnp_pattern;
	_GrDrawCustomPolygon(numpts,points,lp->lnp_option,
			     &_GrPatternFiller,fval,close,TRUE);
	FREE(points);
    }
    reset_ALLOC();
}
Ejemplo n.º 3
0
void GrCustomEllipse(int xc,int yc,int xa,int ya,const GrLineOption *o)
{
    int (*pnts)[2];
    setup_ALLOC();
    pnts = ALLOC(sizeof(int) * 2 * GR_MAX_ELLIPSE_POINTS);
    if (pnts != NULL)
    {
	GrFillArg fval;
	int npts  = GrGenerateEllipse(xc,yc,xa,ya,pnts);
	fval.color = o->lno_color;
	_GrDrawCustomPolygon(npts,pnts,o,&_GrSolidFiller,fval,TRUE,TRUE);
	FREE(pnts);
    }
    reset_ALLOC();
}
Ejemplo n.º 4
0
/**
 * grx_user_draw_polyline:
 * @n_points: the number of points in @points
 * @points: (array length=n_points): an array of #GrxPoint
 * @c: the color
 *
 * Draw a multi-segment line on the current context that connects each point in
 * the @points array using the specified color.
 */
void grx_user_draw_polyline(int numpts,GrxPoint *points,GrxColor c)
{
        int pt;
        GrxPoint *tmp;
        setup_ALLOC();
        tmp = ALLOC(sizeof(GrxPoint) * numpts);

        if (tmp != NULL) {
          for ( pt = 0; pt < numpts; pt++) {
                tmp[pt] = points[pt];
                U2SX(tmp[pt].x,CURC);
                U2SY(tmp[pt].y,CURC);
          }
          grx_draw_polyline(numpts,tmp,c);
          FREE(tmp);
        }
        reset_ALLOC();
}
Ejemplo n.º 5
0
void GrUsrPolygon(int numpts,int points[][2],GrColor c)
{
	int pt;
	int (*tmp)[2];
	setup_ALLOC();
	tmp = ALLOC(sizeof(int) * 2 * numpts);

	if (tmp != NULL) {
	  for ( pt = 0; pt < numpts; pt++) {
		tmp[pt][0] = points[pt][0];
		tmp[pt][1] = points[pt][1];
		U2SX(tmp[pt][0],CURC);
		U2SY(tmp[pt][1],CURC);
	  }
	  GrPolygon(numpts,tmp,c);
	  FREE(tmp);
	}
	reset_ALLOC();
}
Ejemplo n.º 6
0
void GrSetFontPath(char *p)
{
	int  chr,totlen = 0,npath,plen = 0;
	char path[200],*plist[100];
	if(!p || (*p == '\0')) return;
        for (npath = 0; npath < itemsof(plist); ++npath)
          plist[npath] = NULL;
        npath = 0;
	setup_ALLOC();
	path[0] = '\0';
	while(((chr = *p++) != '\0') || (plen > 0)) {
	    int pathchr = TRUE;
	    switch(chr) {
	      case ':':
#ifdef __MSDOS__
		if((plen == 1) && isalpha(path[0])) break;
#endif
	      case ';':
		pathchr = FALSE;
		break;
	      case '\0':
		p--;
		pathchr = FALSE;
		break;
#ifdef __MSDOS__
	      case '\\':
		chr = '/';
		break;
#endif
	      default:
#ifdef __MSDOS__
		chr = tolower(chr);
#endif
		if(isspace(chr)) pathchr = FALSE;
		break;
	    }
	    if(pathchr) {
		path[plen++] = chr;
		continue;
	    }
	    if(plen > 0) {
		if(path[plen - 1] != '/') path[plen++] = '/';
		path[plen++] = '\0';
		plist[npath] = ALLOC((size_t)plen);
		if(plist[npath] == NULL) goto error;
		strcpy(plist[npath],path);
		totlen += plen;
		plen = 0;
		if(++npath == itemsof(plist)) break;
	    }
	}
	if(_GrFontFileInfo.path != NULL) free(_GrFontFileInfo.path);
	_GrFontFileInfo.path  = NULL;
	_GrFontFileInfo.npath = npath;
	if(npath > 0) {
	    _GrFontFileInfo.path = malloc((sizeof(char *) * npath) + totlen);
	    if(_GrFontFileInfo.path == NULL) goto error;
	    p = (char *)(&_GrFontFileInfo.path[npath]);
	    for(plen = 0; plen < npath; plen++) {
		_GrFontFileInfo.path[plen] = p;
		strcpy(p,plist[plen]);
		p += strlen(p) + 1;
	    }
	}
	goto done;
      error:
	if(_GrFontFileInfo.path != NULL) free(_GrFontFileInfo.path);
	_GrFontFileInfo.path  = NULL;
	_GrFontFileInfo.npath = 0;
      done:
        for (npath = 0; npath < itemsof(plist); ++npath)
          FREE(plist[npath]);
	reset_ALLOC();
}
Ejemplo n.º 7
0
void _GrScanEllipse(int xc,int yc,int xa,int ya,GrFiller *f,GrFillArg c,int filled)
{
    int x1,x2,y1,y2;
    if(xa < 0) xa = (-xa);
    if(ya < 0) ya = (-ya);
    x1 = xc - xa;
    y1 = yc - ya;
    x2 = xc + xa;
    y2 = yc + ya;
    clip_ordbox(CURC,x1,y1,x2,y2);
    mouse_block(CURC,x1,y1,x2,y2);
    setup_ALLOC();
    if((xa == 0) || (ya == 0)) (*f->line)(
            (x1 + CURC->gc_xoffset),
            (y1 + CURC->gc_yoffset),
            (x2 - x1),
            (y2 - y1),
            c
        );
    else if((xa > MAXR) || (ya > MAXR)) {   /* Bresenham would overflow !! */
        int (*points)[2] = ALLOC(sizeof(int) * 2 * GR_MAX_ELLIPSE_POINTS);
        if(points != NULL) {
            int count = GrGenerateEllipse(xc,yc,xa,ya,points);
            if(filled) _GrScanConvexPoly(count,points,f,c);
            else       _GrDrawPolygon(count,points,f,c,TRUE);
            FREE(points);
        }
    }
    else {
        int *scans = ALLOC(sizeof(int) * (ya + 1));
        int  row   = ya;
        int  col   = 0;
        if(scans != NULL) {
            long yasq  = umul32(ya,ya);
            long xasq  = umul32(xa,xa);
            long xasq2 = xasq + xasq;
            long yasq2 = yasq + yasq;
            long xasq4 = xasq2 + xasq2;
            long yasq4 = yasq2 + yasq2;
            long error = (xasq2 * (row - 1) * row) +
                         (yasq2 * (1 - xasq))      +
                         xasq;
            while((xasq * row) > (yasq * col)) {
                if(error >= 0) {
                    scans[row] = col;
                    row--;
                    error -= xasq4 * row;
                }
                error += yasq2 * (3 + (col << 1));
                col++;
            }
            error = (yasq2 * (col + 1) * col)         +
                    (xasq2 * ((row * (row - 2)) + 1)) +
                    (yasq  * (1 - xasq2));
            while(row >= 0) {
                scans[row] = col;
                if(error <= 0) {
                    col++;
                    error += yasq4 * col;
                }
                row--;
                error += xasq2 * (2 - (row << 1));
            }
            for(row = y1; row <= y2; row++) {
                col = iabs(yc - row);
                if(!filled && (col < ya)) {
                    x1 = xc - scans[col];
                    x2 = xc - scans[col + 1];
                    if(x1 < x2) x2--;
                    do {
                        clip_ordxrange_(CURC,x1,x2,break,CLIP_EMPTY_MACRO_ARG);
                        (*f->scan)(
                            (x1  + CURC->gc_xoffset),
                            (row + CURC->gc_yoffset),
                            (x2  - x1 + 1),
                            c
                        );
                    } while (0);
                    x1 = xc + scans[col + 1];
                    x2 = xc + scans[col];
                    if(x1 < x2) x1++;
                }
                else {
                    x1 = xc - scans[col];
                    x2 = xc + scans[col];
                }
                clip_ordxrange_(CURC,x1,x2,continue,CLIP_EMPTY_MACRO_ARG);
                (*f->scan)(
                    (x1  + CURC->gc_xoffset),
                    (row + CURC->gc_yoffset),
                    (x2  - x1 + 1),
                    c
                );
            }