mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-21 05:33:45 -04: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
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue