Index: trunk/src_plugins/export_svg/svg.c =================================================================== --- trunk/src_plugins/export_svg/svg.c (revision 36267) +++ trunk/src_plugins/export_svg/svg.c (revision 36268) @@ -91,7 +91,12 @@ return ""; } -static FILE *f = NULL; +typedef struct { + FILE *outf; +} rnd_svg_t; + +static rnd_svg_t pctx_, *pctx = &pctx_; + static int group_open = 0; static int opacity = 100, drawing_mask, drawing_hole, photo_mode, photo_noise, flip; @@ -225,7 +230,7 @@ ctx.view.X2 = PCB->hidlib.size_x; ctx.view.Y2 = PCB->hidlib.size_y; - f = the_file; + pctx->outf = the_file; memcpy(saved_layer_stack, pcb_layer_stack, sizeof(pcb_layer_stack)); @@ -261,7 +266,7 @@ } if (photo_mode) { - rnd_fprintf(f, "\n", + rnd_fprintf(pctx->outf, "\n", 0, 0, PCB->hidlib.size_x, PCB->hidlib.size_y, board_color); } @@ -287,36 +292,36 @@ rnd_conf_update(NULL, -1); /* restore forced sets */ } -static void group_close() +static void group_close(rnd_svg_t *pctx) { if (group_open == 1) { if (gds_len(&sdark) > 0) { - fprintf(f, "\n"); - fprintf(f, "%s", sdark.array); + fprintf(pctx->outf, "\n"); + fprintf(pctx->outf, "%s", sdark.array); gds_truncate(&sdark, 0); } if (gds_len(&sbright) > 0) { - fprintf(f, "\n"); - fprintf(f, "%s", sbright.array); + fprintf(pctx->outf, "\n"); + fprintf(pctx->outf, "%s", sbright.array); gds_truncate(&sbright, 0); } if (gds_len(&snormal) > 0) { - fprintf(f, "\n"); - fprintf(f, "%s", snormal.array); + fprintf(pctx->outf, "\n"); + fprintf(pctx->outf, "%s", snormal.array); gds_truncate(&snormal, 0); } } - fprintf(f, "\n"); + fprintf(pctx->outf, "\n"); } -static void svg_header() +static void svg_header(rnd_svg_t *pctx) { rnd_coord_t w, h, x1, y1, x2, y2; - fprintf(f, "\n"); + fprintf(pctx->outf, "\n"); w = PCB->hidlib.size_x; h = PCB->hidlib.size_y; while((w < RND_MM_TO_COORD(1024)) && (h < RND_MM_TO_COORD(1024))) { @@ -327,7 +332,7 @@ x2 = PCB->hidlib.size_x; y2 = PCB->hidlib.size_y; if (svg_true_size) { - rnd_fprintf(f, "\n", x2, y2, x2, y2); + rnd_fprintf(pctx->outf, "\n", x2, y2, x2, y2); } else { x1 = RND_MM_TO_COORD(2); @@ -334,29 +339,29 @@ y1 = RND_MM_TO_COORD(2); x2 += RND_MM_TO_COORD(5); y2 += RND_MM_TO_COORD(5); - rnd_fprintf(f, "\n", w, h, x1, y1, x2, y2); + rnd_fprintf(pctx->outf, "\n", w, h, x1, y1, x2, y2); } } -static void svg_footer(void) +static void svg_footer(rnd_svg_t *pctx) { while(group_open) { - group_close(); + group_close(pctx); group_open--; } /* blend some noise on top to make it a bit more artificial */ if (photo_mode && photo_noise) { - fprintf(f, "\n"); - fprintf(f, " \n"); - fprintf(f, "\n"); - fprintf(f, "\n"); - rnd_fprintf(f, " \n", + fprintf(pctx->outf, "\n"); + fprintf(pctx->outf, " \n"); + fprintf(pctx->outf, "\n"); + fprintf(pctx->outf, "\n"); + rnd_fprintf(pctx->outf, " \n", 0, 0, PCB->hidlib.size_x, PCB->hidlib.size_y); - fprintf(f, "\n"); + fprintf(pctx->outf, "\n"); } - fprintf(f, "\n"); + fprintf(pctx->outf, "\n"); } static void svg_do_export(rnd_hid_t *hid, rnd_hid_attr_val_t *options) @@ -381,29 +386,30 @@ if (!filename) filename = "pcb.svg"; - f = rnd_fopen_askovr(&PCB->hidlib, svg_cam.active ? svg_cam.fn : filename, "wb", NULL); - if (!f) { + pctx->outf = rnd_fopen_askovr(&PCB->hidlib, svg_cam.active ? svg_cam.fn : filename, "wb", NULL); + if (pctx->outf == NULL) { + TODO("copy error handling from ps"); perror(filename); return; } - svg_header(); + svg_header(pctx); } else - f = NULL; + pctx->outf = NULL; if (!svg_cam.active) pcb_hid_save_and_show_layer_ons(save_ons); - svg_hid_export_to_file(f, options, &xform); + svg_hid_export_to_file(pctx->outf, options, &xform); if (!svg_cam.active) pcb_hid_restore_layer_ons(save_ons); - if (f != NULL) { - svg_footer(); - fclose(f); + if (pctx->outf != NULL) { + svg_footer(pctx); + fclose(pctx->outf); } - f = NULL; + pctx->outf = NULL; if (!svg_cam.active) svg_cam.okempty_content = 1; /* never warn in direct export */ @@ -435,18 +441,18 @@ pcb_cam_set_layer_group(&svg_cam, group, purpose, purpi, flags, xform); - if (svg_cam.fn_changed || (f == NULL)) { - if (f != NULL) { - svg_footer(); - fclose(f); + if (svg_cam.fn_changed || (pctx->outf == NULL)) { + if (pctx->outf != NULL) { + svg_footer(pctx); + fclose(pctx->outf); } - f = rnd_fopen_askovr(&PCB->hidlib, svg_cam.fn, "wb", NULL); - if (f == NULL) { + pctx->outf = rnd_fopen_askovr(&PCB->hidlib, svg_cam.fn, "wb", NULL); + if (pctx->outf == NULL) { perror(svg_cam.fn); return 0; } - svg_header(); + svg_header(pctx); } printf("GRP: '%s'\n", PCB->LayerGroups.grp[group].name); @@ -478,7 +484,7 @@ } while(group_open) { - group_close(); + group_close(pctx); group_open--; } @@ -487,7 +493,7 @@ const char *name; gds_init(&tmp_ln); name = pcb_layer_to_file_name(&tmp_ln, layer, flags, purpose, purpi, PCB_FNS_fixed); - fprintf(f, "outf, "\n"); + fprintf(pctx->outf, " opacity=\"%.2f\"", ((float)opa) / 100.0); + fprintf(pctx->outf, ">\n"); group_open = 1; if (photo_mode) { @@ -618,7 +624,7 @@ if (group_open < sizeof(ind)-1) { ind[group_open] = '\0'; if (s == NULL) - rnd_fprintf(f, ind); + rnd_fprintf(pctx->outf, ind); else rnd_append_printf(s, ind); ind[group_open] = ' '; @@ -626,7 +632,7 @@ } if (s == NULL) - rnd_fprintf(f, ind); + rnd_fprintf(pctx->outf, ind); else rnd_append_printf(s, ind); }