Index: svg.c
===================================================================
--- svg.c (revision 36268)
+++ 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, "