mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-11 04:27:49 -05:00
config_font_parse(): return fail/success
This commit is contained in:
parent
04703c07f0
commit
0d6b5f522e
4 changed files with 35 additions and 11 deletions
|
|
@ -136,6 +136,7 @@ means foot can be PGO:d in e.g. sandboxed build scripts. See
|
|||
(e.g. `\E[38:5...m`)
|
||||
* Frames occasionally being rendered while application synchronized
|
||||
updates is in effect.
|
||||
* Handling of failures to parse the font specification string.
|
||||
|
||||
|
||||
### Security
|
||||
|
|
|
|||
34
config.c
34
config.c
|
|
@ -534,8 +534,16 @@ parse_section_main(const char *key, const char *value, struct config *conf,
|
|||
/* Trim spaces, strictly speaking not necessary, but looks nice :) */
|
||||
while (*font != '\0' && isspace(*font))
|
||||
font++;
|
||||
if (*font != '\0')
|
||||
tll_push_back(conf->fonts[idx], config_font_parse(font));
|
||||
if (*font != '\0') {
|
||||
struct config_font font_data;
|
||||
if (!config_font_parse(font, &font_data)) {
|
||||
LOG_ERR("%s:%d: [default]: %s: invalid font specification",
|
||||
path, lineno, key);
|
||||
free(copy);
|
||||
return false;
|
||||
}
|
||||
tll_push_back(conf->fonts[idx], font_data);
|
||||
}
|
||||
}
|
||||
free(copy);
|
||||
}
|
||||
|
|
@ -2083,8 +2091,14 @@ config_load(struct config *conf, const char *conf_path,
|
|||
conf->colors.selection_bg >> 24 == 0;
|
||||
|
||||
out:
|
||||
if (ret && tll_length(conf->fonts[0]) == 0)
|
||||
tll_push_back(conf->fonts[0], config_font_parse("monospace"));
|
||||
if (ret && tll_length(conf->fonts[0]) == 0) {
|
||||
struct config_font font;
|
||||
if (!config_font_parse("monospace", &font)) {
|
||||
LOG_ERR("failed to load font 'monospace' - no fonts installed?");
|
||||
ret = false;
|
||||
} else
|
||||
tll_push_back(conf->fonts[0], font);
|
||||
}
|
||||
|
||||
free(conf_file.path);
|
||||
if (conf_file.fd >= 0)
|
||||
|
|
@ -2131,10 +2145,12 @@ config_free(struct config conf)
|
|||
user_notifications_free(&conf.notifications);
|
||||
}
|
||||
|
||||
struct config_font
|
||||
config_font_parse(const char *pattern)
|
||||
bool
|
||||
config_font_parse(const char *pattern, struct config_font *font)
|
||||
{
|
||||
FcPattern *pat = FcNameParse((const FcChar8 *)pattern);
|
||||
if (pat == NULL)
|
||||
return false;
|
||||
|
||||
double pt_size = -1.0;
|
||||
FcPatternGetDouble(pat, FC_SIZE, 0, &pt_size);
|
||||
|
|
@ -2150,10 +2166,12 @@ config_font_parse(const char *pattern)
|
|||
char *stripped_pattern = (char *)FcNameUnparse(pat);
|
||||
FcPatternDestroy(pat);
|
||||
|
||||
return (struct config_font){
|
||||
*font = (struct config_font){
|
||||
.pattern = stripped_pattern,
|
||||
.pt_size = pt_size,
|
||||
.px_size = px_size};
|
||||
.px_size = px_size
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
2
config.h
2
config.h
|
|
@ -191,5 +191,5 @@ bool config_load(
|
|||
user_notifications_t *initial_user_notifications, bool errors_are_fatal);
|
||||
void config_free(struct config conf);
|
||||
|
||||
struct config_font config_font_parse(const char *pattern);
|
||||
bool config_font_parse(const char *pattern, struct config_font *font);
|
||||
void config_font_destroy(struct config_font *font);
|
||||
|
|
|
|||
9
main.c
9
main.c
|
|
@ -403,8 +403,13 @@ main(int argc, char *const *argv)
|
|||
config_font_destroy(&it->item);
|
||||
tll_free(conf.fonts[i]);
|
||||
}
|
||||
tll_foreach(conf_fonts, it)
|
||||
tll_push_back(conf.fonts[0], config_font_parse(it->item));
|
||||
tll_foreach(conf_fonts, it) {
|
||||
struct config_font font;
|
||||
if (!config_font_parse(it->item, &font)) {
|
||||
LOG_ERR("%s: invalid font specification", it->item);
|
||||
} else
|
||||
tll_push_back(conf.fonts[0], font);
|
||||
}
|
||||
tll_free(conf_fonts);
|
||||
}
|
||||
if (conf_width > 0 && conf_height > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue