void primattrs(obj *p, struct objattr *obat) /* note: ht, wid, rad and layer are set elsewhere */ /* because of nonuniformities in their design */ /* (this could be further rationalized!) */ { int n; float x; p->o_attr |= obat->a_flags; p->o_text = obat->a_tcolor; checktextcolor(p); if (obat->a_flags & FILLED) { if (obat->a_pcolor == -1.) obat->a_pcolor = getfval ("fillcolor"); p->o_fill = checkcolor((double)obat->a_pcolor); } if (obat->a_flags & EDGED) { if (obat->a_weight == -1.) obat->a_weight = getfval ("lineweight"); if (obat->a_weight >= 0.) p->o_weight = obat->a_weight; if (obat->a_lcolor == -1.) obat->a_lcolor = getfval ("linecolor"); p->o_color = checkcolor((double)obat->a_lcolor); if ((n = (int)getfval("linecap")) >= 0) p->o_attr |= (1 + n%3)*LINECAP; if ((n = (int)getfval("linejoin")) >= 0) p->o_attr |= (1 + n%3)*JOIN; if (n == 0) { /* mitre join */ x = getfval("miterlimit"); if (x >= 1) { for (n = 1; n < 8; n++) if (miters[n] == 0 || miters[n] == x) break; if (n == 8) for (n = 1; n < 7; ++n) miters[n] = miters[n+1]; miters[n] = x; p->o_attr |= n * MITER; } } } else p->o_weight = 0; if (obat->a_dashpat.a != NULL && obat->a_dashpat.a[1] == -1) /* dots */ if ((obat->a_dashpat.a[1] = p->o_weight) == 0) obat->a_dashpat.a[1] = 1/(pgscale*2); p->o_ddpat = obat->a_dashpat; }
void checktextcolor (obj *p) { if (p->o_nt2 > p->o_nt1) { if (p->o_text == -1) p->o_text = getfval("textcolor"); p->o_text = checkcolor((double)p->o_text); } }
void checkcolor(int i, int j){ visit[i][j] = vcnt; for(int k = 0;k < 4; k ++){ int r = i + dir[k][0]; int c = j + dir[k][1]; if(r < 0 || c < 0 || r >= n || c >= m) continue; if(grp[r][c] >= 0){ v[color[grp[r][c]]] = 1; } if(grp[r][c] == grp[i][j] && visit[r][c] != vcnt) { checkcolor(r,c); } } }
double setattr(obj *p, int type, double val) { int cw_switch; double x, y; obj *q; if (p->o_type == BLOCK) { for (q = p->o_next; q != p->o_val[N_VAL].o; q = q->o_next) setattr (q, type, val); } else if (p->o_type <= TEXT) switch (type) { case TCOLOR: if (val >= 0.0 || checkcolor(val) >= 0.0) p->o_text = val; break; case LCOLOR: if (val >= 0.0 || checkcolor(val) >= 0.0) p->o_color = val; break; case PCOLOR: if (val < 0.0 || checkcolor(val) < 0.0) p->o_attr &= ~FILLED; else { p->o_fill = val; /* ignored for TEXT? */ p->o_attr |= FILLED; } break; case LAYER: if (val < -128) val = -128; else if (val > 127) val = 127; p->o_layer = (short)val; if (val > getfval("maxlayer")) setfval ("maxlayer", val); break; case LWEIGHT: p->o_weight = val; break; case NOEDGE: if (val != 0.0) p->o_attr &= ~EDGED; else p->o_attr |= EDGED; break; case CCW: case CW: if (p->o_type == ARC) { cw_switch = (p->o_attr & CW_ARC); if (type == CW) cw_switch = !cw_switch; if (cw_switch) { x = p->o_val[N_VAL+2].f; y = p->o_val[N_VAL+3].f; p->o_val[N_VAL+2] = p->o_val[N_VAL+4]; p->o_val[N_VAL+3] = p->o_val[N_VAL+5]; /* exchange from & to */ p->o_val[N_VAL+4].f = x; p->o_val[N_VAL+5].f = y; p->o_attr ^= (p->o_attr & CW_ARC); } } break; case DIAMETER: val /= 2; case RADIUS: switch (p->o_type) { case ARROW: case LINE: case BOX: case ARC: case SECTOR: p->o_val[N_VAL].f = val; break; case CIRCLE: case ELLIPSE: p->o_wid = val * 2; break; } break; case WIDTH: p->o_wid = val; break; case HEIGHT: p->o_ht = val; break; default: yyerror ("can't happen setattr"); } return val; }
int main(){ while(scanf("%d%d",&n,&m) == 2){ for(int i = 0;i < n;i ++){ scanf("%s",dat[i]); } int grpcnt = 0; for(int i = 0;i < n;i ++) { for(int j = 0;j < m; j++) { if(dat[i][j] == '#') { grp[i][j] = -1; } if(dat[i][j] == '.'){ cnt[grpcnt] = 1; color[grpcnt] = 10; grp[i][j] = grpcnt ++; } } } for(int i = 0;i < n;i ++) { for(int j = 0;j < m; j++) { if(grp[i][j] == -1) continue; if(cnt[grp[i][j]] == 1){ int grpsmin = 6; int vmin = -1; for(int k = 0;k < 4;k ++){ int r = i + dir[k][0]; int c = j + dir[k][1]; if(r < 0 || r >= n || c < 0 || c >= m) continue; if(grp[r][c] != -1) { if(cnt[grp[r][c]] < grpsmin) { grpsmin = cnt[grp[r][c]]; vmin = grp[r][c]; } } } if(vmin == -1) { goto final; } grp[i][j] = vmin; cnt[grp[i][j]] ++; } } } for(int i = 0;i < n;i ++){ for(int j = 0;j < m;j ++){ if(grp[i][j] == -1) continue; memset(v,0,sizeof(v)); ++vcnt; checkcolor(i,j); for(int k = 0; k < 10 ;k++){ if(v[k] == 0){ color[grp[i][j]] = k; break; } } } } for(int i = 0;i < n;i ++) { for(int j = 0; j < m; j++){ if(dat[i][j] == '.') { dat[i][j] = '0' + color[grp[i][j]]; } } printf("%s\n",dat[i]); } continue; final: