From 068d1c548e7aa433498da59371bcc317a7632683 Mon Sep 17 00:00:00 2001 From: gryf Date: Mon, 18 Apr 2022 19:24:04 +0200 Subject: [PATCH] Add function for deducting char size by filename. --- wmdocklib/helpers.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/wmdocklib/helpers.py b/wmdocklib/helpers.py index 8760266..89b9104 100644 --- a/wmdocklib/helpers.py +++ b/wmdocklib/helpers.py @@ -42,6 +42,27 @@ RGB_FILE_LIST = ['/etc/X11/rgb.txt', '/usr/lib/X11/rgb.txt'] +def get_font_char_size(font_name): + """Return char size infered from font name. + + It is expected, that font should have char size included in the file name, + i.e. + + charset_8x12_big_black.xpm + 6x8-small.xpm + + so the pattern searched here would be WxH, where W and H are char width + and height (including interval between chars and lines) and x is literally + x. + """ + res = re.match(r'.*?(?P[0-9]+)(?:\((?P[0-9]+)\))?x(?P[0-9]+).*', + font_name) + if not res: + return None, None + + return int(res.groupdict().get('w')), int(res.groupdict().get('h')) + + def get_center_start_pos(string, areaWidth, offset): """Get the x starting position if we want to paint string centred.""" w = len(string) * char_width