ソースを参照

browser: pt font sizes, <center>ed tables, white canvas for grey text

Hacker News rendered too small, left-aligned and on the dark canvas:
- font-size accepts pt (4/3 px); 10pt/7pt were read as 10/7 px.
- A definite-width table centres inside a <center> parent or with
  align=center (CSS text-align on the parent still does not centre it).
- The white page canvas is chosen for mid-grey author text too
  (luminance below ~150), so #828282 body text gets a white page.

Compat ladder: only 049 changes (its table is now centred; its check
still passes).  cloudron.io, docs.cloudron.io, google.com, getbootstrap
3.4 and lobste.rs render pixel-identical.
Johannes Zellner 14 時間 前
親
コミット
a86bde9cb1
4 ファイル変更、35 行追加、5 行削除
  1. 6 3
      AGENTS.md
  2. 0 0
      docs/userland.html
  3. 24 2
      user/apps/browser/browser.c
  4. 5 0
      user/apps/browser/browser_html.c

+ 6 - 3
AGENTS.md

@@ -1798,7 +1798,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `background-image` with
   `background-image` with
   `repeat`/`position`/`size` (`auto` keeps the legacy stretch, `cover` and
   `repeat`/`position`/`size` (`auto` keeps the legacy stretch, `cover` and
   `contain` scale the image), plus the `background` shorthand URL,
   `contain` scale the image), plus the `background` shorthand URL,
-  font size (`px`/`%`/`em`/`rem`, resolved against the parent for `em`/`%`),
+  font size (`px`/`pt` (4/3 px)/`%`/`em`/`rem`, resolved against the parent
+  for `em`/`%`), a definite-width table centred by a `<center>` parent or
+  `align=center` (not by CSS `text-align`; Hacker News),
   the `font` shorthand, numeric weights, `!important`, line-height,
   the `font` shorthand, numeric weights, `!important`, line-height,
   alignment, margins, padding, per-side borders, `list-style: none`,
   alignment, margins, padding, per-side borders, `list-style: none`,
   `text-transform: uppercase`, `display`, explicit/percentage block
   `text-transform: uppercase`, `display`, explicit/percentage block
@@ -3376,8 +3378,9 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     playing, `pause`/`load` do nothing, `paused` is true).  Bare `&` characters are
     playing, `pause`/`load` do nothing, `paused` is true).  Bare `&` characters are
     consumed by the entity decoder instead of looping forever.  A page with
     consumed by the entity decoder instead of looping forever.  A page with
     no `html`/`body` background gets the dark default canvas unless its
     no `html`/`body` background gets the dark default canvas unless its
-    computed text colour is dark, in which case the canvas is white like a
-    normal browser's.  `@layer` ranks nested layers flat by first
+    computed text colour is dark or mid-grey (luminance below ~150 of 255,
+    so Hacker News' #828282 counts), in which case the canvas is white like
+    a normal browser's.  `@layer` ranks nested layers flat by first
     appearance (a parent layer's own rules lose to its sublayers, the spec
     appearance (a parent layer's own rules lose to its sublayers, the spec
     says the reverse).
     says the reverse).
     Downloads are capped at the helper's 4 MB, run one at a time, cannot be
     Downloads are capped at the helper's 4 MB, run one at a time, cannot be

ファイルの差分が大きいため隠しています
+ 0 - 0
docs/userland.html


+ 24 - 2
user/apps/browser/browser.c

@@ -10186,6 +10186,20 @@ static void alpha_end(struct ngui_rect r, struct ngui_rect box, int a)
 	}
 	}
 }
 }
 
 
+/* A table centred by legacy markup: a <center> parent or align="center".
+ * CSS text-align on the parent does not centre a block table, as in
+ * browsers. */
+static int table_centered(unsigned int node)
+{
+	const char *al = br_find_attr(&doc, node, "align");
+	unsigned int p = doc.nodes[node].parent;
+
+	if (al && (al[0] == 'c' || al[0] == 'C'))
+		return 1;
+	return p < doc.nnode && doc.nodes[p].type == BR_NODE_ELEM &&
+	       doc.nodes[p].tag == BR_TAG_CENTER;
+}
+
 static void layout_block(struct lay *l, unsigned int node,
 static void layout_block(struct lay *l, unsigned int node,
 			 const struct br_style *st, int depth,
 			 const struct br_style *st, int depth,
 			 unsigned short link)
 			 unsigned short link)
@@ -10457,6 +10471,12 @@ static void layout_block(struct lay *l, unsigned int node,
 			ml = free_w;
 			ml = free_w;
 		} else if (st->mr_auto) {
 		} else if (st->mr_auto) {
 			mr = free_w;
 			mr = free_w;
+		} else if (doc.nodes[node].tag == BR_TAG_TABLE &&
+			   table_centered(node)) {
+			/* <center><table width=85%> (Hacker News) and
+			 * <table align=center> centre the table box. */
+			ml = free_w / 2;
+			mr = free_w - ml;
 		}
 		}
 	}
 	}
 	if (doc.nodes[node].tag == BR_TAG_IMG) {
 	if (doc.nodes[node].tag == BR_TAG_IMG) {
@@ -14101,14 +14121,16 @@ static void draw_page(struct ngui_rect page)
 		 * (Infima's light theme: `--ifm-background-color:
 		 * (Infima's light theme: `--ifm-background-color:
 		 * transparent` on html, #1c1e21 text): the page expects the
 		 * transparent` on html, #1c1e21 text): the page expects the
 		 * white canvas of a normal browser, and dark text on the
 		 * white canvas of a normal browser, and dark text on the
-		 * dark default canvas is unreadable. */
+		 * dark default canvas is unreadable.  Mid-grey counts too:
+		 * Hacker News sets #828282 body text on a white page;
+		 * text meant for a dark background is light (> ~200). */
 		if (!bg_found && (body || root) && bs.color != ui.theme.text) {
 		if (!bg_found && (body || root) && bs.color != ui.theme.text) {
 			unsigned int c = bs.color;
 			unsigned int c = bs.color;
 			unsigned int lum = ((c >> 11) & 31) * 8 * 299 +
 			unsigned int lum = ((c >> 11) & 31) * 8 * 299 +
 					   ((c >> 5) & 63) * 4 * 587 +
 					   ((c >> 5) & 63) * 4 * 587 +
 					   (c & 31) * 8 * 114;
 					   (c & 31) * 8 * 114;
 
 
-			if (lum < 100 * 1000)
+			if (lum < 150 * 1000)
 				page_bg = 0xFFFF;
 				page_bg = 0xFFFF;
 		}
 		}
 	}
 	}

+ 5 - 0
user/apps/browser/browser_html.c

@@ -3255,6 +3255,11 @@ static int parse_font_size(const char *s, unsigned int len,
 	} else if (i + 2 <= len && ci_eq_n(s + i, "em", 2)) {
 	} else if (i + 2 <= len && ci_eq_n(s + i, "em", 2)) {
 		*raw = (unsigned short)v100;
 		*raw = (unsigned short)v100;
 		*unit = 2;
 		*unit = 2;
+	} else if (i + 2 <= len && ci_eq_n(s + i, "pt", 2)) {
+		/* 1pt = 4/3 px: Hacker News sets 10pt/7pt, which used to be
+		 * read as 10/7 px. */
+		*raw = (unsigned short)((v100 * 4 / 3 + 50) / 100);
+		*unit = 1;
 	} else if (i < len && s[i] == '%') {
 	} else if (i < len && s[i] == '%') {
 		/* Keep hundredths: 62.5% is a common root size and truncating
 		/* Keep hundredths: 62.5% is a common root size and truncating
 		 * it to 62% makes every rem 1px too small. */
 		 * it to 62% makes every rem 1px too small. */

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません