term: don't use deprecated fcft_size_adjust()

When resizing the font on-the-fly, we now do a complete
font-reload (this is basically what fcft_size_adjust() did anyway).

To get the correct size, we maintain the current size ourselves.

We get the initial size from the user-provided font pattern, by
converting the string to an FcPattern, and using FcPatternGet() to
retrieve both the FC_SIZE and FC_PIXEL_SIZE attributes. These
attributes are then removed from the pattern, and the pattern is
converted back to a string.

The terminal struct maintains a copy of the font sizes. These are
initially set to the sizes from the config.

When the user resizes the font, the terminal-local sizes are
adjusted. To ensure the primary and user-configured fallback fonts are
resizes equally much, convert any pixel sizes to point sizes at this
point.

When the font size is reset, we reload the font sizes from the
config (thus once again returning actual pixel-sizes, if that's what
the user has configured).
This commit is contained in:
Daniel Eklöf 2020-07-07 10:44:55 +02:00
parent 3063204289
commit 69e4213e4a
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 126 additions and 107 deletions

View file

@ -14,6 +14,7 @@
#include <linux/input-event-codes.h>
#include <xkbcommon/xkbcommon.h>
#include <fontconfig/fontconfig.h>
#define LOG_MODULE "config"
#define LOG_ENABLE_DBG 0
@ -265,7 +266,7 @@ parse_section_main(const char *key, const char *value, struct config *conf,
while (*font != '\0' && isspace(*font))
font++;
if (*font != '\0')
tll_push_back(conf->fonts, strdup(font));
tll_push_back(conf->fonts, config_font_parse(font));
}
free(copy);
}
@ -963,7 +964,7 @@ config_load(struct config *conf, const char *conf_path)
out:
if (ret && tll_length(conf->fonts) == 0)
tll_push_back(conf->fonts, strdup("monospace"));
tll_push_back(conf->fonts, config_font_parse("monospace"));
free(default_path);
return ret;
@ -976,7 +977,9 @@ config_free(struct config conf)
free(conf.shell);
free(conf.title);
free(conf.app_id);
tll_free_and_free(conf.fonts, free);
tll_foreach(conf.fonts, it)
config_font_destroy(&it->item);
tll_free(conf.fonts);
free(conf.server_socket_path);
for (enum bind_action_normal i = 0; i < BIND_ACTION_COUNT; i++)
@ -984,3 +987,36 @@ config_free(struct config conf)
for (enum bind_action_search i = 0; i < BIND_ACTION_SEARCH_COUNT; i++)
free(conf.bindings.search[i]);
}
struct config_font
config_font_parse(const char *pattern)
{
FcPattern *pat = FcNameParse((const FcChar8 *)pattern);
double pt_size = -1.0;
FcPatternGetDouble(pat, FC_SIZE, 0, &pt_size);
FcPatternRemove(pat, FC_SIZE, 0);
int px_size = -1;
FcPatternGetInteger(pat, FC_PIXEL_SIZE, 0, &px_size);
FcPatternRemove(pat, FC_PIXEL_SIZE, 0);
if (pt_size == -1. && px_size == -1)
pt_size = 8.0;
char *stripped_pattern = (char *)FcNameUnparse(pat);
FcPatternDestroy(pat);
return (struct config_font){
.pattern = stripped_pattern,
.pt_size = pt_size,
.px_size = px_size};
}
void
config_font_destroy(struct config_font *font)
{
if (font == NULL)
return;
free(font->pattern);
}