]> git.donarmstrong.com Git - lilypond.git/commitdiff
* python/lilylib.py (make_ps_images): only compute bbox when needed.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 30 May 2004 21:55:13 +0000 (21:55 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 30 May 2004 21:55:13 +0000 (21:55 +0000)
* scripts/lilypond-book.py (process_snippets): use lily -f ps
files for generating pngs.

* scm/framework-ps.scm (output-classic-framework-ps): dump EPS
file with PFA fonts included.

* lily/score.cc (default_rendering): put header in too.

* lily/paper-line.cc (LY_DEFINE): change function to
ly:paper-line-extent

* scm/page-layout.scm (default-book-title): only add lines for
non-nil fields.
(default-score-title): idem.

* lily/paper-book.cc (book_title): separate function for the book
title.

* scm/page-layout.scm (default-book-title): only account for
markup fields.

* scm/framework-ps.scm: new file. Move high level interface from
output-ps.scm

* scm/framework-tex.scm (dump-line): new file. High level
interface for output (pages, systems, header).

* lily/paper-book.cc (split_string): new function
(output): output multiple formats, i.e. --format=ps,tex

12 files changed:
ChangeLog
lily/font-metric.cc
lily/paper-book.cc
lily/paper-line.cc
lily/score.cc
lily/stencil-scheme.cc
python/lilylib.py
scm/framework-ps.scm
scm/framework-tex.scm
scm/page-layout.scm
scm/safe-lily.scm
scripts/lilypond-book.py

index bdc094a535afdabfab96631e94cf16317736917d..e9eae179a643aa2c2c6e948f44d6649929ed0996 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2004-05-30  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * python/lilylib.py (make_ps_images): only compute bbox when needed.
+
+       * scripts/lilypond-book.py (process_snippets): use lily -f ps
+       files for generating pngs.
+
+       * scm/framework-ps.scm (output-classic-framework-ps): dump EPS
+       file with PFA fonts included.
+
+       * lily/score.cc (default_rendering): put header in too.
+
+       * lily/paper-line.cc (LY_DEFINE): change function to
+       ly:paper-line-extent
+
+       * scm/page-layout.scm (default-book-title): only add lines for
+       non-nil fields.
+       (default-score-title): idem.
+
        * lily/my-lily-parser.cc (parse_string): delete lexer after use.
 
        * lily/my-lily-lexer.cc (My_lily_lexer): copy keytable.
index 509daa608dc6684df4e85b53c6a14567e3dce9bd..9af80e57387275317987361f05cc07388dde4317 100644 (file)
@@ -196,7 +196,7 @@ LY_DEFINE (ly_font_name,"ly:font-name",
           1, 0, 0,
           (SCM font),
           "Given the font metric @var{font}, "
-          "return the corresponding file name.")
+          "return the corresponding name.")
 {
   Font_metric *fm = unsmob_metrics (font);
       
index acc87f61abbaf35e4829f35d1f0c097c9f23c641..6c5c02dabb61fcd52fa9f6980b84c970d1f284b7 100644 (file)
@@ -154,7 +154,7 @@ Paper_book::output (String outname)
       if (ly_c_module_p (header_))
        scopes = scm_cons (header_, scopes);
   
-      String func_nm = output_format_global;
+      String func_nm = format;
       func_nm = "output-framework-" + func_nm;
        
       SCM func = ly_scheme_function (func_nm.to_str0 ());
@@ -174,8 +174,6 @@ Paper_book::output (String outname)
 void
 Paper_book::classic_output (String outname)
 {
-  String format = "tex";
-  Paper_outputter *out = get_paper_outputter (outname + "." + format, format);
 
   /* Generate all stencils to trigger font loads.  */
   lines ();
@@ -189,19 +187,31 @@ Paper_book::classic_output (String outname)
   if (ly_c_module_p (score_lines_[0].header_))
     scopes = scm_cons (score_lines_[0].header_, scopes);
   //end ugh
-  
-  String func_nm = output_format_global;
-  func_nm = "output-classic-framework-" + func_nm;
+
+
+  Array<String> output_formats = split_string (output_format_global, ',');
+
+  for (int i = 0; i < output_formats.size (); i++)
+    {
+      String format = output_formats[i];
+      String func_nm = format;
+      func_nm = "output-classic-framework-" + func_nm;
       
-  SCM func = ly_scheme_function (func_nm.to_str0 ());
-  scm_apply_0 (func, scm_list_n (out->self_scm (),
-                                self_scm (),
-                                scopes,
-                                dump_fields (),
-                                scm_makfrom0str (outname.to_str0 ()),
-                                SCM_UNDEFINED
-                                )) ;
+      SCM func = ly_scheme_function (func_nm.to_str0 ());
 
+      Paper_outputter *out = get_paper_outputter (outname + "." + format, format);
+
+      scm_apply_0 (func, scm_list_n (out->self_scm (),
+                                    self_scm (),
+                                    scopes,
+                                    dump_fields (),
+                                    scm_makfrom0str (outname.to_str0 ()),
+                                    SCM_UNDEFINED
+                                    )) ;
+
+      scm_gc_unprotect_object (out->self_scm ());
+    }
+  
   progress_indication ("\n");
 }
 
@@ -428,11 +438,11 @@ c_ragged_page_breaks (SCM lines,
   Real book_height =0.;
   for (SCM s = lines ; ly_c_pair_p (s);  s = ly_cdr (s))
     {
-      book_height += unsmob_paper_line (s)->dim ()[Y_AXIS];
+      book_height += unsmob_paper_line (ly_car (s))->dim ()[Y_AXIS];
     }
 
   /*
-    UGH.
+    UGH. following stuff should go out of C++.
    */
   SCM scopes = SCM_EOL;
   if (ly_c_module_p (book->header_))
index b4dbf3b7a10230fa29e7816aa3d1e795cfae0cc4..945435365ec9f19fac24c425dbe47f9ac9c1f6d3 100644 (file)
@@ -91,15 +91,18 @@ Paper_line::to_stencil () const
   return stencil_;
 }
 
-LY_DEFINE (ly_paper_line_height, "ly:paper-line-height",
-          1, 0, 0, (SCM line),
-          "Return the height of @var{line}.")
+LY_DEFINE (ly_paper_line_height, "ly:paper-line-extent",
+          2, 0, 0, (SCM line, SCM axis),
+          "Return the extent of @var{line}.")
 {
   Paper_line *pl = unsmob_paper_line (line);
   SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
-  return scm_make_real (pl->dim ()[Y_AXIS]);
+  SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
+  Axis ax = (Axis)ly_scm2int (axis);
+  return scm_make_real (pl->dim ()[ax]);
 }
 
+
 LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
           1, 0, 0, (SCM line),
           "Return the number of @var{line}.")
index 7757b6a37d5bec7ae773893733116e4e6e27b7e0..aaa6663616390f980b9dea08067d0aa5c69b72af 100644 (file)
@@ -195,7 +195,7 @@ default_rendering (SCM music, SCM outdef,
            ugh, this is strange, Paper_book without a Book object.
           */
          Paper_book *paper_book = new Paper_book ();
-
+         paper_book->header_ = header;
          paper_book->bookpaper_ = unsmob_output_def (scaled_bookdef);
          
          Score_lines sc;
index 7971229f074f3968b10e2e81c05980851ec44c4e..be3831dc7900cac4d2ebe24ad9509e98c333c835 100644 (file)
@@ -13,8 +13,7 @@
   TODO: naming add/combine.
  */
 /*
-  UMGH. junkme!
-  
+  UGH. Junk all mutators.
  */
 LY_DEFINE (ly_stencil_set_extent_x, "ly:stencil-set-extent!",
           3, 0, 0, (SCM stil, SCM axis, SCM np),
index 4df1532a19d04302af197533d9faf5ac54728c94..01b3e8054070dac9a171f7d2020c484368de1dc8 100644 (file)
@@ -456,15 +456,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 +515,8 @@ 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)
+
index 69311a4ad9b494bbcd13472d4a76204bc81ee50d..49f382b227f857a5b40541f44d8afd1b09c594b2 100644 (file)
   (equal? (substring fontname 0 2) "cm"))
 
 
+(define (load-fonts bookpaper)
+  
+  (let*
+      ((fonts (ly:bookpaper-fonts bookpaper))
+       (font-names (uniq-list (sort (map ly:font-filename fonts) string<?)))
+       (pfas (map
+             (lambda (x)
+               (ly:kpathsea-gulp-file (string-append x ".pfa")))
+             
+             (filter string? font-names)))
+       )
+
+    (string-join pfas "\n")))
+
+
 (define (define-fonts bookpaper)
 
   (define font-list (ly:bookpaper-fonts bookpaper))
        "/" command "{ /" command " findfont 1 scalefont } bind def\n")))
   
   (define (guess-ps-fontname basename)
+    
     "We do not have the FontName, try to guess is from basename."
     (cond
+     (#t basename)
      ((tex-font? basename)
       ;; FIXME: we need proper Fontmap for the bluesky CM*, EC* fonts.
       ;; Only the fonts that we trace in mf/ are in our own FontMap.
   (string-append
    "%!PS-Adobe-3.0\n"
    "%%Creator: creator time-stamp \n"
-   "%%Pages: " (number->string page-count) "\n"
-   "%%PageOrder: Ascend\n"
-   "%%DocumentPaperSizes: " (ly:output-def-lookup paper 'papersize) "\n"
-   ;;(string-append "GNU LilyPond (" (lilypond-version) "), ")
-   ;;     (strftime "%c" (localtime (current-time))))
-   ;; FIXME: duplicated in every backend
-   (ps-string-def
-    "lilypond" 'tagline
-    (string-append "Engraved by LilyPond (version " (lilypond-version) ")"))
    ))
 
 (define (dump-page outputter page page-number page-count)
            (length pages)
            #f)
 
+   "%%Pages: " (number->string page-count) "\n"
+   "%%PageOrder: Ascend\n"
+   "%%DocumentPaperSizes: " (ly:output-def-lookup bookpaper 'papersize) "\n"
+    
     (output-variables bookpaper)
     (ly:gulp-file "music-drawing-routines.ps")
     (ly:gulp-file "lilyponddefs.ps")
   ))
 
 
-(define (dump-line outputter system)
-  (ly:outputter-dump-string
-   outputter
-    " start-system {\n set-ps-scale-to-lily-scale\n")
-  (ly:outputter-dump-stencil outputter (ly:page-line-stencil system))
-  (ly:outputter-dump-string
-   outputter
-  "} stop-system\n"))
 
   
 (define-public (output-classic-framework-ps outputter book scopes fields basename)
   (let*
       ((bookpaper  (ly:paper-book-book-paper book))
        (lines (ly:paper-book-lines book))
-       (pageno 0)
-       (page-count (length lines))
+       (y 0.0)
+       (scale (* 2.83464 (ly:output-def-lookup bookpaper 'outputscale)))
+       (total-y (apply + (map (lambda (z) (ly:paper-line-extent z Y))  lines)))
+       (x-ext '(-8 . 0))
+       (lineno 0)
        )
+    
+    (define (dump-line outputter system)
+      (let*
+         ((stil  (ly:paper-line-stencil  system)))
+          
+      (ly:outputter-dump-string
+       outputter
+       (string-append
+       " 0.0 "
+       (ly:number->string y)
+       " start-system {\n set-ps-scale-to-lily-scale\n"))
+      (set! y (+ y (ly:paper-line-extent system Y)))
+      (ly:outputter-dump-stencil outputter stil)
+      (ly:outputter-dump-string
+       outputter
+       "} stop-system\n")))
+
+    (define (to-pt x)
+      (inexact->exact (round (* scale x))))
+    (for-each (lambda (l)
+               (set! x-ext (interval-union x-ext (cons 0.0 (ly:paper-line-extent l X))))
+               )
+               lines)
   (for-each
    (lambda (x)
      (ly:outputter-dump-string outputter x))
    (list
-    (header bookpaper
-           (length pages)
-           #f)
-
+    "%!PS-Adobe-2.0 EPSF-2.0\n"
+    "%%Creator: LilyPond \n"
+    "%%BoundingBox: "
+    (ly:number->string (to-pt (car x-ext))) " "
+    (ly:number->string (to-pt 0)) " " 
+    (ly:number->string (to-pt (cdr x-ext))) " "
+    (ly:number->string (to-pt total-y)) "\n"
+    "%%EndComments\n"
     (output-variables bookpaper)
     (ly:gulp-file "music-drawing-routines.ps")
     (ly:gulp-file "lilyponddefs.ps")
+    (load-fonts bookpaper)
     (define-fonts bookpaper)
     ))
 
   (for-each
    (lambda (line)
-     (set! pageno (1+ pageno))
+     (set! lineno (1+ lineno))
      (dump-line outputter line)) ;   pageno page-count))
    lines)
   (ly:outputter-dump-string outputter "\n")
index 16682df3db5555c01f13c4260e6a32f85c2b4aa5..69d4a99ada1bd3cb4c18872c8e25c8ef9f05ce23 100644 (file)
   (ly:outputter-dump-string
    putter
    (string-append "\\leavevmode\n\\lybox{0}{0}{0}{"
-                 (ly:number->string (ly:paper-line-height line))
+                 (ly:number->string (ly:paper-line-extent line Y))
                  "}{"))
 
    (ly:outputter-dump-stencil putter (ly:paper-line-stencil line))
    (ly:outputter-dump-string
     putter
     (if last?  
+       "}%\n"
        "}\\interscoreline\n"
-       "}%\n"))
-   )
+       )) )
 
 (define-public (output-framework-tex outputter book scopes fields basename)
   (let*
             bookpaper
             (length lines)
             #f)
-   
-   (output-scopes scopes fields basename)
-   (define-fonts bookpaper)
-   (header-end)))
+    "\\def\\lilypondclassic{1}%\n"
+    (output-scopes scopes fields basename)
+    (define-fonts bookpaper)
+    (header-end)))
 
   (for-each
    (lambda (line)
index 5312e1a3b5bf8793c251717743872b8c8149ad38..c8168c138dcc90fa9b69d69b6408ab7a3e01c784 100644 (file)
@@ -78,7 +78,7 @@
   
 (define (robust-line-height line)
   (if (null? line) 0
-      (ly:paper-line-height line)))
+      (ly:paper-line-extent line Y)))
   
 (define (robust-line-number node)
   (if (null? node) 0
   (define (get sym)
     (let ((x (ly:modules-lookup scopes sym)))
       (if (markup? x) x "")))
-
+  (define (has sym)
+    (markup?  (ly:modules-lookup scopes sym)))
+  
   (let ((props (page-properties paper)))
     
     (interpret-markup
      paper props
-     (markup
-      #:column
-      (#:override '(baseline-skip . 4)
-                 #:column
-                 (#:fill-line
-                  (#:normalsize (get 'dedication))
-                  #:fill-line
-                  (#:huge #:bigger #:bigger #:bigger #:bigger #:bold (get 'title))
-                  #:override '(baseline-skip . 3)
-                  #:column
-                  (#:fill-line
-                   (#:large #:bigger #:bigger #:bold (get 'subtitle))
-                   #:fill-line (#:bigger #:bigger #:bold (get 'subsubtitle)))
-                  #:override '(baseline-skip . 5)
-                  #:column ("")
-                  #:override '(baseline-skip . 2.5)
-                  #:column
-                  (#:fill-line
-                   (#:bigger (get 'poet) #:large #:bigger #:caps (get 'composer))
-                   #:fill-line (#:bigger (get 'texttranslator) #:bigger (get 'opus))
-                   #:fill-line
-                   (#:bigger (get 'meter) #:bigger (get 'arranger))
-                   ""
-                   #:fill-line (#:large #:bigger (get 'instrument))
-                   " "
-                   #:fill-line (#:large #:bigger #:caps (get 'piece) ""))))))))
-
+     (make-override-markup
+       '(baseline-skip . 4)
+       (make-column-markup
+       (append
+        (if (has 'dedication)
+            (list (markup #:fill-line
+                    (#:normalsize (get 'dedication))))
+            '())
+        
+        (if (has 'title)
+           (list (markup (#:fill-line
+                          (#:huge #:bigger #:bigger #:bigger #:bigger #:bold (get 'title)))))
+           '())
+
+        (if (or (has 'subtitle) (has 'subsubtitle))
+            (list
+             (make-override-markup
+              '(baseline-skip . 3)
+             (make-column-markup
+              (list
+              (markup #:fill-line
+                      (#:large #:bigger #:bigger #:bold (get 'subtitle))
+                      #:fill-line (#:bigger #:bigger #:bold (get 'subsubtitle)))
+              (markup #:override '(baseline-skip . 5)
+                      #:column ("")))
+
+              ))
+            )
+            '())
+        
+        (list
+         (make-override-markup
+         '(baseline-skip . 2.5)
+         (make-column-markup
+           (append
+            (if (or (has 'poet) (has 'composer))
+               (list (markup #:fill-line
+                             (#:bigger (get 'poet) #:large #:bigger #:caps (get 'composer))))
+               '())
+            (if (or (has 'texttranslator) (has 'opus))
+                (list
+                 (markup 
+                  #:fill-line (#:bigger (get 'texttranslator) #:bigger (get 'opus))))
+                '())
+            (if (or (has 'meter) (has 'arranger))
+                (list
+                 (markup #:fill-line
+                         (#:bigger (get 'meter) #:bigger (get 'arranger))))
+                '())
+
+            (if (has 'instrument)
+                (list ""
+                      (markup #:fill-line (#:large #:bigger (get 'instrument))))
+                '())
+            (if (has 'piece)
+                (list ""
+                      (markup #:fill-line (#:large #:bigger #:caps (get 'piece) "")))
+                '())
+            )))))))
+     )))
+            
+  
 (define-public (default-user-title paper markup)
   "Generate book title from header markup."
   (if (markup? markup)
   
   (define (get sym)
     (let ((x (ly:modules-lookup scopes sym)))
-      (if (and x (not (unspecified? x))) x "")))
+      (if (markup? x) x "")))
+  
+  (define (has sym)
+    (markup? (ly:modules-lookup scopes sym)))
   
   (let ((props (page-properties paper)))
     
     (interpret-markup
      paper props
-     (markup
-      #:column
-      (#:override '(baseline-skip . 4)
-                 #:column
-                 (#:fill-line
-                  ("" (get 'opus))
-                  #:fill-line (#:large #:bigger #:caps (get 'piece) "")))))))
+      (make-override-markup
+       '(baseline-skip . 4)
+       (make-column-markup
+       (append
+        (if (has 'opus)
+            (list (markup #:fill-line ("" (get 'opus))))
+            '())
+        (if (has 'piece)
+            (list (markup #:fill-line (#:large #:bigger #:caps (get 'piece) "")))
+            '()))
+       
+       )))))
index bcd9a41fa4622c111bf4b60a32da80ac209c9893..a99269de54f3a3e0b60530e00bb6a63cc212cd77 100644 (file)
@@ -96,7 +96,7 @@
      ly:paper-get-font
      ly:paper-get-number
      ly:paper-line-break-score
-     ly:paper-line-height
+     ly:paper-line-extent
      ly:paper-line-number
      ly:paper-line-stencil
      ly:paper-line?
index 1da2f27ff794586af7f38114d3a250c9f788c301..c22601f3815c23386dde82a5e5a41a69682c8a06 100644 (file)
@@ -795,9 +795,12 @@ def process_snippets (cmd, snippets):
 
        if format == HTML or format == TEXINFO:
                for i in names:
-                       if os.path.exists (i + '.tex'):
+                       if not os.path.exists (i + '.ps') and os.path.exists (i + '.tex'):
                                to_eps (i)
                                ly.make_ps_images (i + '.eps', resolution=110)
+                       elif os.path.exists (i + '.ps'):
+                               ly.make_ps_images (i + '.ps', resolution=110)
+
 
 LATEX_DOCUMENT = r'''
 %(preamble)s