35gp_app_info app_info = {
37 .desc =
"A bitmap font editor",
39 .license =
"GPL-2.0-or-later",
40 .authors = (gp_app_info_author []) {
41 {.name =
"Cyril Hrubis", .email =
"metan@ucw.cz", .years =
"2026"},
52 gui.
faces[id] = gpf_face_build(gui.font,
id);
62 gpf_face_free(gui.faces[i]);
75 return gui.block_list;
82 if (!blocks || gui.block >= gp_vec_len(blocks))
85 return &blocks[gui.block];
93static void update_metrics(
void)
95 struct gpf_variant *variant = gui.font ? gui.font->variants[gui.variant]
98 int advance = 0, bearing_x = 0, bearing_y = 0;
100 if (gui.font && !gpf_resolve(gui.font, gui.variant, gui.code, &res)) {
101 advance = res.glyph.advance;
102 bearing_x = res.glyph.bearing_x;
103 bearing_y = res.glyph.bearing_y;
108 if (gui.advance_widget) {
109 gp_widget_int_val_set(gui.advance_widget, advance);
112 gp_widget_disabled_set(gui.advance_widget,
116 if (gui.bearing_x_widget)
117 gp_widget_int_val_set(gui.bearing_x_widget, bearing_x);
119 if (gui.bearing_y_widget)
120 gp_widget_int_val_set(gui.bearing_y_widget, bearing_y);
129static void lint_count_set(gp_widget *label,
const char *text)
132 if (label && strcmp(gp_widget_label_get(label), text))
133 gp_widget_label_set(label, text);
136static void update_lint_count(
void)
138 unsigned int errors, warnings;
142 lint_count_set(gui.lint_errors,
"");
143 lint_count_set(gui.lint_warnings,
"");
147 gpf_lint_count(gui.font, &errors, &warnings);
149 snprintf(buf,
sizeof(buf),
"%u", errors);
150 lint_count_set(gui.lint_errors, buf);
152 snprintf(buf,
sizeof(buf),
"%u", warnings);
153 lint_count_set(gui.lint_warnings, buf);
162 gp_widget_label_set(gui.lint_label,
"");
163 gp_widget_label_colors_set(gui.lint_label, GP_WIDGETS_COL_TEXT, GP_WIDGETS_COL_BG);
167 gp_widget_label_printf(gui.lint_label,
" U+%04X %s: %s",
169 gpf_lint_severity_name(finding->
sev),
172 switch (finding->
sev) {
174 gp_widget_label_colors_set(gui.lint_label, GP_WIDGETS_COL_TEXT, GP_WIDGETS_COL_ALERT);
177 gp_widget_label_colors_set(gui.lint_label, GP_WIDGETS_COL_TEXT, GP_WIDGETS_COL_WARN);
183static void update_status(
void)
186 const char *dirty = gui.dirty ?
"*" :
" ";
195 set_lint_label(NULL);
196 gp_widget_label_set(gui.status,
"no font open");
200 if (gpf_code_printable(gui.code))
201 ch[gp_to_utf8(gui.code, ch)] = 0;
206 if (gui.lint_label) {
208 set_lint_label(NULL);
210 set_lint_label(&finding);
213 if (gpf_resolve(gui.font, gui.variant, gui.code, &res)) {
214 gp_widget_label_printf(gui.status,
"%sU+%04X '%s' not in the font",
215 dirty, gui.code, ch);
219 gp_widget_label_printf(gui.status,
"%sU+%04X '%s' %s ink %ux%u",
220 dirty, gui.code, ch, gpf_provenance_name(res.prov),
221 res.glyph.width, res.glyph.height);
223 gpf_resolved_clear(&res);
229static void update_family(
void)
231 if (!gui.family_label)
235 gp_widget_label_set(gui.family_label,
"no font");
239 gp_widget_label_printf(gui.family_label,
"%s %i",
240 gui.font->meta.family, gui.font->meta.size);
243static void button_enable(gp_widget *self)
246 gp_widget_disabled_set(self, 0);
261static void button_disable(gp_widget *self, gp_widget *next)
263 if (!self || gp_widget_disabled_get(self))
267 if (next && !gp_widget_disabled_get(next))
268 gp_widget_focus_set(next);
270 gp_widget_focus_set(gui.canvas);
273 gp_widget_disabled_set(self, 1);
285static void update_undo(
void)
287 int undo = gpf_undo_can_undo(gui.undo);
288 int redo = gpf_undo_can_redo(gui.undo);
291 button_enable(gui.undo_button);
294 button_enable(gui.redo_button);
297 button_disable(gui.undo_button, gui.redo_button);
300 button_disable(gui.redo_button, gui.undo_button);
307static void update_export(
void)
310 button_enable(gui.export_button);
312 button_disable(gui.export_button, gui.family_button);
319static void update_block_start(
void)
323 if (!gui.block_start || !block)
326 gp_widget_tbox_printf(gui.block_start,
"%04X", block->min);
336static void rebuild_blocks(
void)
339 uint32_t
min = block ? block->min : 0;
343 gp_vec_free(gui.block_list);
344 gui.block_list = NULL;
352 for (i = 0; i < gp_vec_len(blocks); i++) {
357 if (blocks[gui.block].min !=
min)
358 gui.browser_page = 0;
362 gp_widget_redraw(gui.blocks);
364 update_block_start();
393 gpf_undo_retarget(gui.undo, gui.font,
id,
code);
409 if (gpf_resolve(gui.font,
id,
code, &res)) {
410 memset(&res, 0,
sizeof(res));
417 gpf_resolved_clear(&res);
423 glyph->
bits = res.glyph.bits;
424 glyph->
width = res.glyph.width;
425 glyph->
height = res.glyph.height;
426 glyph->
advance = res.glyph.advance;
434 res.glyph.bits = NULL;
445 return edit_code(gui.variant,
code);
450 return gpf_gui_edit_code(gui.code);
458unsigned int gpf_gui_accented(uint32_t *codes,
unsigned int max)
461 unsigned int i, n, cnt = 0;
463 if (!gui.update || !gui.font)
466 n = gpf_decompose_accented(gui.code, all, GP_ARRAY_SIZE(all));
468 for (i = 0; i < n && cnt < max; i++) {
472 if (
gpf_resolve(gui.font, gui.variant, all[i], &res))
477 codes[cnt++] = all[i];
488void gpf_gui_pixel_set(
int col,
int height,
int set)
494 if (!glyph || gpf_glyph_pixel_set(glyph, col,
height, set))
497 n = gpf_gui_accented(codes, GP_ARRAY_SIZE(codes));
499 for (i = 0; i < n; i++) {
500 struct gpf_glyph *dep = gpf_gui_edit_code(codes[i]);
503 gpf_glyph_pixel_set(dep, col,
height, set);
538 ret = !gpf_compose(&letter, base, accent, dx, dy) &&
539 glyph_eq(&letter, &res.glyph);
559 numbers.code = glyph->
code;
560 numbers.modified = 1;
578 if (gpf_draw_base(gui.font,
id, decomp, &
base))
581 if (!gpf_accent_ink(gui.font,
id, decomp, &
accent)) {
587 inherits_same(
id, decomp, &
base.glyph, &
accent,
dx, dy))
590 glyph = edit_code(
id, decomp->
code);
593 if (glyph && !gpf_compose(glyph, &
base.glyph, &
accent,
dx, dy) && derived)
594 store_as_saved(
id, glyph);
596 gpf_resolved_clear(&
base);
641void gpf_gui_create_glyph(uint32_t
code)
646 if (!gui.font || !decomp)
651 create_glyph(gui.variant, decomp, 0);
655 if (derives_from(
id, gui.variant) && has_own_base(
id, decomp))
656 create_glyph(
id, decomp, 1);
671 gpf_undo_group_begin(gui.undo);
673 gpf_undo_begin(gui.undo, gui.font, gui.variant, gui.code);
681 gpf_undo_commit(gui.undo, gui.font);
683 gpf_undo_group_end(gui.undo);
697void gpf_gui_set_dirty(
int dirty)
702 button_enable(gui.save_button);
704 button_disable(gui.save_button, gui.export_button);
712int gpf_gui_modified(uint32_t
code)
721 if (gpf_resolve(gui.font, gui.variant,
code, &res))
724 variant = gui.font->variants[res.
ink_from];
727 gpf_resolved_clear(&res);
729 return entry && entry->modified;
734 gpf_gui_set_dirty(1);
742static void redraw(gp_widget *widget,
void (*draw)(gp_widget *self))
748 gp_widget_redraw(widget);
770 redraw(gui.canvas, gpf_canvas_draw);
771 redraw(gui.deps, gpf_deps_draw);
776 redraw(gui.browser, gpf_browser_draw);
777 redraw(gui.strip, gpf_strip_draw);
778 redraw(gui.preview, gpf_preview_draw);
791static void remember_sel(uint32_t
code,
int follow)
801 idx = follow ? gpf_blocks_find(blocks,
code) : (int)gui.block;
802 if (idx < 0 || (
size_t)idx >= gp_vec_len(blocks))
805 sel.min = blocks[idx].
min;
809 if (
code >= blocks[idx].
min &&
code <= blocks[idx].max)
812 sel.table = blocks[idx].min;
814 for (i = 0; i < gp_vec_len(gui.block_sels); i++) {
817 if (cur->
min != sel.min)
820 if (sel.table !=
code)
828 gui.block_sels = gp_vec_new(0,
sizeof(
struct gpf_block_sel));
831 GP_VEC_APPEND(gui.block_sels, sel);
843 for (i = 0; i < gp_vec_len(gui.block_sels); i++) {
846 if (sel.
min != block->min || sel.
table > block->max)
860static void select_code(uint32_t
code,
int follow)
864 remember_sel(
code, follow);
874 select_code(
code, 1);
879 select_code(
code, 0);
885 gui.browser_page = 0;
889 gp_widget_redraw(gui.blocks);
891 update_block_start();
900static void delete_range(uint32_t
min, uint32_t max)
905 gpf_undo_group_begin(gui.undo);
908 struct gpf_variant *variant = gui.font->variants[i];
913 for (code = min; code <= max; code++) {
917 gpf_undo_begin(gui.undo, gui.font, i, code);
921 gpf_undo_commit(gui.undo, gui.font);
925 gpf_undo_group_end(gui.undo);
927 gpf_gui_set_dirty(1);
942void gpf_gui_sync_block(
unsigned int block)
944 if (block == gui.block)
950 gp_widget_redraw(gui.blocks);
952 update_block_start();
954 redraw(gui.preview, gpf_preview_draw);
959 if (gui.variant ==
id)
967void gpf_gui_move_variant(
int offset)
969 int new_variant = gui.variant;
971 new_variant += offset;
979 gpf_gui_set_variant(new_variant);
982void gpf_pixmap_resize(gp_widget_event *ev)
984 gp_widget *self = ev->self;
985 gp_pixmap *pixmap = gp_pixmap_alloc(self->w, self->h, ev->ctx->pixel_type);
987 gp_pixmap_free(gp_widget_pixmap_set(self, pixmap));
990static int pixmap_event(gp_widget_event *ev,
void (*draw)(gp_widget *self))
993 case GP_WIDGET_EVENT_RESIZE:
994 gpf_pixmap_resize(ev);
996 case GP_WIDGET_EVENT_COLOR_SCHEME:
999 case GP_WIDGET_EVENT_FOCUS:
1010static int canvas_on_event(gp_widget_event *ev)
1012 if (ev->type == GP_WIDGET_EVENT_INPUT)
1013 return gpf_canvas_input(ev->input_ev);
1015 return pixmap_event(ev, gpf_canvas_draw);
1018static int update_on_event(gp_widget_event *ev)
1020 if (ev->type != GP_WIDGET_EVENT_WIDGET)
1023 gui.update = gp_widget_bool_get(ev->self);
1028static int deps_on_event(gp_widget_event *ev)
1030 if (ev->type == GP_WIDGET_EVENT_INPUT)
1031 return gpf_deps_input(ev->input_ev);
1033 return pixmap_event(ev, gpf_deps_draw);
1036static int strip_on_event(gp_widget_event *ev)
1038 if (ev->type == GP_WIDGET_EVENT_INPUT)
1039 return gpf_strip_input(ev->input_ev);
1041 return pixmap_event(ev, gpf_strip_draw);
1044static int preview_on_event(gp_widget_event *ev)
1046 return pixmap_event(ev, gpf_preview_draw);
1054static int preview_text_on_event(gp_widget_event *ev)
1056 if (ev->type == GP_WIDGET_EVENT_WIDGET)
1057 redraw(gui.preview, gpf_preview_draw);
1066static int rule_on_event(gp_widget_event *ev,
int *flag)
1068 if (ev->type != GP_WIDGET_EVENT_WIDGET)
1071 *flag = gp_widget_bool_get(ev->self);
1073 redraw(gui.preview, gpf_preview_draw);
1078static int rule_under_on_event(gp_widget_event *ev)
1080 return rule_on_event(ev, &gui.rule_underline);
1083static int rule_strike_on_event(gp_widget_event *ev)
1085 return rule_on_event(ev, &gui.rule_strike);
1088static int rule_over_on_event(gp_widget_event *ev)
1090 return rule_on_event(ev, &gui.rule_overline);
1093static int browser_on_event(gp_widget_event *ev)
1095 if (ev->type == GP_WIDGET_EVENT_INPUT)
1096 return gpf_browser_input(ev->input_ev);
1103 if (ev->type == GP_WIDGET_EVENT_RESIZE)
1104 gui.browser_follow = 1;
1106 return pixmap_event(ev, gpf_browser_draw);
1113static int block_start_on_event(gp_widget_event *ev)
1117 size_t i, found = 0;
1121 case GP_WIDGET_EVENT_NEW:
1122 gp_widget_tbox_filter_set(ev->self, GP_TBOX_FILTER_HEX);
1123 gp_widget_tbox_clear_on_input(ev->self);
1125 case GP_WIDGET_EVENT_WIDGET:
1126 if (ev->sub_type != GP_WIDGET_TBOX_TRIGGER)
1133 if (!blocks || !gp_vec_len(blocks))
1136 code = strtoul(gp_widget_tbox_text(ev->self), &end, 16);
1141 for (i = 0; i < gp_vec_len(blocks); i++) {
1142 if (blocks[i].
min <= code)
1146 gpf_gui_set_block(found);
1148 if (code >= blocks[found].
min && code <= blocks[found].
max)
1149 gpf_gui_select(code);
1152 update_block_start();
1161gp_pixel gpf_gui_back_color(gp_widget *self)
1163 const gp_widget_render_ctx *ctx = gp_widgets_render_ctx();
1165 if (self && self->focused)
1166 return gp_widgets_color(ctx, GP_WIDGETS_COL_FG);
1168 return gp_widgets_color(ctx, GP_WIDGETS_COL_BG);
1175void gpf_gui_set_canvas_zoom(
unsigned int zoom)
1177 gui.canvas_zoom =
GPF_MAX(1u, zoom);
1179 if (gui.canvas_zoom_widget) {
1180 gp_widget_int_val_set(gui.canvas_zoom_widget,
1185static int canvas_zoom_on_event(gp_widget_event *ev)
1187 if (ev->type != GP_WIDGET_EVENT_WIDGET)
1190 gui.canvas_zoom =
GPF_MAX((int64_t)1, gp_widget_int_val_get(ev->self));
1192 redraw(gui.canvas, gpf_canvas_draw);
1197static int advance_on_event(gp_widget_event *ev)
1201 if (ev->type != GP_WIDGET_EVENT_WIDGET)
1210 glyph->
advance = gp_widget_int_val_get(ev->self);
1221static int bearing_on_event(gp_widget_event *ev,
int horiz)
1226 if (ev->type != GP_WIDGET_EVENT_WIDGET)
1229 val = gp_widget_int_val_get(ev->self);
1238 gpf_glyph_shift(glyph, val - glyph->
bearing_x, 0);
1240 gpf_glyph_shift(glyph, 0, val - glyph->
bearing_y);
1248static int bearing_x_on_event(gp_widget_event *ev)
1250 return bearing_on_event(ev, 1);
1253static int bearing_y_on_event(gp_widget_event *ev)
1255 return bearing_on_event(ev, 0);
1258static int zoom_on_event(gp_widget_event *ev)
1260 if (ev->type != GP_WIDGET_EVENT_WIDGET)
1263 gui.zoom =
GPF_MAX((int64_t)1, gp_widget_int_val_get(ev->self));
1266 gui.browser_follow = 1;
1273static int blocks_on_event(gp_widget_event *ev)
1277 if (ev->type != GP_WIDGET_EVENT_WIDGET)
1280 gpf_gui_set_block(gp_widget_choice_sel_get(ev->self));
1297static int glyph_range_del_on_event(gp_widget_event *ev)
1303 if (ev->type != GP_WIDGET_EVENT_WIDGET || !block)
1314 if (gpf_dialog_range(
"Delete glyphs", &
min, &
max))
1317 cnt = gpf_font_range_glyphs(gui.font,
min,
max);
1332static int glyph_clear_on_event(gp_widget_event *ev)
1334 if (ev->type != GP_WIDGET_EVENT_WIDGET || !gui.font)
1337 if (!gpf_font_range_glyphs(gui.font, gui.code, gui.code))
1340 delete_range(gui.code, gui.code);
1345static const char *blocks_get_choice(gp_widget *self,
size_t idx)
1347 static char bufs[4][64];
1348 static unsigned int cur;
1349 char *buf = bufs[cur++ % 4];
1354 if (!blocks || idx >= gp_vec_len(blocks))
1357 snprintf(buf, 64,
"%s %u/%u", blocks[idx].
name, blocks[idx].
coverage,
1363static size_t blocks_get(gp_widget *self,
enum gp_widget_choice_op op)
1368 case GP_WIDGET_CHOICE_OP_SEL:
1370 case GP_WIDGET_CHOICE_OP_CNT:
1377static void blocks_set(gp_widget *self,
size_t sel)
1384static const gp_widget_choice_ops blocks_ops = {
1385 .get_choice = blocks_get_choice,
1390static const gp_widget_choice_desc blocks_desc = {
1399static int block_add_on_event(gp_widget_event *ev)
1406 if (ev->type != GP_WIDGET_EVENT_WIDGET)
1421 if (gpf_font_block_add(gui.font,
min,
max,
name))
1429 gpf_gui_set_block(idx);
1439static int block_del_on_event(gp_widget_event *ev)
1444 if (ev->type != GP_WIDGET_EVENT_WIDGET || !block)
1450 if (block->coverage) {
1451 if (gp_dialog_msg_printf_run(GP_DIALOG_MSG_QUESTION,
1453 "Delete all %u glyphs in %s?",
1455 block->name) != GP_DIALOG_YES)
1461 gpf_font_block_del(gui.font,
min);
1465 if (gui.code >=
min && gui.code <=
max) {
1469 gpf_gui_select(cur->
min);
1477static int is_dir(
const char *path)
1481 if (stat(path, &st))
1484 return S_ISDIR(st.st_mode);
1487static struct gpf_font *load(
const char *path,
char *err,
size_t err_len)
1490 return gpf_font_read(path, err, err_len);
1492 return gpf_bdf_read(path, err, err_len);
1500static void font_set(
struct gpf_font *font,
const char *path,
char *save_path)
1504 gp_vec_free(gui.block_list);
1505 gui.block_list = NULL;
1508 gpf_undo_free(gui.undo);
1509 free(gui.save_path);
1513 gui.save_path = save_path;
1516 gpf_gui_set_dirty(0);
1519 gp_vec_free(gui.block_sels);
1520 gui.block_sels = NULL;
1525 gui.browser_page = 0;
1526 gui.browser_follow = 1;
1527 gui.canvas_zoom = 0;
1530 gp_widget_redraw(gui.blocks);
1541 gp_widget_resize(gui.blocks);
1543 update_block_start();
1548static void save(
void);
1555static int confirm_discard(
const char *title)
1560 switch (gpf_dialog_save(title)) {
1572static void open_font(
void)
1574 gp_dialog_file_opts opts = {
1575 .flags = GP_DIALOG_OPEN_FILE | GP_DIALOG_OPEN_DIR,
1577 char err[GPF_ERR_MAX] =
"";
1583 if (!confirm_discard(
"Open"))
1586 dialog = gp_dialog_file_open_new(NULL, &opts);
1590 if (gp_dialog_run(dialog) != GP_WIDGET_DIALOG_PATH) {
1591 gp_dialog_free(dialog);
1595 picked = gp_dialog_file_path(dialog);
1596 path = picked ? strdup(picked) : NULL;
1598 gp_dialog_free(dialog);
1603 font = load(path, err,
sizeof(err));
1605 gp_dialog_msg_printf_run(GP_DIALOG_MSG_ERR,
"Open",
"%s", err);
1611 font_set(font, path, is_dir(path) ? strdup(path) : NULL);
1619static void create_font(
void)
1628 if (gpf_dialog_family(&
meta, &authors, &advance)) {
1629 gp_vec_free(authors);
1635 gp_vec_free(authors);
1641 font_set(font,
"", NULL);
1644static void new_font(
void)
1646 if (!confirm_discard(
"New font"))
1652static void quit(
void)
1654 if (!confirm_discard(
"Quit"))
1661 gpf_gui_set_dirty(0);
1672static uint32_t wake_up(gp_timer *self)
1676 return GP_TIMER_STOP;
1679static GP_TIMER_DECLARE(wake_timer, 10, 0,
"wake", wake_up, NULL);
1688static void save_on_exit(
void)
1692 if (!gui.dirty || asked)
1697 gp_app_timer_start(&wake_timer);
1699 if (gp_dialog_msg_run(GP_DIALOG_MSG_QUESTION,
"Closing",
1700 "The font has unsaved changes, save them?")
1721 gpf_gui_set_block(block);
1724 gpf_gui_select(code);
1733static void family_changed(
void)
1737 gui.browser_follow = 1;
1742static int undo_redo(
int redo)
1752 what = gpf_redo(gui.undo, gui.font, &
id, &code);
1754 what = gpf_undo(gui.undo, gui.font, &
id, &code);
1760 goto_edit(
id, code);
1769 gpf_gui_set_dirty(!gpf_undo_is_saved(gui.undo));
1778static void edit_family(
void)
1789 meta = gui.font->meta;
1795 if (gpf_dialog_family(&meta, &authors, NULL))
1799 gpf_authors_same(authors, gui.font->authors))
1802 if (gpf_undo_family(gui.undo, gui.font, &meta, authors))
1807 gp_vec_free(authors);
1810static void save(
void)
1812 char err[GPF_ERR_MAX] =
"";
1818 path = gui.save_path ? gui.save_path : gui.path;
1824 if (!is_dir(path)) {
1825 gp_dialog *dialog = gp_dialog_file_save_new(NULL, NULL);
1831 if (gp_dialog_run(dialog) != GP_WIDGET_DIALOG_PATH) {
1832 gp_dialog_free(dialog);
1836 picked = gp_dialog_file_path(dialog);
1838 free(gui.save_path);
1839 gui.save_path = picked ? strdup(picked) : NULL;
1841 gp_dialog_free(dialog);
1846 path = gui.save_path;
1849 if (gpf_font_write(gui.font, path, err,
sizeof(err))) {
1850 gp_dialog_msg_printf_run(GP_DIALOG_MSG_ERR,
"Save",
"%s", err);
1855 gpf_font_simplify(gui.font);
1861 gpf_undo_saved(gui.undo);
1863 gpf_gui_set_dirty(0);
1874static void export_names(
const char *path,
char *
name,
size_t name_len,
1875 char *
id,
size_t id_len)
1877 const char *base = strrchr(path,
'/');
1881 base = base ? base + 1 : path;
1882 dot = strrchr(base,
'.');
1884 snprintf(
name, name_len,
"%.*s",
1885 (
int)(dot ? (
size_t)(dot - base) : strlen(base)), base);
1887 snprintf(
id, id_len,
"%s",
name);
1890 for (i = 0;
id[i]; i++) {
1891 if (!isalnum((
unsigned char)
id[i]))
1908static void export_font(
void)
1910 char err[GPF_ERR_MAX] =
"";
1912 const char *picked, *base, *ext;
1920 dialog = gp_dialog_file_save_new(NULL, NULL);
1924 if (gp_dialog_run(dialog) != GP_WIDGET_DIALOG_PATH) {
1925 gp_dialog_free(dialog);
1929 picked = gp_dialog_file_path(dialog);
1930 path = picked ? strdup(picked) : NULL;
1932 gp_dialog_free(dialog);
1938 base = strrchr(path,
'/');
1939 ext = strrchr(base ? base + 1 : path,
'.');
1941 f = fopen(path,
"w");
1943 gp_dialog_msg_printf_run(GP_DIALOG_MSG_ERR,
"Export",
"%s: %s",
1944 path, strerror(errno));
1949 if (ext && !strcmp(ext,
".c")) {
1952 export_names(path,
name,
sizeof(
name),
id,
sizeof(
id));
1954 ret = gpf_export_c(gui.font,
id,
name, f, err,
sizeof(err));
1956 ret = gpf_bdf_write(gui.font, gui.variant, f, err,
sizeof(err));
1959 if (fclose(f) && !ret) {
1960 snprintf(err,
sizeof(err),
"%s: %s", path, strerror(errno));
1965 gp_dialog_msg_printf_run(GP_DIALOG_MSG_ERR,
"Export",
"%s", err);
1974static void revert(
void)
1981 variant = gui.font->variants[gui.variant];
1996void gpf_gui_shift(
int dx,
int dy)
2014 gpf_glyph_shift(glyph,
dx, dy);
2020 n = gpf_gui_accented(codes, GP_ARRAY_SIZE(codes));
2022 for (i = 0; i < n; i++) {
2023 struct gpf_glyph *dep = gpf_gui_edit_code(codes[i]);
2026 gpf_glyph_shift(dep,
dx, dy);
2038static void copy(
void)
2041 struct gpf_glyph *clip = &gui.clipboard;
2043 if (!gui.font || gpf_resolve(gui.font, gui.variant, gui.code, &res))
2047 res.glyph.height, res.glyph.bearing_x,
2048 res.glyph.bearing_y)) {
2049 gpf_resolved_clear(&res);
2053 clip->
advance = res.glyph.advance;
2054 gui.clipboard_full = 1;
2056 gpf_resolved_clear(&res);
2058 button_enable(gui.paste_button);
2068static void paste(
void)
2070 const struct gpf_glyph *clip = &gui.clipboard;
2074 if (!gui.font || !gui.clipboard_full)
2077 mono = gui.font->variants[gui.variant] &&
2078 gui.font->variants[gui.variant]->spacing_mono;
2102static void lint_jump(
void)
2115 for (i = 0; i < gp_vec_len(findings); i++) {
2116 if (findings[i].
id < gui.variant)
2119 if (findings[i].
id == gui.variant && findings[i].code <= gui.code)
2128 if (!found && gp_vec_len(findings))
2133 gp_widget_label_set(gui.lint_label,
2134 "nothing for the lint to say");
2136 gp_vec_free(findings);
2140 gui.variant = findings[next].
id;
2142 gpf_gui_select(findings[next].
code);
2144 gp_vec_free(findings);
2147static void glyph_command(
int key)
2155 mono = gui.font->variants[gui.variant] &&
2156 gui.font->variants[gui.variant]->spacing_mono;
2158 if ((key == GP_KEY_LEFT_BRACE || key == GP_KEY_RIGHT_BRACE) && mono) {
2159 gp_dialog_msg_run(GP_DIALOG_MSG_INFO,
"Advance",
2160 "A monospace variant has one advance for the "
2161 "whole font, it is not a glyph property.");
2173 gpf_glyph_clear_ink(glyph);
2176 gpf_glyph_flip_h(glyph);
2179 gpf_glyph_flip_v(glyph);
2181 case GP_KEY_LEFT_BRACE:
2185 case GP_KEY_RIGHT_BRACE:
2197static int app_on_event(gp_widget_event *ev)
2202 if (ev->type == GP_WIDGET_EVENT_FREE) {
2207 if (ev->type != GP_WIDGET_EVENT_INPUT)
2210 input = ev->input_ev;
2212 if (input->type != GP_EV_KEY || input->code != GP_EV_KEY_DOWN)
2215 ctrl = gp_ev_any_key_pressed(input, GP_KEY_LEFT_CTRL, GP_KEY_RIGHT_CTRL);
2216 shift = gp_ev_any_key_pressed(input, GP_KEY_LEFT_SHIFT, GP_KEY_RIGHT_SHIFT);
2219 switch (input->key.key) {
2221 return undo_redo(shift);
2248 switch (input->key.key) {
2258 case GP_KEY_LEFT_BRACE:
2259 case GP_KEY_RIGHT_BRACE:
2260 glyph_command(input->key.key);
2267static int lint_on_event(gp_widget_event *ev)
2269 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2275static int open_on_event(gp_widget_event *ev)
2277 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2283static int save_on_event(gp_widget_event *ev)
2285 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2291static int export_on_event(gp_widget_event *ev)
2293 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2299static int new_on_event(gp_widget_event *ev)
2301 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2307static int family_on_event(gp_widget_event *ev)
2309 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2319static int undo_on_event(gp_widget_event *ev)
2321 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2327static int redo_on_event(gp_widget_event *ev)
2329 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2335static int glyph_del_on_event(gp_widget_event *ev)
2337 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2343static int copy_on_event(gp_widget_event *ev)
2345 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2351static int paste_on_event(gp_widget_event *ev)
2353 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2359static int move_left_on_event(gp_widget_event *ev)
2361 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2362 gpf_gui_shift(-1, 0);
2367static int move_right_on_event(gp_widget_event *ev)
2369 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2370 gpf_gui_shift(1, 0);
2375static int move_up_on_event(gp_widget_event *ev)
2377 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2378 gpf_gui_shift(0, 1);
2383static int move_down_on_event(gp_widget_event *ev)
2385 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2386 gpf_gui_shift(0, -1);
2391static int flip_h_on_event(gp_widget_event *ev)
2393 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2394 glyph_command(GP_KEY_X);
2399static int flip_v_on_event(gp_widget_event *ev)
2401 if (ev->type == GP_WIDGET_EVENT_WIDGET)
2402 glyph_command(GP_KEY_Y);
2407static const gp_widget_json_addr app_callbacks[] = {
2408 {.id =
"advance_on_event", .on_event = advance_on_event},
2409 {.id =
"bearing_x_on_event", .on_event = bearing_x_on_event},
2410 {.id =
"bearing_y_on_event", .on_event = bearing_y_on_event},
2411 {.id =
"block_add_on_event", .on_event = block_add_on_event},
2412 {.id =
"block_del_on_event", .on_event = block_del_on_event},
2413 {.id =
"block_start_on_event", .on_event = block_start_on_event},
2414 {.id =
"blocks_desc", .addr = (
void *)&blocks_desc},
2415 {.id =
"blocks_on_event", .on_event = blocks_on_event},
2416 {.id =
"browser_on_event", .on_event = browser_on_event},
2417 {.id =
"canvas_on_event", .on_event = canvas_on_event},
2418 {.id =
"canvas_zoom_on_event", .on_event = canvas_zoom_on_event},
2419 {.id =
"copy_on_event", .on_event = copy_on_event},
2420 {.id =
"deps_on_event", .on_event = deps_on_event},
2421 {.id =
"export_on_event", .on_event = export_on_event},
2422 {.id =
"family_on_event", .on_event = family_on_event},
2423 {.id =
"flip_h_on_event", .on_event = flip_h_on_event},
2424 {.id =
"flip_v_on_event", .on_event = flip_v_on_event},
2425 {.id =
"glyph_clear_on_event", .on_event = glyph_clear_on_event},
2426 {.id =
"glyph_del_on_event", .on_event = glyph_del_on_event},
2427 {.id =
"glyph_range_del_on_event", .on_event = glyph_range_del_on_event},
2428 {.id =
"lint_on_event", .on_event = lint_on_event},
2429 {.id =
"move_down_on_event", .on_event = move_down_on_event},
2430 {.id =
"move_left_on_event", .on_event = move_left_on_event},
2431 {.id =
"move_right_on_event", .on_event = move_right_on_event},
2432 {.id =
"move_up_on_event", .on_event = move_up_on_event},
2433 {.id =
"new_on_event", .on_event = new_on_event},
2434 {.id =
"open_on_event", .on_event = open_on_event},
2435 {.id =
"paste_on_event", .on_event = paste_on_event},
2436 {.id =
"preview_on_event", .on_event = preview_on_event},
2437 {.id =
"preview_text_on_event", .on_event = preview_text_on_event},
2438 {.id =
"redo_on_event", .on_event = redo_on_event},
2439 {.id =
"rule_over_on_event", .on_event = rule_over_on_event},
2440 {.id =
"rule_strike_on_event", .on_event = rule_strike_on_event},
2441 {.id =
"rule_under_on_event", .on_event = rule_under_on_event},
2442 {.id =
"save_on_event", .on_event = save_on_event},
2443 {.id =
"strip_on_event", .on_event = strip_on_event},
2444 {.id =
"undo_on_event", .on_event = undo_on_event},
2445 {.id =
"update_on_event", .on_event = update_on_event},
2446 {.id =
"zoom_on_event", .on_event = zoom_on_event},
2450static const gp_widget_json_callbacks callbacks = {
2451 .addrs = app_callbacks,
2454static gp_widget *widget_by_uid(
const char *uid,
enum gp_widget_type type)
2456 gp_widget *widget = gp_widget_by_uid(gui.uids, uid, type);
2459 fprintf(stderr,
"gpforge: the layout has no '%s'\n", uid);
2464int main(
int argc,
char *argv[])
2466 char err[GPF_ERR_MAX] =
"";
2469 gp_widgets_getopt(&argc, &argv);
2475 gui.font = load(gui.path, err,
sizeof(err));
2477 fprintf(stderr,
"%s\n", err);
2484 gui.browser_follow = 1;
2488 fprintf(stderr,
"gpforge: out of memory\n");
2492 gp_app_on_event_set(app_on_event);
2493 gp_app_event_unmask(GP_WIDGET_EVENT_INPUT);
2495 layout = gp_app_layout_load2(
"gpforge", &callbacks, &gui.uids);
2497 fprintf(stderr,
"gpforge: cannot load the layout\n");
2501 gui.canvas = widget_by_uid(
"canvas", GP_WIDGET_PIXMAP);
2502 gui.browser = widget_by_uid(
"browser", GP_WIDGET_PIXMAP);
2503 gui.preview = widget_by_uid(
"preview", GP_WIDGET_PIXMAP);
2504 gui.strip = widget_by_uid(
"strip", GP_WIDGET_PIXMAP);
2505 gui.deps = widget_by_uid(
"deps", GP_WIDGET_PIXMAP);
2506 gui.status = widget_by_uid(
"status", GP_WIDGET_LABEL);
2507 gui.blocks = widget_by_uid(
"blocks", GP_WIDGET_SPINBUTTON);
2508 gui.block_start = widget_by_uid(
"block_start", GP_WIDGET_TBOX);
2509 gui.preview_text = widget_by_uid(
"preview_text", GP_WIDGET_TBOX);
2510 gui.canvas_zoom_widget = widget_by_uid(
"canvas_zoom", GP_WIDGET_SPINNER);
2511 gui.lint_label = widget_by_uid(
"lint", GP_WIDGET_LABEL);
2512 gui.lint_errors = widget_by_uid(
"lint_errors", GP_WIDGET_LABEL);
2513 gui.lint_warnings = widget_by_uid(
"lint_warnings", GP_WIDGET_LABEL);
2514 gui.save_button = widget_by_uid(
"save", GP_WIDGET_BUTTON);
2515 gui.export_button = widget_by_uid(
"export", GP_WIDGET_BUTTON);
2516 gui.family_button = widget_by_uid(
"family_button", GP_WIDGET_BUTTON);
2517 gui.undo_button = widget_by_uid(
"undo", GP_WIDGET_BUTTON);
2518 gui.redo_button = widget_by_uid(
"redo", GP_WIDGET_BUTTON);
2519 gui.paste_button = widget_by_uid(
"paste", GP_WIDGET_BUTTON);
2520 gui.advance_widget = widget_by_uid(
"advance", GP_WIDGET_SPINNER);
2521 gui.bearing_x_widget = widget_by_uid(
"bearing_x", GP_WIDGET_SPINNER);
2522 gui.bearing_y_widget = widget_by_uid(
"bearing_y", GP_WIDGET_SPINNER);
2524 gp_widget_events_unmask(gui.canvas, GP_WIDGET_EVENT_RESIZE |
2525 GP_WIDGET_EVENT_COLOR_SCHEME |
2526 GP_WIDGET_EVENT_INPUT |
2527 GP_WIDGET_EVENT_FOCUS);
2528 gp_widget_events_unmask(gui.strip, GP_WIDGET_EVENT_RESIZE |
2529 GP_WIDGET_EVENT_COLOR_SCHEME |
2530 GP_WIDGET_EVENT_INPUT |
2531 GP_WIDGET_EVENT_FOCUS);
2532 gp_widget_events_unmask(gui.deps, GP_WIDGET_EVENT_RESIZE |
2533 GP_WIDGET_EVENT_COLOR_SCHEME |
2534 GP_WIDGET_EVENT_INPUT |
2535 GP_WIDGET_EVENT_FOCUS);
2536 gp_widget_events_unmask(gui.preview, GP_WIDGET_EVENT_RESIZE |
2537 GP_WIDGET_EVENT_COLOR_SCHEME);
2538 gp_widget_events_unmask(gui.browser, GP_WIDGET_EVENT_RESIZE |
2539 GP_WIDGET_EVENT_COLOR_SCHEME |
2540 GP_WIDGET_EVENT_INPUT |
2541 GP_WIDGET_EVENT_FOCUS);
2543 gui.family_label = gp_widget_by_uid(gui.uids,
"family", GP_WIDGET_LABEL);
2548 update_lint_count();
2549 update_block_start();
2552 gpf_gui_set_dirty(0);
2558 button_disable(gui.paste_button, NULL);
2560 gp_widgets_main_loop(layout, NULL, 0, NULL);
void gpf_browser_show_sel(void)
Turns the table to the selected glyph.
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.
const struct gpf_ucode_block * gpf_dialog_block_add(void)
Runs the block picker.
The font properties dialog.
The codepoint range dialog.
The unsaved changes dialog.
struct gpf_author * gpf_authors_dup(const struct gpf_author *authors)
Copies a gp_vec of authors.
void gpf_family_meta_guess(struct gpf_family_meta *meta, const char *family, int size, int ascent, int descent, int advance)
Fills in metadata for a font that is only being started.
int gpf_family_meta_same(const struct gpf_family_meta *a, const struct gpf_family_meta *b)
Compares two sets of font metadata.
struct gpf_glyph * gpf_variant_glyph_add(struct gpf_variant *self, uint32_t code)
Adds a glyph to a variant.
void gpf_font_free(struct gpf_font *self)
Frees a font with all its variants and glyphs.
enum gpf_variant_id gpf_variant_parent(enum gpf_variant_id id)
Returns the variant a variant derives its missing glyphs from.
#define GPF_NAME_MAX
Size of the name buffers, including the terminating zero.
void gpf_font_clear_modified(struct gpf_font *self)
Clears the modified flag of all glyphs in all variants.
void gpf_variant_glyph_del(struct gpf_variant *self, uint32_t code)
Removes a glyph from a variant.
struct gpf_variant * gpf_font_variant(struct gpf_font *self, enum gpf_variant_id id, int create)
Returns a font variant.
#define GPF_MAX(a, b)
Returns the larger of two values, evaluates them twice.
gpf_variant_id
Font face variant.
@ GPF_NO_PARENT
What gpf_variant_parent() returns for the base variant.
@ GPF_VARIANTS
Number of font variants.
@ GPF_MONO
Monospace glyphs, the base variant.
struct gpf_glyph * gpf_variant_glyph(struct gpf_variant *self, uint32_t code)
Looks up a glyph in a variant.
@ GPF_GLYPH_INK
Glyph with ink.
@ GPF_GLYPH_METRICS
Glyph with metrics.
int gpf_glyph_set_bits(struct gpf_glyph *self, const uint8_t *bits, unsigned int w, unsigned int h, int bearing_x, int bearing_y)
Stores the glyph ink.
struct gpf_font * gpf_font_create(const struct gpf_family_meta *meta, int advance)
Creates a new font.
The editor state and the functions everything in the GUI goes through.
void gpf_gui_redraw(void)
Repaints everything that shows the font.
void gpf_gui_select_keep(uint32_t code)
Selects a glyph without moving the table to it.
void gpf_gui_edit_begin(void)
Starts an edit, one undo entry.
const struct gpf_ucode_block * gpf_gui_block(void)
The block being browsed.
void gpf_gui_set_block(unsigned int block)
Selects a block and turns the table to its first page.
struct gpf_glyph * gpf_gui_edit_glyph(void)
The glyph entry to edit in the current variant.
void gpf_gui_select(uint32_t code)
Selects a glyph and turns the table to it.
void gpf_gui_invalidate(void)
Throws the compiled faces away.
void gpf_gui_edit_commit(void)
Commits the edit started by gpf_gui_edit_begin() and repaints.
const gp_font_face * gpf_gui_face(enum gpf_variant_id id)
The resolved variant compiled into a gfxprim face.
void gpf_gui_edited(void)
The font changed.
const struct gpf_ucode_block * gpf_gui_blocks(void)
The block list, built on demand.
int gpf_lint_glyph(struct gpf_font *font, enum gpf_variant_id id, uint32_t code, struct gpf_lint_finding *out)
Runs a linter for a single glyph.
struct gpf_lint_finding * gpf_lint(struct gpf_font *font)
Runs linter on a font.
@ GPF_LINT_WARN
Probably a slip. May be deliberate.
@ GPF_LINT_ERROR
The font renders wrong.
The preview, the variant strip and the accented letters strip.
gpf_entry_form
The smallest form an entry can be written in on save.
@ GPF_ENTRY_METRICS
The ink is the parent's, only numbers differ.
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.
A font author, one author line of the family file.
char name[64]
The author's name.
The glyph selected last in a block, to go back to when the block is switched to again.
uint32_t min
The block, by its first codepoint: indices move on a rebuild.
uint32_t code
The glyph selected, the table one or one picked from the accented letters strip, which may be out of ...
uint32_t table
The glyph selected in its table.
uint32_t draw_base
What a new one is drawn from.
enum gpf_accent_place place
Where the accent is placed in the glyph rectangle.
uint32_t base_code
The letter this is an accented form of, e.g. 'i' for 'í'.
uint32_t code
A unicode code point of the accented letter.
struct gpf_author * authors
Font authors.
struct gpf_family_meta meta
Font meta data.
uint8_t kind
enum gpf_glyph_kind
int bearing_y
Glyph bearing y.
uint8_t has_advance
The entry carries an advance.
int dx
Accent offset, positive right and up, compose only.
uint32_t base
Base glyph, GPF_GLYPH_COMPOSE only.
uint32_t accent
Accent to be combined with the base, GPF_GLYPH_COMPOSE only.
uint8_t has_bearing
The entry carries both bearings, see has_advance.
unsigned int height
Glyph ink height.
unsigned int width
Glyph ink width.
int advance
Glyph advance.
uint8_t modified
Glyph was modified flag.
int bearing_x
Glyph bearing x.
uint32_t code
Unicode code point.
gp_font_face * faces[GPF_VARIANTS]
The compiled faces, built lazily, one per variant.
uint32_t code
A unicode code point the finding is for.
enum gpf_lint_severity sev
Severity.
enum gpf_variant_id id
Variant of the glyph the finding is for.
char msg[72]
Linter message.
A resolved glyph and where it was drawn from.
enum gpf_variant_id ink_from
The variant the ink came from.
struct gpf_glyph glyph
Freshly allocated glyph with copied/generated ink.
A unicode block description.
const char * name
Human readable name of the block.
unsigned int coverage
Number of glyphs the font has in this block.
uint32_t max
Last code point in the block.
uint32_t min
First code point in the block.
int advance
Advance for all glyphs.
enum gpf_variant_id id
Font variant e.g. GPF_REGULAR, GPF_MONO, etc.
int spacing_mono
Every glyph has the same advance.
struct gpf_undo * gpf_undo_new(void)
Creates a new undo.
@ GPF_UNDO_FAMILY
The family metadata or the authors changed.
@ GPF_UNDO_GLYPH
A glyph changed.
@ GPF_UNDO_NONE
The journal had nothing at that end.
int gpf_blocks_find(const struct gpf_ucode_block *blocks, uint32_t code)
Looks up a block by a codepoint.
struct gpf_ucode_block * gpf_blocks_build(struct gpf_font *font)
Builds a list of blocks for a font.
static uint32_t gpf_block_glyphs(const struct gpf_ucode_block *block)
Counts number of codepoints in a unicode block.