10#include <utils/gp_vec.h>
17 struct gpf_lint_finding **vec;
18 struct gpf_lint_finding *first;
24 __attribute__((format(printf, 5, 6)));
32 if (sink->found && !sink->vec)
36 vsnprintf(finding.
msg,
sizeof(finding.
msg), fmt, va);
41 if (sink->first && !sink->first->msg[0])
42 *sink->first = finding;
45 GP_VEC_APPEND(*sink->vec, finding);
53static int cell_art(uint32_t
code)
55 return code >= 0x2500 &&
code <= 0x25ff;
58static const char x_letters[] =
"acemnorsuvwxz";
59static const char cap_letters[] =
"BDEFHIKLMNPRT";
61static int in_set(
const char *set, uint32_t
code)
67 return !!strchr(set, (
int)
code);
102 if (same_ink(
glyph, &res.glyph)) {
104 gpf_variant_name(parent));
111 uint32_t code,
const struct gpf_glyph *entry,
115 uint32_t missing = 0;
118 missing = entry->base;
124 missing = entry->accent;
131 "composed from U+%04X, which the font has not got", missing);
140 uint32_t code,
struct sink *sink)
151 entry = gpf_variant_glyph(variant, code);
154 check_compose(font,
id, code, entry, sink);
164 "metrics for a glyph %s has not got",
171 right = res.glyph.bearing_x + (int)res.glyph.width;
172 bottom = res.glyph.bearing_y - (int)res.glyph.height + 1;
174 if (res.glyph.width && res.glyph.advance <= 0) {
176 "ink with an advance of %i", res.glyph.advance);
180 res.glyph.advance != variant->
advance) {
182 "advance %i, the variant's is %i", res.glyph.advance,
186 if (res.glyph.width && !cell_art(code)) {
190 if (res.glyph.bearing_x < 0) {
191 emit(sink,
id, code, sev,
"ink starts %i left of the origin",
192 -res.glyph.bearing_x);
195 if (right > res.glyph.advance) {
196 emit(sink,
id, code, sev,
197 "ink %i wide in a cell of %i", right,
201 if (res.glyph.bearing_y > m->
ascent) {
202 emit(sink,
id, code,
GPF_LINT_WARN,
"ink %i above the ascent",
203 res.glyph.bearing_y - m->
ascent);
206 if (bottom < -m->descent) {
207 emit(sink,
id, code,
GPF_LINT_WARN,
"ink %i below the descent",
212 if (res.glyph.width && m->
x_height && in_set(x_letters, code) &&
213 res.glyph.bearing_y != m->
x_height) {
214 emit(sink,
id, code,
GPF_LINT_WARN,
"x-height %i, the font's is %i",
218 if (res.glyph.width && m->
cap_height && in_set(cap_letters, code) &&
221 "cap height %i, the font's is %i", res.glyph.bearing_y,
227 check_bold(font,
id, code, &res.glyph, sink);
235 struct sink sink = {.first = out};
237 memset(out, 0,
sizeof(*out));
239 check_glyph(font,
id, code, &sink);
247 struct sink sink = {.vec = &vec};
248 uint32_t *codes = gpf_font_codes(font);
252 if (!vec || !codes) {
258 for (j = 0; j < gp_vec_len(codes); j++) {
260 check_glyph(font, i, codes[j], &sink);
269void gpf_lint_count(
struct gpf_font *font,
unsigned int *errors,
270 unsigned int *warnings)
278 for (i = 0; findings && i < gp_vec_len(findings); i++) {
285 gp_vec_free(findings);
gpf_variant_id
Font face variant.
@ GPF_BOLD_MONO
Bold monospace glyphs.
@ 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.
@ GPF_GLYPH_INK
Glyph with ink.
@ GPF_GLYPH_COMPOSE
Glyph is composed from base + accent.
@ GPF_GLYPH_METRICS
Glyph with metrics.
const char * gpf_lint_severity_name(enum gpf_lint_severity sev)
Returns severity name.
struct gpf_lint_finding * gpf_lint(struct gpf_font *font)
Runs linter on a font.
gpf_lint_severity
Linter severity.
@ GPF_LINT_WARN
Probably a slip. May be deliberate.
@ GPF_LINT_ERROR
The font renders wrong.
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.
struct gpf_variant * variants[GPF_VARIANTS]
Variants indexed by gpf_variant_id, NULL when missing.
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 bearing_x
Glyph bearing x.
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.
struct gpf_glyph glyph
Freshly allocated glyph with copied/generated ink.
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.