From 9ca1a02569d3e529c64b9ff0f2208f01a280c956 Mon Sep 17 00:00:00 2001 From: David Mazary Date: Fri, 11 Nov 2011 18:20:29 -0500 Subject: [PATCH] Updated qfont_decode to use Xonotic's qfont_table. --- xonstat/util.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/xonstat/util.py b/xonstat/util.py index ce94a71..b0b5481 100755 --- a/xonstat/util.py +++ b/xonstat/util.py @@ -1,9 +1,10 @@ import re from datetime import datetime +# Map of special chars to ascii from Quake's console.c. qfont_table = [ '\0', '#', '#', '#', '#', '.', '#', '#', - '#', 9, 10, '#', ' ', 13, '.', '.', + '#', '\t', '\n', '#', ' ', '\r', '.', '.', '[', ']', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '<', '=', '>', ' ', '!', '"', '#', '$', '%', '&', '\'', @@ -40,11 +41,14 @@ qfont_table = [ def qfont_decode(qstr=''): """ - Convert a name from qfont to ascii. - 'qstr' must be a unicode string. + Convert the qfont characters in a string to ascii. """ - by = bytearray(qstr, 'latin_1') - return ''.join([qfont_table[b & 0xff] for b in by]) + chars = [] + for c in qstr: + if c >= u'\ue000' and c <= u'\ue0ff': + c = qfont_table[ord(c) - 0xe000] + chars.append(c) + return ''.join(chars) def strip_colors(str=''): -- 2.39.2