mirror of
https://github.com/freedoom/freedoom.git
synced 2025-09-05 07:25:45 -04:00
textgen: Move common code into a common file.
Reduce code duplication by refactoring the textgen and smtextgen scripts.
This commit is contained in:
parent
b6c26942b4
commit
5405104814
3 changed files with 50 additions and 82 deletions
|
@ -35,12 +35,9 @@
|
|||
|
||||
from glob import glob
|
||||
import sys
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
# ImageMagick commands used by this script:
|
||||
CONVERT_COMMAND = 'convert'
|
||||
IDENTIFY_COMMAND = 'identify'
|
||||
from common import *
|
||||
|
||||
# Background color for output files.
|
||||
BACKGROUND_COLOR = '#00ffff'
|
||||
|
@ -49,45 +46,11 @@ BACKGROUND_COLOR = '#00ffff'
|
|||
SPACE_WIDTH = 4
|
||||
|
||||
# Height of the font.
|
||||
FONT_HEIGHT = 7
|
||||
FONT_HEIGHT = 8
|
||||
|
||||
# Regexp to match dimensions/x,y coordinate pair.
|
||||
DIMENSION_MATCH_RE = re.compile(r'(\d+)[x,](\d+)')
|
||||
|
||||
# Output from 'identify' looks like this:
|
||||
# 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')
|
||||
|
||||
def get_image_dimensions(filename):
|
||||
proc = subprocess.Popen([IDENTIFY_COMMAND, filename],
|
||||
stdout=subprocess.PIPE)
|
||||
proc.wait()
|
||||
|
||||
line = proc.stdout.readline().decode('utf-8')
|
||||
match = IDENTIFY_OUTPUT_RE.match(line)
|
||||
assert match is not None
|
||||
return (int(match.group(3)), int(match.group(4)))
|
||||
|
||||
def invoke_command(command):
|
||||
"""Invoke a command, printing the command to stdout.
|
||||
|
||||
Args:
|
||||
command: Command and arguments as a list.
|
||||
"""
|
||||
for arg in command:
|
||||
if arg.startswith('-'):
|
||||
sys.stdout.write("\\\n ")
|
||||
|
||||
if ' ' in arg or '#' in arg:
|
||||
sys.stdout.write(repr(arg))
|
||||
else:
|
||||
sys.stdout.write(arg)
|
||||
|
||||
sys.stdout.write(' ')
|
||||
|
||||
sys.stdout.write('\n')
|
||||
return subprocess.call(command)
|
||||
|
||||
class Font(object):
|
||||
def __init__(self):
|
||||
self.get_font_widths()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue