Index: trunk/src_plugins/export_svg/svg.c =================================================================== --- trunk/src_plugins/export_svg/svg.c (revision 36268) +++ trunk/src_plugins/export_svg/svg.c (revision 36269) @@ -93,6 +93,7 @@ typedef struct { FILE *outf; + gds_t sbright, sdark, snormal, sclip; /* accumulators for various groups generated parallel */ } rnd_svg_t; static rnd_svg_t pctx_, *pctx = &pctx_; @@ -100,7 +101,6 @@ static int group_open = 0; static int opacity = 100, drawing_mask, drawing_hole, photo_mode, photo_noise, flip; -static gds_t sbright, sdark, snormal, sclip; static rnd_composite_op_t drawing_mode; static int comp_cnt, svg_true_size = 0; static long svg_drawn_objs; @@ -220,6 +220,20 @@ return svg_attribute_list; } +void rnd_svg_init(rnd_svg_t *pctx, FILE *f) +{ + memset(pctx, 0, sizeof(rnd_svg_t)); + pctx->outf = f; +} + +void rnd_svg_uninit(rnd_svg_t *pctx) +{ + gds_uninit(&pctx->sbright); + gds_uninit(&pctx->sdark); + gds_uninit(&pctx->snormal); + gds_uninit(&pctx->sclip); +} + void svg_hid_export_to_file(FILE * the_file, rnd_hid_attr_val_t * options, rnd_xform_t *xform) { static int saved_layer_stack[PCB_MAX_LAYER]; @@ -272,10 +286,6 @@ opacity = options[HA_opacity].lng; - gds_init(&sbright); - gds_init(&sdark); - gds_init(&snormal); - if (options[HA_as_shown].lng) { pcb_draw_setup_default_gui_xform(xform); @@ -295,22 +305,22 @@ static void group_close(rnd_svg_t *pctx) { if (group_open == 1) { - if (gds_len(&sdark) > 0) { + if (gds_len(&pctx->sdark) > 0) { fprintf(pctx->outf, "\n"); - fprintf(pctx->outf, "%s", sdark.array); - gds_truncate(&sdark, 0); + fprintf(pctx->outf, "%s", pctx->sdark.array); + gds_truncate(&pctx->sdark, 0); } - if (gds_len(&sbright) > 0) { + if (gds_len(&pctx->sbright) > 0) { fprintf(pctx->outf, "\n"); - fprintf(pctx->outf, "%s", sbright.array); - gds_truncate(&sbright, 0); + fprintf(pctx->outf, "%s", pctx->sbright.array); + gds_truncate(&pctx->sbright, 0); } - if (gds_len(&snormal) > 0) { + if (gds_len(&pctx->snormal) > 0) { fprintf(pctx->outf, "\n"); - fprintf(pctx->outf, "%s", snormal.array); - gds_truncate(&snormal, 0); + fprintf(pctx->outf, "%s", pctx->snormal.array); + gds_truncate(&pctx->snormal, 0); } } @@ -369,6 +379,7 @@ const char *filename; int save_ons[PCB_MAX_LAYER]; rnd_xform_t xform; + FILE *f = NULL; comp_cnt = 0; @@ -386,22 +397,26 @@ if (!filename) filename = "pcb.svg"; - pctx->outf = rnd_fopen_askovr(&PCB->hidlib, svg_cam.active ? svg_cam.fn : filename, "wb", NULL); - if (pctx->outf == NULL) { + f = rnd_fopen_askovr(&PCB->hidlib, svg_cam.active ? svg_cam.fn : filename, "wb", NULL); + if (f == NULL) { TODO("copy error handling from ps"); perror(filename); return; } - svg_header(pctx); } else - pctx->outf = NULL; + f = NULL; + rnd_svg_init(pctx, f); + if (f != NULL) + svg_header(pctx); + if (!svg_cam.active) pcb_hid_save_and_show_layer_ons(save_ons); svg_hid_export_to_file(pctx->outf, options, &xform); + if (!svg_cam.active) pcb_hid_restore_layer_ons(save_ons); @@ -421,6 +436,8 @@ if (!svg_cam.okempty_content) rnd_message(RND_MSG_ERROR, "svg cam export for '%s' failed to produce any content (no objects)\n", options[HA_cam].str); } + + rnd_svg_uninit(pctx); } static int svg_parse_arguments(rnd_hid_t *hid, int *argc, char ***argv) @@ -548,11 +565,11 @@ switch(op) { case RND_HID_COMP_RESET: comp_cnt++; - gds_init(&sclip); - rnd_append_printf(&snormal, "\n"); - rnd_append_printf(&snormal, "\n"); - rnd_append_printf(&snormal, "\n", comp_cnt); - rnd_append_printf(&sclip, "\n", comp_cnt, PCB->hidlib.size_x, PCB->hidlib.size_y); + gds_init(&pctx->sclip); + rnd_append_printf(&pctx->snormal, "\n"); + rnd_append_printf(&pctx->snormal, "\n"); + rnd_append_printf(&pctx->snormal, "\n", comp_cnt); + rnd_append_printf(&pctx->sclip, "\n", comp_cnt, PCB->hidlib.size_x, PCB->hidlib.size_y); break; case RND_HID_COMP_POSITIVE: @@ -561,13 +578,13 @@ break; case RND_HID_COMP_FLUSH: - rnd_append_printf(&snormal, "\n"); - rnd_append_printf(&sclip, "\n"); - gds_append_str(&snormal, sclip.array); - rnd_append_printf(&snormal, "\n"); - rnd_append_printf(&snormal, "\n", comp_cnt, comp_cnt); - rnd_append_printf(&snormal, "\n"); - gds_uninit(&sclip); + rnd_append_printf(&pctx->snormal, "\n"); + rnd_append_printf(&pctx->sclip, "\n"); + gds_append_str(&pctx->snormal, pctx->sclip.array); + rnd_append_printf(&pctx->snormal, "\n"); + rnd_append_printf(&pctx->snormal, "\n", comp_cnt, comp_cnt); + rnd_append_printf(&pctx->snormal, "\n"); + gds_uninit(&pctx->sclip); break; } } @@ -658,12 +675,12 @@ { const char *clip_color = svg_clip_color(gc); - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", x1, y1, w, h, stroke, svg_color(gc), CAPS(gc->cap)); if (clip_color != NULL) { - indent(&sclip); - rnd_append_printf(&sclip, "\n", + indent(&pctx->sclip); + rnd_append_printf(&pctx->sclip, "\n", x1, y1, w, h, stroke, clip_color, CAPS(gc->cap)); } } @@ -681,24 +698,24 @@ if (photo_mode) { rnd_coord_t photo_offs = photo_palette[photo_color].offs; if (photo_offs != 0) { - indent(&sdark); - rnd_append_printf(&sdark, "\n", + indent(&pctx->sdark); + rnd_append_printf(&pctx->sdark, "\n", x1+photo_offs, y1+photo_offs, w, h, photo_palette[photo_color].dark); - indent(&sbright); - rnd_append_printf(&sbright, "\n", + indent(&pctx->sbright); + rnd_append_printf(&pctx->sbright, "\n", x1-photo_offs, y1-photo_offs, w, h, photo_palette[photo_color].bright); } - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", x1, y1, w, h, photo_palette[photo_color].normal); } else { - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", x1, y1, w, h, svg_color(gc)); } if (clip_color != NULL) - rnd_append_printf(&sclip, "\n", + rnd_append_printf(&pctx->sclip, "\n", x1, y1, w, h, clip_color); } @@ -716,24 +733,24 @@ if (photo_mode) { rnd_coord_t photo_offs = photo_palette[photo_color].offs; if (photo_offs != 0) { - indent(&sbright); - rnd_append_printf(&sbright, "\n", + indent(&pctx->sbright); + rnd_append_printf(&pctx->sbright, "\n", x1-photo_offs, y1-photo_offs, x2-photo_offs, y2-photo_offs, gc->width, photo_palette[photo_color].bright, CAPS(gc->cap)); - indent(&sdark); - rnd_append_printf(&sdark, "\n", + indent(&pctx->sdark); + rnd_append_printf(&pctx->sdark, "\n", x1+photo_offs, y1+photo_offs, x2+photo_offs, y2+photo_offs, gc->width, photo_palette[photo_color].dark, CAPS(gc->cap)); } - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", x1, y1, x2, y2, gc->width, photo_palette[photo_color].normal, CAPS(gc->cap)); } else { - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", x1, y1, x2, y2, gc->width, svg_color(gc), CAPS(gc->cap)); } if (clip_color != NULL) { - rnd_append_printf(&sclip, "\n", + rnd_append_printf(&pctx->sclip, "\n", x1, y1, x2, y2, gc->width, clip_color, CAPS(gc->cap)); } } @@ -752,24 +769,24 @@ if (photo_mode) { rnd_coord_t photo_offs = photo_palette[photo_color].offs; if (photo_offs != 0) { - indent(&sbright); - rnd_append_printf(&sbright, "\n", + indent(&pctx->sbright); + rnd_append_printf(&pctx->sbright, "\n", x1-photo_offs, y1-photo_offs, r, r, large, sweep, x2-photo_offs, y2-photo_offs, gc->width, photo_palette[photo_color].bright, CAPS(gc->cap)); - indent(&sdark); - rnd_append_printf(&sdark, "\n", + indent(&pctx->sdark); + rnd_append_printf(&pctx->sdark, "\n", x1+photo_offs, y1+photo_offs, r, r, large, sweep, x2+photo_offs, y2+photo_offs, gc->width, photo_palette[photo_color].dark, CAPS(gc->cap)); } - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", x1, y1, r, r, large, sweep, x2, y2, gc->width, photo_palette[photo_color].normal, CAPS(gc->cap)); } else { - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", x1, y1, r, r, large, sweep, x2, y2, gc->width, svg_color(gc), CAPS(gc->cap)); } if (clip_color != NULL) - rnd_append_printf(&sclip, "\n", + rnd_append_printf(&pctx->sclip, "\n", x1, y1, r, r, large, sweep, x2, y2, gc->width, clip_color, CAPS(gc->cap)); } @@ -842,31 +859,31 @@ if (!drawing_hole) { rnd_coord_t photo_offs = photo_palette[photo_color].offs; if ((!gc->drill) && (photo_offs != 0)) { - indent(&sbright); - rnd_append_printf(&sbright, "\n", + indent(&pctx->sbright); + rnd_append_printf(&pctx->sbright, "\n", cx-photo_offs, cy-photo_offs, r, stroke, photo_palette[photo_color].bright); - indent(&sdark); - rnd_append_printf(&sdark, "\n", + indent(&pctx->sdark); + rnd_append_printf(&pctx->sdark, "\n", cx+photo_offs, cy+photo_offs, r, stroke, photo_palette[photo_color].dark); } - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", cx, cy, r, stroke, photo_palette[photo_color].normal); } else { - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", cx, cy, r, stroke, "#000000"); } } else{ - indent(&snormal); - rnd_append_printf(&snormal, "\n", + indent(&pctx->snormal); + rnd_append_printf(&pctx->snormal, "\n", cx, cy, r, stroke, svg_color(gc)); } if (clip_color != NULL) - rnd_append_printf(&sclip, "\n", + rnd_append_printf(&pctx->sclip, "\n", cx, cy, r, stroke, clip_color); } @@ -901,16 +918,16 @@ if (photo_offs_x != 0) { if (flip) photo_offs_y = -photo_offs_y; - draw_poly(&sbright, gc, n_coords, x, y, dx-photo_offs_x, dy-photo_offs_y, photo_palette[photo_color].bright); - draw_poly(&sdark, gc, n_coords, x, y, dx+photo_offs_x, dy+photo_offs_y, photo_palette[photo_color].dark); + draw_poly(&pctx->sbright, gc, n_coords, x, y, dx-photo_offs_x, dy-photo_offs_y, photo_palette[photo_color].bright); + draw_poly(&pctx->sdark, gc, n_coords, x, y, dx+photo_offs_x, dy+photo_offs_y, photo_palette[photo_color].dark); } - draw_poly(&snormal, gc, n_coords, x, y, dx, dy, photo_palette[photo_color].normal); + draw_poly(&pctx->snormal, gc, n_coords, x, y, dx, dy, photo_palette[photo_color].normal); } else - draw_poly(&snormal, gc, n_coords, x, y, dx, dy, svg_color(gc)); + draw_poly(&pctx->snormal, gc, n_coords, x, y, dx, dy, svg_color(gc)); if (clip_color != NULL) - draw_poly(&sclip, gc, n_coords, x, y, dx, dy, clip_color); + draw_poly(&pctx->sclip, gc, n_coords, x, y, dx, dy, clip_color); } static void svg_fill_polygon(rnd_hid_gc_t gc, int n_coords, rnd_coord_t *x, rnd_coord_t *y)