24static int is_dir(
const char *path)
31 return S_ISDIR(st.st_mode);
34static struct gpf_font *load(
const char *path,
char *err,
size_t err_len)
37 return gpf_font_read(path, err, err_len);
39 return gpf_bdf_read(path, err, err_len);
42static void dump_glyph(
const struct gpf_glyph *glyph)
46 printf(
"U+%04X ", glyph->
code);
48 switch (glyph->
kind) {
50 printf(
"ink adv %i brg %i,%i size %ux%u\n",
54 for (y = 0; y < glyph->
height; y++) {
56 for (x = 0; x < glyph->
width; x++)
64 printf(
" adv %i", glyph->
advance);
66 printf(
" shift %i,%i", glyph->
shift_x, glyph->shift_y);
70 printf(
"compose U+%04X U+%04X at %i,%i\n",
76static void dump(
struct gpf_font *font)
82 printf(
"family %s\n", m->
family);
83 printf(
"size %i ascent %i descent %i line_gap %i\n",
85 printf(
"em %i x_height %i cap_height %i ch_width %i\n",
87 printf(
"underline %i %i strikethrough %i %i overline %i %i\n",
92 printf(
"license %s\n", m->
license);
94 for (j = 0; j < gp_vec_len(font->
authors); j++) {
105 printf(
"variant %s spacing %s derive %s advance %i glyphs %zu\n",
112 dump_glyph(&variant->
glyphs[j]);
119static int face(
struct gpf_font *font,
const char *name)
126 fprintf(stderr,
"unknown variant '%s'\n", name);
134 for (i = 0; i < gp_vec_len(vec); i++) {
141 printf(
"U+%04X %s adv %i brg %i,%i size %ux%u\n",
143 res.glyph.advance, res.glyph.bearing_x,
144 res.glyph.bearing_y, res.glyph.width, res.glyph.height);
146 for (y = 0; y < res.glyph.height; y++) {
148 for (x = 0; x < res.glyph.width; x++)
161static void usage(
const char *name)
164 "usage: %s import <font.bdf> <dir>\n"
165 " %s write <dir> <out-dir>\n"
166 " %s dump <font.bdf|dir>\n"
167 " %s face <font.bdf|dir> <variant>\n"
168 " %s lint <font.bdf|dir>\n"
169 " %s c <font.bdf|dir> <font_id> <family-name>\n"
170 " %s bdf <font.bdf|dir> <variant>\n",
171 name, name, name, name, name, name, name);
174int main(
int argc,
char *argv[])
176 char err[GPF_ERR_MAX] =
"";
184 if (!strcmp(argv[1],
"dump")) {
185 font = load(argv[2], err,
sizeof(err));
187 fprintf(stderr,
"%s\n", err);
197 if (!strcmp(argv[1],
"c")) {
203 font = load(argv[2], err,
sizeof(err));
205 fprintf(stderr,
"%s\n", err);
209 if (gpf_export_c(font, argv[3], argv[4], stdout, err,
sizeof(err))) {
210 fprintf(stderr,
"%s\n", err);
220 if (!strcmp(argv[1],
"bdf")) {
229 fprintf(stderr,
"unknown variant '%s'\n", argv[3]);
233 font = load(argv[2], err,
sizeof(err));
235 fprintf(stderr,
"%s\n", err);
239 if (gpf_bdf_write(font,
id, stdout, err,
sizeof(err))) {
240 fprintf(stderr,
"%s\n", err);
250 if (!strcmp(argv[1],
"lint")) {
252 unsigned int errors = 0, warns = 0;
255 font = load(argv[2], err,
sizeof(err));
257 fprintf(stderr,
"%s\n", err);
263 for (i = 0; findings && i < gp_vec_len(findings); i++) {
271 printf(
"%-10s U+%04X %-5s %s\n",
272 gpf_variant_name(f->
id), f->
code,
273 gpf_lint_severity_name(f->
sev), f->
msg);
276 printf(
"%u errors, %u warnings\n", errors, warns);
278 gp_vec_free(findings);
281 return errors ? 1 : 0;
284 if (!strcmp(argv[1],
"face")) {
292 font = load(argv[2], err,
sizeof(err));
294 fprintf(stderr,
"%s\n", err);
298 ret = face(font, argv[3]);
305 if (!strcmp(argv[1],
"import") || !strcmp(argv[1],
"write")) {
311 font = load(argv[2], err,
sizeof(err));
313 fprintf(stderr,
"%s\n", err);
317 if (gpf_font_write(font, argv[3], err,
sizeof(err))) {
318 fprintf(stderr,
"%s\n", err);
The in-memory font model.
const char * gpf_variant_name(enum gpf_variant_id id)
Returns the name of a variant.
static int gpf_glyph_pixel(const struct gpf_glyph *self, unsigned int x, unsigned int y)
Returns a glyph ink pixel.
int gpf_variant_by_name(const char *name, enum gpf_variant_id *id)
Looks up a variant by its on-disk name.
void gpf_font_free(struct gpf_font *self)
Frees a font with all its variants and glyphs.
static size_t gpf_variant_glyphs(const struct gpf_variant *self)
Returns the number of glyph entries in a variant.
gpf_variant_id
Font face variant.
@ GPF_VARIANTS
Number of font variants.
uint32_t * gpf_font_codes(struct gpf_font *self)
Returns every codepoint the font mentions, in any variant.
@ GPF_GLYPH_INK
Glyph with ink.
@ GPF_GLYPH_COMPOSE
Glyph is composed from base + accent.
@ GPF_GLYPH_METRICS
Glyph with metrics.
struct gpf_lint_finding * gpf_lint(struct gpf_font *font)
Runs linter on a font.
@ GPF_LINT_ERROR
The font renders wrong.
The glyph variant lattice.
const char * gpf_provenance_name(enum gpf_provenance prov)
Returns provenance name.
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.
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.
struct gpf_author * authors
Font authors.
struct gpf_variant * variants[GPF_VARIANTS]
Variants indexed by gpf_variant_id, NULL when missing.
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 shift_x
How far the inherited ink is moved, positive right and up.
int dx
Accent offset, positive right and up, compose only.
uint8_t has_shift
The entry moves the inherited ink, GPF_GLYPH_METRICS only.
uint32_t base
Base glyph, GPF_GLYPH_COMPOSE only.
uint32_t accent
Accent to be combined with the base, GPF_GLYPH_COMPOSE only.
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.
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.
int advance
Advance for all glyphs.
int derive_embolden
Glyphs not drawn here are emboldened from the parent.
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_glyph * glyphs
Glyphs.