/** * Take an html screenshot */ void html_screenshot(const char *path, int mode) { int y, x; int wid, hgt; int a = COLOUR_WHITE; int oa = COLOUR_WHITE; int fg_colour = COLOUR_WHITE; int bg_colour = COLOUR_DARK; wchar_t c = L' '; const char *new_color_fmt = (mode == 0) ? "<font color=\"#%02X%02X%02X\" style=\"background-color: #%02X%02X%02X\">" : "[COLOR=\"#%02X%02X%02X\"]"; const char *change_color_fmt = (mode == 0) ? "</font><font color=\"#%02X%02X%02X\" style=\"background-color: #%02X%02X%02X\">" : "[/COLOR][COLOR=\"#%02X%02X%02X\"]"; const char *close_color_fmt = mode == 0 ? "</font>" : "[/COLOR]"; ang_file *fp; fp = file_open(path, MODE_WRITE, FTYPE_TEXT); /* Oops */ if (!fp) { plog_fmt("Cannot write the '%s' file!", path); return; } /* Retrieve current screen size */ Term_get_size(&wid, &hgt); if (mode == 0) { file_putf(fp, "<!DOCTYPE html><html><head>\n"); file_putf(fp, " <meta='generator' content='%s'>\n", buildid); file_putf(fp, " <title>%s</title>\n", path); file_putf(fp, "</head>\n\n"); file_putf(fp, "<body style='color: #fff; background: #000;'>\n"); file_putf(fp, "<pre>\n"); } else { file_putf(fp, "[CODE][TT][BC=black][COLOR=white]\n"); } /* Dump the screen */ for (y = 0; y < hgt; y++) { for (x = 0; x < wid; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Set the foreground and background */ fg_colour = a % MAX_COLORS; switch (a / MAX_COLORS) { case BG_BLACK: bg_colour = COLOUR_DARK; break; case BG_SAME: bg_colour = fg_colour; break; case BG_DARK: bg_colour = COLOUR_SHADE; break; default: assert((a >= BG_BLACK) && (a < BG_MAX * MAX_COLORS)); } /* Color change */ if (oa != a) { if (oa == COLOUR_WHITE) { /* From the default white to another color */ file_putf(fp, new_color_fmt, angband_color_table[fg_colour][1], angband_color_table[fg_colour][2], angband_color_table[fg_colour][3], angband_color_table[bg_colour][1], angband_color_table[bg_colour][2], angband_color_table[bg_colour][3]); } else if (fg_colour == COLOUR_WHITE && bg_colour == COLOUR_DARK) { /* From another color to the default white */ file_putf(fp, close_color_fmt); } else { /* Change colors */ file_putf(fp, change_color_fmt, angband_color_table[fg_colour][1], angband_color_table[fg_colour][2], angband_color_table[fg_colour][3], angband_color_table[bg_colour][1], angband_color_table[bg_colour][2], angband_color_table[bg_colour][3]); } /* Remember the last color */ oa = a; } /* Write the character and escape special HTML characters */ if (mode == 0) write_html_escape_char(fp, c); else { char mbseq[MB_LEN_MAX+1] = {0}; wctomb(mbseq, c); file_putf(fp, "%s", mbseq); } } /* End the row */ file_putf(fp, "\n"); } /* Close the last font-color tag if necessary */ if (oa != COLOUR_WHITE) file_putf(fp, close_color_fmt); if (mode == 0) { file_putf(fp, "</pre>\n"); file_putf(fp, "</body>\n"); file_putf(fp, "</html>\n"); } else { file_putf(fp, "[/COLOR][/BC][/TT][/CODE]\n"); } /* Close it */ file_close(fp); }
/* Take an html screenshot */ void html_screenshot(const char *name, int mode) { int y, x; int wid, hgt; byte a = TERM_WHITE; byte oa = TERM_WHITE; char c = ' '; const char *new_color_fmt = (mode == 0) ? "<font color=\"#%02X%02X%02X\">" : "[COLOR=\"#%02X%02X%02X\"]"; const char *change_color_fmt = (mode == 0) ? "</font><font color=\"#%02X%02X%02X\">" : "[/COLOR][COLOR=\"#%02X%02X%02X\"]"; const char *close_color_fmt = mode == 0 ? "</font>" : "[/COLOR]"; ang_file *fp; char buf[1024]; path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name); fp = file_open(buf, MODE_WRITE, FTYPE_TEXT); /* Oops */ if (!fp) { plog_fmt("Cannot write the '%s' file!", buf); return; } /* Retrieve current screen size */ Term_get_size(&wid, &hgt); if (mode == 0) { file_putf(fp, "<!DOCTYPE html><html><head>\n"); file_putf(fp, " <meta='generator' content='%s'>\n", buildid); file_putf(fp, " <title>%s</title>\n", name); file_putf(fp, "</head>\n\n"); file_putf(fp, "<body style='color: #fff; background: #000;'>\n"); file_putf(fp, "<pre>\n"); } else { file_putf(fp, "[CODE][TT][BC=black][COLOR=white]\n"); } /* Dump the screen */ for (y = 0; y < hgt; y++) { for (x = 0; x < wid; x++) { /* Get the attr/char */ (void)(Term_what(x, y, &a, &c)); /* Color change */ if (oa != a && c != ' ') { /* From the default white to another color */ if (oa == TERM_WHITE) { file_putf(fp, new_color_fmt, angband_color_table[a][1], angband_color_table[a][2], angband_color_table[a][3]); } /* From another color to the default white */ else if (a == TERM_WHITE) { file_putf(fp, close_color_fmt); } /* Change colors */ else { file_putf(fp, change_color_fmt, angband_color_table[a][1], angband_color_table[a][2], angband_color_table[a][3]); } /* Remember the last color */ oa = a; } /* Write the character and escape special HTML characters */ if (mode == 0) write_html_escape_char(fp, c); else file_putf(fp, "%c", c); } /* End the row */ file_putf(fp, "\n"); } /* Close the last font-color tag if necessary */ if (oa != TERM_WHITE) file_putf(fp, close_color_fmt); if (mode == 0) { file_putf(fp, "</pre>\n"); file_putf(fp, "</body>\n"); file_putf(fp, "</html>\n"); } else { file_putf(fp, "[/COLOR][/BC][/TT][/CODE]\n"); } /* Close it */ file_close(fp); }