From 335573a628ed6ff20640c881935e0648a4819c1a Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Sat, 25 Jun 2022 15:59:42 +0100 Subject: Add option to disable font hinting. Also improve text on non-hidpi screens. --- src/config.c | 6 ++++-- src/entry_backend/harfbuzz.c | 23 +++++++++++++++-------- src/entry_backend/harfbuzz.h | 3 +++ src/main.c | 2 ++ src/tofi.h | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/config.c b/src/config.c index ba5a41c..4b20ab5 100644 --- a/src/config.c +++ b/src/config.c @@ -21,7 +21,7 @@ static char *strip(const char *str); static bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const char *option, const char *value); static char *get_config_path(void); -static int8_t parse_anchor(const char *filename, size_t lineno, const char *str, bool *err); +static uint32_t parse_anchor(const char *filename, size_t lineno, const char *str, bool *err); static bool parse_bool(const char *filename, size_t lineno, const char *str, bool *err); static struct color parse_color(const char *filename, size_t lineno, const char *str, bool *err); static uint32_t parse_uint32(const char *filename, size_t lineno, const char *str, bool *err); @@ -287,6 +287,8 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const tofi->hide_cursor = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "history") == 0) { tofi->use_history = parse_bool(filename, lineno, value, &err); + } else if (strcasecmp(option, "hint-font") == 0) { + tofi->window.entry.harfbuzz.disable_hinting = !parse_bool(filename, lineno, value, &err); } else { PARSE_ERROR(filename, lineno, "Unknown option \"%s\"\n", option); err = true; @@ -334,7 +336,7 @@ bool parse_bool(const char *filename, size_t lineno, const char *str, bool *err) return false; } -int8_t parse_anchor(const char *filename, size_t lineno, const char *str, bool *err) +uint32_t parse_anchor(const char *filename, size_t lineno, const char *str, bool *err) { if(strcasecmp(str, "top-left") == 0) { return ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c index f0a04e0..58f4ca6 100644 --- a/src/entry_backend/harfbuzz.c +++ b/src/entry_backend/harfbuzz.c @@ -109,6 +109,7 @@ void entry_backend_harfbuzz_init( uint32_t *height) { cairo_t *cr = entry->cairo[0].cr; + uint32_t font_size = floor(entry->font_size * PT_TO_DPI); /* Setup FreeType. */ log_debug("Creating FreeType library.\n"); @@ -122,7 +123,9 @@ void entry_backend_harfbuzz_init( log_debug("Loading FreeType font.\n"); err = FT_New_Face( - entry->harfbuzz.ft_library, entry->font_name, 0, + entry->harfbuzz.ft_library, + entry->font_name, + 0, &entry->harfbuzz.ft_face); if (err) { log_error("Error loading font: %s\n", get_ft_error_string(err)); @@ -130,10 +133,10 @@ void entry_backend_harfbuzz_init( } err = FT_Set_Char_Size( entry->harfbuzz.ft_face, - entry->font_size * 64, - entry->font_size * 64, - 96, - 96); + font_size * 64, + font_size * 64, + 0, + 0); if (err) { log_error("Error setting font size: %s\n", get_ft_error_string(err)); @@ -146,15 +149,19 @@ void entry_backend_harfbuzz_init( struct color color = entry->foreground_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_set_font_face(cr, entry->harfbuzz.cairo_face); - cairo_set_font_size(cr, entry->font_size * PT_TO_DPI); + cairo_set_font_size(cr, font_size); cairo_font_options_t *opts = cairo_font_options_create(); - //cairo_font_options_set_hint_style(opts, CAIRO_HINT_STYLE_NONE); + if (entry->harfbuzz.disable_hinting) { + cairo_font_options_set_hint_style(opts, CAIRO_HINT_STYLE_NONE); + } else { + cairo_font_options_set_hint_metrics(opts, CAIRO_HINT_METRICS_ON); + } cairo_set_font_options(cr, opts); /* We also need to set up the font for our other Cairo context. */ cairo_set_font_face(entry->cairo[1].cr, entry->harfbuzz.cairo_face); - cairo_set_font_size(entry->cairo[1].cr, entry->font_size * PT_TO_DPI); + cairo_set_font_size(entry->cairo[1].cr, font_size); cairo_set_font_options(entry->cairo[1].cr, opts); cairo_font_options_destroy(opts); diff --git a/src/entry_backend/harfbuzz.h b/src/entry_backend/harfbuzz.h index 8404032..68bb443 100644 --- a/src/entry_backend/harfbuzz.h +++ b/src/entry_backend/harfbuzz.h @@ -1,6 +1,7 @@ #ifndef ENTRY_BACKEND_HARFBUZZ_H #define ENTRY_BACKEND_HARFBUZZ_H +#include #include #include #include FT_FREETYPE_H @@ -16,6 +17,8 @@ struct entry_backend_harfbuzz { hb_font_t *hb_font; hb_buffer_t *hb_buffer; + + bool disable_hinting; }; void entry_backend_harfbuzz_init(struct entry *entry, uint32_t *width, uint32_t *height); diff --git a/src/main.c b/src/main.c index 120e7c2..3844bbd 100644 --- a/src/main.c +++ b/src/main.c @@ -589,6 +589,7 @@ static void usage() " --hide-cursor Hide the cursor.\n" " --horizontal List results horizontally.\n" " --history Sort results by number of usages.\n" +" --hint-font Perform font hinting.\n" ); } @@ -626,6 +627,7 @@ static void parse_args(struct tofi *tofi, int argc, char *argv[]) {"horizontal", required_argument, NULL, 0}, {"hide-cursor", required_argument, NULL, 0}, {"history", required_argument, NULL, 0}, + {"hint-font", required_argument, NULL, 0}, {NULL, 0, NULL, 0} }; const char *short_options = ":hc:"; diff --git a/src/tofi.h b/src/tofi.h index 1323bd4..ddc46de 100644 --- a/src/tofi.h +++ b/src/tofi.h @@ -48,7 +48,7 @@ struct tofi { } window; /* Options */ - int8_t anchor; + uint32_t anchor; bool hide_cursor; bool use_history; }; -- cgit v1.2.3