Skip to content

Commit

Permalink
Update SVG-header
Browse files Browse the repository at this point in the history
  • Loading branch information
niclas committed Sep 14, 2018
1 parent 3e95956 commit 1bd7954
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
8 changes: 4 additions & 4 deletions xdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,9 @@ void savetops(char* fname, int showsize)
}
}

void fprintsvgstart(FILE* fp)
void fprintsvgstart(FILE* fp, int width, int height)
{
fprintf(fp, "<svg xmlns=\"http://www.w3.org/2000/svg\">\n");
fprintf(fp, "<?xml version=\"1.0\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"%d\" height=\"%d\">\n", width, height);
}

void fprintsvgend(FILE* fp)
Expand Down Expand Up @@ -1202,12 +1202,12 @@ void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth)
}
}

void savetosvg(char* fname, int showsize)
void savetosvg(char* fname, int showsize, int width, int height)
{
FILE* fp;

if ((fp = fopen(fname, "w")) != NULL) {
fprintsvgstart(fp);
fprintsvgstart(fp, width, height);
savesvgnode(fp, topp, showsize, 0);
fprintsvgend(fp);
fclose(fp);
Expand Down
70 changes: 37 additions & 33 deletions xwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern int nodeinfo();
extern int helpinfo();
extern int ncols;
extern void savetops(char*, int);
extern void savetosvg(char*, int);
extern void savetosvg(char*, int, int, int);

/*
* EXPORTS: routines that this module exports outside
Expand Down Expand Up @@ -206,8 +206,9 @@ static char defaultTranslations[] = "\

#define ALL_UNUSED_IMPL_(nargs) UNUSED##nargs
#define ALL_UNUSED_IMPL(nargs) ALL_UNUSED_IMPL_(nargs)
#define UNUSED(...) ALL_UNUSED_IMPL(VA_NUM_ARGS(__VA_ARGS__)) \
(__VA_ARGS__)
#define UNUSED(...) \
ALL_UNUSED_IMPL(VA_NUM_ARGS(__VA_ARGS__)) \
(__VA_ARGS__)

/*
* action routines
Expand Down Expand Up @@ -272,36 +273,6 @@ a_saveps(Widget w, XEvent* e, String* params, Cardinal* num_params)
fprintf(stderr, "saved !\n");
}

static void
a_savesvg(Widget w, XEvent* e, String* params, Cardinal* num_params)
{
char* extension = ".svg";
int len = strlen(res.svgfilename) + 3 + strlen(extension) + 1;
char tmp[len];
char* fname;
int i;

UNUSED(w, e, params, num_params);

for (i = 0; i > -1; ++i) {
snprintf(tmp, len, "%s-%02d%s", res.svgfilename, i, extension);
if (access(tmp, F_OK) == -1) {
fname = tmp;
break;
}
}

if (i < 0) {
fprintf(stderr, "ERROR: there are too many xdu_output files!!!\n");
exit(1);
}

fprintf(stderr, "saving as scalable vector graphic to file: %s ..",
fname);
savetosvg(fname, res.showsize);
fprintf(stderr, "saved !\n");
}

static void
a_up(Widget w, XEvent* e, String* params, Cardinal* num_params)
{
Expand Down Expand Up @@ -393,6 +364,39 @@ static Window win;
static GC gc;
static XtAppContext app_con;

static void
a_savesvg(Widget w, XEvent* e, String* params, Cardinal* num_params)
{
char* extension = ".svg";
int len = strlen(res.svgfilename) + 3 + strlen(extension) + 1;
char tmp[len];
char* fname;
int i;
XWindowAttributes xwa;

XGetWindowAttributes(dpy, win, &xwa);

UNUSED(w, e, params, num_params);

for (i = 0; i > -1; ++i) {
snprintf(tmp, len, "%s-%02d%s", res.svgfilename, i, extension);
if (access(tmp, F_OK) == -1) {
fname = tmp;
break;
}
}

if (i < 0) {
fprintf(stderr, "ERROR: there are too many xdu_output files!!!\n");
exit(1);
}

fprintf(stderr, "saving as scalable vector graphic to file: %s ..",
fname);
savetosvg(fname, res.showsize, xwa.width, xwa.height);
fprintf(stderr, "saved !\n");
}

Widget toplevel;

/*
Expand Down

0 comments on commit 1bd7954

Please sign in to comment.