Files
mtkports/www-client/netsurf/patches/0004-monkey-window-dump-diagnostic.patch
T

98 lines
2.9 KiB
Diff

diff --git a/frontends/monkey/browser.c b/frontends/monkey/browser.c
index 958375486..6b406f552 100644
--- a/frontends/monkey/browser.c
+++ b/frontends/monkey/browser.c
@@ -27,10 +27,13 @@
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/nsurl.h"
+#include "utils/nsoption.h"
#include "netsurf/mouse.h"
#include "netsurf/window.h"
#include "netsurf/browser_window.h"
+#include "netsurf/content_type.h"
#include "netsurf/plotters.h"
+#include "css/utils.h"
#include "monkey/output.h"
#include "monkey/browser.h"
@@ -599,6 +602,69 @@ monkey_window_handle_redraw(int argc, char **argv)
moutf(MOUT_WINDOW, "REDRAW WIN %d STOP", atoi(argv[2]));
}
+/**
+ * WINDOW DUMP <win> [path]
+ *
+ * Port-local diagnostic. The layout dump goes to a file because it is
+ * hundreds of lines, then the head of it is echoed so the box geometry is
+ * visible without any way to get a file off the ramdisk. The LENGTHS line
+ * carries the inputs every CSS length conversion depends on -- if the DPI or
+ * font sizes come out wrong, every box is wrong and nothing plots.
+ */
+static void
+monkey_window_handle_dump(int argc, char **argv)
+{
+ const char *path = (argc > 3) ? argv[3] : "0:/users/admin/nsbox.txt";
+ struct gui_window *gw;
+ char line[512];
+ int lineno;
+ FILE *f;
+
+ if (argc != 3 && argc != 4) {
+ moutf(MOUT_ERROR, "WINDOW DUMP ARGS BAD");
+ return;
+ }
+
+ gw = monkey_find_window_by_num(atoi(argv[2]));
+ if (gw == NULL) {
+ moutf(MOUT_ERROR, "WINDOW NUM BAD");
+ return;
+ }
+
+ /* Raw css_fixed (22.10), not FIXTOINT: a value that is merely small
+ * rather than zero has to stay visible. */
+ moutf(MOUT_WINDOW,
+ "DUMP WIN %s LENGTHS DPI %d FONT_SIZE %d FONT_MIN %d SCALE %d",
+ argv[2], (int) nscss_screen_dpi, nsoption_int(font_size),
+ nsoption_int(font_min_size), nsoption_int(scale));
+
+ f = fopen(path, "w");
+ if (f == NULL) {
+ moutf(MOUT_ERROR, "WINDOW DUMP OPEN FAILED %s", path);
+ return;
+ }
+
+ browser_window_debug_dump(gw->bw, f, CONTENT_DEBUG_RENDER);
+ fclose(f);
+
+ f = fopen(path, "r");
+ if (f == NULL) {
+ moutf(MOUT_ERROR, "WINDOW DUMP REOPEN FAILED %s", path);
+ return;
+ }
+
+ for (lineno = 0; lineno < 40; lineno++) {
+ if (fgets(line, sizeof(line), f) == NULL) {
+ break;
+ }
+ line[strcspn(line, "\n")] = '\0';
+ moutf(MOUT_WINDOW, "DUMP WIN %s BOX %s", argv[2], line);
+ }
+ fclose(f);
+
+ moutf(MOUT_WINDOW, "DUMP WIN %s END LINES %d", argv[2], lineno);
+}
+
static void
monkey_window_handle_reload(int argc, char **argv)
{
@@ -721,6 +787,8 @@ monkey_window_handle_command(int argc, char **argv)
monkey_window_handle_stop(argc, argv);
} else if (strcmp(argv[1], "REDRAW") == 0) {
monkey_window_handle_redraw(argc, argv);
+ } else if (strcmp(argv[1], "DUMP") == 0) {
+ monkey_window_handle_dump(argc, argv);
} else if (strcmp(argv[1], "RELOAD") == 0) {
monkey_window_handle_reload(argc, argv);
} else if (strcmp(argv[1], "EXEC") == 0) {