|
@@ -253,6 +253,12 @@ struct lay_run {
|
|
|
unsigned int form; /* node + 1, 0 = not a control */
|
|
unsigned int form; /* node + 1, 0 = not a control */
|
|
|
unsigned char form_kind;
|
|
unsigned char form_kind;
|
|
|
unsigned char form_disabled;
|
|
unsigned char form_disabled;
|
|
|
|
|
+ /* RUN_PBOX: background colour, background image and its placement
|
|
|
|
|
+ * inside the iw x ih box (relative offsets, drawn size). */
|
|
|
|
|
+ unsigned char pb_has_bg;
|
|
|
|
|
+ unsigned short pb_bg;
|
|
|
|
|
+ short pb_img;
|
|
|
|
|
+ short pb_x, pb_y, pb_w, pb_h;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
struct lay {
|
|
struct lay {
|
|
@@ -466,6 +472,21 @@ static int button_has_elements(unsigned int node)
|
|
|
for (c = doc.nodes[node].first; c; c = doc.nodes[c].next)
|
|
for (c = doc.nodes[node].first; c; c = doc.nodes[c].next)
|
|
|
if (doc.nodes[c].type == BR_NODE_ELEM)
|
|
if (doc.nodes[c].type == BR_NODE_ELEM)
|
|
|
return 1;
|
|
return 1;
|
|
|
|
|
+ /* An empty button whose icon is a ::before/::after box (Docusaurus'
|
|
|
|
|
+ * sidebar caret) is laid out as an element so the box is drawn. */
|
|
|
|
|
+ if (!doc.nodes[node].first && doc.npe_rules) {
|
|
|
|
|
+ struct br_style st, ps;
|
|
|
|
|
+ char buf[8];
|
|
|
|
|
+ int pe;
|
|
|
|
|
+
|
|
|
|
|
+ style_for_node(node, &st);
|
|
|
|
|
+ for (pe = 1; pe <= 2; pe++)
|
|
|
|
|
+ if (!br_pseudo(&doc, node, pe, &st, &ps, buf,
|
|
|
|
|
+ sizeof(buf)) &&
|
|
|
|
|
+ ps.content == BR_CONTENT_EMPTY &&
|
|
|
|
|
+ ps.display != BR_DISPLAY_NONE)
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2341,6 +2362,12 @@ static void run_page_scripts(void)
|
|
|
|
|
|
|
|
/* ---- images ---- */
|
|
/* ---- images ---- */
|
|
|
|
|
|
|
|
|
|
+/* data: images that failed to decode (key = data_img_key()), so a layout
|
|
|
|
|
+ * pass does not retry them on every frame. */
|
|
|
|
|
+#define DATA_IMG_FAIL_MAX 32
|
|
|
|
|
+static unsigned int data_img_fail[DATA_IMG_FAIL_MAX];
|
|
|
|
|
+static int data_img_nfail;
|
|
|
|
|
+
|
|
|
static void image_reset(void)
|
|
static void image_reset(void)
|
|
|
{
|
|
{
|
|
|
int i;
|
|
int i;
|
|
@@ -2356,6 +2383,7 @@ static void image_reset(void)
|
|
|
images[i].disp_last = 0;
|
|
images[i].disp_last = 0;
|
|
|
}
|
|
}
|
|
|
image_count = 0;
|
|
image_count = 0;
|
|
|
|
|
+ data_img_nfail = 0;
|
|
|
image_pixels = 0;
|
|
image_pixels = 0;
|
|
|
image_disp_pixels = 0;
|
|
image_disp_pixels = 0;
|
|
|
image_disp_clock = 0;
|
|
image_disp_clock = 0;
|
|
@@ -4837,6 +4865,130 @@ static void preload_decode(unsigned int node, int bg,
|
|
|
image_repaint();
|
|
image_repaint();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+/* ---- data: URLs ----
|
|
|
|
|
+ *
|
|
|
|
|
+ * `data:[<type>][;base64],<payload>` decoded to bytes from the page heap
|
|
|
|
|
+ * (the caller frees them). The payload is percent-decoded, then base64-
|
|
|
|
|
+ * decoded when the header says so. Infima's menu chevron and many icon
|
|
|
|
|
+ * fonts' fallbacks are inline SVGs written this way. */
|
|
|
|
|
+static int b64_val(int c)
|
|
|
|
|
+{
|
|
|
|
|
+ if (c >= 'A' && c <= 'Z') return c - 'A';
|
|
|
|
|
+ if (c >= 'a' && c <= 'z') return c - 'a' + 26;
|
|
|
|
|
+ if (c >= '0' && c <= '9') return c - '0' + 52;
|
|
|
|
|
+ if (c == '+' || c == '-') return 62;
|
|
|
|
|
+ if (c == '/' || c == '_') return 63;
|
|
|
|
|
+ return -1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int hex_val(int c)
|
|
|
|
|
+{
|
|
|
|
|
+ if (c >= '0' && c <= '9') return c - '0';
|
|
|
|
|
+ c |= 32;
|
|
|
|
|
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
|
|
|
|
+ return -1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int data_url_decode(const char *url, unsigned char **out,
|
|
|
|
|
+ unsigned int *out_len)
|
|
|
|
|
+{
|
|
|
|
|
+ const char *comma, *p;
|
|
|
|
|
+ unsigned int n = 0, len, i;
|
|
|
|
|
+ unsigned char *buf;
|
|
|
|
|
+ int base64 = 0;
|
|
|
|
|
+
|
|
|
|
|
+ *out = 0;
|
|
|
|
|
+ *out_len = 0;
|
|
|
|
|
+ if (!starts_with(url, "data:"))
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ comma = url + 5;
|
|
|
|
|
+ while (*comma && *comma != ',')
|
|
|
|
|
+ comma++;
|
|
|
|
|
+ if (!*comma)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ for (p = url + 5; p + 7 <= comma; p++)
|
|
|
|
|
+ if (!strncmp(p, ";base64", 7))
|
|
|
|
|
+ base64 = 1;
|
|
|
|
|
+ len = s_len(comma + 1);
|
|
|
|
|
+ buf = (unsigned char *)malloc(len + 1);
|
|
|
|
|
+ if (!buf)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ for (i = 0, p = comma + 1; i < len; i++) {
|
|
|
|
|
+ int c = (unsigned char)p[i];
|
|
|
|
|
+
|
|
|
|
|
+ if (c == '%' && i + 2 < len &&
|
|
|
|
|
+ hex_val(p[i + 1]) >= 0 && hex_val(p[i + 2]) >= 0) {
|
|
|
|
|
+ c = hex_val(p[i + 1]) * 16 + hex_val(p[i + 2]);
|
|
|
|
|
+ i += 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ buf[n++] = (unsigned char)c;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (base64) {
|
|
|
|
|
+ unsigned int acc = 0, o = 0;
|
|
|
|
|
+ int bits = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
|
|
+ int v = b64_val(buf[i]);
|
|
|
|
|
+
|
|
|
|
|
+ if (v < 0)
|
|
|
|
|
+ continue; /* padding, whitespace */
|
|
|
|
|
+ acc = (acc << 6) | (unsigned int)v;
|
|
|
|
|
+ bits += 6;
|
|
|
|
|
+ if (bits >= 8) {
|
|
|
|
|
+ bits -= 8;
|
|
|
|
|
+ buf[o++] = (unsigned char)(acc >> bits);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ n = o;
|
|
|
|
|
+ }
|
|
|
|
|
+ buf[n] = 0;
|
|
|
|
|
+ *out = buf;
|
|
|
|
|
+ *out_len = n;
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static unsigned int data_img_key(const char *url, int w, int h)
|
|
|
|
|
+{
|
|
|
|
|
+ return (script_cache_hash(url) ^ ((unsigned int)w * 2654435761u) ^
|
|
|
|
|
+ ((unsigned int)h * 40503u)) | 1u;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* The image index of a data: URL decoded for a w x h box (an SVG is
|
|
|
|
|
+ * rasterized at that size), decoding it on first use; -1 on failure.
|
|
|
|
|
+ * Decoded bitmaps are found again through url_hash, which is distinct
|
|
|
|
|
+ * from the <img> sharing hash because it mixes in the size. */
|
|
|
|
|
+static int data_url_image(const char *url, int w, int h)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned int key, len;
|
|
|
|
|
+ unsigned char *data;
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ if (!starts_with(url, "data:") || w <= 0 || h <= 0)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ key = data_img_key(url, w, h);
|
|
|
|
|
+ for (i = 0; i < image_count; i++)
|
|
|
|
|
+ if (images[i].state == 1 && images[i].url_hash == key)
|
|
|
|
|
+ return i;
|
|
|
|
|
+ for (i = 0; i < data_img_nfail; i++)
|
|
|
|
|
+ if (data_img_fail[i] == key)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ if (image_count < BR_MAX_IMAGES &&
|
|
|
|
|
+ data_url_decode(url, &data, &len) == 0) {
|
|
|
|
|
+ int r = decode_image_data(data, len, &images[image_count],
|
|
|
|
|
+ w, h, w, h);
|
|
|
|
|
+
|
|
|
|
|
+ free(data);
|
|
|
|
|
+ if (r == 0) {
|
|
|
|
|
+ images[image_count].url_hash = key;
|
|
|
|
|
+ return image_count++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (data_img_nfail < DATA_IMG_FAIL_MAX)
|
|
|
|
|
+ data_img_fail[data_img_nfail++] = key;
|
|
|
|
|
+ return -1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* A local file image bypasses the helpers: count its decode so a page opened
|
|
/* A local file image bypasses the helpers: count its decode so a page opened
|
|
|
* from /share or /data still produces the same timing breakdown. */
|
|
* from /share or /data still produces the same timing breakdown. */
|
|
|
static void img_stat_local(int before, unsigned int bytes, unsigned int io_ms)
|
|
static void img_stat_local(int before, unsigned int bytes, unsigned int io_ms)
|
|
@@ -5081,8 +5233,24 @@ static int preload_fill_jobs(void)
|
|
|
preload_node++;
|
|
preload_node++;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (starts_with(bsrc, "data:")) {
|
|
|
|
|
+ /* Inline image: decode now,
|
|
|
|
|
+ * no fetch helper. */
|
|
|
|
|
+ unsigned char *data;
|
|
|
|
|
+ unsigned int len;
|
|
|
|
|
+
|
|
|
|
|
+ preload_node = i + 1;
|
|
|
|
|
+ if (data_url_decode(bsrc, &data,
|
|
|
|
|
+ &len) == 0) {
|
|
|
|
|
+ preload_decode(i, 1, data,
|
|
|
|
|
+ len, 0);
|
|
|
|
|
+ free(data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ nd->bg_img_index = -2;
|
|
|
|
|
+ }
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
if (bsrc[0] &&
|
|
if (bsrc[0] &&
|
|
|
- !starts_with(bsrc, "data:") &&
|
|
|
|
|
resolve_link(page_url, bsrc, url,
|
|
resolve_link(page_url, bsrc, url,
|
|
|
sizeof(url)) == 0) {
|
|
sizeof(url)) == 0) {
|
|
|
if (image_count +
|
|
if (image_count +
|
|
@@ -5150,7 +5318,20 @@ static int preload_fill_jobs(void)
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
src = br_src(&doc, i);
|
|
src = br_src(&doc, i);
|
|
|
- if (!src[0] || starts_with(src, "data:")) {
|
|
|
|
|
|
|
+ if (starts_with(src, "data:")) {
|
|
|
|
|
+ unsigned char *data;
|
|
|
|
|
+ unsigned int len;
|
|
|
|
|
+
|
|
|
|
|
+ preload_node = i + 1;
|
|
|
|
|
+ if (data_url_decode(src, &data, &len) == 0) {
|
|
|
|
|
+ preload_decode(i, 0, data, len, 0);
|
|
|
|
|
+ free(data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ doc.nodes[i].img_index = -2;
|
|
|
|
|
+ }
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!src[0]) {
|
|
|
preload_node++;
|
|
preload_node++;
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -6484,14 +6665,16 @@ static void svg_paint_box(struct ngui *ui, unsigned int node,
|
|
|
int h);
|
|
int h);
|
|
|
|
|
|
|
|
/* Run kinds besides text: img >= 0 an <img> bitmap, -2 a button label,
|
|
/* Run kinds besides text: img >= 0 an <img> bitmap, -2 a button label,
|
|
|
- * RUN_SVG an inline <svg> icon (its node in off). */
|
|
|
|
|
|
|
+ * RUN_SVG an inline <svg> icon (its node in off), RUN_PBOX an empty
|
|
|
|
|
+ * ::before/::after box with a background (Infima's menu chevrons). */
|
|
|
#define RUN_SVG (-3)
|
|
#define RUN_SVG (-3)
|
|
|
|
|
+#define RUN_PBOX (-4)
|
|
|
|
|
|
|
|
static int run_width(const struct lay_run *r)
|
|
static int run_width(const struct lay_run *r)
|
|
|
{
|
|
{
|
|
|
if (r->img >= 0)
|
|
if (r->img >= 0)
|
|
|
return r->iw;
|
|
return r->iw;
|
|
|
- if (r->img == -2 || r->img == RUN_SVG)
|
|
|
|
|
|
|
+ if (r->img == -2 || r->img == RUN_SVG || r->img == RUN_PBOX)
|
|
|
return r->iw;
|
|
return r->iw;
|
|
|
return (int)r->w;
|
|
return (int)r->w;
|
|
|
}
|
|
}
|
|
@@ -6690,6 +6873,29 @@ static void flush_line(struct lay *l)
|
|
|
r->font_px, 0, 0, 0);
|
|
r->font_px, 0, 0, 0);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (r->img == RUN_PBOX) {
|
|
|
|
|
+ struct ngui_rect bx = { x, ry, w, r->ih };
|
|
|
|
|
+
|
|
|
|
|
+ ngui_push_clip(l->ui, bx);
|
|
|
|
|
+ if (r->pb_has_bg)
|
|
|
|
|
+ ngui_fill_rect(l->ui, bx, r->pb_bg);
|
|
|
|
|
+ if (r->pb_img >= 0 && r->pb_img < image_count &&
|
|
|
|
|
+ images[r->pb_img].state == 1) {
|
|
|
|
|
+ /* Rotate about the box centre: the
|
|
|
|
|
+ * image is centred in it here. */
|
|
|
|
|
+ draw_image_transformed(l->ui,
|
|
|
|
|
+ &images[r->pb_img].img,
|
|
|
|
|
+ x + r->pb_x, ry + r->pb_y,
|
|
|
|
|
+ r->pb_w, r->pb_h,
|
|
|
|
|
+ r->transform_scale ?
|
|
|
|
|
+ r->scale_x : 100,
|
|
|
|
|
+ r->transform_scale ?
|
|
|
|
|
+ r->scale_y : 100,
|
|
|
|
|
+ r->transform_scale ?
|
|
|
|
|
+ r->rotate_x100 : 0,
|
|
|
|
|
+ 50, 50, 1, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ ngui_pop_clip(l->ui);
|
|
|
} else if (r->img == RUN_SVG) {
|
|
} else if (r->img == RUN_SVG) {
|
|
|
struct br_style sst;
|
|
struct br_style sst;
|
|
|
|
|
|
|
@@ -7637,6 +7843,10 @@ static void layout_children(struct lay *l, unsigned int parent,
|
|
|
static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
|
const struct br_style *pst, int depth,
|
|
const struct br_style *pst, int depth,
|
|
|
unsigned short link);
|
|
unsigned short link);
|
|
|
|
|
+static int pseudo_box_w(unsigned int node, const struct br_style *st, int pe,
|
|
|
|
|
+ struct br_style *ps, int base);
|
|
|
|
|
+static void emit_pseudo_box(struct lay *l, const struct br_style *parent,
|
|
|
|
|
+ const struct br_style *ps, unsigned short link);
|
|
|
static void layout_grid_children(struct lay *l, unsigned int parent,
|
|
static void layout_grid_children(struct lay *l, unsigned int parent,
|
|
|
const struct br_style *pst, int depth,
|
|
const struct br_style *pst, int depth,
|
|
|
unsigned short link);
|
|
unsigned short link);
|
|
@@ -8464,8 +8674,16 @@ static int svg_decode_image(const unsigned char *data, unsigned int len,
|
|
|
base.color = 0x0000;
|
|
base.color = 0x0000;
|
|
|
br_style_for(&doc, svg, &base, &st);
|
|
br_style_for(&doc, svg, &base, &st);
|
|
|
svg_root_matrix(svg, w, h, m);
|
|
svg_root_matrix(svg, w, h, m);
|
|
|
- svg_vp_w = have_vb ? vb[2] : w;
|
|
|
|
|
- svg_vp_h = have_vb ? vb[3] : h;
|
|
|
|
|
|
|
+ if (!have_vb && nat_w > 0 && nat_h > 0) {
|
|
|
|
|
+ /* No viewBox: user units are CSS pixels of the natural size,
|
|
|
|
|
+ * so the up-to-4x raster (and a box size) must scale them.
|
|
|
|
|
+ * A 40x20 icon used to fill only the top-left quarter of its
|
|
|
|
|
+ * 160x80 bitmap and was drawn at a quarter of its size. */
|
|
|
|
|
+ m[0] = (double)w / nat_w;
|
|
|
|
|
+ m[3] = (double)h / nat_h;
|
|
|
|
|
+ }
|
|
|
|
|
+ svg_vp_w = have_vb ? vb[2] : nat_w;
|
|
|
|
|
+ svg_vp_h = have_vb ? vb[3] : nat_h;
|
|
|
svg_draw_children(&L, svg, m, &st, 255, 0);
|
|
svg_draw_children(&L, svg, m, &st, 255, 0);
|
|
|
bi->native_w = nat_w;
|
|
bi->native_w = nat_w;
|
|
|
bi->native_h = nat_h;
|
|
bi->native_h = nat_h;
|
|
@@ -9266,6 +9484,14 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
|
|
|
|
|
|
|
|
if (depth > 32)
|
|
if (depth > 32)
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
+ if (doc.npe_rules) {
|
|
|
|
|
+ struct br_style ps;
|
|
|
|
|
+
|
|
|
|
|
+ /* Icon boxes (::before/::after with a size) are inline
|
|
|
|
|
+ * content of the element. */
|
|
|
|
|
+ line_w += pseudo_box_w(node, pst, 1, &ps, base) +
|
|
|
|
|
+ pseudo_box_w(node, pst, 2, &ps, base);
|
|
|
|
|
+ }
|
|
|
for (c = doc.nodes[node].first; c; c = doc.nodes[c].next) {
|
|
for (c = doc.nodes[node].first; c; c = doc.nodes[c].next) {
|
|
|
struct br_node *nd = &doc.nodes[c];
|
|
struct br_node *nd = &doc.nodes[c];
|
|
|
struct br_style cs;
|
|
struct br_style cs;
|
|
@@ -9882,6 +10108,9 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
|
int avail = row_right - row_left;
|
|
int avail = row_right - row_left;
|
|
|
int idx, row_top;
|
|
int idx, row_top;
|
|
|
unsigned char row_align = l->align;
|
|
unsigned char row_align = l->align;
|
|
|
|
|
+ int box_left = l->left, box_right = l->right, row_top0 = l->y;
|
|
|
|
|
+ int bw = 0, aw = 0, first_h = -1;
|
|
|
|
|
+ struct br_style bps, aps;
|
|
|
|
|
|
|
|
if (avail < 8 || depth > 48) {
|
|
if (avail < 8 || depth > 48) {
|
|
|
layout_children(l, parent, pst, depth, link);
|
|
layout_children(l, parent, pst, depth, link);
|
|
@@ -9899,6 +10128,20 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /* ::before/::after icon boxes are the row's first and last items
|
|
|
|
|
+ * (Docusaurus' sidebar chevron): reserve their columns. */
|
|
|
|
|
+ if (doc.npe_rules) {
|
|
|
|
|
+ bw = pseudo_box_w(parent, pst, 1, &bps, avail);
|
|
|
|
|
+ aw = pseudo_box_w(parent, pst, 2, &aps, avail);
|
|
|
|
|
+ if (bw + aw > avail - 8) {
|
|
|
|
|
+ bw = 0;
|
|
|
|
|
+ aw = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ row_left += bw;
|
|
|
|
|
+ row_right -= aw;
|
|
|
|
|
+ avail = row_right - row_left;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for (c = doc.nodes[parent].first;
|
|
for (c = doc.nodes[parent].first;
|
|
|
c && nitem < (int)(sizeof(it) / sizeof(it[0]));
|
|
c && nitem < (int)(sizeof(it) / sizeof(it[0]));
|
|
|
c = doc.nodes[c].next) {
|
|
c = doc.nodes[c].next) {
|
|
@@ -10084,10 +10327,41 @@ static void layout_flex_children(struct lay *l, unsigned int parent,
|
|
|
if (k + 1 < count)
|
|
if (k + 1 < count)
|
|
|
x += gap + extra;
|
|
x += gap + extra;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (first_h < 0)
|
|
|
|
|
+ first_h = row_h;
|
|
|
row_top += row_h;
|
|
row_top += row_h;
|
|
|
}
|
|
}
|
|
|
- l->left = row_left;
|
|
|
|
|
- l->right = row_right;
|
|
|
|
|
|
|
+ if (bw || aw) {
|
|
|
|
|
+ int pass;
|
|
|
|
|
+
|
|
|
|
|
+ for (pass = 0; pass < 2; pass++) {
|
|
|
|
|
+ const struct br_style *ps = pass ? &aps : &bps;
|
|
|
|
|
+ int a = pass ? row_right : box_left;
|
|
|
|
|
+ int b = pass ? box_right : row_left;
|
|
|
|
|
+ int h = ps->height_kind ?
|
|
|
|
|
+ style_height_px(ps, box_right - box_left) : 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (!(pass ? aw : bw))
|
|
|
|
|
+ continue;
|
|
|
|
|
+ l->left = l->line_left = l->line_x = l->run_x = a;
|
|
|
|
|
+ l->right = l->line_right = b;
|
|
|
|
|
+ l->y = row_top0;
|
|
|
|
|
+ if (pst->align_items == 1 && first_h > h)
|
|
|
|
|
+ l->y += (first_h - h) / 2;
|
|
|
|
|
+ l->line_y = l->y;
|
|
|
|
|
+ l->line_h = 0;
|
|
|
|
|
+ l->nruns = 0;
|
|
|
|
|
+ l->space_pending = 0;
|
|
|
|
|
+ emit_pseudo_box(l, pst, ps, link);
|
|
|
|
|
+ flush_line(l);
|
|
|
|
|
+ /* The box sits inside the first row; it only makes
|
|
|
|
|
+ * the row taller when it is taller itself. */
|
|
|
|
|
+ if (row_top0 + h > row_top)
|
|
|
|
|
+ row_top = row_top0 + h;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ l->left = box_left;
|
|
|
|
|
+ l->right = box_right;
|
|
|
l->align = row_align;
|
|
l->align = row_align;
|
|
|
l->y = row_top;
|
|
l->y = row_top;
|
|
|
l->line_x = l->left;
|
|
l->line_x = l->left;
|
|
@@ -11056,6 +11330,119 @@ struct br_deferred {
|
|
|
static struct br_deferred deferred[BR_MAX_DEFERRED];
|
|
static struct br_deferred deferred[BR_MAX_DEFERRED];
|
|
|
static int ndeferred;
|
|
static int ndeferred;
|
|
|
|
|
|
|
|
|
|
+/* Outer width of an element's empty ::before (pe 1) / ::after (pe 2) icon
|
|
|
|
|
+ * box, 0 when it has none; *ps receives the pseudo-element's style. */
|
|
|
|
|
+static int pseudo_box_w(unsigned int node, const struct br_style *st, int pe,
|
|
|
|
|
+ struct br_style *ps, int base)
|
|
|
|
|
+{
|
|
|
|
|
+ char buf[8];
|
|
|
|
|
+ int w, h;
|
|
|
|
|
+
|
|
|
|
|
+ if (!doc.npe_rules ||
|
|
|
|
|
+ br_pseudo(&doc, node, pe, st, ps, buf, sizeof(buf)) ||
|
|
|
|
|
+ ps->content != BR_CONTENT_EMPTY || ps->display == BR_DISPLAY_NONE)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ w = ps->width_kind ? style_width_px(ps, base) : 0;
|
|
|
|
|
+ h = ps->height_kind ? style_height_px(ps, base) : 0;
|
|
|
|
|
+ if (ps->min_width_kind == 1 && w < (int)ps->min_width)
|
|
|
|
|
+ w = (int)ps->min_width;
|
|
|
|
|
+ if (w <= 0)
|
|
|
|
|
+ w = h;
|
|
|
|
|
+ if (w <= 0 || w > 512)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ return w + (ps->ml_auto ? 0 : mp_px(ps, 3, base)) + mp_px(ps, 1, base);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* An empty ::before/::after with a size and a background: one run the
|
|
|
|
|
+ * size of the box. Only data: background images are drawn (decoded at
|
|
|
|
|
+ * the background-size); `margin-left: auto` inside a flex parent pushes
|
|
|
|
|
+ * the box to the line's right edge like the flex row would. */
|
|
|
|
|
+static void emit_pseudo_box(struct lay *l, const struct br_style *parent,
|
|
|
|
|
+ const struct br_style *ps, unsigned short link)
|
|
|
|
|
+{
|
|
|
|
|
+ struct lay_run *r;
|
|
|
|
|
+ int lw = l->line_right - l->line_left, w, h, ml, mr, tw, th;
|
|
|
|
|
+ const char *url = ps->bg_image ? br_bg_image_url(ps->bg_image - 1) : "";
|
|
|
|
|
+
|
|
|
|
|
+ if (lw < 8)
|
|
|
|
|
+ lw = 8;
|
|
|
|
|
+ w = ps->width_kind ? style_width_px(ps, lw) : 0;
|
|
|
|
|
+ h = ps->height_kind ? style_height_px(ps, lw) : 0;
|
|
|
|
|
+ if (ps->min_width_kind == 1 && w < (int)ps->min_width)
|
|
|
|
|
+ w = (int)ps->min_width;
|
|
|
|
|
+ if (w <= 0)
|
|
|
|
|
+ w = h;
|
|
|
|
|
+ if (h <= 0)
|
|
|
|
|
+ h = w;
|
|
|
|
|
+ if (w <= 0 || w > 512 || h > 512)
|
|
|
|
|
+ return;
|
|
|
|
|
+ ml = ps->ml_auto ? 0 : mp_px(ps, 3, lw);
|
|
|
|
|
+ mr = mp_px(ps, 1, lw);
|
|
|
|
|
+ if (ml < 0)
|
|
|
|
|
+ ml = 0;
|
|
|
|
|
+ if (mr < 0)
|
|
|
|
|
+ mr = 0;
|
|
|
|
|
+ if (l->line_x + ml + w > l->line_right &&
|
|
|
|
|
+ (l->nruns > 0 || l->line_x > l->line_left))
|
|
|
|
|
+ flush_line(l);
|
|
|
|
|
+ if (l->nruns >= (int)(sizeof(l->runs) / sizeof(l->runs[0])))
|
|
|
|
|
+ flush_line(l);
|
|
|
|
|
+ if (l->nruns == 0) {
|
|
|
|
|
+ l->line_y = l->y;
|
|
|
|
|
+ l->line_h = 0;
|
|
|
|
|
+ start_line(l, ps);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ps->ml_auto && parent->display == BR_DISPLAY_FLEX &&
|
|
|
|
|
+ l->line_right - w - mr > l->line_x)
|
|
|
|
|
+ l->line_x = l->line_right - w - mr;
|
|
|
|
|
+ else
|
|
|
|
|
+ l->line_x += ml;
|
|
|
|
|
+ r = &l->runs[l->nruns++];
|
|
|
|
|
+ memset(r, 0, sizeof(*r));
|
|
|
|
|
+ r->gap = (unsigned short)(l->line_x > l->run_x ?
|
|
|
|
|
+ l->line_x - l->run_x : 0);
|
|
|
|
|
+ r->img = RUN_PBOX;
|
|
|
|
|
+ r->href = link;
|
|
|
|
|
+ r->iw = (unsigned short)w;
|
|
|
|
|
+ r->ih = (unsigned short)h;
|
|
|
|
|
+ r->w = (unsigned short)w;
|
|
|
|
|
+ r->font_px = ps->font_px;
|
|
|
|
|
+ r->pb_has_bg = ps->has_bg;
|
|
|
|
|
+ r->pb_bg = ps->bg;
|
|
|
|
|
+ r->pb_img = -1;
|
|
|
|
|
+ if (ps->transform_set) {
|
|
|
|
|
+ r->transform_scale = 1;
|
|
|
|
|
+ r->scale_x = ps->scale_x;
|
|
|
|
|
+ r->scale_y = ps->scale_y;
|
|
|
|
|
+ r->rotate_x100 = ps->rotate_x100;
|
|
|
|
|
+ }
|
|
|
|
|
+ /* Background size and position, as draw_bg_image() resolves them. */
|
|
|
|
|
+ tw = w;
|
|
|
|
|
+ th = h;
|
|
|
|
|
+ if (ps->bg_size_kind == 1 || ps->bg_size_kind == 2) {
|
|
|
|
|
+ int bw = ps->bg_size_w, bh = ps->bg_size_h;
|
|
|
|
|
+
|
|
|
|
|
+ if (ps->bg_size_kind == 2) {
|
|
|
|
|
+ bw = bw ? w * bw / 100 : 0;
|
|
|
|
|
+ bh = bh ? h * bh / 100 : 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ tw = bw ? bw : (bh ? bh : w);
|
|
|
|
|
+ th = bh ? bh : tw;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (tw > 0 && th > 0 && tw <= 512 && th <= 512 && url[0])
|
|
|
|
|
+ r->pb_img = (short)data_url_image(url, tw, th);
|
|
|
|
|
+ r->pb_w = (short)tw;
|
|
|
|
|
+ r->pb_h = (short)th;
|
|
|
|
|
+ r->pb_x = (short)(ps->bg_pos_x_kind == 1 ?
|
|
|
|
|
+ (w - tw) * ps->bg_pos_x / 100 : ps->bg_pos_x);
|
|
|
|
|
+ r->pb_y = (short)(ps->bg_pos_y_kind == 1 ?
|
|
|
|
|
+ (h - th) * ps->bg_pos_y / 100 : ps->bg_pos_y);
|
|
|
|
|
+ l->line_x += w + mr;
|
|
|
|
|
+ l->run_x = l->line_x;
|
|
|
|
|
+ if (l->line_h < h)
|
|
|
|
|
+ l->line_h = h;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* ::before/::after generated text (br_pseudo()) as literal runs in the
|
|
/* ::before/::after generated text (br_pseudo()) as literal runs in the
|
|
|
* element's line. A block-level pseudo-element gets its own line; its box
|
|
* element's line. A block-level pseudo-element gets its own line; its box
|
|
|
* (margins, padding, background) is not drawn. */
|
|
* (margins, padding, background) is not drawn. */
|
|
@@ -11068,6 +11455,11 @@ static void emit_pseudo(struct lay *l, unsigned int node,
|
|
|
unsigned int i = 0;
|
|
unsigned int i = 0;
|
|
|
int block, space_w;
|
|
int block, space_w;
|
|
|
|
|
|
|
|
|
|
+ if (!n && ps.content == BR_CONTENT_EMPTY &&
|
|
|
|
|
+ ps.display != BR_DISPLAY_NONE) {
|
|
|
|
|
+ emit_pseudo_box(l, st, &ps, link);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
if (!n)
|
|
if (!n)
|
|
|
return;
|
|
return;
|
|
|
block = ps.display == BR_DISPLAY_BLOCK || ps.display == BR_DISPLAY_FLEX;
|
|
block = ps.display == BR_DISPLAY_BLOCK || ps.display == BR_DISPLAY_FLEX;
|