From 69c384e5947a3091c5fb43ebb7983cebae61f545 Mon Sep 17 00:00:00 2001 From: mfrasca <> Date: Sun, 15 Oct 2006 07:13:16 +0000 Subject: [PATCH] 1577063: fonts are hard coded added one more font (derived from 8x8zx, but without so much horizontal spacing). modified the initPixmap so that it reads installed fonts. they MUST be in the same directory as the library itself. the examples still have hard-coded fonts, but that's an other problem. --- MANIFEST | 2 ++ wmdocklib/7x8zx.xpm | 57 ++++++++++++++++++++++++++++++++++++++++ wmdocklib/pywmhelpers.py | 20 ++++++++------ 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 wmdocklib/7x8zx.xpm diff --git a/MANIFEST b/MANIFEST index 4125ff2..136358b 100644 --- a/MANIFEST +++ b/MANIFEST @@ -13,7 +13,9 @@ examples/sample.pywmsetirc wmdocklib/5x7.xpm wmdocklib/6x8.xpm wmdocklib/6x8slant.xpm +wmdocklib/7x8zx.xpm wmdocklib/8x8.xpm +wmdocklib/8x8zx.xpm wmdocklib/README wmdocklib/__init__.py wmdocklib/pywmgeneral.c diff --git a/wmdocklib/7x8zx.xpm b/wmdocklib/7x8zx.xpm new file mode 100644 index 0000000..124584b --- /dev/null +++ b/wmdocklib/7x8zx.xpm @@ -0,0 +1,57 @@ +/* XPM */ +static char *_x_zx[] = { +/* columns rows colors chars-per-pixel */ +"128 48 2 1", +"% c black", +" c gray100", +/* pixels */ +" ", +" % % % %%% % %% % % % % % %%%% %% ", +" % % % % % %%%%% %% % % % % % % % % % % % %% % % ", +" % %%%% % % % % % % % % % % % % % ", +" % % %%%%% % % % % % % %%%%% %%%%% %%%%% % % % % % ", +" % % % % %% % % % % % % % %% % %% % % ", +" % %%%%%% %%%%% % %% %%% % % % % % % % %% % %%%% %%%%% ", +" % % ", +" ", +" %%%% %%%% % %%%%%% %%%% %%%%%% %%%% %%%% %%%% %%%% %%%% %%%%% %%%% ", +"% % % % %% % % % % % % % % % % % % % % % % % % % % % ", +" % %% % % %%%%% %%%%% % %%%% % % % % %%%%% % % % % %% % % %%%%% % ", +" %%%% % % % % % % % % % %%%%% % % % % %%%% %%%%%% % % % ", +"% % % %%%%%% % % % % % % % % % % %%%%% % % % % % % % % ", +"%%%%%% %%%% % %%%% %%%% % %%%% %%%% % % % % % %%%% % % %%%%% %%%% ", +" % ", +" ", +"%%%% %%%%%% %%%%%% %%%% % % %%%%% % % % % % % % % %%%% %%%%% %%%% %%%%% %%%% %%%%%%%% % ", +"% % % % % % % % % % % % % %% %% %% % % % % % % % % % % % % % ", +"% % %%%%% %%%%% % %%%%%% % % %%% % % %% % % % % % % % % % % % % %%%% % % % ", +"% % % % % %%% % % % % % % % % % % % % % % % %%%%% % % % %%%%% % % % % ", +"% % % % % % % % % % % % % % % % % %% % % % % % % % % % % % % % ", +"%%%% %%%%%% % %%%% % % %%%%% %%%% % % %%%%%% % % % % %%%% % %%%% % % %%%% % %%%% ", +" ", +" ", +"% % % % % % % %%%%%%% %%% %%% % % % % %% ", +"% % % % % % % % % % % % %%% % %%% % %%% % %%% % %%%%% ", +"% % % % %% % % % % % % % % % % %%%% % %%%% % % %% % % ", +"% % % % %% % % % % % % %%%% % % % % % %%%% % % % ", +" % % % %% % % % % % % % % % % % % % % % % % % %%%%% ", +" %% % % % % % %%%%%% %%% % %%% % %%%% %%%% %%% %%%% %%%% % % ", +" %%%%%%% %%%% ", +" ", +"% % % % % % ", +"% % % % %% % %%%% %%% %%%% %%%% %%% %%% %%% % % % % % % % % % % ", +"%%%% %% % %% % % % % % % % % % % % % % % % % % % % % % % % % % % ", +"% % % % %% % % % % % % % % % % % % % %%% % % % % % % % % % % % ", +"% % % % % % % % % % % % % % %%%% %%%% % % % % % % % % % % % % %%%% ", +"% % %%% % % % % %% % % % % % %%% % % % %%%% %% %%% % % % % % % ", +" %% % %% %%% ", +" ", +" %%% % %%% % % ", +"%%%%% % % % % % ", +" % %% % %% ", +" % % % % ", +" % % % % ", +"%%%%% %%% % %%% ", +" ", +" ", +}; diff --git a/wmdocklib/pywmhelpers.py b/wmdocklib/pywmhelpers.py index 80dc581..8ab6eb8 100644 --- a/wmdocklib/pywmhelpers.py +++ b/wmdocklib/pywmhelpers.py @@ -208,17 +208,21 @@ def initPixmap(xpm_background=None, tile_width = width tile_height = height - def charsize_from_fontname(font_name): - import re + def readFont(font_name): + # read xpm, skip header and color definitions, fill/trim to 48 lines. + fontdef = readXPM(__file__[:__file__.rfind(os.sep) + 1] + font_name + '.xpm') + fontdef = fontdef[1 + int(fontdef[0].split(' ')[2]):] + fontdef = (fontdef + [' '*128]*48)[:48] - d = re.compile(r'.*([0-9]+)x([0-9]+).*') - m = d.match(font_name) + import re + m = re.match(r'.*([0-9]+)x([0-9]+).*', font_name) if not m: - raise ValueError("can't infer font size from name") - return [int(item) for item in m.groups()] + raise ValueError("can't infer font size from name (does not contain wxh)") + width, height = [int(item) for item in m.groups()] + return width, height, fontdef global char_width, char_height - char_width, char_height = charsize_from_fontname(font_name) + char_width, char_height, fontdef = readFont(font_name) xpm = [ '128 112 %d 1' % (1+len(palette)), @@ -235,7 +239,7 @@ def initPixmap(xpm_background=None, ' '*width + item[:128-width] for item in xpm_background[-margin-1:] ] + [ line.replace('%', fg).replace(' ', bg) - for line in char_defs[font_name] + for line in fontdef ] if 0: print '/* XPM */\nstatic char *_x_[] = {'