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.
This commit is contained in:
Simon Howard 2014-02-05 03:41:23 +00:00
parent 0820d14925
commit eb7d4fb280
2 changed files with 18 additions and 8 deletions

View file

@ -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([