aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-10-16 19:52:12 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-10-16 19:52:12 +0000
commita789230cf9f87c68fcced647d0a1e8edc516f1c2 (patch)
tree13ae47436e665872f368795d2ec3e7881070f247
parentselection: replace \r\n with \n in pasted text (diff)
font: font_from_name() returns an allocated font struct
-rw-r--r--font.c10
-rw-r--r--font.h2
-rw-r--r--main.c20
-rw-r--r--render.c4
-rw-r--r--terminal.h2
5 files changed, 21 insertions, 17 deletions
diff --git a/font.c b/font.c
index 049a3be8..b68e341c 100644
--- a/font.c
+++ b/font.c
@@ -291,8 +291,8 @@ from_name(const char *base_name, const font_list_t *fallbacks, const char *attri
return true;
}
-bool
-font_from_name(font_list_t names, const char *attributes, struct font *font)
+struct font *
+font_from_name(font_list_t names, const char *attributes)
{
if (tll_length(names) == 0)
return false;
@@ -308,10 +308,14 @@ font_from_name(font_list_t names, const char *attributes, struct font *font)
tll_push_back(fallbacks, it->item);
}
+ struct font *font = malloc(sizeof(*font));
bool ret = from_name(tll_front(names), &fallbacks, attributes, font, false);
+ if (!ret)
+ free(font);
+
tll_free(fallbacks);
- return ret;
+ return ret ? font : NULL;
}
static size_t
diff --git a/font.h b/font.h
index 594ae6ec..1d5ad4dc 100644
--- a/font.h
+++ b/font.h
@@ -58,6 +58,6 @@ struct font {
mtx_t lock;
};
-bool font_from_name(font_list_t names, const char *attributes, struct font *result);
+struct font *font_from_name(font_list_t names, const char *attributes);
const struct glyph *font_glyph_for_wc(struct font *font, wchar_t wc);
void font_destroy(struct font *font);
diff --git a/main.c b/main.c
index 0f93e188..e81d2395 100644
--- a/main.c
+++ b/main.c
@@ -623,28 +623,28 @@ main(int argc, char *const *argv)
tll_foreach(conf.fonts, it)
tll_push_back(font_names, it->item);
- if (!font_from_name(font_names, "", &term.fonts[0])) {
+ if ((term.fonts[0] = font_from_name(font_names, "")) == NULL) {
tll_free(font_names);
goto out;
}
- font_from_name(font_names, "style=bold", &term.fonts[1]);
- font_from_name(font_names, "style=italic", &term.fonts[2]);
- font_from_name(font_names, "style=bold italic", &term.fonts[3]);
+ term.fonts[1] = font_from_name(font_names, "style=bold");
+ term.fonts[2] = font_from_name(font_names, "style=italic");
+ term.fonts[3] = font_from_name(font_names, "style=bold italic");
tll_free(font_names);
{
- FT_Face ft_face = term.fonts[0].face;
+ FT_Face ft_face = term.fonts[0]->face;
int max_x_advance = ft_face->size->metrics.max_advance / 64;
int height = ft_face->size->metrics.height / 64;
int descent = ft_face->size->metrics.descender / 64;
int ascent = ft_face->size->metrics.ascender / 64;
- term.fextents.height = height * term.fonts[0].pixel_size_fixup;
- term.fextents.descent = -descent * term.fonts[0].pixel_size_fixup;
- term.fextents.ascent = ascent * term.fonts[0].pixel_size_fixup;
- term.fextents.max_x_advance = max_x_advance * term.fonts[0].pixel_size_fixup;
+ term.fextents.height = height * term.fonts[0]->pixel_size_fixup;
+ term.fextents.descent = -descent * term.fonts[0]->pixel_size_fixup;
+ term.fextents.ascent = ascent * term.fonts[0]->pixel_size_fixup;
+ term.fextents.max_x_advance = max_x_advance * term.fonts[0]->pixel_size_fixup;
LOG_DBG("metrics: height: %d, descent: %d, ascent: %d, x-advance: %d",
height, descent, ascent, max_x_advance);
@@ -1185,7 +1185,7 @@ out:
tll_free_and_free(term.window_title_stack, free);
for (size_t i = 0; i < sizeof(term.fonts) / sizeof(term.fonts[0]); i++)
- font_destroy(&term.fonts[i]);
+ font_destroy(term.fonts[i]);
free(term.search.buf);
diff --git a/render.c b/render.c
index bfd27faa..ff05d501 100644
--- a/render.c
+++ b/render.c
@@ -24,7 +24,7 @@ struct font *
attrs_to_font(struct terminal *term, const struct attributes *attrs)
{
int idx = attrs->italic << 1 | attrs->bold;
- return &term->fonts[idx];
+ return term->fonts[idx];
}
static inline struct rgb
@@ -750,7 +750,7 @@ render_search_box(struct terminal *term)
PIXMAN_OP_SRC, buf->pix, &color,
1, &(pixman_rectangle16_t){0, 0, width, height});
- struct font *font = &term->fonts[0];
+ struct font *font = term->fonts[0];
int x = margin;
int y = margin;
pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]);
diff --git a/terminal.h b/terminal.h
index 72a41fcf..6f6e1d53 100644
--- a/terminal.h
+++ b/terminal.h
@@ -366,7 +366,7 @@ struct terminal {
struct grid alt;
struct grid *grid;
- struct font fonts[4];
+ struct font *fonts[4];
struct {
int height;
int descent;