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.
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);
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 ());
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 ();
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");
}
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_))
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}.")
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;
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),
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.
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)
+
(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")
(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)
(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) "")))
+ '()))
+
+ )))))
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?
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