diff options
Diffstat (limited to 'sway/commands/font.c')
-rw-r--r-- | sway/commands/font.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/sway/commands/font.c b/sway/commands/font.c index c54365b5..9920d03e 100644 --- a/sway/commands/font.c +++ b/sway/commands/font.c | |||
@@ -1,9 +1,9 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <string.h> | 1 | #include <string.h> |
3 | #include "sway/commands.h" | 2 | #include "sway/commands.h" |
4 | #include "sway/config.h" | 3 | #include "sway/config.h" |
5 | #include "log.h" | 4 | #include "log.h" |
6 | #include "stringop.h" | 5 | #include "stringop.h" |
6 | #include <pango/pangocairo.h> | ||
7 | 7 | ||
8 | struct cmd_results *cmd_font(int argc, char **argv) { | 8 | struct cmd_results *cmd_font(int argc, char **argv) { |
9 | struct cmd_results *error = NULL; | 9 | struct cmd_results *error = NULL; |
@@ -16,12 +16,34 @@ struct cmd_results *cmd_font(int argc, char **argv) { | |||
16 | if (strncmp(font, "pango:", 6) == 0) { | 16 | if (strncmp(font, "pango:", 6) == 0) { |
17 | config->pango_markup = true; | 17 | config->pango_markup = true; |
18 | config->font = strdup(font + 6); | 18 | config->font = strdup(font + 6); |
19 | free(font); | ||
19 | } else { | 20 | } else { |
20 | config->pango_markup = false; | 21 | config->pango_markup = false; |
21 | config->font = strdup(font); | 22 | config->font = font; |
22 | } | 23 | } |
23 | 24 | ||
24 | free(font); | 25 | // Parse the font early so we can reject it if it's not valid for pango. |
25 | config_update_font_height(true); | 26 | // Also avoids re-parsing each time we render text. |
27 | PangoFontDescription *font_description = pango_font_description_from_string(config->font); | ||
28 | |||
29 | const char *family = pango_font_description_get_family(font_description); | ||
30 | if (family == NULL) { | ||
31 | pango_font_description_free(font_description); | ||
32 | return cmd_results_new(CMD_FAILURE, "Invalid font family."); | ||
33 | } | ||
34 | |||
35 | const gint size = pango_font_description_get_size(font_description); | ||
36 | if (size == 0) { | ||
37 | pango_font_description_free(font_description); | ||
38 | return cmd_results_new(CMD_FAILURE, "Invalid font size."); | ||
39 | } | ||
40 | |||
41 | if (config->font_description != NULL) { | ||
42 | pango_font_description_free(config->font_description); | ||
43 | } | ||
44 | |||
45 | config->font_description = font_description; | ||
46 | config_update_font_height(); | ||
47 | |||
26 | return cmd_results_new(CMD_SUCCESS, NULL); | 48 | return cmd_results_new(CMD_SUCCESS, NULL); |
27 | } | 49 | } |