// Hyperbolic Rogue -- screenshots in SVG and PNG formats
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
namespace hr {
#if ISMOBILE==1
namespace svg {
bool in = false;
}
#endif
#if ISMOBILE==0
// svg renderer
namespace svg {
#if ISWEB
shstream f;
#else
fhstream f;
#endif
bool in = false;
ld cta(color_t col) {
// col >>= 24;
col &= 0xFF;
return col / 255.0;
}
bool invisible(color_t col) { return (col & 0xFF) == 0; }
void fixgamma(unsigned int& color) {
unsigned char *c = (unsigned char*) (&color);
for(int i=1; i<4; i++) c[i] = 255 * pow(float(c[i] / 255.0), float(shot::gamma));
}
int svgsize;
int divby = 10;
const char* coord(int val) {
static char buf[10][20];
static int id;
id++; id %= 10;
if(divby == 1) {
sprintf(buf[id], "%d", val); return buf[id];
}
else if(divby <= 10) {
sprintf(buf[id], "%.1f", val*1./divby); return buf[id];
}
else {
sprintf(buf[id], "%.2f", val*1./divby); return buf[id];
}
}
char* stylestr(unsigned int fill, unsigned int stroke, ld width=1) {
fixgamma(fill);
fixgamma(stroke);
static char buf[600];
// printf("fill = %08X stroke = %08x\n", fill, stroke);
if(stroke == 0xFF00FF && false) {
stroke = 0x000000FF;
if(fill == 0x332a22ff) fill = 0x000000FF;
else if(fill == 0x686868FF) fill = 0x000000FF;
else if(fill == 0xd0d0d0FF) fill = 0x000000FF;
else fill = 0xFFFFFFFF;
}
sprintf(buf, "style=\"stroke:#%06x;stroke-opacity:%.3" PLDF ";stroke-width:%" PLDF "px;fill:#%06x;fill-opacity:%.3" PLDF "\"",
(stroke>>8) & 0xFFFFFF, cta(stroke),
width/divby,
(fill>>8) & 0xFFFFFF, cta(fill)
);
return buf;
}
void circle(int x, int y, int size, color_t col, color_t fillcol, double linewidth) {
if(!invisible(col) || !invisible(fillcol)) {
if(vid.stretch == 1)
println(f, "");
else
println(f, "");
}
}
string link;
void startstring() {
if(link != "") print(f, "");
}
void stopstring() {
if(link != "") print(f, "");
}
string font = "Times";
void text(int x, int y, int size, const string& str, bool frame, color_t col, int align) {
double dfc = (x - current_display->xcenter) * (x - current_display->xcenter) +
(y - current_display->ycenter) * (y - current_display->ycenter);
dfc /= current_display->radius;
dfc /= current_display->radius;
// 0 = center, 1 = edge
dfc = 1 - dfc;
col = 0xFF + (col << 8);
bool uselatex = font == "latex";
if(!invisible(col)) {
startstring();
string str2 = "";
for(int i=0; i<(int) str.size(); i++)
if(str[i] == '&')
str2 += "&";
else if(str[i] == '<')
str2 += "<";
else if(str[i] == '>')
str2 += ">";
else if(uselatex && str[i] == '#')
str2 += "\\#";
else str2 += str[i];
if(uselatex) str2 = string("\\myfont{")+coord(size)+"}{" + str2 + "}";
print(f, "", str2, "");
stopstring();
println(f);
}
}
void polygon(int *polyx, int *polyy, int polyi, color_t col, color_t outline, double linewidth) {
if(invisible(col) && invisible(outline)) return;
if(polyi < 2) return;
startstring();
for(int i=0; iradius : current_display->scrsize) * linewidth/256), "/>");
stopstring();
println(f);
}
void render(const string& fname, const function& what) {
dynamicval v2(in, true);
dynamicval v3(vid.usingGL, false);
#if ISWEB
f.s = "";
#else
f.f = fopen(fname.c_str(), "wt");
#endif
println(f, "