// Copyright status: this file is in the public domain. #include #include "internal.h" /* * Using LX_XID_Error for tile, stipple, and font means that explicitly * setting those attributes to LX_XID_Error in a new SGC will not push * anything for those fields. * * I consider this acceptable. If it proves to be a problem, I'll fix * it, probably by adding a "pushed this field" bitmask of some sort. */ SGC *lx__new_sgc(LX_CONN *xc) { SGC *sgc; int x; int newn; SGC **newv; sgc = malloc(sizeof(SGC)); if (! sgc) return(0); x = xc->minfreesgc; while ((x < xc->nsgc) && xc->sgcv[x]) x ++; if (x >= xc->nsgc) { newn = xc->nsgc + 16; newv = realloc(xc->sgcv,newn*sizeof(SGC *)); if (! newv) { free(sgc); return(0); } for (x=xc->nsgc;xnsgc; xc->nsgc = newn; xc->sgcv = newv; } xc->sgcv[x] = sgc; xc->minfreesgc = x + 1; sgc->xc = xc; sgc->sgcid = x; sgc->gcid = LX_GC_None; sgc->pushv.core.function = LX_GCFUNCTION_Copy; sgc->pushv.core.plane_mask = ~0U; sgc->pushv.core.foreground = 0; sgc->pushv.core.background = 1; sgc->pushv.core.line_width = 0; sgc->pushv.core.line_style = LX_GCLINESTYLE_Solid; sgc->pushv.core.cap_style = LX_GCCAPSTYLE_Butt; sgc->pushv.core.join_style = LX_GCJOINSTYLE_Miter; sgc->pushv.core.fill_style = LX_GCFILLSTYLE_Solid; sgc->pushv.core.fill_rule = LX_GCFILLRULE_EvenOdd; sgc->pushv.core.tile = LX_XID_Error; sgc->pushv.core.stipple = LX_XID_Error; sgc->pushv.core.tile_stip_x_origin = 0; sgc->pushv.core.tile_stip_y_origin = 0; sgc->pushv.core.font = LX_XID_Error; sgc->pushv.core.subwindow_mode = LX_GCSUBWINDOWMODE_ClipByChildren; sgc->pushv.core.graphics_exposures = 1; sgc->pushv.core.clip_x_origin = 0; sgc->pushv.core.clip_y_origin = 0; sgc->pushv.core.clip_mask = LX_GCCLIPMASK_None; sgc->pushv.core.dash_offset = 0; sgc->pushv.core.dashes = 4; sgc->pushv.core.arc_mode = LX_GCARCMODE_PieSlice; sgc->pushv.ndash = 0; sgc->pushv.adash = 0; sgc->pushv.dashv = 0; sgc->pushv.nrect = -1; sgc->pushv.rectv = 0; sgc->setv.ndash = 0; sgc->setv.ndash = 0; sgc->setv.adash = 0; sgc->setv.dashv = 0; sgc->setv.nrect = -1; sgc->setv.rectv = 0; sgc->set = 0; return(sgc); } void lx__free_sgc(LX_CONN *xc, SGC *sgc) { if ((sgc->xc != xc) || (sgc->sgcid >= xc->nsgc) || (xc->sgcv[sgc->sgcid] != sgc)) { lx_abort(); return; } xc->sgcv[sgc->sgcid] = 0; if (sgc->sgcid < xc->minfreesgc) xc->minfreesgc = sgc->sgcid; free(sgc->setv.dashv); free(sgc->setv.rectv); free(sgc->pushv.dashv); free(sgc->pushv.rectv); free(sgc); } SGC *lx__lookup_sgc(LX_CONN *xc, LX_SGC id) { SGC *sgc; if (id.id >= xc->nsgc) return(0); sgc = xc->sgcv[id.id]; if (! sgc) return(0); if ((sgc->xc != xc) || (sgc->sgcid != id.id)) { lx_abort(); return(0); } return(sgc); } int lx__set_sgc_dash_list_len(SGC_ATTRIBUTES *sa, int len) { char *newv; if (len == sa->ndash) return(0); if (len > sa->adash) { newv = malloc(len); if (! newv) return(1); sa->adash = len; free(sa->dashv); sa->dashv = newv; } sa->ndash = len; return(0); }