6#include <utils/gp_utf.h>
13void gpf_cell_init(
struct gpf_cell *self,
const gp_widget_render_ctx *ctx,
17 unsigned int glyph_w = font->
meta.
em ? (
unsigned int)font->
meta.
em : 8;
18 unsigned int label_w = gp_text_wbbox(ctx->font_mono,
"0000");
19 unsigned int line_h, fixed;
27 line_h =
GPF_MAX(1, top - bottom + 1);
35 self->
pad = ctx->padd;
37 self->
bg = gp_widgets_color(ctx, GP_WIDGETS_COL_FG);
39 self->
label_h = gp_text_height(ctx->font_mono);
42 self->
ref_h = gp_text_height(ctx->font) + 2 * self->
pad;
49 unsigned int fits = (max_h - fixed) / line_h;
55 self->h = self->
zoom * line_h + fixed;
61void gpf_cell_center(
struct gpf_cell *self,
const gp_pixmap *p,
62 unsigned int cols,
unsigned int rows)
65 self->
x0 =
GPF_MAX(0, ((
int)p->w - (
int)(cols * self->
w)) / 2);
66 self->y0 =
GPF_MAX(0, ((
int)p->h - (
int)(rows * self->h)) / 2);
69int gpf_cell_at(
const struct gpf_cell *self,
unsigned int cols,
70 unsigned int rows, gp_coord x, gp_coord y)
78 if ((
unsigned int)x / self->
w >= cols ||
79 (
unsigned int)y / self->h >= rows)
82 return (y / self->h) * cols + x / self->
w;
91static void label_colors(
const gp_widget_render_ctx *ctx, uint32_t code,
92 int have, gp_pixel *bg, gp_pixel *fg)
94 struct gpf_variant *variant = gui.font->variants[gui.variant];
98 if (gpf_gui_modified(
code)) {
99 *bg = gp_widgets_color(ctx, GP_WIDGETS_COL_ALERT);
100 *fg = gp_widgets_color(ctx, GP_WIDGETS_COL_FG);
107 *bg = gp_widgets_color(ctx, GP_WIDGETS_COL_TEXT);
108 *fg = gp_widgets_color(ctx, GP_WIDGETS_COL_FG);
116static int widget_font_has(
const gp_text_style *style, uint32_t
code)
121 return gp_glyph_get(style->font,
code) != gp_glyph_get(style->font,
'?');
130static void draw_cell(gp_pixmap *p,
const gp_widget_render_ctx *ctx,
131 const struct gpf_cell *self,
int x,
int y, uint32_t
code,
136 int oy = split + (int)self->
pad + (
int)self->
zoom * self->
top;
138 gp_pixel bg, ink, label_bg, label_fg;
142 bg =
code == gui.code ? gp_widgets_color(ctx, GP_WIDGETS_COL_SELECT)
145 ink = gp_widgets_color(ctx, GP_WIDGETS_COL_TEXT);
147 gp_fill_rect_xywh(p, x, y, self->
w, self->h, bg);
150 label_fg = have ? ink : gp_widgets_color(ctx, GP_WIDGETS_COL_DISABLED);
152 label_colors(ctx,
code, have, &label_bg, &label_fg);
154 gp_fill_rect_xywh(p, x, y, self->
w, self->
label_h, label_bg);
156 snprintf(buf,
sizeof(buf),
"%04X",
code);
159 gp_text(p, ctx->font_mono, x + self->
w/2, y,
160 GP_ALIGN_CENTER | GP_VALIGN_BELOW, label_fg, label_bg, buf);
167 if (gpf_code_printable(
code) && widget_font_has(ctx->font,
code)) {
170 ch[gp_to_utf8(
code, ch)] = 0;
172 gp_text(p, ctx->font, x + self->
w/2,
174 GP_ALIGN_CENTER | GP_VALIGN_BELOW,
175 gp_widgets_color(ctx, GP_WIDGETS_COL_DISABLED), bg, ch);
179 gp_hline_xxy(p, x, x + (
int)self->
w - 1, split,
180 gp_widgets_color(ctx, GP_WIDGETS_COL_DISABLED));
186 ox = x + ((int)self->
w - (int)self->
zoom * glyph->
advance) / 2;
188 for (gy = 0; gy < glyph->
height; gy++) {
189 for (gx = 0; gx < glyph->
width; gx++) {
190 int px = ox + (int)self->
zoom *
192 int py = oy - (int)self->
zoom *
204 if (py <= split || py + (
int)self->
zoom > y + (
int)self->h)
207 if (px < x || px + (
int)self->
zoom > x + (
int)self->
w)
210 gp_fill_rect_xywh(p, px, py, self->
zoom, self->
zoom, ink);
215void gpf_cell_draw(gp_pixmap *p,
const gp_widget_render_ctx *ctx,
216 const struct gpf_cell *self,
int x,
int y, uint32_t
code)
219 int have = !
gpf_resolve(gui.font, gui.variant, code, &res);
221 draw_cell(p, ctx, self, self->
x0 + x, self->y0 + y, code,
222 have ? &res.
glyph : NULL, have);
228void gpf_cell_draw_glyph(gp_pixmap *p,
const gp_widget_render_ctx *ctx,
229 const struct gpf_cell *self,
int x,
int y,
233 int have = !
gpf_resolve(gui.font, gui.variant, code, &res);
238 draw_cell(p, ctx, self, self->
x0 + x, self->y0 + y, code,
glyph, have);
241void gpf_cell_grid(gp_pixmap *p,
const gp_widget_render_ctx *ctx,
242 const struct gpf_cell *self,
unsigned int cols,
245 gp_pixel col = gp_widgets_color(ctx, GP_WIDGETS_COL_DISABLED);
246 unsigned int w = cols * self->
w;
247 unsigned int h = rows * self->h;
250 int x0 = self->
x0, y0 = self->y0;
252 for (i = 0; i <= cols; i++)
253 gp_vline_xyy(p, x0 + i * self->
w, y0, y0 + h, col);
255 for (i = 0; i <= rows; i++)
256 gp_hline_xxy(p, x0, x0 + w, y0 + i * self->h, col);
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.
struct gpf_glyph * gpf_variant_glyph(struct gpf_variant *self, uint32_t code)
Looks up a glyph in a variant.
void gpf_font_ink_extent(struct gpf_font *self, int *top, int *bottom)
Returns how far the ink of the whole font reaches.
#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.
The glyph variant lattice.
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 label_h
The height of the codepoint line at the top.
unsigned int w
The cell size in pixels.
int x0
Where the grid starts in the pixmap, see gpf_cell_center().
unsigned int pad
The theme's padding, above the glyph and below it.
int top
How far the font's ink reaches above the baseline, at least the ascent.
unsigned int zoom
The pixel multiplier, the table's, or less when there is no room.
unsigned int ref_h
The line under it, where the widget font draws the character.
struct gpf_family_meta meta
Font meta data.
int bearing_y
Glyph bearing y.
unsigned int height
Glyph ink height.
unsigned int width
Glyph ink width.
int advance
Glyph advance.
int bearing_x
Glyph bearing x.
uint32_t code
Unicode code point.
A resolved glyph and where it was drawn from.
struct gpf_glyph glyph
Freshly allocated glyph with copied/generated ink.