mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-22 05:33:45 -04:00
font: move metrics from terminal struct to font struct
This commit is contained in:
parent
431800a8a5
commit
bc86cd61c7
5 changed files with 35 additions and 34 deletions
16
font.c
16
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]));
|
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);
|
underline_strikeout_metrics(font);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
font.h
6
font.h
|
|
@ -46,6 +46,12 @@ struct font {
|
||||||
double pixel_size_fixup; /* Scale factor - should only be used with ARGB32 glyphs */
|
double pixel_size_fixup; /* Scale factor - should only be used with ARGB32 glyphs */
|
||||||
bool bgr; /* True for FC_RGBA_BGR and FC_RGBA_VBGR */
|
bool bgr; /* True for FC_RGBA_BGR and FC_RGBA_VBGR */
|
||||||
|
|
||||||
|
/* font extents */
|
||||||
|
int height;
|
||||||
|
int descent;
|
||||||
|
int ascent;
|
||||||
|
int max_x_advance;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int position;
|
int position;
|
||||||
int thickness;
|
int thickness;
|
||||||
|
|
|
||||||
22
render.c
22
render.c
|
|
@ -83,19 +83,19 @@ pixman_color_dim_for_search(pixman_color_t *color)
|
||||||
static inline int
|
static inline int
|
||||||
font_baseline(const struct terminal *term)
|
font_baseline(const struct terminal *term)
|
||||||
{
|
{
|
||||||
assert(term->fextents.ascent >= 0);
|
assert(term->fonts[0]->ascent >= 0);
|
||||||
assert(term->fextents.descent >= 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
|
#if 0
|
||||||
LOG_INFO("height=%d, ascent=%d, descent=%d, diff=%d",
|
LOG_INFO("height=%d, ascent=%d, descent=%d, diff=%d",
|
||||||
term->fextents.height,
|
term->fonts[0]->height,
|
||||||
term->fextents.ascent, term->fextents.descent,
|
term->fonts[0]->ascent, term->fonts[0]->descent,
|
||||||
diff);
|
diff);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return term->fextents.height - diff / 2 - term->fextents.descent;
|
return term->fonts[0]->height - diff / 2 - term->fonts[0]->descent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -103,12 +103,12 @@ draw_bar(const struct terminal *term, pixman_image_t *pix,
|
||||||
const struct font *font,
|
const struct font *font,
|
||||||
const pixman_color_t *color, int x, int y)
|
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_image_fill_rectangles(
|
||||||
PIXMAN_OP_SRC, pix, color,
|
PIXMAN_OP_SRC, pix, color,
|
||||||
1, &(pixman_rectangle16_t){
|
1, &(pixman_rectangle16_t){
|
||||||
x, baseline,
|
x, baseline,
|
||||||
font->underline.thickness, term->fextents.ascent + term->fextents.descent});
|
font->underline.thickness, term->fonts[0]->ascent + term->fonts[0]->descent});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -280,7 +280,7 @@ render_cell(struct terminal *term, pixman_image_t *pix,
|
||||||
if (!(cell->attrs.blink && term->blink.state == BLINK_OFF)) {
|
if (!(cell->attrs.blink && term->blink.state == BLINK_OFF)) {
|
||||||
pixman_image_composite32(
|
pixman_image_composite32(
|
||||||
PIXMAN_OP_OVER, glyph->pix, NULL, pix, 0, 0, 0, 0,
|
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);
|
glyph->width, glyph->height);
|
||||||
}
|
}
|
||||||
} else {
|
} 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_t *src = pixman_image_create_solid_fill(&fg);
|
||||||
pixman_image_composite32(
|
pixman_image_composite32(
|
||||||
PIXMAN_OP_OVER, src, glyph->pix, pix, 0, 0, 0, 0,
|
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);
|
glyph->width, glyph->height);
|
||||||
pixman_image_unref(src);
|
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_t *src = pixman_image_create_solid_fill(&fg);
|
||||||
pixman_image_composite32(
|
pixman_image_composite32(
|
||||||
PIXMAN_OP_OVER, src, glyph->pix, buf->pix, 0, 0, 0, 0,
|
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);
|
glyph->width, glyph->height);
|
||||||
pixman_image_unref(src);
|
pixman_image_unref(src);
|
||||||
|
|
||||||
|
|
|
||||||
19
terminal.c
19
terminal.c
|
|
@ -377,21 +377,6 @@ initialize_fonts(struct terminal *term, const struct config *conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
tll_free(font_names);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -529,8 +514,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* Cell dimensions are based on the font metrics. Obviously */
|
/* Cell dimensions are based on the font metrics. Obviously */
|
||||||
term->cell_width = (int)ceil(term->fextents.max_x_advance);
|
term->cell_width = term->fonts[0]->max_x_advance;
|
||||||
term->cell_height = (int)ceil(term->fextents.height);
|
term->cell_height = term->fonts[0]->height;
|
||||||
LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height);
|
LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height);
|
||||||
|
|
||||||
/* Start the slave/client */
|
/* Start the slave/client */
|
||||||
|
|
|
||||||
|
|
@ -265,12 +265,6 @@ struct terminal {
|
||||||
struct grid *grid;
|
struct grid *grid;
|
||||||
|
|
||||||
struct font *fonts[4];
|
struct font *fonts[4];
|
||||||
struct {
|
|
||||||
int height;
|
|
||||||
int descent;
|
|
||||||
int ascent;
|
|
||||||
int max_x_advance;
|
|
||||||
} fextents;
|
|
||||||
|
|
||||||
tll(int) tab_stops;
|
tll(int) tab_stops;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue