|
@@ -21,6 +21,7 @@
|
|
|
#include "uhttp.h"
|
|
#include "uhttp.h"
|
|
|
#include "img.h"
|
|
#include "img.h"
|
|
|
#include "inflate.h"
|
|
#include "inflate.h"
|
|
|
|
|
+#include "ufont.h"
|
|
|
|
|
|
|
|
/* Start wide enough for the desktop nav; smaller screens fall back to
|
|
/* Start wide enough for the desktop nav; smaller screens fall back to
|
|
|
* 960x640 and 780x540, which still fit a 1024x768 panel. */
|
|
* 960x640 and 780x540, which still fit a 1024x768 panel. */
|
|
@@ -119,6 +120,7 @@ static unsigned short img_h[BR_MAX_NODES];
|
|
|
* for page/CSS fetches, where the heap has no room for another multi-megabyte
|
|
* for page/CSS fetches, where the heap has no room for another multi-megabyte
|
|
|
* body. Decode arenas are allocated per image instead of living here. */
|
|
* body. Decode arenas are allocated per image instead of living here. */
|
|
|
static unsigned char *image_io_buf;
|
|
static unsigned char *image_io_buf;
|
|
|
|
|
+static struct ufont_face *font_faces[BR_MAX_FACES];
|
|
|
#define image_file_buf (image_io_buf)
|
|
#define image_file_buf (image_io_buf)
|
|
|
#define image_comp_buf (image_io_buf + BR_IMG_FILE_MAX)
|
|
#define image_comp_buf (image_io_buf + BR_IMG_FILE_MAX)
|
|
|
#define BR_PAGE_COMP_MAX (2u * BR_IMG_FILE_MAX)
|
|
#define BR_PAGE_COMP_MAX (2u * BR_IMG_FILE_MAX)
|
|
@@ -172,7 +174,7 @@ struct lay_run {
|
|
|
signed short dy; /* inline image vertical offset */
|
|
signed short dy; /* inline image vertical offset */
|
|
|
unsigned short iw, ih;
|
|
unsigned short iw, ih;
|
|
|
unsigned short w;
|
|
unsigned short w;
|
|
|
- unsigned char font_px, bold, italic, mono, underline;
|
|
|
|
|
|
|
+ unsigned char font_px, bold, italic, mono, underline, font_face;
|
|
|
unsigned char has_lit;
|
|
unsigned char has_lit;
|
|
|
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;
|
|
@@ -503,6 +505,7 @@ static int heap_start(void)
|
|
|
|
|
|
|
|
static void heap_clear(void)
|
|
static void heap_clear(void)
|
|
|
{
|
|
{
|
|
|
|
|
+ memset(font_faces, 0, sizeof(font_faces));
|
|
|
ngui_font_detach(&ui);
|
|
ngui_font_detach(&ui);
|
|
|
heap_reset();
|
|
heap_reset();
|
|
|
image_io_buf = 0;
|
|
image_io_buf = 0;
|
|
@@ -1823,6 +1826,48 @@ static int read_url(const char *url, unsigned int cap, unsigned char **out,
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* Load every @font-face the parser registered. Local files go through
|
|
|
|
|
+ * ufont_face_open_path(); remote files use the fetch helper (identity, the
|
|
|
|
|
+ * TTF parser has no gzip). A failed face stays NULL: layout then falls back
|
|
|
|
|
+ * to the built-in regular/bold/italic/mono set. */
|
|
|
|
|
+static void load_font_faces(void)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned int i;
|
|
|
|
|
+
|
|
|
|
|
+ memset(font_faces, 0, sizeof(font_faces));
|
|
|
|
|
+ for (i = 1; i <= (unsigned int)br_font_face_count() &&
|
|
|
|
|
+ i <= BR_MAX_FACES; i++) {
|
|
|
|
|
+ const char *url = br_font_face_url((int)i);
|
|
|
|
|
+ const char *base = br_font_face_base((int)i);
|
|
|
|
|
+ char abs[BR_URL_MAX];
|
|
|
|
|
+
|
|
|
|
|
+ if (!url || !url[0])
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (resolve_link(base && base[0] ? base : page_url, url, abs,
|
|
|
|
|
+ sizeof(abs)) != 0)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (abs[0] == '/') {
|
|
|
|
|
+ font_faces[i - 1] = ufont_face_open_path(abs);
|
|
|
|
|
+ } else if (is_http(abs)) {
|
|
|
|
|
+ unsigned char *buf;
|
|
|
|
|
+ char err[64];
|
|
|
|
|
+ int rv, tr = 0;
|
|
|
|
|
+
|
|
|
|
|
+ buf = (unsigned char *)malloc(UFONT_MAX_FILE);
|
|
|
|
|
+ if (!buf)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ rv = fetch_remote(abs, UFONT_MAX_FILE, 0, 0, buf,
|
|
|
|
|
+ UFONT_MAX_FILE, image_io_buf,
|
|
|
|
|
+ BR_PAGE_COMP_MAX, &fetch_meta, &tr,
|
|
|
|
|
+ err, sizeof(err));
|
|
|
|
|
+ if (rv > 0)
|
|
|
|
|
+ font_faces[i - 1] = ufont_face_open_mem(buf,
|
|
|
|
|
+ rv);
|
|
|
|
|
+ free(buf);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* Remote scripts are cached under /share for the current boot, like the
|
|
/* Remote scripts are cached under /share for the current boot, like the
|
|
|
* stylesheet cache, so reloads and later visits skip the network. */
|
|
* stylesheet cache, so reloads and later visits skip the network. */
|
|
|
static int script_cache_count;
|
|
static int script_cache_count;
|
|
@@ -2252,11 +2297,15 @@ static int load_stylesheets(void)
|
|
|
return FETCH_ABORT;
|
|
return FETCH_ABORT;
|
|
|
if (rv != 0)
|
|
if (rv != 0)
|
|
|
continue;
|
|
continue;
|
|
|
- if (len)
|
|
|
|
|
|
|
+ if (len) {
|
|
|
|
|
+ br_set_font_base(url);
|
|
|
br_parse_css_text(&doc, (const char *)data, len);
|
|
br_parse_css_text(&doc, (const char *)data, len);
|
|
|
|
|
+ }
|
|
|
sheets++;
|
|
sheets++;
|
|
|
}
|
|
}
|
|
|
|
|
+ br_set_font_base(page_url);
|
|
|
br_parse_inline_css(&doc);
|
|
br_parse_inline_css(&doc);
|
|
|
|
|
+ load_font_faces();
|
|
|
br_reset_styles(&doc);
|
|
br_reset_styles(&doc);
|
|
|
layout_valid = 0;
|
|
layout_valid = 0;
|
|
|
return 0;
|
|
return 0;
|
|
@@ -2843,6 +2892,53 @@ static void navigate(const char *input, int push)
|
|
|
|
|
|
|
|
/* ---- layout ---- */
|
|
/* ---- layout ---- */
|
|
|
|
|
|
|
|
|
|
+static struct ufont_face *style_face(const struct br_style *st)
|
|
|
|
|
+{
|
|
|
|
|
+ if (st && st->font_face && st->font_face <= BR_MAX_FACES)
|
|
|
|
|
+ return font_faces[st->font_face - 1];
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static struct ufont_face *run_face(const struct lay_run *r)
|
|
|
|
|
+{
|
|
|
|
|
+ if (r->font_face && r->font_face <= BR_MAX_FACES)
|
|
|
|
|
+ return font_faces[r->font_face - 1];
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static unsigned int face_text_width(struct ngui *gui,
|
|
|
|
|
+ const struct br_style *st,
|
|
|
|
|
+ const char *s, unsigned int n)
|
|
|
|
|
+{
|
|
|
|
|
+ return ngui_text_width_face(gui, style_face(st), s, n, st->font_px,
|
|
|
|
|
+ st->bold, st->italic, st->mono);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int face_line_height(struct ngui *gui, const struct br_style *st)
|
|
|
|
|
+{
|
|
|
|
|
+ return ngui_text_line_height_face(gui, style_face(st), st->font_px,
|
|
|
|
|
+ st->mono);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static unsigned int run_text_width(struct ngui *gui,
|
|
|
|
|
+ const struct lay_run *r,
|
|
|
|
|
+ const char *s, unsigned int n)
|
|
|
|
|
+{
|
|
|
|
|
+ return ngui_text_width_face(gui, run_face(r), s, n, r->font_px,
|
|
|
|
|
+ r->bold, r->italic, r->mono);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int run_line_height(struct ngui *gui, const struct lay_run *r)
|
|
|
|
|
+{
|
|
|
|
|
+ return ngui_text_line_height_face(gui, run_face(r), r->font_px,
|
|
|
|
|
+ r->mono);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int run_ascent(struct ngui *gui, const struct lay_run *r)
|
|
|
|
|
+{
|
|
|
|
|
+ return ngui_text_ascent_face(gui, run_face(r), r->font_px, r->mono);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static struct br_style base_style(void)
|
|
static struct br_style base_style(void)
|
|
|
{
|
|
{
|
|
|
struct br_style s = { 0 };
|
|
struct br_style s = { 0 };
|
|
@@ -3065,10 +3161,11 @@ static void flush_line(struct lay *l)
|
|
|
ngui_frame(l->ui, box,
|
|
ngui_frame(l->ui, box,
|
|
|
focused ? l->ui->theme.accent :
|
|
focused ? l->ui->theme.accent :
|
|
|
l->ui->theme.border);
|
|
l->ui->theme.border);
|
|
|
- ngui_text_px(l->ui, x + 6, ry + 2,
|
|
|
|
|
- r->lit, s_len(r->lit), fg,
|
|
|
|
|
- r->font_px, r->bold,
|
|
|
|
|
- r->italic, r->mono);
|
|
|
|
|
|
|
+ ngui_text_px_face(l->ui, run_face(r),
|
|
|
|
|
+ x + 6, ry + 2,
|
|
|
|
|
+ r->lit, s_len(r->lit),
|
|
|
|
|
+ fg, r->font_px, r->bold,
|
|
|
|
|
+ r->italic, r->mono);
|
|
|
if (focused && fs &&
|
|
if (focused && fs &&
|
|
|
(r->form_kind == FORM_TEXT ||
|
|
(r->form_kind == FORM_TEXT ||
|
|
|
r->form_kind == FORM_PASSWORD ||
|
|
r->form_kind == FORM_PASSWORD ||
|
|
@@ -3076,12 +3173,10 @@ static void flush_line(struct lay *l)
|
|
|
int cw = 0;
|
|
int cw = 0;
|
|
|
|
|
|
|
|
if (fs->len && fs->caret)
|
|
if (fs->len && fs->caret)
|
|
|
- cw = (int)ngui_text_width_px(
|
|
|
|
|
- l->ui, r->lit,
|
|
|
|
|
|
|
+ cw = (int)run_text_width(
|
|
|
|
|
+ l->ui, r, r->lit,
|
|
|
fs->caret < fs->len ?
|
|
fs->caret < fs->len ?
|
|
|
- fs->caret : fs->len,
|
|
|
|
|
- r->font_px, r->bold,
|
|
|
|
|
- r->italic, r->mono);
|
|
|
|
|
|
|
+ fs->caret : fs->len);
|
|
|
ngui_fill_rect(l->ui,
|
|
ngui_fill_rect(l->ui,
|
|
|
(struct ngui_rect){
|
|
(struct ngui_rect){
|
|
|
x + 6 + cw,
|
|
x + 6 + cw,
|
|
@@ -3105,10 +3200,11 @@ static void flush_line(struct lay *l)
|
|
|
ngui_frame(l->ui,
|
|
ngui_frame(l->ui,
|
|
|
(struct ngui_rect){x, ry, w, hh},
|
|
(struct ngui_rect){x, ry, w, hh},
|
|
|
l->ui->theme.border);
|
|
l->ui->theme.border);
|
|
|
- ngui_text_px(l->ui, x + 6, ry + 2,
|
|
|
|
|
- r->lit, s_len(r->lit), r->color,
|
|
|
|
|
- r->font_px, r->bold, r->italic,
|
|
|
|
|
- r->mono);
|
|
|
|
|
|
|
+ ngui_text_px_face(l->ui, run_face(r),
|
|
|
|
|
+ x + 6, ry + 2, r->lit,
|
|
|
|
|
+ s_len(r->lit), r->color,
|
|
|
|
|
+ r->font_px, r->bold, r->italic,
|
|
|
|
|
+ r->mono);
|
|
|
} else if (r->img >= 0) {
|
|
} else if (r->img >= 0) {
|
|
|
struct br_image *bi = &images[r->img];
|
|
struct br_image *bi = &images[r->img];
|
|
|
if (bi->state == 1) {
|
|
if (bi->state == 1) {
|
|
@@ -3134,16 +3230,13 @@ static void flush_line(struct lay *l)
|
|
|
doc.text + r->off;
|
|
doc.text + r->off;
|
|
|
unsigned int n = r->has_lit ? s_len(r->lit) :
|
|
unsigned int n = r->has_lit ? s_len(r->lit) :
|
|
|
r->len;
|
|
r->len;
|
|
|
- ngui_text_px(l->ui, x, ry, s, n,
|
|
|
|
|
- r->color, r->font_px, r->bold,
|
|
|
|
|
- r->italic, r->mono);
|
|
|
|
|
|
|
+ ngui_text_px_face(l->ui, run_face(r), x, ry,
|
|
|
|
|
+ s, n, r->color, r->font_px,
|
|
|
|
|
+ r->bold, r->italic, r->mono);
|
|
|
if (r->underline)
|
|
if (r->underline)
|
|
|
ngui_fill_rect(l->ui,
|
|
ngui_fill_rect(l->ui,
|
|
|
(struct ngui_rect){x,
|
|
(struct ngui_rect){x,
|
|
|
- ry +
|
|
|
|
|
- ngui_text_ascent(l->ui,
|
|
|
|
|
- r->font_px,
|
|
|
|
|
- r->mono) + 2,
|
|
|
|
|
|
|
+ ry + run_ascent(l->ui, r) + 2,
|
|
|
w, 1}, r->color);
|
|
w, 1}, r->color);
|
|
|
}
|
|
}
|
|
|
if (r->form || r->href) {
|
|
if (r->form || r->href) {
|
|
@@ -3153,8 +3246,7 @@ static void flush_line(struct lay *l)
|
|
|
r->form - 1 : r->href;
|
|
r->form - 1 : r->href;
|
|
|
int hh = (r->form || r->img >= 0) ?
|
|
int hh = (r->form || r->img >= 0) ?
|
|
|
r->ih :
|
|
r->ih :
|
|
|
- ngui_text_line_height(l->ui,
|
|
|
|
|
- r->font_px, r->mono);
|
|
|
|
|
|
|
+ run_line_height(l->ui, r);
|
|
|
int merge = nhits > 0 &&
|
|
int merge = nhits > 0 &&
|
|
|
hits[nhits - 1].node == target &&
|
|
hits[nhits - 1].node == target &&
|
|
|
hits[nhits - 1].y == ry &&
|
|
hits[nhits - 1].y == ry &&
|
|
@@ -3197,8 +3289,7 @@ static void add_run(struct lay *l, unsigned short off, unsigned short len,
|
|
|
{
|
|
{
|
|
|
unsigned int n = lit ? s_len(lit) : len;
|
|
unsigned int n = lit ? s_len(lit) : len;
|
|
|
const char *tp = lit ? lit : doc.text + off;
|
|
const char *tp = lit ? lit : doc.text + off;
|
|
|
- int w = (int)ngui_text_width_px(l->ui, tp, n, st->font_px,
|
|
|
|
|
- st->bold, st->italic, st->mono);
|
|
|
|
|
|
|
+ int w = (int)face_text_width(l->ui, st, tp, n);
|
|
|
|
|
|
|
|
if (l->nruns >= (int)(sizeof(l->runs) / sizeof(l->runs[0])))
|
|
if (l->nruns >= (int)(sizeof(l->runs) / sizeof(l->runs[0])))
|
|
|
flush_line(l);
|
|
flush_line(l);
|
|
@@ -3237,28 +3328,27 @@ static void add_run(struct lay *l, unsigned short off, unsigned short len,
|
|
|
r->bold = st->bold;
|
|
r->bold = st->bold;
|
|
|
r->italic = st->italic;
|
|
r->italic = st->italic;
|
|
|
r->mono = st->mono;
|
|
r->mono = st->mono;
|
|
|
|
|
+ r->font_face = st->font_face;
|
|
|
/* A control with its own background is a button, not body copy;
|
|
/* A control with its own background is a button, not body copy;
|
|
|
* an inherited link underline would strike through the fill. */
|
|
* an inherited link underline would strike through the fill. */
|
|
|
r->underline = st->underline && !st->has_bg;
|
|
r->underline = st->underline && !st->has_bg;
|
|
|
r->w = (unsigned short)w;
|
|
r->w = (unsigned short)w;
|
|
|
if (r->has_lit)
|
|
if (r->has_lit)
|
|
|
- r->w = (unsigned short)ngui_text_width_px(
|
|
|
|
|
- l->ui, r->lit, s_len(r->lit), r->font_px,
|
|
|
|
|
- r->bold, r->italic, r->mono);
|
|
|
|
|
|
|
+ r->w = (unsigned short)run_text_width(
|
|
|
|
|
+ l->ui, r, r->lit, s_len(r->lit));
|
|
|
w = r->w;
|
|
w = r->w;
|
|
|
}
|
|
}
|
|
|
l->line_x += w;
|
|
l->line_x += w;
|
|
|
l->run_x = l->line_x;
|
|
l->run_x = l->line_x;
|
|
|
{
|
|
{
|
|
|
- int lh = ngui_text_line_height(l->ui, st->font_px, st->mono);
|
|
|
|
|
|
|
+ int lh = face_line_height(l->ui, st);
|
|
|
|
|
|
|
|
if (st->line_h_px)
|
|
if (st->line_h_px)
|
|
|
lh = st->line_h_px;
|
|
lh = st->line_h_px;
|
|
|
else if (st->line_h_pct)
|
|
else if (st->line_h_pct)
|
|
|
lh = st->font_px * st->line_h_pct / 100;
|
|
lh = st->font_px * st->line_h_pct / 100;
|
|
|
- if (lh < ngui_text_line_height(l->ui, st->font_px, st->mono))
|
|
|
|
|
- lh = ngui_text_line_height(l->ui, st->font_px,
|
|
|
|
|
- st->mono);
|
|
|
|
|
|
|
+ if (lh < face_line_height(l->ui, st))
|
|
|
|
|
+ lh = face_line_height(l->ui, st);
|
|
|
if (l->line_h < lh)
|
|
if (l->line_h < lh)
|
|
|
l->line_h = lh;
|
|
l->line_h = lh;
|
|
|
}
|
|
}
|
|
@@ -3277,9 +3367,7 @@ static void add_image_run(struct lay *l, unsigned int node,
|
|
|
start_line(l, st);
|
|
start_line(l, st);
|
|
|
if (l->space_pending &&
|
|
if (l->space_pending &&
|
|
|
(l->nruns > 0 || l->line_x > l->line_left)) {
|
|
(l->nruns > 0 || l->line_x > l->line_left)) {
|
|
|
- int sp = (int)ngui_text_width_px(l->ui, " ", 1, st->font_px,
|
|
|
|
|
- st->bold, st->italic,
|
|
|
|
|
- st->mono);
|
|
|
|
|
|
|
+ int sp = (int)face_text_width(l->ui, st, " ", 1);
|
|
|
if (l->line_x + sp <= l->line_right)
|
|
if (l->line_x + sp <= l->line_right)
|
|
|
l->line_x += sp;
|
|
l->line_x += sp;
|
|
|
}
|
|
}
|
|
@@ -3296,16 +3384,14 @@ static void add_image_run(struct lay *l, unsigned int node,
|
|
|
s_append(tmp, &n, "[", sizeof(tmp));
|
|
s_append(tmp, &n, "[", sizeof(tmp));
|
|
|
s_append(tmp, &n, alt[0] ? alt : "image", sizeof(tmp));
|
|
s_append(tmp, &n, alt[0] ? alt : "image", sizeof(tmp));
|
|
|
s_append(tmp, &n, "]", sizeof(tmp));
|
|
s_append(tmp, &n, "]", sizeof(tmp));
|
|
|
- w = (int)ngui_text_width_px(l->ui, tmp, n, gs.font_px,
|
|
|
|
|
- gs.bold, gs.italic, gs.mono);
|
|
|
|
|
|
|
+ w = (int)face_text_width(l->ui, &gs, tmp, n);
|
|
|
if (l->line_x + w > l->line_right &&
|
|
if (l->line_x + w > l->line_right &&
|
|
|
(l->nruns > 0 || l->line_x > l->line_left))
|
|
(l->nruns > 0 || l->line_x > l->line_left))
|
|
|
flush_line(l);
|
|
flush_line(l);
|
|
|
add_run(l, 0, 0, &gs, href, tmp);
|
|
add_run(l, 0, 0, &gs, href, tmp);
|
|
|
if (!l->draw) {
|
|
if (!l->draw) {
|
|
|
int t = l->line_y < 0 ? 0 : l->line_y;
|
|
int t = l->line_y < 0 ? 0 : l->line_y;
|
|
|
- int hh = ngui_text_line_height(l->ui, gs.font_px,
|
|
|
|
|
- gs.mono);
|
|
|
|
|
|
|
+ int hh = face_line_height(l->ui, &gs);
|
|
|
|
|
|
|
|
if (t > 65535)
|
|
if (t > 65535)
|
|
|
t = 65535;
|
|
t = 65535;
|
|
@@ -3434,6 +3520,7 @@ static void add_image_run(struct lay *l, unsigned int node,
|
|
|
r->bold = st->bold;
|
|
r->bold = st->bold;
|
|
|
r->italic = st->italic;
|
|
r->italic = st->italic;
|
|
|
r->mono = st->mono;
|
|
r->mono = st->mono;
|
|
|
|
|
+ r->font_face = st->font_face;
|
|
|
r->underline = 0;
|
|
r->underline = 0;
|
|
|
}
|
|
}
|
|
|
if (node < BR_MAX_NODES) {
|
|
if (node < BR_MAX_NODES) {
|
|
@@ -3454,8 +3541,7 @@ static void add_image_run(struct lay *l, unsigned int node,
|
|
|
static int text_width(struct lay *l, const char *s, unsigned int n,
|
|
static int text_width(struct lay *l, const char *s, unsigned int n,
|
|
|
const struct br_style *st)
|
|
const struct br_style *st)
|
|
|
{
|
|
{
|
|
|
- return (int)ngui_text_width_px(l->ui, s, n, st->font_px,
|
|
|
|
|
- st->bold, st->italic, st->mono);
|
|
|
|
|
|
|
+ return (int)face_text_width(l->ui, st, s, n);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Longest prefix that fits in maxw, at least one byte. */
|
|
/* Longest prefix that fits in maxw, at least one byte. */
|
|
@@ -3521,8 +3607,7 @@ static void emit_text(struct lay *l, const char *s, unsigned int len,
|
|
|
{
|
|
{
|
|
|
unsigned int i = 0;
|
|
unsigned int i = 0;
|
|
|
unsigned int base;
|
|
unsigned int base;
|
|
|
- int space_w = (int)ngui_text_width_px(l->ui, " ", 1, st->font_px,
|
|
|
|
|
- st->bold, st->italic, st->mono);
|
|
|
|
|
|
|
+ int space_w = (int)face_text_width(l->ui, st, " ", 1);
|
|
|
|
|
|
|
|
if (!s || !len)
|
|
if (!s || !len)
|
|
|
return;
|
|
return;
|
|
@@ -3648,8 +3733,7 @@ static void add_form_run(struct lay *l, unsigned int node,
|
|
|
h = 40;
|
|
h = 40;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- tw = (int)ngui_text_width_px(l->ui, text, s_len(text), st->font_px,
|
|
|
|
|
- st->bold, st->italic, st->mono);
|
|
|
|
|
|
|
+ tw = (int)face_text_width(l->ui, st, text, s_len(text));
|
|
|
if (kind == FORM_BUTTON || kind == FORM_SUBMIT || kind == FORM_RESET) {
|
|
if (kind == FORM_BUTTON || kind == FORM_SUBMIT || kind == FORM_RESET) {
|
|
|
w = tw + 18;
|
|
w = tw + 18;
|
|
|
if (w < 64)
|
|
if (w < 64)
|
|
@@ -3692,6 +3776,7 @@ static void add_form_run(struct lay *l, unsigned int node,
|
|
|
r->bold = st->bold;
|
|
r->bold = st->bold;
|
|
|
r->italic = st->italic;
|
|
r->italic = st->italic;
|
|
|
r->mono = st->mono;
|
|
r->mono = st->mono;
|
|
|
|
|
+ r->font_face = st->font_face;
|
|
|
r->underline = 0;
|
|
r->underline = 0;
|
|
|
r->form = node + 1;
|
|
r->form = node + 1;
|
|
|
r->form_kind = (unsigned char)kind;
|
|
r->form_kind = (unsigned char)kind;
|
|
@@ -3990,11 +4075,11 @@ static void draw_svg(struct ngui *ui, unsigned node,
|
|
|
continue;
|
|
continue;
|
|
|
s = doc.text + doc.nodes[t].text_off;
|
|
s = doc.text + doc.nodes[t].text_off;
|
|
|
n = doc.nodes[t].text_len;
|
|
n = doc.nodes[t].text_len;
|
|
|
- tw = ngui_text_width_px(ui, s, n, px, st.bold,
|
|
|
|
|
- st.italic, st.mono);
|
|
|
|
|
|
|
+ tw = face_text_width(ui, &st, s, n);
|
|
|
tx = ox + (int)nd->svg_x * dw / vw;
|
|
tx = ox + (int)nd->svg_x * dw / vw;
|
|
|
ty = oy + (int)nd->svg_y * dh / vh -
|
|
ty = oy + (int)nd->svg_y * dh / vh -
|
|
|
- ngui_text_ascent(ui, px, st.mono);
|
|
|
|
|
|
|
+ ngui_text_ascent_face(ui, style_face(&st), px,
|
|
|
|
|
+ st.mono);
|
|
|
anchor = st.align;
|
|
anchor = st.align;
|
|
|
if (nd->attr_flags & BR_ATTR_ANCHOR_MIDDLE)
|
|
if (nd->attr_flags & BR_ATTR_ANCHOR_MIDDLE)
|
|
|
anchor = BR_ALIGN_CENTER;
|
|
anchor = BR_ALIGN_CENTER;
|
|
@@ -4004,8 +4089,9 @@ static void draw_svg(struct ngui *ui, unsigned node,
|
|
|
tx -= (int)tw / 2;
|
|
tx -= (int)tw / 2;
|
|
|
else if (anchor == BR_ALIGN_RIGHT)
|
|
else if (anchor == BR_ALIGN_RIGHT)
|
|
|
tx -= (int)tw;
|
|
tx -= (int)tw;
|
|
|
- ngui_text_px(ui, tx, ty, s, n, st.color, px,
|
|
|
|
|
- st.bold, st.italic, st.mono);
|
|
|
|
|
|
|
+ ngui_text_px_face(ui, style_face(&st), tx, ty, s, n,
|
|
|
|
|
+ st.color, px, st.bold, st.italic,
|
|
|
|
|
+ st.mono);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -4422,16 +4508,12 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
|
|
|
unsigned int tn = nd->text_len;
|
|
unsigned int tn = nd->text_len;
|
|
|
|
|
|
|
|
if (doc.nodes[node].tag == BR_TAG_PRE) {
|
|
if (doc.nodes[node].tag == BR_TAG_PRE) {
|
|
|
- w += (int)ngui_text_width_px(ui, t, tn,
|
|
|
|
|
- pst->font_px, pst->bold, pst->italic,
|
|
|
|
|
- pst->mono);
|
|
|
|
|
|
|
+ w += (int)face_text_width(ui, pst, t, tn);
|
|
|
} else {
|
|
} else {
|
|
|
unsigned int ti = 0;
|
|
unsigned int ti = 0;
|
|
|
int first = 1;
|
|
int first = 1;
|
|
|
int lead = w > 0 && tn > 0 && text_space(t[0]);
|
|
int lead = w > 0 && tn > 0 && text_space(t[0]);
|
|
|
- int sp = (int)ngui_text_width_px(ui, " ", 1,
|
|
|
|
|
- pst->font_px, pst->bold, pst->italic,
|
|
|
|
|
- pst->mono);
|
|
|
|
|
|
|
+ int sp = (int)face_text_width(ui, pst, " ", 1);
|
|
|
|
|
|
|
|
while (ti < tn) {
|
|
while (ti < tn) {
|
|
|
unsigned int ts;
|
|
unsigned int ts;
|
|
@@ -4446,10 +4528,8 @@ static int intrinsic_width(struct ngui *ui, unsigned int node,
|
|
|
if (!first || lead)
|
|
if (!first || lead)
|
|
|
w += sp;
|
|
w += sp;
|
|
|
lead = 0;
|
|
lead = 0;
|
|
|
- w += (int)ngui_text_width_px(ui,
|
|
|
|
|
- t + ts, ti - ts,
|
|
|
|
|
- pst->font_px, pst->bold,
|
|
|
|
|
- pst->italic, pst->mono);
|
|
|
|
|
|
|
+ w += (int)face_text_width(ui, pst,
|
|
|
|
|
+ t + ts, ti - ts);
|
|
|
first = 0;
|
|
first = 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|