20static void spacing_str(
char *buf,
size_t len)
24 ch[gp_to_utf8(gui.code, ch)] = 0;
26 snprintf(buf, len,
"non%snon HOH%sHOH", ch, ch);
33static const char *block_sample(
char *buf,
size_t len)
44 sample = gpf_ucode_block_sample(block->name);
48 for (code = block->min; code <= block->max; code++) {
57 pos += gp_to_utf8(code, buf + pos);
71static const char *custom_line(
void)
75 if (!gui.preview_text)
78 text = gp_widget_tbox_text(gui.preview_text);
80 if (!text || !text[0])
93static void draw_rule(gp_pixmap *p,
const gp_text_style *style,
int x,
94 int baseline,
unsigned int w,
95 enum gp_text_decor_type type, gp_pixel fg)
97 gp_fill_rect_xywh(p, x, baseline - gp_text_decor_pos(style, type),
98 w, gp_text_decor_thickness(style, type), fg);
101static void draw_rules(gp_pixmap *p,
const gp_text_style *style,
int x,
int y,
102 const char *str, gp_pixel fg)
104 int baseline = y + (int)gp_text_ascent(style);
105 unsigned int w = gp_text_wbbox(style, str);
107 if (gui.rule_underline) {
108 draw_rule(p, style, x, baseline, w, GP_TEXT_DECOR_UNDERLINE,
112 if (gui.rule_strike) {
113 draw_rule(p, style, x, baseline, w,
114 GP_TEXT_DECOR_STRIKETHROUGH, fg);
117 if (gui.rule_overline)
118 draw_rule(p, style, x, baseline, w, GP_TEXT_DECOR_OVERLINE, fg);
136static int lines_height(
const gp_font_face *face,
137 const struct preview_line *lines,
unsigned int cnt)
142 for (i = 0; i < cnt; i++) {
143 for (z = 1; z <= MAX_ZOOM; z++) {
144 if (lines[i].zooms & (1u << (z - 1)))
145 h += z * gp_font_height(face) + ZOOM_GAP;
148 h += LINE_GAP - ZOOM_GAP;
161static void lines_fit(
const gp_font_face *face,
struct preview_line *lines,
162 unsigned int cnt,
int h)
164 static const unsigned int prio[] = {1, 2, 0};
167 for (i = 0; i < GP_ARRAY_SIZE(prio); i++) {
171 lines[prio[i]].zooms |= 2;
173 if (lines_height(face, lines, cnt) > h)
174 lines[prio[i]].zooms &= ~2u;
177 for (i = 0; i < cnt; i++) {
178 if (!(lines[i].zooms & 2))
182 for (i = 0; i < cnt; i++)
185 if (lines_height(face, lines, cnt) <= h)
188 for (i = 0; i < cnt; i++)
189 lines[i].zooms &= ~4u;
192void gpf_preview_draw(gp_widget *self)
194 gp_pixmap *p = gp_widget_pixmap_get(self);
195 const gp_widget_render_ctx *ctx = gp_widgets_render_ctx();
196 const gp_font_face *face = gpf_gui_face(gui.variant);
197 gp_text_style style = {};
198 struct preview_line lines[3];
199 const char *custom = custom_line();
200 char sample[256], spacing[64];
201 unsigned int i, z, cnt = 0;
208 fg = gp_widgets_color(ctx, GP_WIDGETS_COL_TEXT);
209 bg = gp_widgets_color(ctx, GP_WIDGETS_COL_FG);
218 spacing_str(spacing,
sizeof(spacing));
224 lines[cnt++] = (
struct preview_line){
225 .str = block_sample(sample,
sizeof(sample)), .zooms = 1};
226 lines[cnt++] = (
struct preview_line){.str = spacing, .zooms = 1};
229 lines[cnt++] = (
struct preview_line){.str = custom, .zooms = 1};
231 lines_fit(face, lines, cnt, p->h);
233 for (i = 0; i < cnt; i++) {
234 for (z = 1; z <= MAX_ZOOM; z++) {
235 if (!(lines[i].zooms & (1u << (z - 1))))
238 style.pixel_xmul = z;
239 style.pixel_ymul = z;
241 gp_text(p, &style, 2, y, GP_ALIGN_RIGHT | GP_VALIGN_BELOW,
242 fg, bg, lines[i].str);
244 draw_rules(p, &style, 2, y, lines[i].str, fg);
246 y += gp_text_height(&style) + ZOOM_GAP;
249 y += LINE_GAP - ZOOM_GAP;
270static const char *fit_label(
const gp_widget_render_ctx *ctx,
273 const char *name = gpf_variant_name(
id);
275 if (gp_text_wbbox(ctx->font, name) <= cell_w)
278 name = short_names[id];
280 if (gp_text_wbbox(ctx->font, name) <= cell_w)
286static void draw_variant(gp_pixmap *p,
const gp_widget_render_ctx *ctx,
290 unsigned int label_h = gp_text_height(ctx->font);
291 unsigned int line_h = gui.font->meta.ascent + gui.font->meta.descent;
292 unsigned int gx, gy, zoom;
298 bg =
id == gui.variant ? gp_widgets_color(ctx, GP_WIDGETS_COL_SELECT)
299 : gpf_gui_back_color(gui.strip);
300 fg = gp_widgets_color(ctx, GP_WIDGETS_COL_TEXT);
302 gp_fill_rect_xywh(p, x, 0, cell_w, p->h, bg);
304 label = fit_label(ctx,
id, cell_w - 2);
312 gp_text(p, ctx->font, x + cell_w/2, 0,
313 GP_ALIGN_CENTER | GP_VALIGN_BELOW, fg, bg, label);
319 zoom =
GPF_MAX(1u, (p->h - label_h - 2) / line_h);
324 oy = label_h + 2 + zoom * gui.font->meta.ascent;
325 ox = x + ((int)cell_w - zoom * res.glyph.advance) / 2;
327 for (gy = 0; gy < res.glyph.height; gy++) {
328 for (gx = 0; gx < res.glyph.width; gx++) {
333 ox + zoom * (res.glyph.bearing_x + (
int)gx),
334 oy - zoom * (res.glyph.bearing_y - (
int)gy),
342void gpf_strip_draw(gp_widget *self)
344 gp_pixmap *p = gp_widget_pixmap_get(self);
345 const gp_widget_render_ctx *ctx = gp_widgets_render_ctx();
346 unsigned int i, cell_w;
351 gp_fill(p, gpf_gui_back_color(self));
359 draw_variant(p, ctx, i, cell_w);
369#define GPF_DEPS_MAX 256
385static int deps_codes(uint32_t *codes,
unsigned int max,
unsigned int *cnt)
387 *cnt = gpf_decompose_by_accent(gui.code, codes, max);
392 *cnt = gpf_decompose_accented(gpf_decompose_base(gui.code), codes, max);
403static int compose_preview(uint32_t code,
const struct gpf_glyph *accent,
413 if (gpf_draw_base(gui.font, gui.variant, decomp, &base))
416 gpf_accent_offset(gui.font, &base.glyph, accent, decomp->
place,
419 ret = gpf_compose(out, &base.glyph, accent, dx, dy);
426static int deps_grid(gp_pixmap *p,
struct gpf_cell *cell,
unsigned int *cols,
429 const gp_widget_render_ctx *ctx = gp_widgets_render_ctx();
434 gpf_cell_init(cell, ctx, p->h);
436 cell->
bg = gpf_gui_back_color(gui.deps);
438 *cols =
GPF_MAX(1u, p->w / cell->
w);
439 *rows =
GPF_MAX(1u, p->h / cell->h);
441 gpf_cell_center(cell, p, *cols, *rows);
452static int deps_list(uint32_t *codes,
unsigned int max,
unsigned int *cnt,
453 unsigned int visible)
455 int compose = deps_codes(codes, max, cnt);
456 uint32_t anchor = compose ? gui.code : gpf_decompose_base(gui.code);
459 if (anchor != gui.deps_anchor) {
460 gui.deps_anchor = anchor;
466 else if (gui.deps_off > *cnt - visible)
467 gui.deps_off = *cnt - visible;
477static int deps_scroll(
int delta)
479 gp_pixmap *p = gp_widget_pixmap_get(gui.deps);
480 uint32_t codes[GPF_DEPS_MAX];
482 unsigned int cols, rows, cnt, visible;
485 if (deps_grid(p, &cell, &cols, &rows))
488 visible = cols * rows;
490 deps_list(codes, GPF_DEPS_MAX, &cnt, visible);
495 off = (long)gui.deps_off + delta;
499 if ((
unsigned int)off == gui.deps_off)
504 gpf_deps_draw(gui.deps);
505 gp_widget_redraw(gui.deps);
510void gpf_deps_draw(gp_widget *self)
512 gp_pixmap *p = gp_widget_pixmap_get(self);
513 const gp_widget_render_ctx *ctx = gp_widgets_render_ctx();
514 uint32_t codes[GPF_DEPS_MAX];
517 unsigned int cols, rows, cnt, shown, i;
521 gp_fill(p, gp_widgets_color(ctx, GP_WIDGETS_COL_BG));
523 if (deps_grid(p, &cell, &cols, &rows))
526 compose = deps_list(codes, GPF_DEPS_MAX, &cnt, cols * rows);
528 shown =
GPF_MIN(cnt - gui.deps_off, cols * rows);
535 if (compose &&
gpf_resolve(gui.font, gui.variant, gui.code, &accent))
538 for (i = 0; i < shown; i++) {
539 uint32_t code = codes[gui.deps_off + i];
540 int x = (i % cols) * cell.
w;
541 int y = (i / cols) * cell.h;
544 if (compose && !compose_preview(
code, &
accent.glyph, &glyph)) {
545 gpf_cell_draw_glyph(p, ctx, &cell, x, y,
code, &glyph);
550 gpf_cell_draw(p, ctx, &cell, x, y,
code);
554 gpf_resolved_clear(&
accent);
557 gpf_cell_grid(p, ctx, &cell, cols, (shown + cols - 1) / cols);
560int gpf_deps_input(gp_event *ev)
562 gp_pixmap *p = gp_widget_pixmap_get(gui.deps);
563 uint32_t codes[GPF_DEPS_MAX];
566 unsigned int cols, rows, cnt, idx;
572 if (ev->type == GP_EV_REL && ev->code == GP_EV_REL_WHEEL)
573 return deps_scroll(ev->val < 0 ? 1 : -1);
575 if (ev->type != GP_EV_KEY || ev->code != GP_EV_KEY_DOWN)
578 if (ev->key.key != GP_BTN_LEFT && ev->key.key != GP_BTN_TOUCH)
581 if (deps_grid(p, &cell, &cols, &rows))
584 deps_list(codes, GPF_DEPS_MAX, &cnt, cols * rows);
586 cell_idx = gpf_cell_at(&cell, cols, rows, ev->st->cursor_x,
593 if (idx >=
GPF_MIN(cnt - gui.deps_off, cols * rows))
599 gpf_gui_select_keep(codes[idx]);
605 if (
gpf_resolve(gui.font, gui.variant, codes[idx], &res))
606 gpf_gui_create_glyph(codes[idx]);
613int gpf_strip_input(gp_event *ev)
615 gp_pixmap *p = gp_widget_pixmap_get(gui.strip);
616 unsigned int cell_w, id;
621 if (ev->type == GP_EV_REL && ev->code == GP_EV_REL_WHEEL) {
622 gpf_gui_move_variant(ev->val);
626 if (ev->type != GP_EV_KEY || ev->code != GP_EV_KEY_DOWN)
629 switch (ev->key.key) {
633 id = ev->st->cursor_x / cell_w;
637 gpf_gui_set_variant(
id);
642 gpf_gui_move_variant(-1);
645 gpf_gui_move_variant(1);
648 gpf_gui_set_variant(0);
Accented letters: the decomposition table and accent composition.
const struct gpf_decomposition * gpf_decompose(uint32_t code)
Looks up the decomposition of an accented letter.
static int gpf_glyph_pixel(const struct gpf_glyph *self, unsigned int x, unsigned int y)
Returns a glyph ink pixel.
#define GPF_MAX(a, b)
Returns the larger of two values, evaluates them twice.
gpf_variant_id
Font face variant.
@ GPF_BOLD_MONO
Bold monospace glyphs.
@ GPF_VARIANTS
Number of font variants.
@ GPF_MONO
Monospace glyphs, the base variant.
@ GPF_REGULAR
Proportional glyphs, "regular" on disk.
#define GPF_MIN(a, b)
Returns the smaller of two values, evaluates them twice.
The editor state and the functions everything in the GUI goes through.
const struct gpf_ucode_block * gpf_gui_block(void)
The block being browsed.
The preview, the variant strip and the accented letters strip.
void gpf_resolved_clear(struct gpf_resolved *self)
Clears the resolved glyph.
int gpf_resolve(struct gpf_font *font, enum gpf_variant_id id, uint32_t code, struct gpf_resolved *res)
Resolves a glyph variant metric and ink.
gp_pixel bg
The color the cells are drawn on, the selected one is highlighted instead.
unsigned int w
The cell size in pixels.
enum gpf_accent_place place
Where the accent is placed in the glyph rectangle.
uint32_t code
A unicode code point of the accented letter.
uint32_t accent
Accent to be combined with the base, GPF_GLYPH_COMPOSE only.
uint32_t code
Unicode code point.
A resolved glyph and where it was drawn from.
A unicode block description.
The BMP part of unicode block table and the blocks of a font.