13static const char *dialog_json =
15" \"info\": {\"version\": 1, \"license\": \"GPL-2.0-or-later\"},\n"
19" \"type\": \"frame\",\n"
20" \"uid\": \"title\",\n"
25" {\"cols\": 2, \"rows\": 3, \"uniform\": false, \"border\": \"none\",\n"
27" {\"type\": \"label\", \"text\": \"family\", \"halign\": \"right\"},\n"
28" {\"type\": \"label\", \"text\": \"license\", \"halign\": \"right\"},\n"
29" {\"type\": \"label\", \"text\": \"default glyph U+\",\n"
30" \"halign\": \"right\"},\n"
31" {\"type\": \"tbox\", \"uid\": \"family\", \"len\": 24,\n"
32" \"halign\": \"fill\", \"focused\": true, \"on_event\": \"check\"},\n"
33" {\"type\": \"tbox\", \"uid\": \"license\", \"len\": 24,\n"
34" \"halign\": \"fill\"},\n"
35" {\"type\": \"tbox\", \"uid\": \"default_glyph\", \"len\": 6,\n"
36" \"tattr\": \"mono\", \"halign\": \"left\"}\n"
39" {\"cols\": 2, \"uniform\": true, \"border\": \"none\",\n"
40" \"align\": \"fill\",\n"
42" {\"type\": \"frame\", \"title\": \"Line box\", \"align\": \"fill\",\n"
43" \"widget\": {\"cols\": 2, \"rows\": 5, \"border\": \"none\",\n"
45" {\"type\": \"label\", \"text\": \"size\", \"halign\": \"right\"},\n"
46" {\"type\": \"label\", \"text\": \"ascent\", \"halign\": \"right\"},\n"
47" {\"type\": \"label\", \"text\": \"descent\", \"halign\": \"right\"},\n"
48" {\"type\": \"label\", \"text\": \"line gap\", \"halign\": \"right\"},\n"
49" {\"type\": \"label\", \"text\": \"mono advance\", \"halign\": \"right\"},\n"
50" {\"type\": \"spinner\", \"uid\": \"size\", \"on_event\": \"check\"},\n"
51" {\"type\": \"spinner\", \"uid\": \"ascent\", \"on_event\": \"check\"},\n"
52" {\"type\": \"spinner\", \"uid\": \"descent\", \"on_event\": \"check\"},\n"
53" {\"type\": \"spinner\", \"uid\": \"line_gap\"},\n"
54" {\"type\": \"spinner\", \"uid\": \"advance\"}\n"
58" {\"type\": \"frame\", \"title\": \"Letters\", \"align\": \"fill\",\n"
59" \"widget\": {\"cols\": 3, \"rows\": 4, \"border\": \"none\",\n"
61" {\"type\": \"label\", \"text\": \"em\", \"halign\": \"right\"},\n"
62" {\"type\": \"label\", \"text\": \"x-height\", \"halign\": \"right\"},\n"
63" {\"type\": \"label\", \"text\": \"cap height\", \"halign\": \"right\"},\n"
64" {\"type\": \"label\", \"text\": \"digit width\", \"halign\": \"right\"},\n"
65" {\"type\": \"spinner\", \"uid\": \"em\"},\n"
66" {\"type\": \"spinner\", \"uid\": \"x_height\", \"on_event\": \"check\"},\n"
67" {\"type\": \"spinner\", \"uid\": \"cap_height\", \"on_event\": \"check\"},\n"
68" {\"type\": \"spinner\", \"uid\": \"ch_width\"},\n"
69" {\"type\": \"label\", \"text\": \"\"},\n"
70" {\"type\": \"button\", \"label\": \"measure\", \"uid\": \"x_height_m\",\n"
71" \"on_event\": \"measure_x_height\"},\n"
72" {\"type\": \"button\", \"label\": \"measure\", \"uid\": \"cap_height_m\",\n"
73" \"on_event\": \"measure_cap_height\"},\n"
74" {\"type\": \"button\", \"label\": \"measure\", \"uid\": \"ch_width_m\",\n"
75" \"on_event\": \"measure_ch_width\"}\n"
81" {\"type\": \"frame\", \"title\": \"Rules\", \"halign\": \"fill\",\n"
82" \"widget\": {\"cols\": 3, \"rows\": 4, \"border\": \"none\",\n"
84" {\"type\": \"label\", \"text\": \"\"},\n"
85" {\"type\": \"label\", \"text\": \"underline\", \"halign\": \"right\"},\n"
86" {\"type\": \"label\", \"text\": \"strikethrough\", \"halign\": \"right\"},\n"
87" {\"type\": \"label\", \"text\": \"overline\", \"halign\": \"right\"},\n"
88" {\"type\": \"label\", \"text\": \"above baseline\"},\n"
89" {\"type\": \"spinner\", \"uid\": \"underline_pos\"},\n"
90" {\"type\": \"spinner\", \"uid\": \"strike_pos\"},\n"
91" {\"type\": \"spinner\", \"uid\": \"overline_pos\"},\n"
92" {\"type\": \"label\", \"text\": \"thickness\"},\n"
93" {\"type\": \"spinner\", \"uid\": \"underline_thickness\"},\n"
94" {\"type\": \"spinner\", \"uid\": \"strike_thickness\"},\n"
95" {\"type\": \"spinner\", \"uid\": \"overline_thickness\"}\n"
99" {\"type\": \"frame\", \"title\": \"Authors\", \"halign\": \"fill\",\n"
100" \"widget\": {\"rows\": 2, \"border\": \"none\", \"halign\": \"fill\",\n"
102" {\"type\": \"table\", \"uid\": \"authors\", \"min_rows\": 3,\n"
103" \"halign\": \"fill\", \"col_ops\": \"authors_ops\",\n"
105" {\"label\": \"years\", \"id\": \"years\", \"min_size\": 9},\n"
106" {\"label\": \"name\", \"id\": \"name\", \"min_size\": 16,\n"
108" {\"label\": \"email\", \"id\": \"email\", \"min_size\": 16,\n"
112" {\"cols\": 5, \"border\": \"none\", \"halign\": \"fill\",\n"
113" \"cfill\": \"0, 1, 1, 0, 0\",\n"
115" {\"type\": \"tbox\", \"uid\": \"author_years\", \"len\": 9,\n"
116" \"max_len\": 31, \"help\": \"2024\"},\n"
117" {\"type\": \"tbox\", \"uid\": \"author_name\", \"len\": 12,\n"
118" \"max_len\": 63, \"help\": \"name\", \"halign\": \"fill\"},\n"
119" {\"type\": \"tbox\", \"uid\": \"author_email\", \"len\": 12,\n"
120" \"max_len\": 63, \"help\": \"email\", \"halign\": \"fill\"},\n"
121" {\"type\": \"button\", \"label\": \"add\", \"uid\": \"author_add\",\n"
122" \"on_event\": \"author_add\"},\n"
123" {\"type\": \"button\", \"label\": \"remove\",\n"
124" \"uid\": \"author_del\", \"on_event\": \"author_del\"}\n"
130" {\"type\": \"label\", \"uid\": \"note\", \"text\": \"\", \"width\": 40,\n"
131" \"halign\": \"fill\"},\n"
133" \"halign\": \"fill\",\n"
134" \"cpadf\": \"1, 1, 1\",\n"
135" \"cfill\": \"0, 0\",\n"
136" \"border\": \"none\",\n"
137" \"uniform\": true,\n"
139" {\"type\": \"button\", \"halign\": \"fill\", \"label\": \"Cancel\",\n"
140" \"btype\": \"cancel\", \"on_event\": \"cancel\"},\n"
141" {\"type\": \"button\", \"halign\": \"fill\", \"label\": \"OK\",\n"
142" \"btype\": \"ok\", \"uid\": \"ok\", \"on_event\": \"ok\"}\n"
156static const struct field {
161#define FIELD(name, min, max) \
162 {#name, offsetof(struct gpf_family_meta, name), min, max}
164 FIELD(ascent, 1, 255),
165 FIELD(descent, 0, 255),
166 FIELD(line_gap, 0, 255),
168 FIELD(x_height, 0, 255),
169 FIELD(cap_height, 0, 255),
170 FIELD(ch_width, 0, 255),
171 FIELD(underline_pos, -255, 255),
172 FIELD(underline_thickness, 0, 255),
173 FIELD(strike_pos, -255, 255),
174 FIELD(strike_thickness, 0, 255),
175 FIELD(overline_pos, -255, 255),
176 FIELD(overline_thickness, 0, 255),
180#define FIELDS (sizeof(fields) / sizeof(fields[0]))
183 const struct field *field)
185 return *(
const int *)((
const char *)meta + field->off);
188static void field_set(
struct gpf_family_meta *meta,
const struct field *field,
191 *(
int *)((
char *)meta + field->off) = val;
194static gp_htable *uids;
200static const char *author_msg;
208static gp_widget *spinner(
const char *uid)
210 return gp_widget_by_uid(uids, uid, GP_WIDGET_SPINNER);
213static int spinner_val(
const char *uid)
215 gp_widget *widget = spinner(uid);
217 return widget ? gp_widget_int_val_get(widget) : 0;
220static const char *tbox_text(
const char *uid)
222 gp_widget *widget = gp_widget_by_uid(uids, uid, GP_WIDGET_TBOX);
224 return widget ? gp_widget_tbox_text(widget) :
"";
232static void check(
void)
234 gp_widget *note = gp_widget_by_uid(uids,
"note", GP_WIDGET_LABEL);
235 gp_widget *ok = gp_widget_by_uid(uids,
"ok", GP_WIDGET_BUTTON);
236 int ascent = spinner_val(
"ascent");
237 int size = spinner_val(
"size");
238 const char *msg =
"";
240 if (size < ascent || size > ascent + spinner_val(
"descent"))
241 msg =
"the size is not within the line box";
243 if (spinner_val(
"x_height") > ascent)
244 msg =
"the x-height is above the ascent";
246 if (spinner_val(
"cap_height") > ascent)
247 msg =
"the cap height is above the ascent";
252 if (!tbox_text(
"family")[0])
253 msg =
"the family needs a name";
256 gp_widget_label_set(note, msg);
259 gp_widget_disabled_set(ok, !tbox_text(
"family")[0]);
262static int check_on_event(gp_widget_event *ev)
264 if (ev->type == GP_WIDGET_EVENT_WIDGET)
270static void measure(
enum gpf_measure what,
const char *uid)
272 gp_widget *widget = spinner(uid);
275 if (!widget || creating ||
gpf_measure(gui.font, gui.variant, what, &val))
278 gp_widget_int_val_set(widget, val);
283static int measure_x_height_on_event(gp_widget_event *ev)
285 if (ev->type == GP_WIDGET_EVENT_WIDGET)
291static int measure_cap_height_on_event(gp_widget_event *ev)
293 if (ev->type == GP_WIDGET_EVENT_WIDGET)
299static int measure_ch_width_on_event(gp_widget_event *ev)
301 if (ev->type == GP_WIDGET_EVENT_WIDGET)
313static int authors_seek_row(gp_widget *self,
int op,
unsigned int pos)
315 gp_widget_table_priv *priv = gp_widget_table_priv_get(self);
316 size_t len = gp_vec_len(*authors);
319 case GP_TABLE_ROW_RESET:
322 case GP_TABLE_ROW_ADVANCE:
323 priv->row_idx += pos;
325 case GP_TABLE_ROW_MAX:
329 return priv->row_idx < len;
332static int authors_get_cell(gp_widget *self, gp_widget_table_cell *cell,
335 gp_widget_table_priv *priv = gp_widget_table_priv_get(self);
336 const struct gpf_author *author = &(*authors)[priv->row_idx];
340 cell->text = author->
years;
343 cell->text = author->
name;
346 cell->text = author->
email;
353static void tbox_set(
const char *uid,
const char *text)
355 gp_widget *widget = gp_widget_by_uid(uids, uid, GP_WIDGET_TBOX);
358 gp_widget_tbox_set(widget, text);
362static int authors_on_event(gp_widget_event *ev)
367 if (ev->type != GP_WIDGET_EVENT_WIDGET ||
368 !gp_widget_table_sel_has(ev->self))
371 row = gp_widget_table_sel_get(ev->self);
372 if (row >= gp_vec_len(*authors))
375 author = &(*authors)[row];
377 tbox_set(
"author_years", author->
years);
378 tbox_set(
"author_name", author->
name);
379 tbox_set(
"author_email", author->
email);
384static const gp_widget_table_col_ops authors_ops = {
385 .seek_row = authors_seek_row,
386 .get_cell = authors_get_cell,
387 .on_event = authors_on_event,
389 {.id =
"years", .idx = AUTHORS_YEARS},
390 {.id =
"name", .idx = AUTHORS_NAME},
391 {.id =
"email", .idx = AUTHORS_EMAIL},
396static gp_widget *authors_table(
void)
398 return gp_widget_by_uid(uids,
"authors", GP_WIDGET_TABLE);
401static int author_add_on_event(gp_widget_event *ev)
403 const char *
years = tbox_text(
"author_years");
404 const char *
name = tbox_text(
"author_name");
405 const char *
email = tbox_text(
"author_email");
406 gp_widget *table = authors_table();
408 if (ev->type != GP_WIDGET_EVENT_WIDGET)
414 author_msg =
"out of memory";
417 tbox_set(
"author_years",
"");
418 tbox_set(
"author_name",
"");
419 tbox_set(
"author_email",
"");
423 gp_widget_table_refresh(table);
430static int author_del_on_event(gp_widget_event *ev)
432 gp_widget *table = authors_table();
434 if (ev->type != GP_WIDGET_EVENT_WIDGET || !table)
439 if (!gp_widget_table_sel_has(table))
440 author_msg =
"select an author to remove";
444 gp_widget_table_refresh(table);
451static int ok_on_event(gp_widget_event *ev)
453 gp_dialog *dialog = ev->self->priv;
455 if (ev->type != GP_WIDGET_EVENT_WIDGET)
458 dialog->retval = GP_DIALOG_YES;
463static int cancel_on_event(gp_widget_event *ev)
465 gp_dialog *dialog = ev->self->priv;
467 if (ev->type != GP_WIDGET_EVENT_WIDGET)
470 dialog->retval = GP_DIALOG_NO;
475static const gp_widget_json_addr addrs[] = {
476 {.id =
"author_add", .on_event = author_add_on_event},
477 {.id =
"author_del", .on_event = author_del_on_event},
478 {.id =
"authors_ops", .addr = (
void *)&authors_ops},
479 {.id =
"cancel", .on_event = cancel_on_event},
480 {.id =
"check", .on_event = check_on_event},
481 {.id =
"measure_cap_height", .on_event = measure_cap_height_on_event},
482 {.id =
"measure_ch_width", .on_event = measure_ch_width_on_event},
483 {.id =
"measure_x_height", .on_event = measure_x_height_on_event},
484 {.id =
"ok", .on_event = ok_on_event},
492static void measure_enable(
const char *uid,
enum gpf_measure what)
494 gp_widget *widget = gp_widget_by_uid(uids, uid, GP_WIDGET_BUTTON);
500 none = creating ||
gpf_measure(gui.font, gui.variant, what, &val);
502 gp_widget_disabled_set(widget, none);
509static void load_advance(
const int *advance)
511 gp_widget *widget = spinner(
"advance");
518 gp_widget_int_set(widget, 1, 255, *
advance);
522 mono = gui.font ? gui.font->variants[
GPF_MONO] : NULL;
524 gp_widget_int_set(widget, 0, 255, mono ? mono->
advance : 0);
525 gp_widget_disabled_set(widget, 1);
533 for (i = 0; i < FIELDS; i++) {
534 widget = spinner(fields[i].uid);
536 gp_widget_int_set(widget, fields[i].min, fields[i].max,
537 field_get(meta, &fields[i]));
541 widget = gp_widget_by_uid(uids,
"family", GP_WIDGET_TBOX);
543 gp_widget_tbox_set(widget, meta->
family);
545 widget = gp_widget_by_uid(uids,
"license", GP_WIDGET_TBOX);
547 gp_widget_tbox_set(widget, meta->
license);
549 widget = gp_widget_by_uid(uids,
"default_glyph", GP_WIDGET_TBOX);
552 gp_widget_tbox_printf(widget,
"%04X",
555 gp_widget_tbox_filter_set(widget, GP_TBOX_FILTER_HEX);
569 for (i = 0; i < FIELDS; i++) {
570 if (spinner(fields[i].uid))
571 field_set(meta, &fields[i], spinner_val(fields[i].uid));
574 snprintf(meta->
family,
sizeof(meta->
family),
"%s", tbox_text(
"family"));
576 tbox_text(
"license"));
579 meta->
default_glyph = strtoul(tbox_text(
"default_glyph"), NULL, 16);
581 if (
advance && spinner(
"advance"))
582 *
advance = spinner_val(
"advance");
588 gp_dialog dialog = {};
589 gp_widget_json_callbacks callbacks = {
590 .default_priv = &dialog,
601 authors = edit_authors;
604 dialog.layout = gp_dialog_layout_load(
"gpforge_family", &callbacks,
609 frame = gp_widget_by_uid(uids,
"title", GP_WIDGET_FRAME);
611 gp_widget_frame_title_set(frame, creating ?
"New font" :
617 if (gp_dialog_run(&dialog) == GP_DIALOG_YES) {
622 gp_htable_free(uids);
624 gp_widget_free(dialog.layout);
The font properties dialog.
const char * gpf_author_invalid(const char *years, const char *name, const char *email)
Checks the fields of an author.
void gpf_authors_del(struct gpf_author **authors, size_t idx)
Removes an author from a gp_vec of authors.
@ GPF_MONO
Monospace glyphs, the base variant.
int gpf_authors_add(struct gpf_author **authors, const char *years, const char *name, const char *email)
Appends an author to a gp_vec of authors.
The editor state and the functions everything in the GUI goes through.
gpf_measure
The family metrics that are measured off the glyphs.
@ GPF_MEASURE_CH_WIDTH
The advance of the '0' glyph.
@ GPF_MEASURE_CAP_HEIGHT
The top of the 'H' ink above the baseline.
@ GPF_MEASURE_X_HEIGHT
The top of the 'x' ink above the baseline.
A font author, one author line of the family file.
char years[32]
Copyright years, e.g. "2024", "2019-2024" or "2019,2023".
char email[64]
The author's email, without the angle brackets.
char name[64]
The author's name.
int advance
Advance for all glyphs.