(NAME . FILE-NAME) tuples for font descriptions.
(write-preamble): display BeginFont DSC comments.
* python/fontextract.py (write_extracted_fonts): new file. Extract
font resources from a PS file.
* scripts/lilypond-book.py (option_definitions): --psfonts option.
(Compile_error.process_include): do_file returns chunks.
* make/ly-vars.make (DVIPS_FLAGS): don't load .map file.
* make/lysdoc-targets.make: .texi is .PRECIOUS
* scripts/lilypond-book.py (write_if_updated): new function.
+2005-04-13 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ * scm/framework-ps.scm (write-preamble): use (NAME . CONTENTS) and
+ (NAME . FILE-NAME) tuples for font descriptions.
+ (write-preamble): display BeginFont DSC comments.
+
+ * python/fontextract.py (write_extracted_fonts): new file. Extract
+ font resources from a PS file.
+
+ * scripts/lilypond-book.py (option_definitions): --psfonts option.
+ (Compile_error.process_include): do_file returns chunks.
+
+ * make/ly-vars.make (DVIPS_FLAGS): don't load .map file.
+
+ * make/lysdoc-targets.make: .texi is .PRECIOUS
+
+ * scripts/lilypond-book.py (write_if_updated): new function.
+
2005-04-13 Jan Nieuwenhuizen <janneke@gnu.org>
* scm/framework-eps.scm (dump-stencils-as-EPSes): Massage messages.
2005-04-13 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * scm/framework-eps.scm (dump-stencils-as-EPSes): no massages.
+
* input/regression/markup-syntax.ly: remove \score.
* scm/define-markup-commands.scm (draw-circle): add fill argument
include $(depth)/make/stepmake.make
+$(outdir)/NEWS.nexi: NEWS.tely
"
}
+
+%{
+
+For maintenance reasons, we don't excercise the entire markup command set.
+
+%}
+
\version "2.5.2"
\score {
{
\combine "X" "+"
\combine "o" "/"
\box \column { \line { "string 1" } \line { "string 2" } }
- "$\\emptyset$"
\italic Norsk
\super "2"
\dynamic sfzp
#:combine "X" "+"
#:combine "o" "/"
#:box #:column ("string 1" "string 2")
- "$\\emptyset$"
- #:draw-circle 1 0.3
" "
#:italic "Norsk"
#:super "2"
"@end table\n"
"\n"
"This function is useful to call from the command line: @code{lilypond -e\n"
- "\"(ly : set - option 'midi-debug #t)\"}.\n")
+ "\"(ly:set-option 'midi-debug #t)\"}.\n")
{
if (val == SCM_UNDEFINED)
val = SCM_BOOL_T;
.SUFFIXES: .doc .dvi .tely .texi .ly
-$(outdir)/%.latex: %.doc
+$(outdir)/%.latex $(outdir)/%.fonts.ps: %.doc
$(PYTHON) $(LILYPOND_BOOK) $(LILYPOND_BOOK_INCLUDES) --process='$(LILYPOND) $(LILYPOND_BOOK_INCLUDES)' --output=$(outdir) --verbose $(LILYPOND_BOOK_FLAGS) $<
# don't do ``cd $(outdir)'', and assume that $(outdir)/.. is the src dir.
# it is not, for --srcdir builds
$(outdir)/%.texi: %.tely
rm -f $$(grep -LF '% eof' $(outdir)/lily-*systems.tex 2>/dev/null)
- $(PYTHON) $(LILYPOND_BOOK) $(LILYPOND_BOOK_INCLUDES) --process='$(LILYPOND) $(LILYPOND_BOOK_INCLUDES)' --output=$(outdir) --format=$(LILYPOND_BOOK_FORMAT) --verbose $(LILYPOND_BOOK_FLAGS) $<
+ $(PYTHON) $(LILYPOND_BOOK) --psfonts=$(basename $<).fonts.ps $(LILYPOND_BOOK_INCLUDES) --process='$(LILYPOND) $(LILYPOND_BOOK_INCLUDES)' --output=$(outdir) --format=$(LILYPOND_BOOK_FORMAT) --verbose $(LILYPOND_BOOK_FLAGS) $<
$(outdir)/%.texi: $(outdir)/%.tely
rm -f $$(grep -LF '% eof' $(outdir)/lily-*systems.tex 2>/dev/null)
$(outdir)/%.pdf: $(outdir)/%.dvi
dvips $(DVIPS_FLAGS) -o $@.pdfps -t $(DVIPS_PAPERSIZE) $<
# without -dSAFER
+# gs 8.15 complains of safety of loading a ttf directly
gs -dCompatibilityLevel=1.2 -sPAPERSIZE=a4 -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$@ -dCompatibilityLevel=1.2 -sPAPERSIZE=a4 -c .setpdfwrite -f $@.pdfps
$(outdir)/%.html.omf: %.tely
EXTRA_DIST_FILES +=$(TELY_FILES) $(LY_FILES) $(ITEXI_FILES) $(ITELY_FILES) $(ILY_FILES)
-# not mf/out , not mf/$(outdir)
-DVIPS_FLAGS= -u+$(builddir)/mf/out/lilypond.map -Ppdf
+DVIPS_FLAGS= -h $(notdir $(basename $<)).fonts.ps
local-WWW: $(outdir)/$(NAME).html $(outdir)/$(NAME).ps.gz $(outdir)/$(NAME).pdf
+
+.PRECIOUS: $(outdir)/$(NAME).texi
--- /dev/null
+import re
+import getopt
+import sys
+import os
+import string
+
+dsr_font_regex = re.compile ('%%DocumentSuppliedResources: font (.*)')
+begin_font_regex = re.compile ('%%BeginFont: (.*)')
+end_font_regex = re.compile ('%%EndFont')
+verbose = 0
+
+try:
+ import gettext
+ gettext.bindtextdomain ('lilypond', localedir)
+ gettext.textdomain ('lilypond')
+ _ = gettext.gettext
+except:
+ def _ (s):
+ return s
+
+def scan_files (files):
+ file_of_font_dict = {}
+ for f in files:
+ if verbose:
+ sys.stderr.write (_('Scanning %s') % f + '\n')
+
+ header = open (f, 'r').read ()
+ idx = 0
+
+ extract_from_this = []
+ while idx < len (header):
+ match = dsr_font_regex.search (header[idx:])
+ if not match:
+ break
+ name = match.group (1)
+ idx += match.end (1)
+ if file_of_font_dict.has_key (name):
+ continue
+
+ file_of_font_dict[name] = f
+
+ return file_of_font_dict
+
+def get_file_fonts_dict (file_of_font_dict):
+ dict = {}
+ for (n, f) in file_of_font_dict.items ():
+ if not dict.has_key (f):
+ dict[f] = []
+
+ dict[f].append (n)
+
+ return dict
+
+def extract_fonts_from_file (extract_from_this, font_dict, filename):
+ if extract_from_this:
+ curr_font = []
+ curr_font_name = []
+ in_font = 0
+ for l in open (filename).readlines ():
+ if not in_font and begin_font_regex.match (l):
+ in_font = 1
+ curr_font_name = begin_font_regex.match (l).group (1)
+ curr_font = []
+ elif in_font and end_font_regex.match (l):
+ in_font = 0
+
+ if curr_font_name in extract_from_this:
+ font_dict[curr_font_name] = string.join (curr_font, '')
+ if verbose:
+ sys.stderr.write (_('Extracted %s')
+ % curr_font_name + '\n')
+
+ extract_from_this.remove (curr_font_name)
+ elif in_font:
+ curr_font.append (l)
+ if not extract_from_this:
+ break
+
+ if extract_from_this:
+ sys.stderr.write ("Failed to extract %s from %s\n"
+ % (string.join (extract_from_this, ', '), f))
+
+def write_extracted_fonts (output_file_name, font_dict):
+ output = open (output_file_name, 'w')
+ output.write ('''%!PS-Adobe-3.0
+%%Creator: lilypond-extract-fonts
+''')
+
+ for x in font_dict.keys ():
+ output.write ('%%%%DocumentSuppliedResources: font %s\n' % x)
+
+ output.write ('''%%EndComments\n''')
+
+ for (k,v) in font_dict.items ():
+ output.write ('\n%%%%BeginFont: %s\n' % k)
+ output.write (v)
+ output.write ('\n%%%%EndFont')
+
+
+def extract_fonts (output_file_name, input_files):
+ d = scan_files (input_files)
+ ff = get_file_fonts_dict (d)
+
+ font_dict = {}
+ for (file, fonts) in ff.items ():
+ extract_fonts_from_file (fonts, font_dict, file)
+
+ write_extracted_fonts (output_file_name, font_dict)
+
+
+if __name__ == '__main__':
+ extract_fonts ('fonts.ps', sys.argv[1:])
(equal? (substring fontname 0 2) "cm")
(equal? (substring fontname 0 2) "ec")))
-(define (ps-embed-pfa body font-name version)
- (string-append
- (format
- "%%BeginResource: font ~a
-~a
-%%EndResource\n"
- font-name body)))
-
(define (define-fonts paper)
(define font-list (ly:paper-fonts paper))
name 'pre "PFA" 1 'post))
(define (write-preamble paper load-fonts? port)
+ (define (load-font font-pair)
+ (let* ((name (car font-pair))
+ (file-name (cdr font-pair))
+
+ (bare-file-name (ly:find-file file-name))
+ (cffname (string-append file-name ".cff.ps"))
+ (cff-file-name (ly:find-file cffname)))
+
+ (cons
+ (munge-lily-font-name name)
+ (cond
+ ((and bare-file-name (string-match "\\.pfa" bare-file-name))
+ (cached-file-contents bare-file-name))
+ ((and bare-file-name (string-match "\\.pfb" bare-file-name))
+ (ly:pfb->pfa bare-file-name))
+
+ ((string-match "([eE]mmentaler|[Aa]ybabtu)" file-name)
+ (cached-file-contents
+ (format "~a.pfa" (munge-lily-font-name file-name))))
+
+ ((and bare-file-name
+ (string-match "\\.(otf|cff)" bare-file-name))
+
+ ; replace with the CFF.ps, which lives in a
+ ; separate subdir.
+ (for-each (lambda (tup)
+ (set! bare-file-name
+ (string-regexp-substitute
+ (car tup) (cdr tup) bare-file-name)))
+ '(("/fonts/otf/" . "/ps/")
+ ("/fonts/cff/" . "/ps/")
+ ("\\.(otf|cff)" . ".cff.ps")))
+
+ (cached-file-contents bare-file-name))
+ ((and bare-file-name (string-match "\\.ttf" bare-file-name))
+ (ly:ttf->pfa bare-file-name))
+ (bare-file-name (cached-file-contents bare-file-name))
+ (cff-file-name (cached-file-contents cff-file-name))
+ (else
+ (ly:warning (_ "can't find CFF/PFA/PFB font ~S=~S" name file-name))
+ (cons font-name ""))))))
+
(define (load-fonts paper)
(let* ((fonts (ly:paper-fonts paper))
+
(all-font-names
(map
(lambda (font)
(cond
- ((string? (ly:font-file-name font)) (list (ly:font-file-name font)))
+ ((string? (ly:font-file-name font))
+ (list (cons (ly:font-name font)
+ (ly:font-file-name font))))
((ly:pango-font? font)
- (map cdr (ly:pango-font-physical-fonts font)))
- (else (ly:font-sub-fonts font))))
+ (ly:pango-font-physical-fonts font))
+ (else
+ (ly:font-sub-fonts font))))
fonts))
-
(font-names
(uniq-list
- (sort (apply append all-font-names) string<?)))
- (pfas (map
- (lambda (x)
- (let* ((bare-file-name (ly:find-file x))
- (cffname (string-append x ".cff.ps"))
- (cff-file-name (ly:find-file cffname)))
-
-
- (cond
- ((and bare-file-name (string-match "\\.pfa" bare-file-name))
- (cached-file-contents bare-file-name))
- ((and bare-file-name (string-match "\\.pfb" bare-file-name))
- (ly:pfb->pfa bare-file-name))
-
- ((string-match "([eE]mmentaler|[Aa]ybabtu)" x)
- (cached-file-contents
- (format "~a.pfa" (munge-lily-font-name x))))
-
- ((and bare-file-name
- (string-match "\\.(otf|cff)" bare-file-name))
-
- ; replace with the CFF.ps, which lives in a
- ; separate subdir.
- (for-each (lambda (tup)
- (set! bare-file-name
- (string-regexp-substitute
- (car tup) (cdr tup) bare-file-name)))
- '(("/fonts/otf/" . "/ps/")
- ("/fonts/cff/" . "/ps/")
- ("\\.(otf|cff)" . ".cff.ps")))
-
- (cached-file-contents bare-file-name))
- ((and bare-file-name (string-match "\\.ttf" bare-file-name))
- (ly:ttf->pfa bare-file-name))
- (bare-file-name (cached-file-contents bare-file-name))
- (cff-file-name (cached-file-contents cff-file-name))
- (else
- (ly:warning (_ "can't find CFF/PFA/PFB font ~S" x))
- ""))))
- (filter string? font-names))))
- pfas))
+ (sort (apply append all-font-names)
+ (lambda (x y) (string<? (car x) (car y))))))
+
+ (pfas (map load-font font-names)))
+ pfas))
(if load-fonts?
- (for-each (lambda (f) (display f port)) (load-fonts paper)))
+ (for-each
+ (lambda (f)
+ (format port "\n%%BeginFont: ~a\n" (car f))
+ (display (cdr f) port)
+ (display "\n%%EndFont\n" port))
+ (load-fonts paper)))
+
(display (setup paper) port)
; adobe note 5002: should initialize variables before loading routines.
#f)))
(if (or (not (= arglen siglen)) (< siglen 0) (< arglen 0))
(ly:error (string-append make-name ": "
- (_ "Wrong number of arguments. Expect: ~A, found ~A: ~S")
- (list siglen arglen args))))
+ (_ "Wrong number of arguments. Expect: ~A, found ~A: ~S"))
+ siglen arglen args))
(if error-msg
(ly:error
(string-append
(defs (ly:output-def-lookup layout 'text-font-defaults))
(props (ly:grob-alist-chain grob defs))
(circle (Text_interface::interpret_markup
- layout props (make-draw-circle-markup 0.8 0.1)))
+ layout props (make-draw-circle-markup 0.8 0.1 #f)))
(text-stencil (Text_interface::interpret_markup layout props text)))
+
(ly:stencil-add (centered-stencil text-stencil) circle)))
depth = ..
-SEXECUTABLES=convert-ly lilypond-book abc2ly etf2ly mup2ly midi2ly ps2png lilypond-pdfpc-helper
+SEXECUTABLES=convert-ly lilypond-book abc2ly etf2ly mup2ly midi2ly ps2png lilypond-pdfpc-helper lilypond-extract-fonts
STEPMAKE_TEMPLATES=script help2man po
LOCALSTEPMAKE_TEMPLATES = lilypond
#if __name__ == '__main__':
import lilylib as ly
+import fontextract
global _;_=ly._
global re;re = ly.re
_ ("write output to DIR")),
(_ ("COMMAND"), 'P', 'process',
_ ("process ly_files using COMMAND FILE...")),
+ (_('FILE'), '', 'psfonts',
+ _('extract all PS snippet fonts into FILE')),
('', 'V', 'verbose',
_ ("be verbose")),
('', 'v', 'version',
if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
lilypond_binary = 'lilypond'
+psfonts_file = ''
use_hash_p = 1
format = 0
output_name = 0
NOINDENT: INDENT,
}
+
# Recognize special sequences in the input.
#
# (?P<name>regex) -- Assign result of REGEX to NAME.
ly.exit (1)
return format
+def write_if_updated (file_name, lines):
+ try:
+ f = open (file_name)
+ oldstr = f.read ()
+ new_str = string.join (lines, '')
+ if old == new_str:
+ ly.progress (_ ("Output file is up to date."))
+ return
+ except:
+ pass
+
+ ly.progress (_ ("Writing output file."))
+ open (file_name, 'w').writelines (lines)
+
def do_file (input_filename):
# Ugh.
if not input_filename or input_filename == '-':
output_filename = '-'
output_file = sys.stdout
else:
- if not output_name:
- output_filename = input_base + format2ext[format]
- else:
+ if output_name:
if not os.path.isdir (output_name):
os.mkdir (output_name, 0777)
- output_filename = (output_name
- + '/' + input_base
- + format2ext[format])
+ os.chdir (output_name)
+ output_filename = input_base + format2ext[format]
if os.path.exists (input_filename) \
and os.path.exists (output_filename) \
and os.path.samefile (output_filename, input_fullname):
_ ("Output would overwrite input file; use --output."))
ly.exit (2)
- output_file = open (output_filename, 'w')
- if output_name:
- os.chdir (output_name)
try:
ly.progress (_ ("Reading %s...") % input_fullname)
source = in_handle.read ()
break
if filter_cmd:
- output_file.writelines ([c.filter_text () \
- for c in chunks])
-
+ write_if_updated (output_filename,
+ [c.filter_text () for c in chunks])
elif process_cmd:
do_process_cmd (chunks, input_fullname)
ly.progress (_ ("Compiling %s...") % output_filename)
- output_file.writelines ([s.replacement_text () \
- for s in chunks])
+ write_if_updated (output_filename,
+ [s.replacement_text ()
+ for s in chunks])
ly.progress ('\n')
+
+
def process_include (snippet):
os.chdir (original_dir)
name = snippet.substring ('filename')
ly.progress (_ ("Processing include: %s") % name)
ly.progress ('\n')
- do_file (name)
+ return do_file (name)
- map (process_include,
- filter (lambda x: is_derived_class (x.__class__,
- Include_snippet),
- chunks))
+ include_chunks = map (process_include,
+ filter (lambda x: is_derived_class (x.__class__,
+ Include_snippet),
+ chunks))
+
+
+ return chunks + reduce (lambda x,y: x + y, include_chunks, [])
+
except Compile_error:
os.chdir (original_dir)
ly.progress (_ ("Removing `%s'") % output_filename)
ly.progress ('\n')
-
- os.unlink (output_filename)
raise Compile_error
def do_options ():
- global format, output_name
+ global format, output_name, psfonts_file
global filter_cmd, process_cmd, verbose_p
(sh, long) = ly.getopt_args (option_definitions)
sys.exit (0)
elif o == '--verbose' or o == '-V':
verbose_p = 1
+ elif o == '--psfonts':
+ psfonts_file = a
elif o == '--warranty' or o == '-w':
if 1 or status:
ly.warranty ()
ly.setup_environment ()
try:
- do_file (file)
+ chunks = do_file (file)
+ if psfonts_file:
+ snippet_chunks = filter (lambda x: is_derived_class (x.__class__,
+ Lilypond_snippet),
+ chunks)
+ fontextract.extract_fonts (psfonts_file,
+ [x.basename() + '.eps'
+ for x in snippet_chunks])
+
except Compile_error:
ly.exit (1)