fcft: adjust to fcft-2.0 API changes

* font_*() -> fcft_*()
* struct font -> struct fcft_font
* struct glyph -> struct fcft_glyph
* enum subpixel_order -> enum fcft_subpixel
This commit is contained in:
Daniel Eklöf 2020-04-21 19:29:36 +02:00
parent e2c48c0c2e
commit 7194f65ae9
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 48 additions and 48 deletions

View file

@ -196,7 +196,7 @@ static const struct wp_presentation_feedback_listener presentation_feedback_list
.discarded = &discarded, .discarded = &discarded,
}; };
static struct font * static struct fcft_font *
attrs_to_font(const struct terminal *term, const struct attributes *attrs) attrs_to_font(const struct terminal *term, const struct attributes *attrs)
{ {
int idx = attrs->italic << 1 | attrs->bold; int idx = attrs->italic << 1 | attrs->bold;
@ -263,7 +263,7 @@ draw_unfocused_block(const struct terminal *term, pixman_image_t *pix,
static void static void
draw_bar(const struct terminal *term, pixman_image_t *pix, draw_bar(const struct terminal *term, pixman_image_t *pix,
const struct font *font, const struct fcft_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->fonts[0]->ascent; int baseline = y + font_baseline(term) - term->fonts[0]->ascent;
@ -276,7 +276,7 @@ draw_bar(const struct terminal *term, pixman_image_t *pix,
static void static void
draw_underline(const struct terminal *term, pixman_image_t *pix, draw_underline(const struct terminal *term, pixman_image_t *pix,
const struct font *font, const struct fcft_font *font,
const pixman_color_t *color, int x, int y, int cols) const pixman_color_t *color, int x, int y, int cols)
{ {
pixman_image_fill_rectangles( pixman_image_fill_rectangles(
@ -288,7 +288,7 @@ draw_underline(const struct terminal *term, pixman_image_t *pix,
static void static void
draw_strikeout(const struct terminal *term, pixman_image_t *pix, draw_strikeout(const struct terminal *term, pixman_image_t *pix,
const struct font *font, const struct fcft_font *font,
const pixman_color_t *color, int x, int y, int cols) const pixman_color_t *color, int x, int y, int cols)
{ {
pixman_image_fill_rectangles( pixman_image_fill_rectangles(
@ -300,7 +300,7 @@ draw_strikeout(const struct terminal *term, pixman_image_t *pix,
static void static void
draw_cursor(const struct terminal *term, const struct cell *cell, draw_cursor(const struct terminal *term, const struct cell *cell,
const struct font *font, pixman_image_t *pix, pixman_color_t *fg, const struct fcft_font *font, pixman_image_t *pix, pixman_color_t *fg,
const pixman_color_t *bg, int x, int y, int cols) const pixman_color_t *bg, int x, int y, int cols)
{ {
pixman_color_t cursor_color; pixman_color_t cursor_color;
@ -402,9 +402,9 @@ render_cell(struct terminal *term, pixman_image_t *pix,
color_dim_for_search(&bg); color_dim_for_search(&bg);
} }
struct font *font = attrs_to_font(term, &cell->attrs); struct fcft_font *font = attrs_to_font(term, &cell->attrs);
const struct glyph *glyph = cell->wc != 0 const struct fcft_glyph *glyph = cell->wc != 0
? font_glyph_for_wc(font, cell->wc, term->font_subpixel) ? fcft_glyph_for_wc(font, cell->wc, term->font_subpixel)
: NULL; : NULL;
int cell_cols = glyph != NULL ? max(1, glyph->cols) : 1; int cell_cols = glyph != NULL ? max(1, glyph->cols) : 1;
@ -1527,7 +1527,7 @@ render_search_box(struct terminal *term)
PIXMAN_OP_SRC, buf->pix, &transparent, PIXMAN_OP_SRC, buf->pix, &transparent,
1, &(pixman_rectangle16_t){0, 0, width - visible_width, height}); 1, &(pixman_rectangle16_t){0, 0, width - visible_width, height});
struct font *font = term->fonts[0]; struct fcft_font *font = term->fonts[0];
int x = width - visible_width + margin; int x = width - visible_width + margin;
int y = margin; int y = margin;
pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]); pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]);
@ -1553,7 +1553,7 @@ render_search_box(struct terminal *term)
if (i == term->search.cursor) if (i == term->search.cursor)
draw_bar(term, buf->pix, font, &fg, x, y); draw_bar(term, buf->pix, font, &fg, x, y);
const struct glyph *glyph = font_glyph_for_wc(font, term->search.buf[i], true); const struct fcft_glyph *glyph = fcft_glyph_for_wc(font, term->search.buf[i], true);
if (glyph == NULL) if (glyph == NULL)
continue; continue;

View file

@ -512,12 +512,12 @@ initialize_render_workers(struct terminal *term)
} }
static bool static bool
term_set_fonts(struct terminal *term, struct font *fonts[static 4]) term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
{ {
for (size_t i = 0; i < 4; i++) { for (size_t i = 0; i < 4; i++) {
assert(fonts[i] != NULL); assert(fonts[i] != NULL);
font_destroy(term->fonts[i]); fcft_destroy(term->fonts[i]);
term->fonts[i] = fonts[i]; term->fonts[i] = fonts[i];
} }
@ -579,12 +579,12 @@ get_font_dpi(const struct terminal *term)
return dpi; return dpi;
} }
static enum subpixel_order static enum fcft_subpixel
get_font_subpixel(const struct terminal *term) get_font_subpixel(const struct terminal *term)
{ {
if (term->colors.alpha != 0xffff) { if (term->colors.alpha != 0xffff) {
/* Can't do subpixel rendering on transparent background */ /* Can't do subpixel rendering on transparent background */
return FCFT_SUBPIXEL_ORDER_NONE; return FCFT_SUBPIXEL_NONE;
} }
enum wl_output_subpixel wl_subpixel; enum wl_output_subpixel wl_subpixel;
@ -612,20 +612,20 @@ get_font_subpixel(const struct terminal *term)
wl_subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN; wl_subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
switch (wl_subpixel) { switch (wl_subpixel) {
case WL_OUTPUT_SUBPIXEL_UNKNOWN: return FCFT_SUBPIXEL_ORDER_DEFAULT; case WL_OUTPUT_SUBPIXEL_UNKNOWN: return FCFT_SUBPIXEL_DEFAULT;
case WL_OUTPUT_SUBPIXEL_NONE: return FCFT_SUBPIXEL_ORDER_NONE; case WL_OUTPUT_SUBPIXEL_NONE: return FCFT_SUBPIXEL_NONE;
case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: return FCFT_SUBPIXEL_ORDER_HORIZONTAL_RGB; case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: return FCFT_SUBPIXEL_HORIZONTAL_RGB;
case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: return FCFT_SUBPIXEL_ORDER_HORIZONTAL_BGR; case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: return FCFT_SUBPIXEL_HORIZONTAL_BGR;
case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: return FCFT_SUBPIXEL_ORDER_VERTICAL_RGB; case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: return FCFT_SUBPIXEL_VERTICAL_RGB;
case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: return FCFT_SUBPIXEL_ORDER_VERTICAL_BGR; case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: return FCFT_SUBPIXEL_VERTICAL_BGR;
} }
return FCFT_SUBPIXEL_ORDER_DEFAULT; return FCFT_SUBPIXEL_DEFAULT;
} }
static bool static bool
load_fonts_from_conf(const struct terminal *term, const struct config *conf, load_fonts_from_conf(const struct terminal *term, const struct config *conf,
struct font *fonts[static 4]) struct fcft_font *fonts[static 4])
{ {
const size_t count = tll_length(conf->fonts); const size_t count = tll_length(conf->fonts);
const char *names[count]; const char *names[count];
@ -642,15 +642,15 @@ load_fonts_from_conf(const struct terminal *term, const struct config *conf,
fonts[0] = fonts[1] = fonts[2] = fonts[3] = NULL; fonts[0] = fonts[1] = fonts[2] = fonts[3] = NULL;
bool ret = bool ret =
(fonts[0] = font_from_name(count, names, attrs0)) != NULL && (fonts[0] = fcft_from_name(count, names, attrs0)) != NULL &&
(fonts[1] = font_from_name(count, names, attrs1)) != NULL && (fonts[1] = fcft_from_name(count, names, attrs1)) != NULL &&
(fonts[2] = font_from_name(count, names, attrs2)) != NULL && (fonts[2] = fcft_from_name(count, names, attrs2)) != NULL &&
(fonts[3] = font_from_name(count, names, attrs3)) != NULL; (fonts[3] = fcft_from_name(count, names, attrs3)) != NULL;
if (!ret) { if (!ret) {
LOG_ERR("failed to load primary fonts"); LOG_ERR("failed to load primary fonts");
for (size_t i = 0; i < 4; i++) { for (size_t i = 0; i < 4; i++) {
font_destroy(fonts[i]); fcft_destroy(fonts[i]);
fonts[i] = NULL; fonts[i] = NULL;
} }
} }
@ -731,8 +731,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
.font_dpi = 0, .font_dpi = 0,
.font_adjustments = 0, .font_adjustments = 0,
.font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */ .font_subpixel = (conf->colors.alpha == 0xffff /* Can't do subpixel rendering on transparent background */
? FCFT_SUBPIXEL_ORDER_DEFAULT ? FCFT_SUBPIXEL_DEFAULT
: FCFT_SUBPIXEL_ORDER_NONE), : FCFT_SUBPIXEL_NONE),
.cursor_keys_mode = CURSOR_KEYS_NORMAL, .cursor_keys_mode = CURSOR_KEYS_NORMAL,
.keypad_keys_mode = KEYPAD_NUMERICAL, .keypad_keys_mode = KEYPAD_NUMERICAL,
.auto_margin = true, .auto_margin = true,
@ -1045,7 +1045,7 @@ term_destroy(struct terminal *term)
tll_free_and_free(term->window_title_stack, free); tll_free_and_free(term->window_title_stack, free);
for (size_t i = 0; i < sizeof(term->fonts) / sizeof(term->fonts[0]); i++) for (size_t i = 0; i < sizeof(term->fonts) / sizeof(term->fonts[0]); i++)
font_destroy(term->fonts[i]); fcft_destroy(term->fonts[i]);
free(term->search.buf); free(term->search.buf);
@ -1280,18 +1280,18 @@ term_reset(struct terminal *term, bool hard)
static bool static bool
term_font_size_adjust(struct terminal *term, double amount) term_font_size_adjust(struct terminal *term, double amount)
{ {
struct font *fonts[4] = { struct fcft_font *fonts[4] = {
font_size_adjust(term->fonts[0], amount), fcft_size_adjust(term->fonts[0], amount),
font_size_adjust(term->fonts[1], amount), fcft_size_adjust(term->fonts[1], amount),
font_size_adjust(term->fonts[2], amount), fcft_size_adjust(term->fonts[2], amount),
font_size_adjust(term->fonts[3], amount), fcft_size_adjust(term->fonts[3], amount),
}; };
if (fonts[0] == NULL || fonts[1] == NULL || if (fonts[0] == NULL || fonts[1] == NULL ||
fonts[2] == NULL || fonts[3] == NULL) fonts[2] == NULL || fonts[3] == NULL)
{ {
for (size_t i = 0; i < 4; i++) for (size_t i = 0; i < 4; i++)
font_destroy(fonts[i]); fcft_destroy(fonts[i]);
return false; return false;
} }
@ -1322,7 +1322,7 @@ term_font_size_decrease(struct terminal *term)
bool bool
term_font_size_reset(struct terminal *term) term_font_size_reset(struct terminal *term)
{ {
struct font *fonts[4]; struct fcft_font *fonts[4];
if (!load_fonts_from_conf(term, term->conf, fonts)) if (!load_fonts_from_conf(term, term->conf, fonts))
return false; return false;
@ -1341,7 +1341,7 @@ term_font_dpi_changed(struct terminal *term)
LOG_DBG("DPI changed (%u -> %u): reloading fonts", term->font_dpi, dpi); LOG_DBG("DPI changed (%u -> %u): reloading fonts", term->font_dpi, dpi);
term->font_dpi = dpi; term->font_dpi = dpi;
struct font *fonts[4]; struct fcft_font *fonts[4];
if (!load_fonts_from_conf(term, term->conf, fonts)) if (!load_fonts_from_conf(term, term->conf, fonts))
return false; return false;
@ -1352,25 +1352,25 @@ term_font_dpi_changed(struct terminal *term)
double amount = term->font_adjustments * 0.5; double amount = term->font_adjustments * 0.5;
struct font *adjusted_fonts[4] = { struct fcft_font *adjusted_fonts[4] = {
font_size_adjust(fonts[0], amount), fcft_size_adjust(fonts[0], amount),
font_size_adjust(fonts[1], amount), fcft_size_adjust(fonts[1], amount),
font_size_adjust(fonts[2], amount), fcft_size_adjust(fonts[2], amount),
font_size_adjust(fonts[3], amount), fcft_size_adjust(fonts[3], amount),
}; };
if (adjusted_fonts[0] == NULL || adjusted_fonts[1] == NULL || if (adjusted_fonts[0] == NULL || adjusted_fonts[1] == NULL ||
adjusted_fonts[2] == NULL || adjusted_fonts[3] == NULL) adjusted_fonts[2] == NULL || adjusted_fonts[3] == NULL)
{ {
for (size_t i = 0; i < 4; i++) for (size_t i = 0; i < 4; i++)
font_destroy(adjusted_fonts[i]); fcft_destroy(adjusted_fonts[i]);
/* At least use the newly re-loaded default fonts */ /* At least use the newly re-loaded default fonts */
term->font_adjustments = 0; term->font_adjustments = 0;
return term_set_fonts(term, fonts); return term_set_fonts(term, fonts);
} else { } else {
for (size_t i = 0; i < 4; i++) for (size_t i = 0; i < 4; i++)
font_destroy(fonts[i]); fcft_destroy(fonts[i]);
return term_set_fonts(term, adjusted_fonts); return term_set_fonts(term, adjusted_fonts);
} }
@ -1381,7 +1381,7 @@ term_font_dpi_changed(struct terminal *term)
void void
term_font_subpixel_changed(struct terminal *term) term_font_subpixel_changed(struct terminal *term)
{ {
enum subpixel_order subpixel = get_font_subpixel(term); enum fcft_subpixel subpixel = get_font_subpixel(term);
if (term->font_subpixel == subpixel) if (term->font_subpixel == subpixel)
return; return;

View file

@ -214,10 +214,10 @@ struct terminal {
struct grid alt; struct grid alt;
struct grid *grid; struct grid *grid;
struct font *fonts[4]; struct fcft_font *fonts[4];
int font_dpi; int font_dpi;
int font_adjustments; int font_adjustments;
enum subpixel_order font_subpixel; enum fcft_subpixel font_subpixel;
tll(struct ptmx_buffer) ptmx_buffer; tll(struct ptmx_buffer) ptmx_buffer;