mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-24 01:40:12 -05:00
font: from_name() returns an allocated font struct
This commit is contained in:
parent
928e86b423
commit
bf5ad13df0
1 changed files with 19 additions and 22 deletions
41
font.c
41
font.c
|
|
@ -247,8 +247,8 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx, const font_li
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static struct font *
|
||||||
from_name(const char *base_name, const font_list_t *fallbacks, const char *attributes, struct font *font, bool is_fallback)
|
from_name(const char *base_name, const font_list_t *fallbacks, const char *attributes, bool is_fallback)
|
||||||
{
|
{
|
||||||
size_t attr_len = attributes == NULL ? 0 : strlen(attributes);
|
size_t attr_len = attributes == NULL ? 0 : strlen(attributes);
|
||||||
bool have_attrs = attr_len > 0;
|
bool have_attrs = attr_len > 0;
|
||||||
|
|
@ -265,13 +265,13 @@ from_name(const char *base_name, const font_list_t *fallbacks, const char *attri
|
||||||
FcPattern *pattern = FcNameParse((const unsigned char *)name);
|
FcPattern *pattern = FcNameParse((const unsigned char *)name);
|
||||||
if (pattern == NULL) {
|
if (pattern == NULL) {
|
||||||
LOG_ERR("%s: failed to lookup font", name);
|
LOG_ERR("%s: failed to lookup font", name);
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FcConfigSubstitute(NULL, pattern, FcMatchPattern)) {
|
if (!FcConfigSubstitute(NULL, pattern, FcMatchPattern)) {
|
||||||
LOG_ERR("%s: failed to do config substitution", name);
|
LOG_ERR("%s: failed to do config substitution", name);
|
||||||
FcPatternDestroy(pattern);
|
FcPatternDestroy(pattern);
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FcDefaultSubstitute(pattern);
|
FcDefaultSubstitute(pattern);
|
||||||
|
|
@ -281,13 +281,16 @@ from_name(const char *base_name, const font_list_t *fallbacks, const char *attri
|
||||||
if (result != FcResultMatch) {
|
if (result != FcResultMatch) {
|
||||||
LOG_ERR("%s: failed to match font", name);
|
LOG_ERR("%s: failed to match font", name);
|
||||||
FcPatternDestroy(pattern);
|
FcPatternDestroy(pattern);
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct font *font = malloc(sizeof(*font));
|
||||||
|
|
||||||
if (!from_font_set(pattern, fonts, 0, fallbacks, attributes, font, is_fallback)) {
|
if (!from_font_set(pattern, fonts, 0, fallbacks, attributes, font, is_fallback)) {
|
||||||
|
free(font);
|
||||||
FcFontSetDestroy(fonts);
|
FcFontSetDestroy(fonts);
|
||||||
FcPatternDestroy(pattern);
|
FcPatternDestroy(pattern);
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_fallback) {
|
if (is_fallback) {
|
||||||
|
|
@ -295,7 +298,7 @@ from_name(const char *base_name, const font_list_t *fallbacks, const char *attri
|
||||||
FcPatternDestroy(pattern);
|
FcPatternDestroy(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct font *
|
struct font *
|
||||||
|
|
@ -315,14 +318,10 @@ font_from_name(font_list_t names, const char *attributes)
|
||||||
tll_push_back(fallbacks, it->item);
|
tll_push_back(fallbacks, it->item);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct font *font = malloc(sizeof(*font));
|
struct font *font = from_name(tll_front(names), &fallbacks, attributes, false);
|
||||||
bool ret = from_name(tll_front(names), &fallbacks, attributes, font, false);
|
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
free(font);
|
|
||||||
|
|
||||||
tll_free(fallbacks);
|
tll_free(fallbacks);
|
||||||
return ret ? font : NULL;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
|
|
@ -351,17 +350,15 @@ glyph_for_wchar(const struct font *font, wchar_t wc, struct glyph *glyph)
|
||||||
|
|
||||||
/* Try user configured fallback fonts */
|
/* Try user configured fallback fonts */
|
||||||
tll_foreach(font->fallbacks, it) {
|
tll_foreach(font->fallbacks, it) {
|
||||||
struct font *fallback = malloc(sizeof(*fallback));
|
struct font *fallback = from_name(it->item, NULL, "", true);
|
||||||
|
if (fallback == NULL)
|
||||||
if (from_name(it->item, NULL, "", fallback, true)) {
|
continue;
|
||||||
if (glyph_for_wchar(fallback, wc, glyph)) {
|
|
||||||
LOG_DBG("%C: used fallback %s (fixup = %f)",
|
|
||||||
wc, it->item, fallback->pixel_size_fixup);
|
|
||||||
font_destroy(fallback);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (glyph_for_wchar(fallback, wc, glyph)) {
|
||||||
|
LOG_DBG("%C: used fallback %s (fixup = %f)",
|
||||||
|
wc, it->item, fallback->pixel_size_fixup);
|
||||||
font_destroy(fallback);
|
font_destroy(fallback);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue