Index: work/util/ttf2lht/drv_poly.c =================================================================== --- work/util/ttf2lht/drv_poly.c (revision 20262) +++ work/util/ttf2lht/drv_poly.c (revision 20263) @@ -2,6 +2,7 @@ #include "drv_poly.h" #include "../../../trunk/src_plugins/import_ttf/str_approx.h" #include "temp_copy.c" +#include "../../../trunk/src/box.h" #define APPEND(list, pl) \ do { \ @@ -103,45 +104,73 @@ { poly_pcb_ttf_stroke_t *s = (poly_pcb_ttf_stroke_t *)s_; pcb_pline_t *pl, *next; - int err = 0; + int err = 0, n, valids; + pcb_box_t bbox; pline_close(s); - s->pa = malloc(sizeof(pcb_polyarea_t)); - pcb_polyarea_init(s->pa); - for(pl = s->pos; pl != NULL; pl = next) { + s->numpa = 0; + for(pl = s->pos; pl != NULL; pl = pl->next) + s->numpa++; + + s->pa = malloc(sizeof(pcb_polyarea_t *) * s->numpa); + for(pl = s->pos, n = 0; pl != NULL; pl = next, n++) { + s->pa[n] = malloc(sizeof(pcb_polyarea_t)); + pcb_polyarea_init(s->pa[n]); next = pl->next; pl->next = NULL; - if (!pcb_polyarea_contour_include(s->pa, pl)) { + if (!pcb_polyarea_contour_include(s->pa[n], pl)) { fprintf(stderr, "Failed to include positive outline\n"); err++; } } + /* subtract all holes from all positive pa's; error happens if none of the + subtraction worked */ for(pl = s->neg; pl != NULL; pl = next) { + int worked = 0; next = pl->next; pl->next = NULL; - if (!pcb_polyarea_contour_include(s->pa, pl)) { + for(n = 0; n < s->numpa; n++) { + pcb_box_t *pab = (pcb_box_t *)&s->pa[n]->contour_tree->bbox; + pcb_box_t *plb = (pcb_box_t *)&pl->tree->bbox; + if ((pcb_box_intersect(pab, plb)) && (pcb_polyarea_contour_include(s->pa[n], pl))) + worked++; + } + + if (!worked) { err++; fprintf(stderr, "Failed to include negative outline\n"); } } - if ((err == 0) && (pcb_poly_valid(s->pa))) { + memcpy(&bbox, &s->pa[0]->contour_tree->bbox, sizeof(pcb_box_t)); + valids = pcb_poly_valid(s->pa[0]); + for(n = 1; n < s->numpa; n++) { + if (pcb_poly_valid(s->pa[n])) { + pcb_box_bump_box(&bbox, (pcb_box_t *)&s->pa[n]->contour_tree->bbox); + valids++; + } + } + + if ((err == 0) && (valids > 0)) { s->spid = 0; - printf(" width=%fmil; delta=12.0mil;\n", OTX(&s->s, s->pa->contour_tree->bbox.x2 - s->pa->contour_tree->bbox.x1)); + printf(" width=%fmil; delta=12.0mil;\n", OTX(&s->s, bbox.X2 - bbox.X1)); printf(" li:objects {\n"); - r_NoHolesPolygonDicer(s->pa, emit, s); + for(n = 0; n < s->numpa; n++) + r_NoHolesPolygonDicer(s->pa[n], emit, s); printf(" }\n"); } else { - fprintf(stderr, "Invalid outlines\n"); - pcb_polyarea_free(&s->pa); + fprintf(stderr, "Invalid outlines err=%d valids=%d numpa=%d\n", err, valids, s->numpa); + for(n = 0; n < s->numpa; n++) + pcb_polyarea_free(&(s->pa[n])); } printf(" }\n"); s->neg = s->pos = s->curr = NULL; - + free(s->pa); + s->numpa = 0; } void stroke_poly_uninit(pcb_ttf_stroke_t *s_) Index: work/util/ttf2lht/drv_poly.h =================================================================== --- work/util/ttf2lht/drv_poly.h (revision 20262) +++ work/util/ttf2lht/drv_poly.h (revision 20263) @@ -11,7 +11,8 @@ pcb_pline_t *pos, *neg; /* the resulting polyarea */ - pcb_polyarea_t *pa; + int numpa; + pcb_polyarea_t **pa; int spid; double maxx, maxy;