aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-26 17:54:32 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-26 18:02:35 +0000
commitbc86cd61c75f984633eb226692a30832c58efb17 (patch)
tree7acacdfbf567e52d5331bf7710557195d6800980
parentfont: cleanup and return error when failing to load font file (diff)
font: move metrics from terminal struct to font struct
-rw-r--r--font.c16
-rw-r--r--font.h6
-rw-r--r--render.c22
-rw-r--r--terminal.c19
-rw-r--r--terminal.h6
5 files changed, 35 insertions, 34 deletions
diff --git a/font.c b/font.c
index 8f7d6f78..378fd415 100644
--- a/font.c
+++ b/font.c
@@ -245,6 +245,22 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx,
font->glyph_cache = calloc(cache_size, sizeof(font->glyph_cache[0]));
}
+ double max_x_advance = ft_face->size->metrics.max_advance / 64.;
+ double height= ft_face->size->metrics.height / 64.;
+ double descent = ft_face->size->metrics.descender / 64.;
+ double ascent = ft_face->size->metrics.ascender / 64.;
+
+ font->height = ceil(height * font->pixel_size_fixup);
+ font->descent = ceil(-descent * font->pixel_size_fixup);
+ font->ascent = ceil(ascent * font->pixel_size_fixup);
+ font->max_x_advance = ceil(max_x_advance * font->pixel_size_fixup);
+
+ LOG_DBG("%s: size=%f, pixel-size=%f, dpi=%f, fixup-factor: %f, "
+ "line-height: %d, ascent: %d, descent: %d, x-advance: %d",
+ font->name, size, pixel_size, dpi, font->pixel_size_fixup,
+ font->height, font->ascent, font->descent,
+ font->max_x_advance);
+
underline_strikeout_metrics(font);
return true;
}
diff --git a/font.h b/font.h
index 9eebd0a9..a01416dc 100644
--- a/font.h
+++ b/font.h
@@ -46,6 +46,12 @@ struct font {
double pixel_size_fixup; /* Scale factor - should only be used with ARGB32 glyphs */
bool bgr; /* True for FC_RGBA_BGR and FC_RGBA_VBGR */
+ /* font extents */
+ int height;
+ int descent;
+ int ascent;
+ int max_x_advance;
+
struct {
int position;
int thickness;
diff --git a/render.c b/render.c
index 41462aa4..23f72870 100644
--- a/render.c
+++ b/render.c
@@ -83,19 +83,19 @@ pixman_color_dim_for_search(pixman_color_t *color)
static inline int
font_baseline(const struct terminal *term)
{
- assert(term->fextents.ascent >= 0);
- assert(term->fextents.descent >= 0);
+ assert(term->fonts[0]->ascent >= 0);
+ assert(term->fonts[0]->descent >= 0);
- int diff = term->fextents.height - (term->fextents.ascent + term->fextents.descent);
+ int diff = term->fonts[0]->height - (term->fonts[0]->ascent + term->fonts[0]->descent);
#if 0
LOG_INFO("height=%d, ascent=%d, descent=%d, diff=%d",
- term->fextents.height,
- term->fextents.ascent, term->fextents.descent,
+ term->fonts[0]->height,
+ term->fonts[0]->ascent, term->fonts[0]->descent,
diff);
#endif
- return term->fextents.height - diff / 2 - term->fextents.descent;
+ return term->fonts[0]->height - diff / 2 - term->fonts[0]->descent;
}
static void
@@ -103,12 +103,12 @@ draw_bar(const struct terminal *term, pixman_image_t *pix,
const struct font *font,
const pixman_color_t *color, int x, int y)
{
- int baseline = y + font_baseline(term) - term->fextents.ascent;
+ int baseline = y + font_baseline(term) - term->fonts[0]->ascent;
pixman_image_fill_rectangles(
PIXMAN_OP_SRC, pix, color,
1, &(pixman_rectangle16_t){
x, baseline,
- font->underline.thickness, term->fextents.ascent + term->fextents.descent});
+ font->underline.thickness, term->fonts[0]->ascent + term->fonts[0]->descent});
}
static void
@@ -280,7 +280,7 @@ render_cell(struct terminal *term, pixman_image_t *pix,
if (!(cell->attrs.blink && term->blink.state == BLINK_OFF)) {
pixman_image_composite32(
PIXMAN_OP_OVER, glyph->pix, NULL, pix, 0, 0, 0, 0,
- x + glyph->x, y + term->fextents.ascent - glyph->y,
+ x + glyph->x, y + term->fonts[0]->ascent - glyph->y,
glyph->width, glyph->height);
}
} else {
@@ -289,7 +289,7 @@ render_cell(struct terminal *term, pixman_image_t *pix,
pixman_image_t *src = pixman_image_create_solid_fill(&fg);
pixman_image_composite32(
PIXMAN_OP_OVER, src, glyph->pix, pix, 0, 0, 0, 0,
- x + glyph->x, y + term->fextents.ascent - glyph->y,
+ x + glyph->x, y + term->fonts[0]->ascent - glyph->y,
glyph->width, glyph->height);
pixman_image_unref(src);
}
@@ -786,7 +786,7 @@ render_search_box(struct terminal *term)
pixman_image_t *src = pixman_image_create_solid_fill(&fg);
pixman_image_composite32(
PIXMAN_OP_OVER, src, glyph->pix, buf->pix, 0, 0, 0, 0,
- x + glyph->x, y + term->fextents.ascent - glyph->y,
+ x + glyph->x, y + term->fonts[0]->ascent - glyph->y,
glyph->width, glyph->height);
pixman_image_unref(src);
diff --git a/terminal.c b/terminal.c
index a5c3f82c..b6c8beac 100644
--- a/terminal.c
+++ b/terminal.c
@@ -377,21 +377,6 @@ initialize_fonts(struct terminal *term, const struct config *conf)
}
tll_free(font_names);
-
- 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;
-
- LOG_DBG("metrics: height: %d, descent: %d, ascent: %d, x-advance: %d",
- height, descent, ascent, max_x_advance);
-
return true;
}
@@ -529,8 +514,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
goto err;
/* Cell dimensions are based on the font metrics. Obviously */
- term->cell_width = (int)ceil(term->fextents.max_x_advance);
- term->cell_height = (int)ceil(term->fextents.height);
+ term->cell_width = term->fonts[0]->max_x_advance;
+ term->cell_height = term->fonts[0]->height;
LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height);
/* Start the slave/client */
diff --git a/terminal.h b/terminal.h
index 8e0e83c8..bc43edeb 100644
--- a/terminal.h
+++ b/terminal.h
@@ -265,12 +265,6 @@ struct terminal {
struct grid *grid;
struct font *fonts[4];
- struct {
- int height;
- int descent;
- int ascent;
- int max_x_advance;
- } fextents;
tll(int) tab_stops;