diff --git a/screenshot.cpp b/screenshot.cpp
index 395aac48..cd8093e3 100644
--- a/screenshot.cpp
+++ b/screenshot.cpp
@@ -22,11 +22,7 @@ EX always_false in;
#endif
#if CAP_SVG
- #if ISWEB
- shstream f;
- #else
- fhstream f;
- #endif
+ hstream *svgf;
EX bool in = false;
@@ -90,20 +86,20 @@ EX always_false in;
EX void circle(int x, int y, int size, color_t col, color_t fillcol, double linewidth) {
if(!invisible(col) || !invisible(fillcol)) {
if(pconf.stretch == 1)
- println(f, "");
+ println(*svgf, "");
else
- println(f, "");
+ println(*svgf, "");
}
}
EX string link;
void startstring() {
- if(link != "") print(f, "");
+ if(link != "") print(*svgf, "");
}
void stopstring() {
- if(link != "") print(f, "");
+ if(link != "") print(*svgf, "");
}
string font = "Times";
@@ -142,18 +138,18 @@ EX always_false in;
else str2 += str[i];
if(uselatex) str2 = string("\\myfont{")+coord(size)+"}{" + str2 + "}";
- print(f, "" + str2 + "";
- print(f,
+ print(*svgf,
stylestr(col, frame ? 0x0000000FF : 0, (1<", str2, "");
stopstring();
- println(f);
+ println(*svgf);
}
}
@@ -173,43 +169,54 @@ EX always_false in;
startstring();
for(int i=0; iradius : current_display->scrsize) * linewidth/256), "/>");
+ print(*svgf, "\" ", stylestr(col, outline, (hyperbolic ? current_display->radius : current_display->scrsize) * linewidth/256), "/>");
stopstring();
- println(f);
+ println(*svgf);
}
+ // 0: file, 1: string, 2: web
+ EX int svg_mode = ISWEB ? 2 : 0;
+
+ EX shstream sout;
+ fhstream sfile;
+
EX void render(const string& fname, const function& what IS(shot::default_screenshot_content)) {
+
+ if(svg_mode) svgf = &sout;
+ else { svgf = &sfile; sfile.f = fopen(fname.c_str(), "wt"); if(!sfile.f) { printf("could not open the file\n"); return; } }
+
dynamicval v2(in, true);
dynamicval v3(vid.usingGL, false);
-
- #if ISWEB
- f.s = "";
- #else
- f.f = fopen(fname.c_str(), "wt");
- #endif
- println(f, "");
- #if ISWEB
- EM_ASM_({
- var x=window.open();
- x.document.open();
- x.document.write(UTF8ToString($0));
- x.document.close();
- }, f.s.c_str());
- #else
- fclose(f.f); f.f = NULL;
- #endif
+ if(svg_mode == 2) {
+ #if ISWEB
+ EM_ASM_({
+ var x=window.open();
+ x.document.open();
+ x.document.write(UTF8ToString($0));
+ x.document.close();
+ }, sout.s.c_str());
+ #else
+ printf("%s\n", sout.s.c_str());
+ #endif
+ sout.s = "";
+ }
+
+ if(sfile.f) fclose(sfile.f), sfile.f = nullptr;
}
#if CAP_COMMANDLINE && CAP_SHOT