parallel_textgen: separate font_render and invoke_command

Replace font_render with get_command which returns the command line
instead of executing it. Move invoke_command to font_render callers.
This commit is contained in:
RjY 2017-03-14 13:14:16 +00:00
parent e94bcdd9ea
commit 946db56ccd

View file

@ -138,9 +138,11 @@ class Font(object):
return command_line return command_line
def render_text(self, text, output_filename, def get_command(self, text, output_filename,
color=COLOR_WHITE, bgcolor=BACKGROUND_COLOR): color=COLOR_WHITE, bgcolor=BACKGROUND_COLOR):
"""Render text to a file with the given background color.""" """Get command line to render text to a file
with the given background color.
"""
if UPPERCASE_FONT: if UPPERCASE_FONT:
text = text.upper() text = text.upper()
@ -152,13 +154,14 @@ class Font(object):
command_line.append(output_filename) command_line.append(output_filename)
invoke_command(command_line) return command_line
def generate_graphics(graphics, color=COLOR_WHITE, bgcolor=BACKGROUND_COLOR): def generate_graphics(graphics, color=COLOR_WHITE, bgcolor=BACKGROUND_COLOR):
for name, text in sorted(graphics.items()): for name, text in sorted(graphics.items()):
print("# %s.gif: '%s'" % (name, text)) print("# %s.gif: '%s'" % (name, text))
font.render_text(text, '%s.gif' % name, cmd = font.get_command(text, '%s.gif' % name,
color=color, bgcolor=bgcolor) color=color, bgcolor=bgcolor)
invoke_command(cmd)
def generate_kerning_test(): def generate_kerning_test():
pairs = [] pairs = []
@ -169,7 +172,8 @@ def generate_kerning_test():
if font.kerning_adjust(char1, char2) != 0: if font.kerning_adjust(char1, char2) != 0:
pairs.append(char1 + char2) pairs.append(char1 + char2)
font.render_text(" ".join(pairs), "kerning.gif") cmd = font.get_command(" ".join(pairs), "kerning.gif")
invoke_command(cmd)
font = Font('fontchars', kerning_table=FONT_KERNING_RULES) font = Font('fontchars', kerning_table=FONT_KERNING_RULES)