#
# source file of the GNU LilyPond music typesetter
#
-# (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+# (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
# Jan Nieuwenhuizen <janneke@gnu.org>
### subst:\(^\|[^._a-z]\)\(abspath\|identify\|warranty\|progress\|warning\|error\|exit\|getopt_args\|option_help_str\|options_help_str\|help\|setup_temp\|read_pipe\|system\|cleanup_temp\|strip_extension\|cp_to_dir\|mkdir_p\|init\) *(
def warranty ():
identify (sys.stdout)
sys.stdout.write ('\n')
- sys.stdout.write (_ ("Copyright (c) %s by") % '1998--2004')
+ sys.stdout.write (_ ("Copyright (c) %s by") % '1998--2005')
sys.stdout.write ('\n')
map (lambda x: sys.stdout.write (' %s\n' % x), __main__.copyright)
sys.stdout.write ('\n')
return __main__.temp_dir
def command_name (cmd):
-
+ # Strip all stuf after command,
# deal with "((latex ) >& 1 ) .." too
- cmd = re.match ("([\(\)]*)([^ ]*)", cmd).group(2)
+ cmd = re.match ('([\(\)]*)([^\\\ ]*)', cmd).group (2)
return os.path.basename (cmd)
def error_log (name):
'TEXMF' : "{%s,%s}" % (datadir, texmf) ,
- # FIXME: check if these can be fully reset.
- #'GS_FONTPATH' : "", #type1_paths,
- 'GS_FONTPATH' : datadir + '/fonts/type1',
- 'GS_LIB' : datadir + '/ps',
+ # 'GS_FONTPATH' : type1_paths,
+ # 'GS_LIB' : datadir + '/ps',
+ 'GS_FONTPATH' : "",
+ 'GS_LIB' : "",
}
# $TEXMF is special, previous value is already taken care of
return gr
-def make_ps_images (ps_name, resolution = 90):
- ## todo:
- ## have better algorithm for deciding when to crop page,
- ## and when to show full page
- base = re.sub (r'\.e?ps', '', ps_name)
-
+def make_ps_images (ps_name, resolution = 90, papersize = "a4",
+ rename_page1_p = 0):
+ base = os.path.basename (re.sub (r'\.e?ps', '', ps_name))
header = open (ps_name).read (1024)
- match = re.search (BOUNDING_BOX_RE, header, re.MULTILINE)
- bbox = []
- if match:
- bbox = map (string.atoi, match.groups ())
-
+ png1 = base + '.png'
+ pngn = base + '-page%d.png'
+ output_file = pngn
multi_page = re.search ('\n%%Pages: ', header)
- cmd = ''
- if multi_page == None:
-
- 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.
-
- margin = 3
- fo = open (trans_ps, 'w')
- fo.write ('%d %d translate\n' % (-bbox[0] + margin,
- -bbox[1] + margin))
- fo.close ()
-
- x = (2* margin + bbox[2] - bbox[0]) \
- * resolution / 72.0
- y = (2* margin + bbox[3] - bbox[1]) \
- * resolution / 72.0
- if x == 0:
- x = 1
- if y == 0:
- y = 1
-
- cmd = r'''gs -g%dx%d -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -r%d -dNOPAUSE %s %s -c showpage -c quit ''' % \
- (x, y, output_file, resolution, trans_ps, ps_name)
-
- rms = glob.glob (base + '-page*.png')
- map (os.unlink, rms)
+ # png16m is because Lily produces color nowadays.
+ if not multi_page:
+ cmd = r'''gs\
+ -dEPSCrop\
+ -dGraphicsAlphaBits=4\
+ -dNOPAUSE\
+ -dTextAlphaBits=4\
+ -sDEVICE=png16m\
+ -sOutputFile='%(output_file)s'\
+ -sPAPERSIZE=%(papersize)s\
+ -q\
+ -r%(resolution)d\
+ '%(ps_name)s'\
+ -c showpage\
+ -c quit ''' % vars ()
else:
- output_file = re.sub (r'\.e?ps', '-page%d.png', ps_name)
-
- rmfile = base + '.png'
- if os.path.isfile (rmfile):
- os.unlink (rmfile)
-
- cmd = r'''gs -s -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c showpage -c quit''' % (output_file,
- resolution, ps_name)
+ cmd = r'''gs\
+ -s\
+ -dGraphicsAlphaBits=4\
+ -dNOPAUSE\
+ -dTextAlphaBits=4\
+ -sDEVICE=png16m\
+ -sOutputFile='%(output_file)s'\
+ -sPAPERSIZE=%(papersize)s\
+ -q\
+ -r%(resolution)d\
+ '%(ps_name)s'\
+ -c quit''' % vars ()
+
+ remove = glob.glob (png1) + glob.glob (base + '-page*.png')
+ map (os.unlink, remove)
status = system (cmd)
signal = 0xf & status
exit_status = status >> 8
-
if status:
- os.unlink (png)
- error (_ ("Removing output file"))
+ remove = glob.glob (png1) + glob.glob (base + '-page*.png')
+ map (os.unlink, remove)
+ error (_ ("%s exited with status: %d") % ('GS', status))
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)
-
- files = glob.glob (re.sub ('%d', '*', output_file))
+ if rename_page1_p or not multi_page:
+ os.rename (pngn % 1, png1)
+ files = glob.glob (png1) + glob.glob (re.sub ('%d', '*', output_file))
return files
-