X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=python%2Flilylib.py;h=0f48d4dac05465d0e1bc156d0fa938a0106ab7a5;hb=579aea8221a7182aa988dd67a00b9bc8bf12638c;hp=b3dde26a20795792a3899d1dae072ed203750b71;hpb=7af4bf1f7440843fa24de456edc04ad31b616cf9;p=lilypond.git diff --git a/python/lilylib.py b/python/lilylib.py index b3dde26a20..0f48d4dac0 100644 --- a/python/lilylib.py +++ b/python/lilylib.py @@ -30,7 +30,9 @@ import glob # If set, LILYPONDPREFIX must take prevalence # if datadir is not set, we're doing a build and LILYPONDPREFIX -import getopt, os, sys +import getopt +import os +import sys datadir = '@local_lilypond_datadir@' if not os.path.isdir (datadir): datadir = '@lilypond_datadir@' @@ -129,7 +131,7 @@ def exit (i): if __main__.verbose_p: raise _ ('Exiting (%d)...') % i else: - sys.exit (1) + sys.exit (i) def getopt_args (opts): '''Construct arguments (LONG, SHORT) for getopt from list of options.''' @@ -235,9 +237,9 @@ def setup_temp (): def command_name (cmd): - # deal with "((latex ) >& 1 ) .." too + # deal with "((latex ) >& 1 ) .." too cmd = re.match ("([\(\)]*)([^ ]*)", cmd).group(2) - return os.path.split (cmd)[1] + return os.path.basename (cmd) def error_log (name): name = re.sub('[^a-z]','x', name) @@ -276,7 +278,7 @@ def read_pipe (cmd, mode = 'r'): if error_log_file: os.unlink (error_log_file) - exit (status) + exit (1) if __main__.verbose_p: progress ('\n') @@ -332,7 +334,7 @@ Exit status of CMD ''' sys.stderr.write (open (error_log_file).read ()) if error_log_file: os.unlink (error_log_file) - exit (status) + exit (1) if error_log_file: os.unlink (error_log_file) @@ -433,6 +435,7 @@ def print_environment (): for (k,v) in os.environ.items (): sys.stderr.write ("%s=\"%s\"\n" % (k, v)) +BOUNDING_BOX_RE = '^%%BoundingBox: (-?[0-9]+) (-?[0-9]+) (-?[0-9]+) (-?[0-9]+)' def get_bbox (filename): bbox = filename + '.bbox' ## -sOutputFile does not work with bbox? @@ -440,8 +443,7 @@ def get_bbox (filename): (filename, bbox) system (cmd, progress_p = 1) box = open (bbox).read () - m = re.match ('^%%BoundingBox: ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)', - box) + m = re.match (BOUNDING_BOX_RE, box) gr = [] if m: gr = map (string.atoi, m.groups ()) @@ -456,15 +458,22 @@ def make_ps_images (ps_name, resolution = 90): base = re.sub (r'\.e?ps', '', ps_name) header = open (ps_name).read (1024) + + match = re.match (BOUNDING_BOX_RE, header) + bbox = [] + if match: + bbox = map (string.atoi, match.groups ()) + multi_page = re.search ('\n%%Pages: ', header) cmd = '' if multi_page == None: - bbox = get_bbox (ps_name) + + if bbox == []: + bbox = get_bbox (ps_name) + trans_ps = ps_name + '.trans.ps' output_file = re.sub (r'\.e?ps', '.png', ps_name) - - # need to have margin, otherwise edges of letters will # be cropped off. @@ -508,3 +517,10 @@ def make_ps_images (ps_name, resolution = 90): os.unlink (png) error (_ ("Removing output file")) exit (1) + + + cmd = r'''gs -s -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c quit''' % (output_file, + resolution, ps_name) + + return output_file +