|
gpforge
An advanced bitmap font editor
|
The in-memory font model. More...
#include <stdint.h>#include <stddef.h>#include <utils/gp_vec.h>Go to the source code of this file.
Data Structures | |
| struct | gpf_glyph |
| A glyph. More... | |
| struct | gpf_variant |
| A font variant. More... | |
| struct | gpf_block_decl |
| A declared unicode block. More... | |
| struct | gpf_author |
| A font author, one author line of the family file. More... | |
| struct | gpf_family_meta |
| Font family meta data. More... | |
| struct | gpf_font |
| A font family. More... | |
Enumerations | |
| enum | gpf_variant_id { GPF_MONO , GPF_REGULAR , GPF_BOLD_MONO , GPF_BOLD , GPF_VARIANTS , GPF_NO_PARENT = GPF_VARIANTS } |
| Font face variant. More... | |
| enum | gpf_glyph_kind { GPF_GLYPH_INK , GPF_GLYPH_METRICS , GPF_GLYPH_COMPOSE } |
| A glyph entry type. More... | |
Functions | |
| const char * | gpf_variant_name (enum gpf_variant_id id) |
| Returns the name of a variant. | |
| int | gpf_variant_by_name (const char *name, enum gpf_variant_id *id) |
| Looks up a variant by its on-disk name. | |
| enum gpf_variant_id | gpf_variant_parent (enum gpf_variant_id id) |
| Returns the variant a variant derives its missing glyphs from. | |
| struct gpf_font * | gpf_font_new (void) |
| Allocates an empty font. | |
| void | gpf_font_free (struct gpf_font *self) |
| Frees a font with all its variants and glyphs. | |
| 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. | |
| struct gpf_font * | gpf_font_create (const struct gpf_family_meta *meta, int advance) |
| Creates a new font. | |
| 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_variant * | gpf_font_variant (struct gpf_font *self, enum gpf_variant_id id, int create) |
| Returns a font variant. | |
| static size_t | gpf_variant_glyphs (const struct gpf_variant *self) |
| Returns the number of glyph entries in a variant. | |
| uint32_t * | gpf_font_codes (struct gpf_font *self) |
| Returns every codepoint the font mentions, in any variant. | |
| void | gpf_font_clear_modified (struct gpf_font *self) |
| Clears the modified flag of all glyphs in all variants. | |
| void | gpf_font_ink_extent (struct gpf_font *self, int *top, int *bottom) |
| Returns how far the ink of the whole font reaches. | |
| int | gpf_font_block_add (struct gpf_font *self, uint32_t min, uint32_t max, const char *name) |
| Declares a unicode block. | |
| void | gpf_font_block_del (struct gpf_font *self, uint32_t min) |
| Removes a block declaration. | |
| unsigned int | gpf_font_block_clear (struct gpf_font *self, uint32_t min, uint32_t max) |
| Deletes every glyph in a range, in all variants. | |
| unsigned int | gpf_font_range_glyphs (struct gpf_font *self, uint32_t min, uint32_t max) |
| Counts glyph entries in a range, in all variants. | |
| int | gpf_font_block_declared (struct gpf_font *self, uint32_t min) |
| Checks whether a block is declared. | |
| const char * | gpf_author_invalid (const char *years, const char *name, const char *email) |
| Checks the fields of an author. | |
| 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. | |
| void | gpf_authors_del (struct gpf_author **authors, size_t idx) |
| Removes an author from a gp_vec of authors. | |
| struct gpf_author * | gpf_authors_dup (const struct gpf_author *authors) |
| Copies a gp_vec of authors. | |
| int | gpf_authors_same (const struct gpf_author *a, const struct gpf_author *b) |
| Compares two gp_vecs of authors, NULL being the same as empty. | |
| struct gpf_glyph * | gpf_variant_glyph (struct gpf_variant *self, uint32_t code) |
| Looks up a glyph in a variant. | |
| struct gpf_glyph * | gpf_variant_glyph_add (struct gpf_variant *self, uint32_t code) |
| Adds a glyph to a variant. | |
| void | gpf_variant_glyph_del (struct gpf_variant *self, uint32_t code) |
| Removes a glyph from a variant. | |
| void | gpf_glyph_clear (struct gpf_glyph *self) |
| Frees the ink and zeroes the glyph, keeping only the code. | |
| 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. | |
| static int | gpf_glyph_pixel (const struct gpf_glyph *self, unsigned int x, unsigned int y) |
| Returns a glyph ink pixel. | |
The in-memory font model.
A font is a family of four variants: mono, regular, bold-mono and bold. Each variant holds a sparse array of glyphs sorted by unicode codepoint, which matches the on-disk order so that saving reshuffles nothing.
Definition in file font.h.
| enum gpf_glyph_kind |
A glyph entry type.
What a glyph entry stored in a variant carries: the ink itself, numbers only with the ink derived from the parent, or a composition.
| enum gpf_variant_id |
Font face variant.
| Enumerator | |
|---|---|
| GPF_MONO | Monospace glyphs, the base variant. |
| GPF_REGULAR | Proportional glyphs, "regular" on disk. |
| GPF_BOLD_MONO | Bold monospace glyphs. |
| GPF_BOLD | Bold glyphs. |
| GPF_VARIANTS | Number of font variants. |
| GPF_NO_PARENT | What gpf_variant_parent() returns for the base variant. |
| const char * gpf_author_invalid | ( | const char * | years, |
| const char * | name, | ||
| const char * | email ) |
Checks the fields of an author.
The years are digits, '-' for a range and ',' for a list, and start with a digit; the name is not empty; the email has an '@' and no whitespace or angle brackets; and all of them fit struct gpf_author.
| years | Copyright years, e.g. "2019-2024". |
| name | The author's name. |
| The author's email, without the angle brackets. |
Definition at line 397 of file font.c.
References gpf_author::email, gpf_author::name, and gpf_author::years.
Referenced by gpf_authors_add().
| 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.
| authors | A gp_vec of authors, allocated when it is NULL. |
| years | Copyright years, e.g. "2019-2024". |
| name | The author's name. |
| The author's email, without the angle brackets. |
Definition at line 426 of file font.c.
References gpf_author::email, gpf_author_invalid(), gpf_author::name, and gpf_author::years.
| void gpf_authors_del | ( | struct gpf_author ** | authors, |
| size_t | idx ) |
| struct gpf_author * gpf_authors_dup | ( | const struct gpf_author * | authors | ) |
| int gpf_authors_same | ( | const struct gpf_author * | a, |
| const struct gpf_author * | b ) |
Compares two gp_vecs of authors, NULL being the same as empty.
| a | A gp_vec of authors, may be NULL. |
| b | A gp_vec of authors, may be NULL. |
Definition at line 472 of file font.c.
References gpf_author::email, gpf_author::name, and gpf_author::years.
| 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.
Sets what is asked for and guesses the rest, so that nothing is zero; the guesses are to be overwritten as the font is drawn.
| meta | The metadata to fill in. |
| family | A family name, "New" is used when NULL or empty. |
| size | Font size. |
| ascent | Font ascent. |
| descent | Font descent. |
| advance | The mono advance, used as the ch_width. |
Definition at line 72 of file font.c.
References gpf_family_meta::ascent, gpf_family_meta::cap_height, gpf_family_meta::ch_width, gpf_family_meta::default_glyph, gpf_family_meta::descent, gpf_family_meta::em, gpf_family_meta::family, gpf_font::meta, gpf_family_meta::overline_pos, gpf_family_meta::overline_thickness, gpf_family_meta::size, gpf_family_meta::strike_pos, gpf_family_meta::strike_thickness, gpf_family_meta::underline_pos, gpf_family_meta::underline_thickness, and gpf_family_meta::x_height.
| int gpf_family_meta_same | ( | const struct gpf_family_meta * | a, |
| const struct gpf_family_meta * | b ) |
Compares two sets of font metadata.
Strings are compared up to their terminating zero, what is past the end of a string does not count.
| a | Font metadata. |
| b | Font metadata. |
Definition at line 122 of file font.c.
References gpf_family_meta::ascent, gpf_family_meta::cap_height, gpf_family_meta::ch_width, gpf_family_meta::default_glyph, gpf_family_meta::descent, gpf_family_meta::em, gpf_family_meta::family, gpf_family_meta::license, gpf_family_meta::line_gap, gpf_family_meta::overline_pos, gpf_family_meta::overline_thickness, gpf_family_meta::size, gpf_family_meta::strike_pos, gpf_family_meta::strike_thickness, gpf_family_meta::underline_pos, gpf_family_meta::underline_thickness, and gpf_family_meta::x_height.
| int gpf_font_block_add | ( | struct gpf_font * | self, |
| uint32_t | min, | ||
| uint32_t | max, | ||
| const char * | name ) |
Declares a unicode block.
Declaring an already declared block is a no-op.
| self | A font. |
| min | The first codepoint of the block. |
| max | The last codepoint of the block. |
| name | The block name, may be NULL. |
Definition at line 364 of file font.c.
References gpf_font::blocks, gpf_font_block_declared(), gpf_block_decl::max, gpf_block_decl::min, and gpf_block_decl::name.
| unsigned int gpf_font_block_clear | ( | struct gpf_font * | self, |
| uint32_t | min, | ||
| uint32_t | max ) |
Deletes every glyph in a range, in all variants.
| self | A font. |
| min | The first codepoint of the range. |
| max | The last codepoint of the range, inclusive. |
Definition at line 550 of file font.c.
References GPF_VARIANTS, and gpf_font::variants.
| int gpf_font_block_declared | ( | struct gpf_font * | self, |
| uint32_t | min ) |
Checks whether a block is declared.
| self | A font. |
| min | The first codepoint of the block. |
Definition at line 352 of file font.c.
References gpf_font::blocks, and gpf_block_decl::min.
Referenced by gpf_font_block_add().
| void gpf_font_block_del | ( | struct gpf_font * | self, |
| uint32_t | min ) |
Removes a block declaration.
Does not touch any glyphs: a block that has glyphs stays on the font's list regardless.
| self | A font. |
| min | The first codepoint of the block, an undeclared one is a no-op. |
Definition at line 563 of file font.c.
References gpf_font::blocks, and gpf_block_decl::min.
| void gpf_font_clear_modified | ( | struct gpf_font * | self | ) |
Clears the modified flag of all glyphs in all variants.
Forgets which glyphs were edited, which is what writing the font makes true.
| self | A font. |
Definition at line 269 of file font.c.
References gpf_variant::glyphs, gpf_variant_glyphs(), GPF_VARIANTS, gpf_glyph::modified, and gpf_font::variants.
| uint32_t * gpf_font_codes | ( | struct gpf_font * | self | ) |
Returns every codepoint the font mentions, in any variant.
| self | A font. |
Definition at line 317 of file font.c.
References gpf_glyph::code, gpf_variant::glyphs, gpf_variant_glyphs(), GPF_VARIANTS, and gpf_font::variants.
Referenced by gpf_face_build().
| struct gpf_font * gpf_font_create | ( | const struct gpf_family_meta * | meta, |
| int | advance ) |
Creates a new font.
The font has the metadata and an empty mono variant of the advance, the other variants appear when something is drawn in them.
| meta | Font metadata, copied. |
| advance | The advance of the mono variant. |
Definition at line 100 of file font.c.
References gpf_variant::advance, gpf_font_free(), gpf_font_new(), gpf_font_variant(), GPF_MONO, and gpf_font::meta.
| void gpf_font_free | ( | struct gpf_font * | self | ) |
Frees a font with all its variants and glyphs.
| self | A font, may be NULL. |
Definition at line 159 of file font.c.
References gpf_font::authors, gpf_font::blocks, gpf_font::comments, GPF_VARIANTS, and gpf_font::variants.
Referenced by gpf_font_create(), and gpf_font_read().
| void gpf_font_ink_extent | ( | struct gpf_font * | self, |
| int * | top, | ||
| int * | bottom ) |
Returns how far the ink of the whole font reaches.
This is not always the ascent and the descent: an accent that does not fit over a capital sticks out of the box, and a cell that is drawn as tall as the box would cut it off. The result is never smaller than the box.
| self | A font. |
| top | Set to the highest ink row, positive up from the baseline. |
| bottom | Set to the lowest ink row, positive up from the baseline. |
Definition at line 285 of file font.c.
References gpf_family_meta::ascent, gpf_glyph::bearing_y, gpf_family_meta::descent, gpf_variant::glyphs, gpf_variant_glyphs(), GPF_VARIANTS, gpf_glyph::height, gpf_font::meta, and gpf_font::variants.
Referenced by gpf_cell_init().
| struct gpf_font * gpf_font_new | ( | void | ) |
Allocates an empty font.
The font has no variants and zeroed metadata apart from the line thicknesses, which are set to one.
Definition at line 58 of file font.c.
References gpf_font::meta, gpf_family_meta::overline_thickness, gpf_family_meta::strike_thickness, and gpf_family_meta::underline_thickness.
Referenced by gpf_bdf_read(), gpf_font_create(), and gpf_font_read().
| unsigned int gpf_font_range_glyphs | ( | struct gpf_font * | self, |
| uint32_t | min, | ||
| uint32_t | max ) |
Counts glyph entries in a range, in all variants.
| self | A font. |
| min | The first codepoint of the range. |
| max | The last codepoint of the range, inclusive. |
Definition at line 527 of file font.c.
References gpf_glyph::code, gpf_variant::glyphs, gpf_variant_glyphs(), GPF_VARIANTS, and gpf_font::variants.
| struct gpf_variant * gpf_font_variant | ( | struct gpf_font * | self, |
| enum gpf_variant_id | id, | ||
| int | create ) |
Returns a font variant.
A newly allocated variant is empty, has spacing_mono set for the mono variants and derive_embolden set for the bold ones.
| self | A font. |
| id | A variant id. |
| create | Allocate the variant when it is missing. |
Definition at line 175 of file font.c.
References gpf_variant::derive_embolden, gpf_variant::glyphs, GPF_BOLD, GPF_BOLD_MONO, GPF_MONO, GPF_VARIANTS, gpf_variant::id, gpf_variant::spacing_mono, and gpf_font::variants.
Referenced by gpf_font_create().
| void gpf_glyph_clear | ( | struct gpf_glyph * | self | ) |
Frees the ink and zeroes the glyph, keeping only the code.
| self | A glyph. |
Definition at line 576 of file font.c.
References gpf_glyph::bits, and gpf_glyph::code.
|
inlinestatic |
Returns a glyph ink pixel.
| self | A glyph. |
| x | The column in the trimmed ink. |
| y | The row in the trimmed ink. |
Definition at line 623 of file font.h.
References gpf_glyph::bits, gpf_glyph::height, and gpf_glyph::width.
Referenced by gpf_compose_remainder().
| 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.
Trims empty rows and columns and adjusts the bearings. An empty bitmap produces an empty glyph with zero bearings.
| self | A glyph. |
| bits | The ink, one byte per pixel, w * h, row major, copied. |
| w | The bitmap width. |
| h | The bitmap height. |
| bearing_x | The bearing x of the bitmap left column. |
| bearing_y | The bearing y of the bitmap top row. |
Definition at line 585 of file font.c.
References gpf_glyph::bearing_x, gpf_glyph::bearing_y, gpf_glyph::bits, gpf_glyph::height, and gpf_glyph::width.
| int gpf_variant_by_name | ( | const char * | name, |
| enum gpf_variant_id * | id ) |
Looks up a variant by its on-disk name.
| name | A variant name, e.g. "regular". |
| id | Set to the variant id on success. |
Definition at line 31 of file font.c.
References GPF_VARIANTS.
| struct gpf_glyph * gpf_variant_glyph | ( | struct gpf_variant * | self, |
| uint32_t | code ) |
Looks up a glyph in a variant.
| self | A font variant. |
| code | A unicode codepoint. |
Definition at line 231 of file font.c.
References gpf_glyph::code, and gpf_variant::glyphs.
Referenced by gpf_gui_modified(), and gpf_resolve_derived().
| struct gpf_glyph * gpf_variant_glyph_add | ( | struct gpf_variant * | self, |
| uint32_t | code ) |
Adds a glyph to a variant.
The new glyph is zeroed apart from the code, i.e. an empty GPF_GLYPH_INK.
| self | A font variant. |
| code | A unicode codepoint. |
Definition at line 242 of file font.c.
References gpf_glyph::code, and gpf_variant::glyphs.
| void gpf_variant_glyph_del | ( | struct gpf_variant * | self, |
| uint32_t | code ) |
Removes a glyph from a variant.
Reverting an overlay is exactly this.
| self | A font variant. |
| code | A unicode codepoint, a missing one is a no-op. |
Definition at line 489 of file font.c.
References gpf_glyph::bits, and gpf_variant::glyphs.
Referenced by gpf_font_simplify().
|
inlinestatic |
Returns the number of glyph entries in a variant.
| self | A font variant. |
Definition at line 411 of file font.h.
References gpf_variant::glyphs.
Referenced by gpf_font_clear_modified(), gpf_font_codes(), gpf_font_ink_extent(), gpf_font_range_glyphs(), and gpf_font_simplify().
| const char * gpf_variant_name | ( | enum gpf_variant_id | id | ) |
Returns the name of a variant.
| id | A variant id. |
Definition at line 23 of file font.c.
References GPF_VARIANTS.
| enum gpf_variant_id gpf_variant_parent | ( | enum gpf_variant_id | id | ) |
Returns the variant a variant derives its missing glyphs from.
Regular and bold-mono derive from mono, bold derives from regular.
| id | A variant id. |
Definition at line 45 of file font.c.
References GPF_BOLD, GPF_BOLD_MONO, GPF_MONO, GPF_NO_PARENT, and GPF_REGULAR.
Referenced by gpf_entry_form(), and gpf_font_simplify().