mirror of
https://github.com/swaywm/sway.git
synced 2026-04-05 07:15:41 -04:00
Reject font values that are invalid for pango
Use pango to parse font configuration early, and reject the command as invalid if the value is invalid for pango. Since we're already parsing the font into a `PangoFontDescription`, keep that instance around and avoid re-parsing the font each time we render text. Fixes: https://github.com/swaywm/sway/issues/6805
This commit is contained in:
parent
9e8866ae20
commit
75605491a5
5 changed files with 30 additions and 6 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "sway/config.h"
|
||||
#include "log.h"
|
||||
#include "stringop.h"
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
struct cmd_results *cmd_font(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
|
|
@ -22,6 +23,28 @@ struct cmd_results *cmd_font(int argc, char **argv) {
|
|||
config->font = font;
|
||||
}
|
||||
|
||||
// Parse the font early so we can reject it if it's not valid for pango.
|
||||
// Also avoids re-parsing each time we render text.
|
||||
PangoFontDescription *font_description = pango_font_description_from_string(config->font);
|
||||
|
||||
const char *family = pango_font_description_get_family(font_description);
|
||||
if (family == NULL) {
|
||||
pango_font_description_free(font_description);
|
||||
return cmd_results_new(CMD_FAILURE, "Invalid font family.");
|
||||
}
|
||||
|
||||
const gint size = pango_font_description_get_size(font_description);
|
||||
if (size == 0) {
|
||||
pango_font_description_free(font_description);
|
||||
return cmd_results_new(CMD_FAILURE, "Invalid font size.");
|
||||
}
|
||||
|
||||
if (config->font_description != NULL) {
|
||||
pango_font_description_free(config->font_description);
|
||||
}
|
||||
|
||||
config->font_description = font_description;
|
||||
config_update_font_height();
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue