From: Han-Wen Nienhuys Date: Wed, 13 Apr 2005 13:18:09 +0000 (+0000) Subject: * scm/framework-ps.scm (write-preamble): use (NAME . CONTENTS) and X-Git-Tag: release/2.5.19~13 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ea6d4c224d988252a9cff44776d0159b4c26a443;p=lilypond.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 089e0eed51..bea5059631 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,29 @@ +2005-04-13 Han-Wen Nienhuys + + * 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 * scm/framework-eps.scm (dump-stencils-as-EPSes): Massage messages. 2005-04-13 Han-Wen Nienhuys + * 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 diff --git a/Documentation/topdocs/GNUmakefile b/Documentation/topdocs/GNUmakefile index d607526ace..43c2b26ab1 100644 --- a/Documentation/topdocs/GNUmakefile +++ b/Documentation/topdocs/GNUmakefile @@ -7,3 +7,4 @@ HTML_FILES=$(addprefix $(outdir)/, $(TEXI_FILES:.texi=.html) $(TELY_FILES:.tely= include $(depth)/make/stepmake.make +$(outdir)/NEWS.nexi: NEWS.tely diff --git a/input/regression/markup-scheme.ly b/input/regression/markup-scheme.ly index c1f85aa4cf..10f9124b87 100644 --- a/input/regression/markup-scheme.ly +++ b/input/regression/markup-scheme.ly @@ -7,6 +7,13 @@ " } + +%{ + +For maintenance reasons, we don't excercise the entire markup command set. + +%} + \version "2.5.2" \score { { @@ -25,7 +32,6 @@ \combine "X" "+" \combine "o" "/" \box \column { \line { "string 1" } \line { "string 2" } } - "$\\emptyset$" \italic Norsk \super "2" \dynamic sfzp @@ -46,8 +52,6 @@ #:combine "X" "+" #:combine "o" "/" #:box #:column ("string 1" "string 2") - "$\\emptyset$" - #:draw-circle 1 0.3 " " #:italic "Norsk" #:super "2" diff --git a/lily/scm-option.cc b/lily/scm-option.cc index a4ded95e86..e7042cc44d 100644 --- a/lily/scm-option.cc +++ b/lily/scm-option.cc @@ -99,7 +99,7 @@ LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), "@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; diff --git a/make/ly-rules.make b/make/ly-rules.make index 391fcd84ed..c943392e6c 100644 --- a/make/ly-rules.make +++ b/make/ly-rules.make @@ -1,14 +1,14 @@ .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) @@ -36,6 +36,7 @@ $(outdir)/%-book.ps: $(outdir)/%.ps $(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 diff --git a/make/ly-vars.make b/make/ly-vars.make index 60194e5798..4cf95cd913 100644 --- a/make/ly-vars.make +++ b/make/ly-vars.make @@ -17,5 +17,4 @@ TEXINFO_SOURCES += $(TELY_FILES) $(ITELY_FILES) $(ITEXI_FILES) 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 diff --git a/make/lysdoc-targets.make b/make/lysdoc-targets.make index a3a313758b..147ee6366f 100644 --- a/make/lysdoc-targets.make +++ b/make/lysdoc-targets.make @@ -1,3 +1,5 @@ local-WWW: $(outdir)/$(NAME).html $(outdir)/$(NAME).ps.gz $(outdir)/$(NAME).pdf + +.PRECIOUS: $(outdir)/$(NAME).texi diff --git a/python/fontextract.py b/python/fontextract.py new file mode 100644 index 0000000000..12f4313b27 --- /dev/null +++ b/python/fontextract.py @@ -0,0 +1,112 @@ +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:]) diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index 167ca93990..6275b12ec6 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -39,14 +39,6 @@ (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)) @@ -202,65 +194,80 @@ 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) stringpfa 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) (stringregex) -- Assign result of REGEX to NAME. @@ -1324,6 +1329,20 @@ def guess_format (input_filename): 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 == '-': @@ -1351,15 +1370,12 @@ def do_file (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): @@ -1367,9 +1383,6 @@ def do_file (input_filename): _ ("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 () @@ -1413,37 +1426,41 @@ def do_file (input_filename): 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) @@ -1489,6 +1506,8 @@ def do_options (): 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 () @@ -1521,7 +1540,15 @@ def main (): 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)