From b49b1c1a6595a00d93e9e904d6723034b6f12530 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Mon, 27 Jun 2022 09:41:31 +0200 Subject: src/prompt-box.vala: Use regular expression to split KEY_FONT_NAME into font_family and font_size. This now also supports font family names containing blanks. Fixes: https://github.com/ArcticaProject/arctica-greeter/issues/34 --- src/prompt-box.vala | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/prompt-box.vala') diff --git a/src/prompt-box.vala b/src/prompt-box.vala index 43e6cf4..1a0007f 100644 --- a/src/prompt-box.vala +++ b/src/prompt-box.vala @@ -28,9 +28,8 @@ public class PromptBox : FadableBox public signal void name_clicked (); public static string font = AGSettings.get_string (AGSettings.KEY_FONT_NAME); - public static string font_family = font.split_set(" ")[0]; - public static int font_size = int.parse(font.split_set(" ")[1]); - + public static string font_family = "sans"; + public static int font_size = 11; public bool has_errors { get; set; default = false; } public string id { get; construct; } @@ -175,6 +174,16 @@ public class PromptBox : FadableBox fixed.add (small_box_widget); fixed.add (box_grid); + + /* Split font family and size via regular expression. */ + Regex font_regexp = new Regex ("^([[:blank:]]*)(?[ a-zA-Z0-9]+) (?[0-9]+)([[:blank:]]*)$"); + MatchInfo font_info; + if (font_regexp.match(font, 0, out font_info)) { + font_family = font_info.fetch_named("font_family"); + font_size = int.parse(font_info.fetch_named("font_size")); + } + debug ("Using font family '%s'.", font_family); + debug ("Using font size base '%d'.", font_size); } protected virtual Gtk.Grid create_name_grid () -- cgit v1.2.3