From eb7d4fb280dff1c890b97b4bd08538334d3f1aa1 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 5 Feb 2014 03:41:23 +0000 Subject: [PATCH] textgen: Reduce height of lowercase graphics. If a text string contains all lower-case characters, then generate it at a reduced height. This is necessary for certain graphics, like the WIF graphic ("FINISHED") on the intermission screen, otherwise it ends up in the wrong location (#49). Adjust the offsets for some graphics in the build config to compensate, and fix up the vertical offsets for WICOLON/WIMINUS while we're at it. --- buildcfg.txt | 12 ++++++------ graphics/text/textgen | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/buildcfg.txt b/buildcfg.txt index 0e319269..49026884 100644 --- a/buildcfg.txt +++ b/buildcfg.txt @@ -799,8 +799,8 @@ M_THERML -2 0 M_ENDGAM 0 1 M_PAUSE 0 0 M_MESSG 0 1 -M_MSGON 0 1 -M_MSGOFF 0 1 +M_MSGON 0 -3 +M_MSGOFF 0 -3 M_HURT 0 0 M_JKILL 0 0 M_ROUGH 0 0 @@ -814,8 +814,8 @@ M_SAVEG 0 0 M_LOADG 0 0 M_DISP 0 0 M_MSENS 0 1 -M_GDHIGH -20 1 -M_GDLOW -20 1 +M_GDHIGH -20 -3 +M_GDLOW -20 -3 M_DETAIL 0 1 M_DISOPT 0 0 M_SCRNSZ 0 1 @@ -881,7 +881,7 @@ WIOSTF 0 0 WITIME 0 0 WIPAR 0 0 WIMSTAR 0 0 -WIMINUS 0 -5 +WIMINUS 0 0 WIPCNT 0 0 WINUM0 0 0 WINUM1 0 0 @@ -893,7 +893,7 @@ WINUM6 0 0 WINUM7 0 0 WINUM8 0 0 WINUM9 0 0 -WICOLON 0 -1 +WICOLON 0 0 WISUCKS 0 0 WIFRGS 0 0 WIP1 0 0 diff --git a/graphics/text/textgen b/graphics/text/textgen index 1b69b897..30243d7d 100755 --- a/graphics/text/textgen +++ b/graphics/text/textgen @@ -55,6 +55,7 @@ BACKGROUND_COLOR = '#00ffff' # Height of font in pixels. FONT_HEIGHT = 16 +FONT_LC_HEIGHT = 12 # Width of a space character in pixels. SPACE_WIDTH = 10 @@ -63,6 +64,9 @@ SPACE_WIDTH = 10 # fontchars/font033.gif GIF 9x16 9x16+0+0 8-bit sRGB 32c 194B 0.000u 0:00.000 IDENTIFY_OUTPUT_RE = re.compile(r'(\S+)\s(\S+)\s(\d+)x(\d+)\s') +# Regexp to identify strings that are all lowercase (can use shorter height) +LOWERCASE_RE = re.compile(r'^[a-z\!\. ]*$') + def get_image_dimensions(filename): proc = subprocess.Popen([IDENTIFY_COMMAND, filename], stdout=subprocess.PIPE) @@ -173,9 +177,14 @@ class Font(object): """Command line construction helper, used in render functions""" width = self.text_width(text) + if LOWERCASE_RE.match(text): + height = FONT_LC_HEIGHT + else: + height = FONT_HEIGHT + command_line = [ CONVERT_COMMAND, - '-size', '%ix%i' % (width, FONT_HEIGHT), + '-size', '%ix%i' % (width, height), 'xc:none', ] @@ -186,7 +195,8 @@ class Font(object): filename = self.char_filename(c) command_line.extend([ '-draw', - 'image over %i,0 0,0 %s' % (x, filename) + 'image over %i,%i 0,0 %s' % + (x, height - FONT_HEIGHT, filename) ]) command_line.extend([