static void AddToBlock(struct block *block,char *mapname, char *dir) {
    int i, val, j;
    int len = strlen(mapname);

    if ( mapname[len-7]=='.' ) len -= 7;
    for ( i=0; i<block->cur; ++i ) {
        if ( (val=strncmp(block->maps[i],mapname,len))==0 )
            return;		/* Duplicate */
        else if ( val>0 )
            break;
    }
    if ( block->tot==0 ) {
        block->tot = 10;
        block->maps = galloc(10*sizeof(char *));
        block->dirs = galloc(10*sizeof(char *));
    } else if ( block->cur>=block->tot ) {
        block->tot += 10;
        block->maps = grealloc(block->maps,block->tot*sizeof(char *));
        block->dirs = grealloc(block->dirs,block->tot*sizeof(char *));
    }
    for ( j=block->cur; j>=i; --j ) {
        block->maps[j+1] = block->maps[j];
        block->dirs[j+1] = block->dirs[j];
    }
    block->maps[i] = copyn(mapname,len);
    block->dirs[i] = dir;
    ++block->cur;
}
Ejemplo n.º 2
0
static int name_char(struct temp_font *tf,int ch, char *name) {

    if ( tf->is_adobe )
return( find_char(tf,name));
    if ( ch>=tf->max_alloc ) {
	if ( tf->max_alloc==256 ) tf->max_alloc = 128*256; else tf->max_alloc = 65536;
	tf->per_char = grealloc(tf->per_char,tf->max_alloc*sizeof(XCharStruct));
	tf->kerns = grealloc(tf->kerns,tf->max_alloc*sizeof(struct kern_info *));
    }
    if ( ch!=-1 && ch<256 && name[0]!='\0')
	tf->names[ch] = copy(name);
return( ch );
}
Ejemplo n.º 3
0
char *canontoken(char *str)
{
    static unsigned char *canon;
    static int allocated;
    unsigned char c, *p, *q;
    int len;

    p = (unsigned char *) str;
    len = strlen(str);
    if (len >= allocated) {
	allocated = len + 1 + 10;
	canon = grealloc(canon, allocated);
	if (!canon)
	    return NULL;
    }
    q = (unsigned char *) canon;
    while ((c = *p++)) {
	/* if (isalnum(c) == FALSE) */
	    /* continue; */
	if (isupper(c))
	    c = tolower(c);
	*q++ = c;
    }
    *q = '\0';
    return (char*)canon;
}
Ejemplo n.º 4
0
static void SplitSpirosAndAddAndCut(SplineSet *spl,SplineSet *spl2,int spiro_index) {
    /* OK, spl was an open contour and we just cut it at spiro_index */
    /* We don't need to rotate the spiros */
    /* The first half of spl remains in it. (We'll leave all spiros up to and including spiro_index) */
    /* If spl->spiros[spiro_index] != spl->first->me we must add spl->first here */
    /* In the spl2 we either start out with spl->spiros[spiro_index] or with spl->first */
    /* then add all spiros after spiro_index */

    spl2->spiros = galloc((spl->spiro_cnt-spiro_index+2) * sizeof(spiro_cp));
    spl2->spiro_max = spl->spiro_cnt-spiro_index+2;
    if ( spl2->first->me.x == spl->spiros[spiro_index].x &&
            spl2->first->me.y == spl->spiros[spiro_index].y ) {
        memcpy(spl2->spiros,spl->spiros+spiro_index,(spl->spiro_cnt-spiro_index)*sizeof(spiro_cp));
        spl2->spiros[0].ty = SPIRO_OPEN_CONTOUR;
        memcpy(spl->spiros+spiro_index+1,spl->spiros+spl->spiro_cnt-1,sizeof(spiro_cp));
        spl2->spiro_cnt = spl->spiro_cnt-spiro_index;
        spl->spiro_cnt = spiro_index+2;
    } else {
        spl2->spiros[0].x = spl2->first->me.x;
        spl2->spiros[0].y = spl2->first->me.y;
        spl2->spiros[0].ty = SPIRO_OPEN_CONTOUR;
        memcpy(spl2->spiros+1,spl->spiros+spiro_index+1,(spl->spiro_cnt-(spiro_index+1))*sizeof(spiro_cp));
        spl2->spiro_cnt = spl->spiro_cnt-spiro_index;
        if ( spiro_index+3>spl->spiro_max )
            spl->spiros = grealloc(spl->spiros,(spl->spiro_max=spiro_index+3)*sizeof(spiro_cp));
        memcpy(spl->spiros+spiro_index+1,spl2->spiros,sizeof(spiro_cp));
        spl->spiros[spiro_index+1].ty = SPIRO_G4;
        memcpy(spl->spiros+spiro_index+2,spl->spiros+spl->spiro_cnt-1,sizeof(spiro_cp));
        spl->spiro_cnt = spiro_index+3;
    }
}
Ejemplo n.º 5
0
static int AddProtocol(unichar_t *prefix,int len) {

    if ( plen>=pmax ) {
	pmax += 20;		/* We're never going to support 20 protocols? */
	if ( plen==0 ) {
	    protocols = (struct protocols *) galloc(pmax*sizeof(struct protocols));
	} else {
	    protocols = (struct protocols *) grealloc(protocols,pmax*sizeof(struct protocols));
	}
    }
    memset(protocols+plen,0,sizeof(struct protocols));
    if ( uc_strncmp(prefix,"file",len)==0 ) {
	protocols[plen].handle = NULL;
	protocols[plen].dispatcher = _GIO_fileDispatch;
	protocols[plen].cancel = NULL;
	protocols[plen].term = NULL;
	protocols[plen].dothread = false;
    } else {
return( false );
    }
    protocols[plen].index = plen;
    protocols[plen].proto = u_copyn(prefix,len);
    ++plen;
return( true );
}
Ejemplo n.º 6
0
void gv_argvlist_set_item(gv_argvlist_t *list, int index, char *item)
{
    if (index >= list->alloc) {
	list->alloc = index + 10;
	list->argv = grealloc(list->argv, (list->alloc)*(sizeof(char*)));
    }
    list->argv[index] = item;
}
Ejemplo n.º 7
0
void FVAddEncodingSlot(FontViewBase *fv,int gid) {
    EncMap *map = fv->map;
    int enc;

    enc = MapAddEncodingSlot(map,gid);

    fv->selected = grealloc(fv->selected,map->enccount);
    fv->selected[enc] = 0;
    FVAdjustScrollBarRows(fv,enc);
}
Ejemplo n.º 8
0
static int MapAddEncodingSlot(EncMap *map,int gid) {
    int enc;

    if ( map->enccount>=map->encmax )
	map->map = grealloc(map->map,(map->encmax+=10)*sizeof(int));
    enc = map->enccount++;
    map->map[enc] = gid;
    map->backmap[gid] = enc;
return( enc );
}
Ejemplo n.º 9
0
char *xml_string(char *s)
{
    static char *buf = NULL;
    static int bufsize = 0;
    char *p, *sub;
    int len, pos = 0;

    if (!buf) {
	bufsize = 64;
	buf = gmalloc(bufsize);
    }

    p = buf;
    while (*s) {
	if (pos > (bufsize - 8)) {
	    bufsize *= 2;
	    buf = grealloc(buf, bufsize);
	    p = buf + pos;
	}
	/* these are safe even if string is already UTF-8 coded
	 * since UTF-8 strings won't contain '<' or '>' */
	if (*s == '<') {
	    sub = "&lt;";
	    len = 4;
	} else if (*s == '>') {
	    sub = "&gt;";
	    len = 4;
	} else if (*s == '"') {
	    sub = "&quot;";
	    len = 6;
	} else if (*s == '-') {	/* can't be used in xml comment strings */
	    sub = "&#45;";
	    len = 5;
	} else if (*s == '\'') {
	    sub = "&#39;";
	    len = 5;
	}
	/* escape '&' only if not part of a legal entity sequence */
	else if (*s == '&' && !(xml_isentity(s))) {
	    sub = "&amp;";
	    len = 5;
	} else {
	    sub = s;
	    len = 1;
	}
	while (len--) {
	    *p++ = *sub++;
	    pos++;
	}
	s++;
    }
    *p = '\0';
    return buf;
}
Ejemplo n.º 10
0
void CVMergeSplineSets(CharView *cv, SplinePoint *active, SplineSet *activess,
	SplinePoint *merge, SplineSet *mergess) {
    SplinePointList *spl;

    cv->joinvalid = true;
    cv->joinpos = *merge; cv->joinpos.selected = false;

    if ( active->prev==NULL )
	SplineSetReverse(activess);
    if ( merge->next==NULL )
	SplineSetReverse(mergess);
    active->nextcp = merge->nextcp;
    active->nonextcp = merge->nonextcp;
    active->nextcpdef = merge->nextcpdef;
    active->next = merge->next;
    if ( merge->next!= NULL ) {
	active->next->from = active;
	activess->last = mergess->last;
    }
    merge->next = NULL;
    if ( mergess==activess ) {
	activess->first = activess->last = active;
	SplinePointMDFree(cv->b.sc,merge);
	if ( activess->spiro_cnt!=0 ) {
	    activess->spiros[0].ty = activess->spiros[activess->spiro_cnt-2].ty;
	    activess->spiros[activess->spiro_cnt-2] = activess->spiros[activess->spiro_cnt-1];
	    --activess->spiro_cnt;
	}
    } else {
	mergess->last = merge;
	if ( mergess==cv->b.layerheads[cv->b.drawmode]->splines )
	    cv->b.layerheads[cv->b.drawmode]->splines = mergess->next;
	else {
	    for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl->next!=mergess; spl=spl->next );
	    spl->next = mergess->next;
	}
	if ( activess->spiros && mergess->spiros ) {
	    if ( activess->spiro_cnt+mergess->spiro_cnt > activess->spiro_max )
		activess->spiros = grealloc(activess->spiros,
			(activess->spiro_max = activess->spiro_cnt+mergess->spiro_cnt)*sizeof(spiro_cp));
	    memcpy(activess->spiros+activess->spiro_cnt-1,
		    mergess->spiros+1, (mergess->spiro_cnt-1)*sizeof(spiro_cp));
	    activess->spiro_cnt += mergess->spiro_cnt-2;
	} else
	    SplineSetSpirosClear(activess);
	SplinePointListMDFree(cv->b.sc,mergess);
    }
    if (( active->pointtype==pt_curve || active->pointtype==pt_hvcurve ) &&
	    !active->nonextcp && !active->noprevcp &&
	    !active->nextcpdef && !active->prevcpdef &&
	    !BpColinear(&active->prevcp,&active->me,&active->nextcp))
	active->nextcpdef = active->prevcpdef = true;
    SplineSetJoinCpFixup(active);
}
Ejemplo n.º 11
0
int ReadOtherSubrsFile(char *filename) {
    FILE *os = fopen(filename,"r");
    char buffer[500];
    char **lines=NULL;
    int l=0, lmax=0;
    int sub_num = -1;
    const char **co=NULL, **osubs[14];
    int i;

    if ( os==NULL )
return( false );
    while ( fgets(buffer,sizeof(buffer),os)!=NULL ) {
	int len = strlen(buffer);
	if ( len>0 && (buffer[len-1]=='\r' || buffer[len-1]=='\n')) {
	    if ( len>1 && (buffer[len-2]=='\r' || buffer[len-2]=='\n'))
		buffer[len-2] = '\0';
	    else
		buffer[len-1] = '\0';
	}
	if ( buffer[0]=='%' && buffer[1]=='%' && buffer[2]=='%' && buffer[3]=='%' ) {
	    if ( sub_num == -1 )
		co = CopyLines(lines,l,true);
	    else if ( sub_num<14 )
		osubs[sub_num] = CopyLines(lines,l,false);
	    else if ( sub_num==14 )
		LogError( _("Too many subroutines. We can deal with at most 14 (0-13)\n") );
	    ++sub_num;
	    l = 0;
	} else {
	    if ( l>=lmax ) {
		lmax += 100;
		lines = grealloc(lines,lmax*sizeof(char *));
	    }
	    lines[l++] = copy(buffer);
	}
    }
    fclose( os );
    /* we just read a copyright notice? That's no use */
    if ( sub_num<=0 )
return( false );
    while ( sub_num<14 ) {
	osubs[sub_num] = gcalloc(2,sizeof(char *));
	osubs[sub_num][0] = copy("{}");
	++sub_num;
    }
    DefaultOtherSubrs();
    othersubrs_copyright[0] = co;
    for ( i=0; i<14; ++i )
	othersubrs[i] = osubs[i];
    free(lines);
return( true );
}
Ejemplo n.º 12
0
/* fullColor:
 * Return "/prefix/str"
 */
static char* fullColor (char* prefix, char* str)
{
    static char *fulls;
    static int allocated;
    int len = strlen (prefix) + strlen (str) + 3;

    if (len >= allocated) {
	allocated = len + 10;
	fulls = grealloc(fulls, allocated);
    }
    sprintf (fulls, "/%s/%s", prefix, str);
    return fulls;
}
Ejemplo n.º 13
0
static int MenuDataAdd(PyObject *func,PyObject *check,PyObject *data,int is_cv) {
    Py_INCREF(func);
    if ( check!=NULL )
        Py_INCREF(check);
    Py_INCREF(data);

    if ( is_cv ) {
        if ( cvpy_menu_cnt >= cvpy_menu_max )
            cvpy_menu_data = grealloc(cvpy_menu_data,(cvpy_menu_max+=10)*sizeof(struct python_menu_info));
        cvpy_menu_data[cvpy_menu_cnt].func = func;
        cvpy_menu_data[cvpy_menu_cnt].check_enabled = check;
        cvpy_menu_data[cvpy_menu_cnt].data = data;
        return( cvpy_menu_cnt++ );
    } else {
        if ( fvpy_menu_cnt >= fvpy_menu_max )
            fvpy_menu_data = grealloc(fvpy_menu_data,(fvpy_menu_max+=10)*sizeof(struct python_menu_info));
        fvpy_menu_data[fvpy_menu_cnt].func = func;
        fvpy_menu_data[fvpy_menu_cnt].check_enabled = check;
        fvpy_menu_data[fvpy_menu_cnt].data = data;
        return( fvpy_menu_cnt++ );
    }
}
Ejemplo n.º 14
0
int PSDictChangeEntry(struct psdict *dict, char *key, char *newval) {
    int i;

    if ( dict==NULL )
return( -1 );

    for ( i=0; i<dict->next; ++i )
	if ( strcmp(dict->keys[i],key)==0 )
    break;
    if ( i==dict->next ) {
	if ( dict->next>=dict->cnt ) {
	    dict->cnt += 10;
	    dict->keys = grealloc(dict->keys,dict->cnt*sizeof(char *));
	    dict->values = grealloc(dict->values,dict->cnt*sizeof(char *));
	}
	dict->keys[dict->next] = copy(key);
	dict->values[dict->next] = NULL;
	++dict->next;
    }
    free(dict->values[i]);
    dict->values[i] = copy(newval);
return( i );
}
Ejemplo n.º 15
0
int resizeString(TString *v, int size)
{
  // Cannot shrink used data
  assert(size > v->used);

  void *newData;

  // Prevent memory leak by using a temporary pointer
  newData = grealloc(v->data, size * sizeof(char));
  if (newData == NULL)
    return E_ALLOC;

  v->data = newData;
  v->capacity = size;

  return E_OK;
}
Ejemplo n.º 16
0
static void SplineFindQuestionablePoints(struct qg_data *data,Spline *s) {
    DBounds b;
    BasePoint bp;
    real bottomy;
    QuestionableGrid *qg;

    /* Find the bounding box of the spline. It's quadratic, so only one cp */
    b.minx = b.maxx = s->from->me.x;
    b.miny = b.maxy = s->from->me.y;
    if ( s->from->nextcp.x > b.maxx ) b.maxx = s->from->nextcp.x;
    else if ( s->from->nextcp.x < b.minx ) b.minx = s->from->nextcp.x;
    if ( s->from->nextcp.y > b.maxy ) b.maxy = s->from->nextcp.y;
    else if ( s->from->nextcp.y < b.miny ) b.miny = s->from->nextcp.y;
    if ( s->to->me.x > b.maxx ) b.maxx = s->to->me.x;
    else if ( s->to->me.x < b.minx ) b.minx = s->to->me.x;
    if ( s->to->me.y > b.maxy ) b.maxy = s->to->me.y;
    else if ( s->to->me.y < b.miny ) b.miny = s->to->me.y;

    b.minx -= data->within; b.maxx += data->within;
    b.miny -= data->within; b.maxy += data->within;

    bp.x = floor(b.minx)+.5;
    if ( bp.x<b.minx ) ++bp.x;
    bottomy = floor(b.miny)+.5;
    if ( bottomy<b.miny ) ++bottomy;
    for ( ; bp.x<=b.maxx; ++bp.x ) {
	for ( bp.y = bottomy; bp.y<=b.maxy; ++bp.y ) {
	    bigreal dist = SplineMinDistanceToPoint(s,&bp);
	    if ( dist<data->within ) {
		int pt = NearestPt(s,&bp);
		if ( !Duplicate(data,pt,floor(bp.x),floor(bp.y),dist)) {
		    if ( data->cur>=data->max )
			data->qg = grealloc(data->qg,(data->max += 100) * sizeof(QuestionableGrid));
		    qg = &data->qg[data->cur];
		    qg->sc = data->sc;
		    qg->size = data->cur_size;
		    qg->nearestpt = pt;
		    qg->x = floor(bp.x); qg->y = floor(bp.y);
		    qg->distance = dist;
		    ++data->cur;
		}
	    }
	}
    }
}
Ejemplo n.º 17
0
static void CVMergeSPLS(CharView *cv,SplineSet *ss, SplinePoint *base,SplinePoint *sp) {
    int order2 = cv->b.layerheads[cv->b.drawmode]->order2;

    cv->joinvalid = true;
    cv->joinpos = *sp; cv->joinpos.selected = false;
    if ( sp->prev!=NULL )
	SplineSetReverse(cv->p.spl);
    if ( sp->prev!=NULL )
	IError("Base point not at start of splineset in CVMouseDownPoint");
    /* remove the old spl entry from the chain */
    if ( cv->p.spl==cv->b.layerheads[cv->b.drawmode]->splines )
	cv->b.layerheads[cv->b.drawmode]->splines = cv->p.spl->next;
    else { SplineSet *temp;
	for ( temp = cv->b.layerheads[cv->b.drawmode]->splines; temp->next!=cv->p.spl; temp = temp->next );
	temp->next = cv->p.spl->next;
    }
    if ( order2 && (!RealNear(base->nextcp.x,sp->prevcp.x) ||
	    !RealNear(base->nextcp.y,sp->prevcp.y)) ) {
	base->nonextcp = sp->noprevcp = true;
	base->nextcp = base->me;
	sp->prevcp = sp->me;
    }
    SplineMake(base,sp,order2);
    SplineCharDefaultNextCP(base);
    SplineCharDefaultPrevCP(sp);
    if ( sp->pointtype==pt_tangent ) {
	SplineCharTangentNextCP(sp);
	if ( sp->next ) SplineRefigure(sp->next );
    }
    ss->last = cv->p.spl->last;
    if ( ss->spiros && cv->p.spl->spiros ) {
	if ( ss->spiro_cnt+cv->p.spl->spiro_cnt > ss->spiro_max )
	    ss->spiros = grealloc(ss->spiros,
		    (ss->spiro_max = ss->spiro_cnt+cv->p.spl->spiro_cnt)*sizeof(spiro_cp));
	memcpy(ss->spiros+ss->spiro_cnt-1,
		cv->p.spl->spiros+1, (cv->p.spl->spiro_cnt-1)*sizeof(spiro_cp));
	ss->spiro_cnt += cv->p.spl->spiro_cnt-2;
    } else
	SplineSetSpirosClear(ss);
    cv->p.spl->last = cv->p.spl->first = NULL;
    SplinePointListFree(cv->p.spl);
    cv->p.spl = NULL;
}
Ejemplo n.º 18
0
static int MapAddEnc(SplineFont *sf,SplineChar *sc,EncMap *basemap, EncMap *map,int baseenc, int gid, FontViewBase *fv) {
    int any = false, enc;

    if ( gid>=map->backmax ) {
	map->backmap = grealloc(map->backmap,(map->backmax+=10)*sizeof(int));
	memset(map->backmap+map->backmax-10,-1,10*sizeof(int));
    }
    if ( map->enc->psnames!=NULL ) {
	/* Check for multiple encodings */
	for ( enc = map->enc->char_cnt-1; enc>=0; --enc ) {
	    if ( map->enc->psnames[enc]!=NULL && strcmp(sc->name,map->enc->psnames[enc])==0 ) {
		if ( !any ) {
		    map->backmap[gid] = enc;
		    any = true;
		}
		map->map[enc] = gid;
	    }
	}
    } else {
	enc = SFFindSlot(sf,map,sc->unicodeenc,sc->name);
	if ( enc!=-1 ) {
	    map->map[enc] = gid;
	    map->backmap[gid] = enc;
	    any = true;
	}
    }
    if ( basemap!=NULL && map->enc==basemap->enc && baseenc!=-1 ) {
	if ( baseenc>=map->enccount ) {
	    if ( map==fv->map )
		FVAddEncodingSlot(fv,gid);
	    else
		MapAddEncodingSlot(map,gid);
	} else {
	    map->map[baseenc] = gid;
	    if ( map->backmap[gid]==-1 )
		map->backmap[gid] = baseenc;
	}
	any = true;
    }
return( any );
}
Ejemplo n.º 19
0
static void BdfP_Invoked(GWindow v, GMenuItem *mi, GEvent *e) {
    struct bdf_dlg *bd = (struct bdf_dlg *) GDrawGetUserData(v);
    BDFFont *bdf = bd->cur->bdf;
    char *prop_name = cu_copy(mi->ti.text);
    int sel = bd->cur->sel_prop;
    int i;

    if ( sel>=bdf->prop_cnt ) {
	/* Create a new one */
	if ( bdf->prop_cnt>=bdf->prop_max )
	    bdf->props = grealloc(bdf->props,(bdf->prop_max+=10)*sizeof(BDFProperties));
	sel = bd->cur->sel_prop = bdf->prop_cnt++;
	bdf->props[sel].name = prop_name;
	for ( i=0; StandardProps[i].name!=NULL; ++i )
	    if ( strcmp(prop_name,StandardProps[i].name)==0 )
	break;
	if ( StandardProps[i].name!=NULL ) {
	    bdf->props[sel].type = StandardProps[i].type;
	    if ( (bdf->props[sel].type&~prt_property)==prt_string ||
		    (bdf->props[sel].type&~prt_property)==prt_atom)
		bdf->props[sel].u.str = NULL;
	    else
		bdf->props[sel].u.val = 0;
	    if ( StandardProps[i].defaultable )
		_BdfP_DefaultCurrent(bd);
	    else if ( (bdf->props[sel].type&~prt_property)==prt_string ||
		    (bdf->props[sel].type&~prt_property)==prt_atom)
		bdf->props[sel].u.str = copy("");
	} else {
	    bdf->props[sel].type = prt_property|prt_string;
	    bdf->props[sel].u.str = copy("");
	}
    } else {
	free(bdf->props[sel].name);
	bdf->props[sel].name = prop_name;
    }
    GDrawRequestExpose(bd->v,NULL,false);
}
Ejemplo n.º 20
0
/* Fgets:
 * Read a complete line.
 * Return pointer to line, 
 * or 0 on EOF
 */
static char *Fgets(FILE * fp)
{
    static int bsize = 0;
    static char *buf;
    char *lp;
    int len;

    len = 0;
    do {
	if (bsize - len < BUFSIZ) {
	    bsize += BUFSIZ;
	    buf = grealloc(buf, bsize);
	}
	lp = fgets(buf + len, bsize - len, fp);
	if (lp == 0)
	    break;
	len += strlen(lp);	/* since lp != NULL, len > 0 */
    } while (buf[len - 1] != '\n');

    if (len > 0)
	return buf;
    else
	return 0;
}
Ejemplo n.º 21
0
void SFAddGlyphAndEncode(SplineFont *sf,SplineChar *sc,EncMap *basemap, int baseenc) {
    int gid, mapfound = false;
    FontViewBase *fv;
    BDFFont *bdf;

    if ( sf->cidmaster==NULL ) {
	if ( sf->glyphcnt+1>=sf->glyphmax )
	    sf->glyphs = grealloc(sf->glyphs,(sf->glyphmax+=10)*sizeof(SplineChar *));
	gid = sf->glyphcnt++;
	for ( bdf = sf->bitmaps; bdf!=NULL; bdf=bdf->next ) {
	    if ( sf->glyphcnt+1>=bdf->glyphmax )
		bdf->glyphs = grealloc(bdf->glyphs,(bdf->glyphmax=sf->glyphmax)*sizeof(BDFChar *));
	    if ( sf->glyphcnt>bdf->glyphcnt ) {
		memset(bdf->glyphs+bdf->glyphcnt,0,(sf->glyphcnt-bdf->glyphcnt)*sizeof(BDFChar *));
		bdf->glyphcnt = sf->glyphcnt;
	    }
	}
	for ( fv=sf->fv; fv!=NULL; fv = fv->nextsame ) {
	    EncMap *map = fv->map;
	    if ( gid>=map->backmax )
		map->backmap = grealloc(map->backmap,(map->backmax=gid+10)*sizeof(int));
	    map->backmap[gid] = -1;
	}
    } else {
	gid = baseenc;
	if ( baseenc+1>=sf->glyphmax )
	    sf->glyphs = grealloc(sf->glyphs,(sf->glyphmax = baseenc+10)*sizeof(SplineChar *));
	if ( baseenc>=sf->glyphcnt ) {
	    memset(sf->glyphs+sf->glyphcnt,0,(baseenc+1-sf->glyphcnt)*sizeof(SplineChar *));
	    sf->glyphcnt = baseenc+1;
	    for ( bdf = sf->cidmaster->bitmaps; bdf!=NULL; bdf=bdf->next ) {
		if ( baseenc+1>=bdf->glyphmax )
		    bdf->glyphs = grealloc(bdf->glyphs,(bdf->glyphmax=baseenc+10)*sizeof(BDFChar *));
		if ( baseenc+1>bdf->glyphcnt ) {
		    memset(bdf->glyphs+bdf->glyphcnt,0,(baseenc+1-bdf->glyphcnt)*sizeof(BDFChar *));
		    bdf->glyphcnt = baseenc+1;
		}
	    }
	    for ( fv=sf->fv; fv!=NULL; fv = fv->nextsame ) if ( fv->sf==sf ) {
		EncMap *map = fv->map;
		if ( gid>=map->backmax )
		    map->backmap = grealloc(map->backmap,(map->backmax=gid+10)*sizeof(int));
		map->backmap[gid] = -1;
	    }
	}
    }
    sf->glyphs[gid] = NULL;
    for ( fv=sf->fv; fv!=NULL; fv = fv->nextsame ) {
	EncMap *map = fv->map;

	FVBiggerGlyphCache(fv,gid);

	if ( !MapAddEnc(sf,sc,basemap,map,baseenc,gid,fv) )
	    FVAddEncodingSlot(fv,gid);
	if ( map==basemap ) mapfound = true;
	if ( fv->normal!=NULL ) {
	    if ( !MapAddEnc(sf,sc,basemap,fv->normal,baseenc,gid,fv))
		MapAddEncodingSlot(fv->normal,gid);
	}
    }
    if ( !mapfound && basemap!=NULL )
	MapAddEnc(sf,sc,basemap,basemap,baseenc,gid,fv);
    sf->glyphs[gid] = sc;
    sc->orig_pos = gid;
    sc->parent = sf;
    SFHashGlyph(sf,sc);
}
Ejemplo n.º 22
0
/* a variant of xml_string for urls in hrefs */
char *xml_url_string(char *s)
{
    static char *buf = NULL;
    static int bufsize = 0;
    char *p, *sub;
#if 0
    char *prev = NULL;
#endif
    int len, pos = 0;

    if (!buf) {
	bufsize = 64;
	buf = gmalloc(bufsize);
    }

    p = buf;
    while (s && *s) {
	if (pos > (bufsize - 8)) {
	    bufsize *= 2;
	    buf = grealloc(buf, bufsize);
	    p = buf + pos;
	}
	/* escape '&' only if not part of a legal entity sequence */
	if (*s == '&' && !(xml_isentity(s))) {
	    sub = "&amp;";
	    len = 5;
	}
	/* '<' '>' are safe to substitute even if string is already UTF-8 coded
	 * since UTF-8 strings won't contain '<' or '>' */
	else if (*s == '<') {
	    sub = "&lt;";
	    len = 4;
	}
	else if (*s == '>') {
	    sub = "&gt;";
	    len = 4;
	}
#if 0
	else if (*s == '-') {	/* can't be used in xml comment strings */
	    sub = "&#45;";
	    len = 5;
	}
	else if (*s == ' ' && prev && *prev == ' ') {
	    /* substitute 2nd and subsequent spaces with required_spaces */
	    sub = "&#160;";  /* inkscape doesn't recognise &nbsp; */
	    len = 6;
	}
#endif
	else if (*s == '"') {
	    sub = "&quot;";
	    len = 6;
	}
	else if (*s == '\'') {
	    sub = "&#39;";
	    len = 5;
	}
	else {
	    sub = s;
	    len = 1;
	}
	while (len--) {
	    *p++ = *sub++;
	    pos++;
	}
#if 0
	prev = s;
#endif
	s++;
    }
    *p = '\0';
    return buf;
}
Ejemplo n.º 23
0
EncMap *EncMapFromEncoding(SplineFont *sf,Encoding *enc) {
    int i,j, extras, found, base, unmax;
    int *encoded, *unencoded;
    EncMap *map;
    struct altuni *altuni;
    SplineChar *sc;

    if ( enc==NULL )
return( NULL );

    base = enc->char_cnt;
    if ( enc->is_original )
	base = 0;
    else if ( enc->char_cnt<=256 )
	base = 256;
    else if ( enc->char_cnt<=0x10000 )
	base = 0x10000;
    if (base==0) 
return( NULL );
    encoded = galloc(base*sizeof(int));
    memset(encoded,-1,base*sizeof(int));
    unencoded = galloc(sf->glyphcnt*sizeof(int));
    unmax = sf->glyphcnt;

    for ( i=extras=0; i<sf->glyphcnt; ++i ) if ( (sc=sf->glyphs[i])!=NULL ) {
	found = false;
	if ( enc->psnames!=NULL ) {
	    for ( j=enc->char_cnt-1; j>=0; --j ) {
		if ( enc->psnames[j]!=NULL &&
			strcmp(enc->psnames[j],sc->name)==0 ) {
		    found = true;
		    encoded[j] = i;
		}
	    }
	}
	if ( !found ) {
	    if ( sc->unicodeenc!=-1 &&
		     sc->unicodeenc<unicode4_size &&
		     (j = EncFromUni(sc->unicodeenc,enc))!= -1 )
		encoded[j] = i;
	    else {
		/* I don't think extras can surpass unmax now, but it doesn't */
		/*  hurt to leave the code (it's from when we encoded duplicates see below) */
		if ( extras>=unmax ) unencoded = grealloc(unencoded,(unmax+=300)*sizeof(int));
		unencoded[extras++] = i;
	    }
	    for ( altuni=sc->altuni; altuni!=NULL; altuni=altuni->next ) {
		if ( altuni->unienc!=-1 &&
			 altuni->unienc<unicode4_size &&
			 altuni->vs==-1 &&
			 altuni->fid==0 &&
			 (j = EncFromUni(altuni->unienc,enc))!= -1 )
		    encoded[j] = i;
		/* I used to have code here to add these unencoded duplicates */
		/*  but I don't really see any reason to do so. The main unicode */
		/*  will occur, and any encoded duplicates so the glyph won't */
		/*  vanish */
	    }
	}
    }

    /* Some glyphs have both a pua encoding and an encoding in a non-bmp */
    /*  plane. Big5HK does and the AMS glyphs do */
    if ( enc->is_unicodefull && (sf->uni_interp == ui_trad_chinese ||
				 sf->uni_interp == ui_ams )) {
	extern const int cns14pua[], amspua[];
	const int *pua = sf->uni_interp == ui_ams? amspua : cns14pua;
	for ( i=0xe000; i<0xf8ff; ++i ) {
	    if ( pua[i-0xe000]!=0 )
		encoded[pua[i-0xe000]] = encoded[i];
	}
    }

    if ( enc->psnames != NULL ) {
	/* Names are more important than unicode code points for some encodings */
	/*  AdobeStandard for instance which won't work if you have a glyph  */
	/*  named "f_i" (must be "fi") even though the code point is correct */
	/* The code above would match f_i where AS requires fi, so force the */
	/*  names to be correct. */
	for ( j=0; j<enc->char_cnt; ++j ) {
	    if ( encoded[j]!=-1 && enc->psnames[j]!=NULL &&
		    strcmp(sf->glyphs[encoded[j]]->name,enc->psnames[j])!=0 ) {
		free(sf->glyphs[encoded[j]]->name);
		sf->glyphs[encoded[j]]->name = copy(enc->psnames[j]);
	    }
	}
    }

    map = chunkalloc(sizeof(EncMap));
    map->enccount = map->encmax = base + extras;
    map->map = galloc(map->enccount*sizeof(int));
    memcpy(map->map,encoded,base*sizeof(int));
    memcpy(map->map+base,unencoded,extras*sizeof(int));
    map->backmax = sf->glyphcnt;
    map->backmap = galloc(sf->glyphcnt*sizeof(int));
    memset(map->backmap,-1,sf->glyphcnt*sizeof(int));	/* Just in case there are some unencoded glyphs (duplicates perhaps) */
    for ( i = map->enccount-1; i>=0; --i ) if ( map->map[i]!=-1 )
	map->backmap[map->map[i]] = i;
    map->enc = enc;

    free(encoded);
    free(unencoded);

return( map );
}
Ejemplo n.º 24
0
static int growcol_key(GGadget *g, GEvent *event) {
    GRowCol *grc = (GRowCol *) g;
    uint16 keysym = event->u.chr.keysym;
    int sofar_pos = grc->sofar_pos;
    int loff, xoff, sel=-1;
    int refresh = false;

    if ( event->type == et_charup )
return( false );
    if ( !g->takes_input || (g->state!=gs_enabled && g->state!=gs_active && g->state!=gs_focused ))
return(false );

    if ( grc->ispopup && event->u.chr.keysym == GK_Return ) {
	GRowColDoubleClick(grc);
return( true );
    }

    if ( event->u.chr.keysym == GK_Return || event->u.chr.keysym == GK_Tab ||
	    event->u.chr.keysym == GK_BackTab || event->u.chr.keysym == GK_Escape )
return( false );

    GDrawCancelTimer(grc->enduser); grc->enduser = NULL; grc->sofar_pos = 0;

    loff = 0x80000000; xoff = 0x80000000; sel = -1;
    if ( keysym == GK_Home || keysym == GK_KP_Home || keysym == GK_Begin || keysym == GK_KP_Begin ) {
	loff = -grc->loff;
	xoff = -grc->xoff;
	sel = 0;
    } else if ( keysym == GK_End || keysym == GK_KP_End ) {
	loff = GRowColTopInWindow(grc,grc->ltot-1)-grc->loff;
	xoff = -grc->xoff;
	sel = grc->ltot-1;
    } else if ( keysym == GK_Up || keysym == GK_KP_Up ) {
	if (( sel = GRowColGetFirstSelPos(&grc->g)-1 )<0 ) {
	    /*if ( grc->loff!=0 ) loff = -1; else loff = 0;*/
	    sel = 0;
	}
    } else if ( keysym == GK_Down || keysym == GK_KP_Down ) {
	if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 )
	    ++sel;
	else
	    /*if ( grc->loff + GRowColLinesInWindow(grc,grc->loff)<grc->ltot ) loff = 1; else loff = 0;*/
	    sel = 0;
    } else if ( keysym == GK_Left || keysym == GK_KP_Left ) {
	xoff = -GDrawPointsToPixels(grc->g.base,6);
    } else if ( keysym == GK_Right || keysym == GK_KP_Right ) {
	xoff = GDrawPointsToPixels(grc->g.base,6);
    } else if ( keysym == GK_Page_Up || keysym == GK_KP_Page_Up ) {
	loff = GRowColTopInWindow(grc,grc->loff);
	if ( loff == grc->loff )		/* Normally we leave one line in window from before, except if only one line fits */
	    loff = GRowColTopInWindow(grc,grc->loff-1);
	loff -= grc->loff;
	if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 ) {
	    if (( sel += loff )<0 ) sel = 0;
	}
    } else if ( keysym == GK_Page_Down || keysym == GK_KP_Page_Down ) {
	loff = GRowColLinesInWindow(grc,grc->loff)-1;
	if ( loff<=0 ) loff = 1;
	if ( loff + grc->loff >= grc->ltot )
	    loff = GRowColTopInWindow(grc,grc->ltot-1)-grc->loff;
	if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 ) {
	    if (( sel += loff )>=grc->ltot ) sel = grc->ltot-1;
	}
    } else if ( keysym == GK_BackSpace && grc->orderer ) {
	/* ordered lists may be reversed by typing backspace */
	grc->backwards = !grc->backwards;
	GRowColOrderIt(grc);
	sel = GRowColGetFirstSelPos(&grc->g);
	if ( sel!=-1 ) {
	    int top = GRowColTopInWindow(grc,grc->ltot-1);
	    grc->loff = sel-1;
	    if ( grc->loff > top )
		grc->loff = top;
	    if ( sel-1<0 )
		grc->loff = 0;
	}
	GScrollBarSetPos(&grc->vsb->g,grc->loff);
	_ggadget_redraw(&grc->g);
return( true );
    } else if ( event->u.chr.chars[0]!='\0' && grc->orderer ) {
	int len = u_strlen(event->u.chr.chars);
	if ( sofar_pos+len >= grc->sofar_max ) {
	    if ( grc->sofar_max == 0 )
		grc->sofar = galloc((grc->sofar_max = len+10) * sizeof(unichar_t));
	    else
		grc->sofar = grealloc(grc->sofar,(grc->sofar_max = sofar_pos+len+10)*sizeof(unichar_t));
	}
	u_strcpy(grc->sofar+sofar_pos,event->u.chr.chars);
	grc->sofar_pos = sofar_pos + len;
	sel = GRowColFindPosition(grc,grc->sofar);
	grc->enduser = GDrawRequestTimer(grc->g.base,GRowColTypeTime,0,NULL);
    }

    if ( loff==0x80000000 && sel>=0 ) {
	if ( sel>=grc->ltot ) sel = grc->ltot-1;
	if ( sel<grc->loff ) loff = sel-grc->loff;
	else if ( sel>=grc->loff+GRowColLinesInWindow(grc,grc->loff) )
	    loff = sel-(grc->loff+GRowColLinesInWindow(grc,grc->loff)-1);
    } else
	sel = -1;
    if ( sel!=-1 ) {
	int wassel = grc->ti[sel]->selected;
	refresh = GRowColAnyOtherSels(grc,sel) || !wassel;
	GRowColSelectOne(&grc->g,sel);
	if ( refresh )
	    GRowColSelected(grc);
    }
    if ( loff!=0x80000000 || xoff!=0x80000000 ) {
	if ( loff==0x80000000 ) loff = 0;
	if ( xoff==0x80000000 ) xoff = 0;
	GRowColScrollBy(grc,loff,xoff);
    }
    if ( refresh )
	_ggadget_redraw(g);
    if ( loff!=0x80000000 || xoff!=0x80000000 || sel!=-1 )
return( true );

return( false );
}
Ejemplo n.º 25
0
/*
	cgraph requires 

*/
void graph_init(graph_t * g, boolean use_rankdir)
{
    char *p;
    double xf;
    static char *rankname[] = { "local", "global", "none", NULL };
    static int rankcode[] = { LOCAL, GLOBAL, NOCLUST, LOCAL };
    static char *fontnamenames[] = {"gd","ps","svg", NULL};
    static int fontnamecodes[] = {NATIVEFONTS,PSFONTS,SVGFONTS,-1};
    int rankdir;
    GD_drawing(g) = NEW(layout_t);

    /* set this up fairly early in case any string sizes are needed */
    if ((p = agget(g, "fontpath")) || (p = getenv("DOTFONTPATH"))) {
	/* overide GDFONTPATH in local environment if dot
	 * wants its own */
#ifdef HAVE_SETENV
	setenv("GDFONTPATH", p, 1);
#else
	static char *buf = 0;

	buf = grealloc(buf, strlen("GDFONTPATH=") + strlen(p) + 1);
	strcpy(buf, "GDFONTPATH=");
	strcat(buf, p);
	putenv(buf);
#endif
    }

    GD_charset(g) = findCharset (g);

    if (!HTTPServerEnVar) {
	Gvimagepath = agget (g, "imagepath");
	if (!Gvimagepath)
	    Gvimagepath = Gvfilepath;
    }

    GD_drawing(g)->quantum =
	late_double(g, agfindgraphattr(g, "quantum"), 0.0, 0.0);

    /* setting rankdir=LR is only defined in dot,
     * but having it set causes shape code and others to use it. 
     * The result is confused output, so we turn it off unless requested.
     * This effective rankdir is stored in the bottom 2 bits of g->u.rankdir.
     * Sometimes, the code really needs the graph's rankdir, e.g., neato -n
     * with record shapes, so we store the real rankdir in the next 2 bits.
     */
    rankdir = RANKDIR_TB;
    if ((p = agget(g, "rankdir"))) {
	if (streq(p, "LR"))
	    rankdir = RANKDIR_LR;
	else if (streq(p, "BT"))
	    rankdir = RANKDIR_BT;
	else if (streq(p, "RL"))
	    rankdir = RANKDIR_RL;
    }
    if (use_rankdir)
	SET_RANKDIR (g, (rankdir << 2) | rankdir);
    else
	SET_RANKDIR (g, (rankdir << 2));

    xf = late_double(g, agfindgraphattr(g, "nodesep"),
		DEFAULT_NODESEP, MIN_NODESEP);
    GD_nodesep(g) = POINTS(xf);

    p = late_string(g, agfindgraphattr(g, "ranksep"), NULL);
    if (p) {
	if (sscanf(p, "%lf", &xf) == 0)
	    xf = DEFAULT_RANKSEP;
	else {
	    if (xf < MIN_RANKSEP)
		xf = MIN_RANKSEP;
	}
	if (strstr(p, "equally"))
	    GD_exact_ranksep(g) = TRUE;
    } else
	xf = DEFAULT_RANKSEP;
    GD_ranksep(g) = POINTS(xf);

    GD_showboxes(g) = late_int(g, agfindgraphattr(g, "showboxes"), 0, 0);
    p = late_string(g, agfindgraphattr(g, "fontnames"), NULL);
    GD_fontnames(g) = maptoken(p, fontnamenames, fontnamecodes);

    setRatio(g);
    GD_drawing(g)->filled =
	getdoubles2ptf(g, "size", &(GD_drawing(g)->size));
    getdoubles2ptf(g, "page", &(GD_drawing(g)->page));

    GD_drawing(g)->centered = mapbool(agget(g, "center"));

    if ((p = agget(g, "rotate")))
	GD_drawing(g)->landscape = (atoi(p) == 90);
    else if ((p = agget(g, "orientation")))
	GD_drawing(g)->landscape = ((p[0] == 'l') || (p[0] == 'L'));
    else if ((p = agget(g, "landscape")))
	GD_drawing(g)->landscape = mapbool(p);

    p = agget(g, "clusterrank");
    CL_type = maptoken(p, rankname, rankcode);
    p = agget(g, "concentrate");
    Concentrate = mapbool(p);
    State = GVBEGIN;
    EdgeLabelsDone = 0;

    GD_drawing(g)->dpi = 0.0;
    if (((p = agget(g, "dpi")) && p[0])
	|| ((p = agget(g, "resolution")) && p[0]))
	GD_drawing(g)->dpi = atof(p);

    do_graph_label(g);

    Initial_dist = MYHUGE;

    G_ordering = agfindgraphattr(g, "ordering");
    G_gradientangle = agfindgraphattr(g,"gradientangle");
    G_margin = agfindgraphattr(g, "margin");

    /* initialize nodes */
    N_height = agfindnodeattr(g, "height");
    N_width = agfindnodeattr(g, "width");
    N_shape = agfindnodeattr(g, "shape");
    N_color = agfindnodeattr(g, "color");
    N_fillcolor = agfindnodeattr(g, "fillcolor");
    N_style = agfindnodeattr(g, "style");
    N_fontsize = agfindnodeattr(g, "fontsize");
    N_fontname = agfindnodeattr(g, "fontname");
    N_fontcolor = agfindnodeattr(g, "fontcolor");
    N_label = agfindnodeattr(g, "label");
    if (!N_label)
	N_label = agattr(g, AGNODE, "label", NODENAME_ESC);
    N_xlabel = agfindnodeattr(g, "xlabel");
    N_showboxes = agfindnodeattr(g, "showboxes");
    N_penwidth = agfindnodeattr(g, "penwidth");
    N_ordering = agfindnodeattr(g, "ordering");
    N_margin = agfindnodeattr(g, "margin");
    /* attribs for polygon shapes */
    N_sides = agfindnodeattr(g, "sides");
    N_peripheries = agfindnodeattr(g, "peripheries");
    N_skew = agfindnodeattr(g, "skew");
    N_orientation = agfindnodeattr(g, "orientation");
    N_distortion = agfindnodeattr(g, "distortion");
    N_fixed = agfindnodeattr(g, "fixedsize");
    N_imagescale = agfindnodeattr(g, "imagescale");
    N_nojustify = agfindnodeattr(g, "nojustify");
    N_layer = agfindnodeattr(g, "layer");
    N_group = agfindnodeattr(g, "group");
    N_comment = agfindnodeattr(g, "comment");
    N_vertices = agfindnodeattr(g, "vertices");
    N_z = agfindnodeattr(g, "z");
    N_gradientangle = agfindnodeattr(g,"gradientangle");

    /* initialize edges */
    E_weight = agfindedgeattr(g, "weight");
    E_color = agfindedgeattr(g, "color");
    E_fillcolor = agfindedgeattr(g, "fillcolor");
    E_fontsize = agfindedgeattr(g, "fontsize");
    E_fontname = agfindedgeattr(g, "fontname");
    E_fontcolor = agfindedgeattr(g, "fontcolor");
    E_label = agfindedgeattr(g, "label");
    E_xlabel = agfindedgeattr(g, "xlabel");
    E_label_float = agfindedgeattr(g, "labelfloat");
    /* vladimir */
    E_dir = agfindedgeattr(g, "dir");
    E_arrowhead = agfindedgeattr(g, "arrowhead");
    E_arrowtail = agfindedgeattr(g, "arrowtail");
    E_headlabel = agfindedgeattr(g, "headlabel");
    E_taillabel = agfindedgeattr(g, "taillabel");
    E_labelfontsize = agfindedgeattr(g, "labelfontsize");
    E_labelfontname = agfindedgeattr(g, "labelfontname");
    E_labelfontcolor = agfindedgeattr(g, "labelfontcolor");
    E_labeldistance = agfindedgeattr(g, "labeldistance");
    E_labelangle = agfindedgeattr(g, "labelangle");
    /* end vladimir */
    E_minlen = agfindedgeattr(g, "minlen");
    E_showboxes = agfindedgeattr(g, "showboxes");
    E_style = agfindedgeattr(g, "style");
    E_decorate = agfindedgeattr(g, "decorate");
    E_arrowsz = agfindedgeattr(g, "arrowsize");
    E_constr = agfindedgeattr(g, "constraint");
    E_layer = agfindedgeattr(g, "layer");
    E_comment = agfindedgeattr(g, "comment");
    E_tailclip = agfindedgeattr(g, "tailclip");
    E_headclip = agfindedgeattr(g, "headclip");
    E_penwidth = agfindedgeattr(g, "penwidth");

    /* background */
    GD_drawing(g)->xdots = init_xdot (g);

    /* initialize id, if any */

    if ((p = agget(g, "id")) && *p)
	GD_drawing(g)->id = strdup_and_subst_obj(p, g);
}
Ejemplo n.º 26
0
static void InsertSubMenus(PyObject *args,GMenuItem2 **mn, int is_cv) {
    int i, j, cnt;
    PyObject *func, *check, *data;
    char *shortcut_str;
    GMenuItem2 *mmn;

    /* I've done type checking already */
    cnt = PyTuple_Size(args);
    func = PyTuple_GetItem(args,0);
    if ( (check = PyTuple_GetItem(args,1))==Py_None )
        check = NULL;
    data = PyTuple_GetItem(args,2);
    if ( PyTuple_GetItem(args,4)==Py_None )
        shortcut_str = NULL;
    else {
#if PY_MAJOR_VERSION >= 3
        PyObject *obj = PyUnicode_AsUTF8String(PyTuple_GetItem(args,4));
        shortcut_str = PyBytes_AsString(obj);
#else /* PY_MAJOR_VERSION >= 3 */
        shortcut_str = PyBytes_AsString(PyTuple_GetItem(args,4));
#endif /* PY_MAJOR_VERSION >= 3 */
    }

    for ( i=5; i<cnt; ++i ) {
        PyObject *submenu_utf8 = PYBYTES_UTF8(PyTuple_GetItem(args,i));
        unichar_t *submenuu = utf82u_copy( PyBytes_AsString(submenu_utf8) );
        Py_DECREF(submenu_utf8);

        j = 0;
        if ( *mn != NULL ) {
            for ( j=0; (*mn)[j].ti.text!=NULL || (*mn)[j].ti.line; ++j ) {
                if ( (*mn)[j].ti.text==NULL )
                    continue;
                if ( u_strcmp((*mn)[j].ti.text,submenuu)==0 )
                    break;
            }
        }
        if ( *mn==NULL || (*mn)[j].ti.text==NULL ) {
            *mn = grealloc(*mn,(j+2)*sizeof(GMenuItem2));
            memset(*mn+j,0,2*sizeof(GMenuItem2));
        }
        mmn = *mn;
        if ( mmn[j].ti.text==NULL ) {
            mmn[j].ti.text = submenuu;
            mmn[j].ti.fg = mmn[j].ti.bg = COLOR_DEFAULT;
            if ( i!=cnt-1 ) {
                mmn[j].mid = -1;
                mmn[j].moveto = is_cv ? cvpy_tllistcheck : fvpy_tllistcheck;
                mn = &mmn[j].sub;
            } else {
                mmn[j].shortcut = shortcut_str;
                mmn[j].invoke = is_cv ? cvpy_menuactivate : fvpy_menuactivate;
                mmn[j].mid = MenuDataAdd(func,check,data,is_cv);
            }
        } else {
            if ( i!=cnt-1 )
                mn = &mmn[j].sub;
            else {
                mmn[j].shortcut = shortcut_str;
                mmn[j].invoke = is_cv ? cvpy_menuactivate : fvpy_menuactivate;
                mmn[j].mid = MenuDataAdd(func,check,data,is_cv);
                fprintf( stderr, "Redefining menu item %s\n", u2utf8_copy(submenuu) );
                free(submenuu);
            }
        }
    }
}
Ejemplo n.º 27
0
static void InsertSubMenus(PyObject *args,struct python_menu_shell *mn, int is_cv) {
    int i, j, cnt;
    PyObject *func, *check, *data;
    char *shortcut_str;

    /* I've done type checking already */
    cnt = PyTuple_Size(args);
    func = PyTuple_GetItem(args,0);
    if ( (check = PyTuple_GetItem(args,1))==Py_None )
	check = NULL;
    data = PyTuple_GetItem(args,2);
    if ( PyTuple_GetItem(args,4)==Py_None )
	shortcut_str = NULL;
    else
	shortcut_str = PyString_AsString(PyTuple_GetItem(args,4));

    for ( i=5; i<cnt; ++i ) {
	PyObject *submenu_utf8 = PyString_AsEncodedObject(PyTuple_GetItem(args,i),
		"UTF-8",NULL);
	char *submenu = copy( PyString_AsString(submenu_utf8) );
	Py_DECREF(submenu_utf8);

	j = 0;
	if ( mn->menu!=NULL ) {
	    for ( j=0; mn->menu[j].name!=NULL || mn->menu[j].line; ++j ) {
		if ( mn->menu[j].name==NULL )
	    continue;
		if ( strcmp(mn->menu[j].name,submenu)==0 )
	    break;
	    }
	}
	if ( mn->menu==NULL || mn->menu[j].name==NULL ) {
	    if ( mn->cnt<=mn->max )
		mn->menu = grealloc(mn->menu,((mn->max+=5)+1)*sizeof(struct python_menu_info));
	    memset(mn->menu+j,0,2*sizeof(struct python_menu_info));
	}
	if ( mn->menu[j].name==NULL )
	    mn->menu[j].name = submenu;
	else {
	    if ( mn->menu[j].func!=NULL ) {
		Py_DECREF(mn->menu[j].func);
		Py_DECREF(mn->menu[j].data);
	    }
	    if ( mn->menu[j].check_enabled!=NULL ) {
		Py_DECREF(mn->menu[j].check_enabled);
	    }
	    mn->menu[j].func = mn->menu[j].data = mn->menu[j].check_enabled = NULL;
	}
	if ( i!=cnt-1 ) {
	    if ( mn->menu[j].sub_menu==NULL )
		mn->menu[j].sub_menu = gcalloc(1,sizeof(struct python_menu_shell));
	    mn = mn->menu[j].sub_menu;
	} else {
	    Py_INCREF(func);
	    if ( check!=NULL )
		Py_INCREF(check);
	    Py_INCREF(data);

	    mn->menu[j].shortcut_str = copy(shortcut_str);
	    mn->menu[j].func = func;
	    mn->menu[j].check_enabled = check;
	    mn->menu[j].data = data;
	    mn->menu[j].sub_menu = NULL;
	}
    }
}
Ejemplo n.º 28
0
int colorxlate(char *str, gvcolor_t * color, color_type_t target_type)
{
    static hsvrgbacolor_t *last;
    static unsigned char *canon;
    static int allocated;
    unsigned char *p, *q;
    hsvrgbacolor_t fake;
    unsigned char c;
    double H, S, V, A, R, G, B;
    double C, M, Y, K;
    unsigned int r, g, b, a;
    int len, rc;

    color->type = target_type;

    rc = COLOR_OK;
    for (; *str == ' '; str++);	/* skip over any leading whitespace */
    p = (unsigned char *) str;

    /* test for rgb value such as: "#ff0000"
       or rgba value such as "#ff000080" */
    a = 255;			/* default alpha channel value=opaque in case not supplied */
    if ((*p == '#')
	&& (sscanf((char *) p, "#%2x%2x%2x%2x", &r, &g, &b, &a) >= 3)) {
	switch (target_type) {
	case HSVA_DOUBLE:
	    R = (double) r / 255.0;
	    G = (double) g / 255.0;
	    B = (double) b / 255.0;
	    A = (double) a / 255.0;
	    rgb2hsv(R, G, B, &H, &S, &V);
	    color->u.HSVA[0] = H;
	    color->u.HSVA[1] = S;
	    color->u.HSVA[2] = V;
	    color->u.HSVA[3] = A;
	    break;
	case RGBA_BYTE:
	    color->u.rgba[0] = r;
	    color->u.rgba[1] = g;
	    color->u.rgba[2] = b;
	    color->u.rgba[3] = a;
	    break;
	case CMYK_BYTE:
	    R = (double) r / 255.0;
	    G = (double) g / 255.0;
	    B = (double) b / 255.0;
	    rgb2cmyk(R, G, B, &C, &M, &Y, &K);
	    color->u.cmyk[0] = (int) C *255;
	    color->u.cmyk[1] = (int) M *255;
	    color->u.cmyk[2] = (int) Y *255;
	    color->u.cmyk[3] = (int) K *255;
	    break;
	case RGBA_WORD:
	    color->u.rrggbbaa[0] = r * 65535 / 255;
	    color->u.rrggbbaa[1] = g * 65535 / 255;
	    color->u.rrggbbaa[2] = b * 65535 / 255;
	    color->u.rrggbbaa[3] = a * 65535 / 255;
	    break;
	case RGBA_DOUBLE:
	    color->u.RGBA[0] = (double) r / 255.0;
	    color->u.RGBA[1] = (double) g / 255.0;
	    color->u.RGBA[2] = (double) b / 255.0;
	    color->u.RGBA[3] = (double) a / 255.0;
	    break;
	case COLOR_STRING:
	    break;
	case COLOR_INDEX:
	    break;
	}
	return rc;
    }

    /* test for hsv value such as: ".6,.5,.3" */
    if (((c = *p) == '.') || isdigit(c)) {
	len = strlen((char*)p);
	if (len >= allocated) {
	    allocated = len + 1 + 10;
	    canon = grealloc(canon, allocated);
	    if (! canon) {
		rc = COLOR_MALLOC_FAIL;
		return rc;
	    }
	}
	q = canon;
	while ((c = *p++)) {
	    if (c == ',')
		c = ' ';
	    *q++ = c;
	}
	*q = '\0';

	if (sscanf((char *) canon, "%lf%lf%lf", &H, &S, &V) == 3) {
	    /* clip to reasonable values */
	    H = MAX(MIN(H, 1.0), 0.0);
	    S = MAX(MIN(S, 1.0), 0.0);
	    V = MAX(MIN(V, 1.0), 0.0);
	    switch (target_type) {
	    case HSVA_DOUBLE:
		color->u.HSVA[0] = H;
		color->u.HSVA[1] = S;
		color->u.HSVA[2] = V;
		color->u.HSVA[3] = 1.0; /* opaque */
		break;
	    case RGBA_BYTE:
		hsv2rgb(H, S, V, &R, &G, &B);
		color->u.rgba[0] = (int) (R * 255);
		color->u.rgba[1] = (int) (G * 255);
		color->u.rgba[2] = (int) (B * 255);
		color->u.rgba[3] = 255;	/* opaque */
		break;
	    case CMYK_BYTE:
		hsv2rgb(H, S, V, &R, &G, &B);
		rgb2cmyk(R, G, B, &C, &M, &Y, &K);
		color->u.cmyk[0] = (int) C *255;
		color->u.cmyk[1] = (int) M *255;
		color->u.cmyk[2] = (int) Y *255;
		color->u.cmyk[3] = (int) K *255;
		break;
	    case RGBA_WORD:
		hsv2rgb(H, S, V, &R, &G, &B);
		color->u.rrggbbaa[0] = (int) (R * 65535);
		color->u.rrggbbaa[1] = (int) (G * 65535);
		color->u.rrggbbaa[2] = (int) (B * 65535);
		color->u.rrggbbaa[3] = 65535;	/* opaque */
		break;
	    case RGBA_DOUBLE:
		hsv2rgb(H, S, V, &R, &G, &B);
		color->u.RGBA[0] = R;
		color->u.RGBA[1] = G;
		color->u.RGBA[2] = B;
		color->u.RGBA[3] = 1.0;	/* opaque */
		break;
	    case COLOR_STRING:
		break;
	    case COLOR_INDEX:
		break;
	    }
	    return rc;
	}
    }

    /* test for known color name (generic, not renderer specific known names) */
    fake.name = resolveColor(str);
    if (!fake.name)
	return COLOR_MALLOC_FAIL;
    if ((last == NULL)
	|| (last->name[0] != fake.name[0])
	|| (strcmp(last->name, fake.name))) {
	last = (hsvrgbacolor_t *) bsearch((void *) &fake,
				      (void *) color_lib,
				      sizeof(color_lib) /
				      sizeof(hsvrgbacolor_t), sizeof(fake),
				      colorcmpf);
    }
    if (last != NULL) {
	switch (target_type) {
	case HSVA_DOUBLE:
	    color->u.HSVA[0] = ((double) last->h) / 255.0;
	    color->u.HSVA[1] = ((double) last->s) / 255.0;
	    color->u.HSVA[2] = ((double) last->v) / 255.0;
	    color->u.HSVA[3] = ((double) last->a) / 255.0;
	    break;
	case RGBA_BYTE:
	    color->u.rgba[0] = last->r;
	    color->u.rgba[1] = last->g;
	    color->u.rgba[2] = last->b;
	    color->u.rgba[3] = last->a;
	    break;
	case CMYK_BYTE:
	    R = (last->r) / 255.0;
	    G = (last->g) / 255.0;
	    B = (last->b) / 255.0;
	    rgb2cmyk(R, G, B, &C, &M, &Y, &K);
	    color->u.cmyk[0] = (int) C * 255;
	    color->u.cmyk[1] = (int) M * 255;
	    color->u.cmyk[2] = (int) Y * 255;
	    color->u.cmyk[3] = (int) K * 255;
	    break;
	case RGBA_WORD:
	    color->u.rrggbbaa[0] = last->r * 65535 / 255;
	    color->u.rrggbbaa[1] = last->g * 65535 / 255;
	    color->u.rrggbbaa[2] = last->b * 65535 / 255;
	    color->u.rrggbbaa[3] = last->a * 65535 / 255;
	    break;
	case RGBA_DOUBLE:
	    color->u.RGBA[0] = last->r / 255.0;
	    color->u.RGBA[1] = last->g / 255.0;
	    color->u.RGBA[2] = last->b / 255.0;
	    color->u.RGBA[3] = last->a / 255.0;
	    break;
	case COLOR_STRING:
	    break;
	case COLOR_INDEX:
	    break;
	}
	return rc;
    }

    /* if we're still here then we failed to find a valid color spec */
    rc = COLOR_UNKNOWN;
    switch (target_type) {
    case HSVA_DOUBLE:
	color->u.HSVA[0] = color->u.HSVA[1] = color->u.HSVA[2] = 0.0;
	color->u.HSVA[3] = 1.0; /* opaque */
	break;
    case RGBA_BYTE:
	color->u.rgba[0] = color->u.rgba[1] = color->u.rgba[2] = 0;
	color->u.rgba[3] = 255;	/* opaque */
	break;
    case CMYK_BYTE:
	color->u.cmyk[0] =
	    color->u.cmyk[1] = color->u.cmyk[2] = color->u.cmyk[3] = 0;
	break;
    case RGBA_WORD:
	color->u.rrggbbaa[0] = color->u.rrggbbaa[1] = color->u.rrggbbaa[2] = 0;
	color->u.rrggbbaa[3] = 65535;	/* opaque */
	break;
    case RGBA_DOUBLE:
	color->u.RGBA[0] = color->u.RGBA[1] = color->u.RGBA[2] = 0.0;
	color->u.RGBA[3] = 1.0;	/* opaque */
	break;
    case COLOR_STRING:
	break;
    case COLOR_INDEX:
	break;
    }
    return rc;
}
Ejemplo n.º 29
0
void init_ugraph(graph_t *g)
{
	char		*p;
	double		xf;
	static char *rankname[] = {"local","global","none",NULL};
	static int	rankcode[] =  {LOCAL, GLOBAL, NOCLUST, LOCAL};
	double X,Y,Z,x,y;

	GD_drawing(g) = NEW(layout_t);

	/* set this up fairly early in case any string sizes are needed */
	if ((p = agget(g,"fontpath")) || (p = getenv("DOTFONTPATH"))) {
		/* overide GDFONTPATH in local environment if dot
		 * wants its own */
#ifdef HAVE_SETENV
		setenv("GDFONTPATH", p, 1);
#else
		static char *buf=0;

		buf=grealloc(buf,strlen("GDFONTPATH=")+strlen(p)+1);
		strcpy(buf,"GDFONTPATH=");
		strcat(buf,p);
		putenv(buf);
#endif
	}

	GD_drawing(g)->quantum = late_double(g,agfindattr(g,"quantum"),0.0,0.0);
 	GD_drawing(g)->font_scale_adj = 1.0;

    /* setting rankdir=LR is only defined in dot,
     * but having it set causes shape code and others to use it. 
     * The result is confused output, so we turn it off unless requested.
     */
	if (UseRankdir)
		GD_left_to_right(g) = ((p = agget(g,"rankdir")) && streq(p,"LR"));
	else
		GD_left_to_right(g) = FALSE;
	do_graph_label(g);
	xf = late_double(g,agfindattr(g,"nodesep"),DEFAULT_NODESEP,MIN_NODESEP);
	GD_nodesep(g) = POINTS(xf);

	p = late_string(g,agfindattr(g,"ranksep"),NULL);
	if (p) {
			if (sscanf(p,"%lf",&xf) == 0) xf = DEFAULT_RANKSEP;
			else {if (xf < MIN_RANKSEP) xf = MIN_RANKSEP;}
			if (strstr(p,"equally")) GD_exact_ranksep(g) = TRUE;
	}
	else xf = DEFAULT_RANKSEP;
	GD_ranksep(g) = POINTS(xf);

	GD_showboxes(g) = late_int(g,agfindattr(g,"showboxes"),0,0);

	Epsilon = .0001 * agnnodes(g);
	getdoubles2pt(g,"size",&(GD_drawing(g)->size));
	getdoubles2pt(g,"page",&(GD_drawing(g)->page));
	getdouble(g,"epsilon",&Epsilon);
	getdouble(g,"nodesep",&Nodesep);
	getdouble(g,"nodefactor",&Nodefactor);

	X = Y = Z = x = y = 0.0;
	if ((p = agget(g,"viewport")))
            sscanf(p,"%lf,%lf,%lf,%lf,%lf",&X,&Y,&Z,&x,&y);
	GD_drawing(g)->viewport.size.x = ROUND(X); /* viewport size in dev units - pixels */
	GD_drawing(g)->viewport.size.y = ROUND(Y);
	GD_drawing(g)->viewport.zoom = Z;    /* scaling factor */
	GD_drawing(g)->viewport.focus.x = x; /* graph coord of focus - points */
	GD_drawing(g)->viewport.focus.y = y; 

	GD_drawing(g)->centered = mapbool(agget(g,"center"));
	if ((p = agget(g,"rotate"))) GD_drawing(g)->landscape = (atoi(p) == 90);
	else {		/* today we learned the importance of backward compatibilty */
		if ((p = agget(g,"orientation")))
			GD_drawing(g)->landscape = ((p[0] == 'l') || (p[0] == 'L'));
	}

	p = agget(g,"clusterrank");
	CL_type = maptoken(p,rankname,rankcode);
	p = agget(g,"concentrate");
	Concentrate = mapbool(p);
	
	Nodesep = 1.0;
	Nodefactor = 1.0;
	Initial_dist = MYHUGE;
}
Ejemplo n.º 30
0
static void CVMouseDownSpiroPoint(CharView *cv, GEvent *event) {
    SplineSet *sel, *ss;
    SplineChar *sc = cv->b.sc;
    spiro_cp *base, *cp;
    int base_index, cp_index, i;
    char ty = (cv->active_tool==cvt_curve?SPIRO_G4:
			    cv->active_tool==cvt_hvcurve?SPIRO_G2:
			    cv->active_tool==cvt_corner?SPIRO_CORNER:
			    cv->active_tool==cvt_tangent?SPIRO_LEFT:
			    /*cv->active_tool==cvt_pen?*/SPIRO_RIGHT);

    cv->active_spl = NULL;
    cv->active_sp = NULL;

    sel = CVAnySelPointList(cv);
    if ( sel!=NULL ) {
	if ( SPIRO_SELECTED(&sel->spiros[0]) ) base_index = 0;
	else base_index = sel->spiro_cnt-2;
	base = &sel->spiros[base_index];
	if ( base==cv->p.spiro )
return;			/* We clicked on the active point, that's a no-op */
    }
    CVPreserveState(&cv->b);
    CVClearSel(cv);
    if ( sel!=NULL ) {
	if ( (cp = cv->p.spiro)!=NULL )
	    cp_index = cp-cv->p.spl->spiros;
	cv->lastselcp = base;
	ss = sel;
	if ( base_index!=sel->spiro_cnt-2 ) {
	    SplineSetReverse(sel);
	    base = &sel->spiros[sel->spiro_cnt-2];
	    if ( cv->p.spl==sel ) {
		cp_index = sel->spiro_cnt-2-cp_index;
		cp = &sel->spiros[cp_index];
	    }
	}
	if ( cp==NULL || (cp_index!=0 && cp_index!=cv->p.spl->spiro_cnt-2) ||
		cp==base || !SPIRO_SPL_OPEN(cv->p.spl)) {
	    /* Add a new point */
	    if ( sel->spiro_cnt>=sel->spiro_max )
		sel->spiros = grealloc(sel->spiros,(sel->spiro_max += 10)*sizeof(spiro_cp));
	    cp = &sel->spiros[sel->spiro_cnt-1];
	    cp[1] = cp[0];		/* Move the final 'z' */
	    cp->x = cv->p.cx;
	    cp->y = cv->p.cy;
	    cp->ty = ty;
	    SPIRO_DESELECT(cp-1);
	    ++sel->spiro_cnt;
	} else if ( cv->p.spl==sel ) {
	    /* Close the current spline set */
	    sel->spiros[0].ty = ty;
	    cv->joinvalid = true;
	    cv->joincp = *cp; SPIRO_DESELECT(&cv->joincp);
	} else {
	    /* Merge two spline sets */
	    SplinePoint *sp = cp_index==0 ? cv->p.spl->first : cv->p.spl->last;
	    SplinePoint *basesp = base_index==0 ? sel->first : sel->last;
	    cv->joincp = *cp; SPIRO_DESELECT(&cv->joincp);
	    CVMergeSPLS(cv,ss,basesp,sp);
	}
    } else if ( cv->p.spline!=NULL ) {
	/* Add an intermediate point on an already existing spline */
	ss = cv->p.spl;
	if ( ss->spiro_cnt>=ss->spiro_max )
	    ss->spiros = grealloc(ss->spiros,(ss->spiro_max += 10)*sizeof(spiro_cp));
	for ( i=ss->spiro_cnt-1; i>cv->p.spiro_index; --i )
	    ss->spiros[i+1] = ss->spiros[i];
	++ss->spiro_cnt;
	cp = &ss->spiros[cv->p.spiro_index+1];
	cp->x = cv->p.cx;
	cp->y = cv->p.cy;
	cp->ty = ty;
	ss = cv->p.spl;
	cv->joinvalid = true;
	cv->joincp = *cp; SPIRO_DESELECT(&cv->joincp);
    } else {
	/* A new point on a new (open) contour */
	ss = chunkalloc(sizeof(SplineSet));
	ss->next = cv->b.layerheads[cv->b.drawmode]->splines;
	cv->b.layerheads[cv->b.drawmode]->splines = ss;
	ss->spiros = galloc((ss->spiro_max=10)*sizeof(spiro_cp));
	cp = &ss->spiros[0];
	cp->x = cv->p.cx;
	cp->y = cv->p.cy;
	cp->ty = SPIRO_OPEN_CONTOUR;
	cp[1].x = cp[1].y = 0; cp[1].ty = 'z';
	ss->spiro_cnt = 2;
    }
    SPIRO_SELECT(cp);

    SSRegenerateFromSpiros(ss);

    cv->active_spl = ss;
    cv->active_cp = cp;
    CVSetCharChanged(cv,true);
    CVInfoDraw(cv,cv->gw);
    SCUpdateAll(sc);
}