CVSROOT: /cvsroot/lilypond Module name: lilypond Branch: Changes by: Han-Wen Nienhuys <[EMAIL PROTECTED]> 05/06/29 10:55:46
Modified files: . : ChangeLog Documentation/topdocs: NEWS.tely scm : define-markup-commands.scm lily-library.scm Added files: input/regression: markup-word-wrap.ly Log message: * Documentation/topdocs/NEWS.tely (Top): refresh. * scm/define-markup-commands.scm (wordwrap-string): new function: split string in paras and words. (wordwrap-markups): new function. (wordwrap-stencils): new function. (justify): use it. (wordwrap): use it. (wordwrap-string): use it (justify-string): use it. * scm/lily-library.scm (regexp-split): new function. * scm/define-markup-commands.scm: remove encoded-simple. remove font-markup. (fontsize): remove old version of fontsize. (wordwrap): new markup function. Wrap into paragraphs. CVSWeb URLs: http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ChangeLog.diff?tr1=1.3839&tr2=1.3840&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/Documentation/topdocs/NEWS.tely.diff?tr1=1.40&tr2=1.41&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/input/regression/markup-word-wrap.ly?rev=1.1 http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/define-markup-commands.scm.diff?tr1=1.95&tr2=1.96&r1=text&r2=text http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/scm/lily-library.scm.diff?tr1=1.37&tr2=1.38&r1=text&r2=text Patches: Index: lilypond/ChangeLog diff -u lilypond/ChangeLog:1.3839 lilypond/ChangeLog:1.3840 --- lilypond/ChangeLog:1.3839 Wed Jun 29 09:49:32 2005 +++ lilypond/ChangeLog Wed Jun 29 10:55:44 2005 @@ -1,5 +1,18 @@ 2005-06-29 Han-Wen Nienhuys <[EMAIL PROTECTED]> + * Documentation/topdocs/NEWS.tely (Top): refresh. + + * scm/define-markup-commands.scm (wordwrap-string): new function: + split string in paras and words. + (wordwrap-markups): new function. + (wordwrap-stencils): new function. + (justify): use it. + (wordwrap): use it. + (wordwrap-string): use it + (justify-string): use it. + + * scm/lily-library.scm (regexp-split): new function. + * scm/define-markup-commands.scm: remove encoded-simple. remove font-markup. (fontsize): remove old version of fontsize. Index: lilypond/Documentation/topdocs/NEWS.tely diff -u lilypond/Documentation/topdocs/NEWS.tely:1.40 lilypond/Documentation/topdocs/NEWS.tely:1.41 --- lilypond/Documentation/topdocs/NEWS.tely:1.40 Mon Jun 27 18:11:22 2005 +++ lilypond/Documentation/topdocs/NEWS.tely Wed Jun 29 10:55:45 2005 @@ -28,311 +28,21 @@ @node Top @top @end ifnottex [EMAIL PROTECTED] New features in 2.6 since 2.4 [EMAIL PROTECTED] New features in 2.7 since 2.6 @itemize @bullet @item -Global font styles (roman, sans, typewriter) can be defined for each [EMAIL PROTECTED] block, with - [EMAIL PROTECTED] -#(define fonts - (make-pango-font-tree - "Times New Roman" "Helvetica" "Courier" - (/ myStaffSize 20))) [EMAIL PROTECTED] verbatim - - [EMAIL PROTECTED] -Newly created staves and lyric lines, can be put in any vertical order, -by setting @code{alignBelowContext} or @code{alignAboveContext} -properties in the newly created context. An example of the use of this -is in @inputfileref{input/regression,alignment-order.ly}. - -This feature has been sponsored by Bertalan Fodor. - - [EMAIL PROTECTED] -Staves may be stopped and started halfway a line, e.g. - [EMAIL PROTECTED],fragment,verbatim] -b4 b \stopStaff b \startStaff b [EMAIL PROTECTED] lilypond - [EMAIL PROTECTED] -This feature has been sponsored by Hans Forbrich. - [EMAIL PROTECTED] -Grid lines, vertical lines synchronized with notes, can be drawn across -staves, by adding suitable engravers. -An example is in @inputfileref{input/regression,grid-lines.ly}, - [EMAIL PROTECTED] - [EMAIL PROTECTED] -Lines, such as glissandi or Text-spanner lines, can have arrows at the -end, e.g. - [EMAIL PROTECTED],fragment] -\override Glissando #'arrow = ##t -b''2 \glissando b' [EMAIL PROTECTED] lilypond - [EMAIL PROTECTED] -Chord names may now be rendered in Italian and French. - [EMAIL PROTECTED] [EMAIL PROTECTED] now makes @file{lilypond} print line numbers -relative to the input file for every error message. - [EMAIL PROTECTED] -The command @code{\epsfile} allows inclusion of EPS graphics into -markup texts. - [EMAIL PROTECTED] -There is a music function @code{\displayMusic}, which will display a -music expression as indented Scheme code. - [EMAIL PROTECTED] -Automatic beaming is now specified explicitly for each moment -throughout a measure, which enables automatic beaming in compound -measures, as demonstrated in the following item. - [EMAIL PROTECTED] -A plus sign was added to the number font. This enables printing of -compound time signatures - [EMAIL PROTECTED] - [EMAIL PROTECTED] -A new @code{\circle} markup command allows for all kinds of circled -texts - [EMAIL PROTECTED] - [EMAIL PROTECTED] -String numbers are now printed on chords as well - [EMAIL PROTECTED],relative=1,raggedright,fragment,verbatim] -<c\1 e\2 g\3> [EMAIL PROTECTED] lilypond - -See also @inputfileref{input/regression,string-number.ly}. - -This feature was sponsored by Gunther Strube. - [EMAIL PROTECTED] -Notes with ledger lines will be kept at a distance, so they never -disappear. - [EMAIL PROTECTED] -Clefs that are below notes of other staves are now spaced according to -engraving conventions. - [EMAIL PROTECTED] -Markup texts can be appended to a @code{\score} block or toplevel -music expression, for example, - [EMAIL PROTECTED] -\relative @{ c' d e @} -\markup @{ first text @} -\markup @{ second text @} [EMAIL PROTECTED] example [EMAIL PROTECTED] FIXME, cannot use toplevel music examples in lilypond-book, [EMAIL PROTECTED] but it works at toplevel too, as shown. [EMAIL PROTECTED],raggedright] -\paper { - vsize = 60\mm - hsize = 60\mm - %% FIXME? - printpagenumber = ##f -} -\header { - tagline = "" -} -\book { - \score { - \relative { c' d e } - } - \markup { first text } - \markup { second text } -} [EMAIL PROTECTED] lilypond - - -See @inputfileref{input/regression,score-text.ly}. - - [EMAIL PROTECTED] [EMAIL PROTECTED]'s @code{kpathsea} library is loaded dynamically, so installing -LilyPond does not require installing @TeX{} anymore. - [EMAIL PROTECTED] -Point and click editing is now supported in the PS/PDF backend as -well. -See [EMAIL PROTECTED] [EMAIL PROTECTED]/../user/out-www/lilypond/Point-and-click.html,Point and click}. [EMAIL PROTECTED] ifhtml [EMAIL PROTECTED] -the section Point and click in he user manual. [EMAIL PROTECTED] ifnothtml - [EMAIL PROTECTED] -White mensural ligatures now conform more closely to Renaissance -usage. - - [EMAIL PROTECTED] -With the new @code{tieWaitForNote} property, arpeggios may be written -out using ties, for example, - [EMAIL PROTECTED],verbatim,relative=1,raggedright] -\set tieWaitForNote = ##t -\grace { c16[~ e~ g]~ } <c, e g>4 [EMAIL PROTECTED] lilypond - -Thanks to Steve Doonan for funding development of this feature. - [EMAIL PROTECTED] -Individual objects may be assigned colors, for example, - [EMAIL PROTECTED],relative=1,verbatim,raggedright] - \override NoteHead #'color = #red - c4 [EMAIL PROTECTED] lilypond - [EMAIL PROTECTED] -The PostScript backend is now used by default. This backend requires -less machinery to run, and gives more consistent results. - -Ghostscript 8.x is required for PDF output. Earlier versions may hang -while converting PostScript to PDF. - [EMAIL PROTECTED] -Separator slashes may be inserted between systems in a score. For an -example, see @inputfileref{input/regression,system-separator.ly}: - [EMAIL PROTECTED] -Locations of errors in the input are now calculated more precisely. - - - [EMAIL PROTECTED] -LilyPond now uses Pango and FontConfig for selecting and rendering -UTF-8 input in [EMAIL PROTECTED] backends. A font may be selected by using a -FontConfig name, - [EMAIL PROTECTED] -\override TextScript #'font-name = #"Serif" [EMAIL PROTECTED] example - - [EMAIL PROTECTED] -or using the classic font selection mechanism - [EMAIL PROTECTED] -\override TextScript #'font-family = #'roman -\override TextScript #'font-series = #'bold [EMAIL PROTECTED] example - -Any Type1 and TrueType font recognized by FontConfig is available in -LilyPond as well. - [EMAIL PROTECTED] -Metrics of blocks of text can be retrieved from (La)@TeX{} directly, -using the @code{-f texstr} output backend. This provides exact metrics -for texts, including kerning and accents. - [EMAIL PROTECTED] -LilyPond now uses FreeType to read the Feta font as an OpenType -font. This is a cleaner design and more robust. Recent versions of -FontForge (2004 1211 or newer) and Freetype are required. - [EMAIL PROTECTED] -The SVG backend is now a fully functional backend. - [EMAIL PROTECTED] -A new script, @code{\espressivo} has been added, for a combination of -crescendo and decrescendo on a single note. - [EMAIL PROTECTED] -In markups, expressions stacked with @code{\column}, [EMAIL PROTECTED], etc, are not grouped with @code{< ... >} anymore, -but with @[EMAIL PROTECTED] ... @}}, eg: [EMAIL PROTECTED] -\markup \column @{ - \line @{ first line @} - \line @{ second line @} [EMAIL PROTECTED] [EMAIL PROTECTED] example - [EMAIL PROTECTED] -LilyPond will now avoid line breaks that cause long texts to stick -outside of the page staff. - [EMAIL PROTECTED] -Grace notes following a main note, used to be entered by letting the -grace notes follow a skip in a parallel expression, for example, - [EMAIL PROTECTED] - << { d1 } - { s2 \grace { c16[ d] } } >> - c4 [EMAIL PROTECTED] verbatim - [EMAIL PROTECTED] -This can now be shortened by doing - [EMAIL PROTECTED] -\afterGrace @{ d1 @} @{ c16[ d] @} [EMAIL PROTECTED] example - [EMAIL PROTECTED] -Pagebreaks can now be forced or forbidden after title blocks. This is -achieved by setting @code{breakbefore} in the @code{\header} block to -true or false. - [EMAIL PROTECTED] -Shaped note heads. This feature has been sponsored by Jonathan Walther, - [EMAIL PROTECTED],fragment,verbatim,raggedright] - \set shapeNoteStyles = ##(do re mi fa #f la ti) - c d e f g a b c d e f g a b c [EMAIL PROTECTED] lilypond - [EMAIL PROTECTED] -Layout for titles, page header and footer can now be entered as [EMAIL PROTECTED] commands. - [EMAIL PROTECTED] Positioning of slurs can now be adjusted manually - [EMAIL PROTECTED] Grace notes are correctly quoted and formatted when using cue notes. - [EMAIL PROTECTED] Cue notes can now be created with - [EMAIL PROTECTED] -\cueDuring [EMAIL PROTECTED] [EMAIL PROTECTED] @{ @var{music} @} [EMAIL PROTECTED] example - [EMAIL PROTECTED] -This will set stem directions and put the cue notes in the @code{cue} [EMAIL PROTECTED] - [EMAIL PROTECTED] Stemlets, short stems over beamed rests, have been added. - [EMAIL PROTECTED],verbatim,fragment,raggedright] -\override Stem #'stemlet-length = #0.75 -c8[ r8 c16 r16 c8] [EMAIL PROTECTED] lilypond +Markup now supports formatting of text paragraphs, using [EMAIL PROTECTED] and @code{\justify}. +This feature was sponsored by Sven Axelsson. @end itemize @ifhtml For older news, go to [EMAIL PROTECTED]://lilypond.org/doc/v2.4/Documentation/topdocs/out-www/NEWS.html}. [EMAIL PROTECTED]://lilypond.org/doc/v2.6/Documentation/topdocs/out-www/NEWS.html}. @end ifhtml @bye Index: lilypond/scm/define-markup-commands.scm diff -u lilypond/scm/define-markup-commands.scm:1.95 lilypond/scm/define-markup-commands.scm:1.96 --- lilypond/scm/define-markup-commands.scm:1.95 Wed Jun 29 09:49:33 2005 +++ lilypond/scm/define-markup-commands.scm Wed Jun 29 10:55:45 2005 @@ -371,9 +371,17 @@ (remove ly:stencil-empty? stencils)))) -(def-markup-command (wordwrap layout props args) (markup-list?) - "Perform simple wordwrap on @var{args}" - +(define (wordwrap-stencils stencils + justify base-space line-width + ) + + "Perform simple wordwrap, return stencil of each line." + (define space (if justify + + ;; justify only stretches lines. + (* 0.7 base-space) + base-space)) + (define (take-list width space stencils accumulator accumulated-width) "Return (head-list . tail) pair, with head-list fitting into width" @@ -383,7 +391,6 @@ ((first (car stencils)) (first-wid (cdr (ly:stencil-extent (car stencils) X))) (newwid (+ space first-wid accumulated-width)) - (word-space (chain-assoc-get 'word-space props)) ) (if @@ -396,24 +403,10 @@ newwid) (cons accumulator stencils)) ))) - - (let* - ((line-width (chain-assoc-get 'linewidth props)) - (justify (chain-assoc-get 'word-wrap-justify props #f)) - (base-space (chain-assoc-get 'word-space props)) - (space (if justify - - ;; justify only stretches lines. - (* 0.7 base-space) - base-space)) - - (baseline-skip (chain-assoc-get 'baseline-skip props))) (let loop ((lines '()) - (todo - (remove ly:stencil-empty? - (map (lambda (m) (interpret-markup layout props m)) args)))) + (todo stencils)) (let* ((line-break (take-list line-width space todo @@ -426,6 +419,7 @@ ((not justify) space) ;; don't stretch last line of paragraph. + ;; hmmm . bug - will overstretch the last line in some case. ((null? (cdr line-break)) base-space) ((null? line-stencils) 0.0) @@ -440,21 +434,71 @@ (loop (cons line lines) (cdr line-break)) - (stack-lines DOWN 0.0 baseline-skip (reverse (cons line lines))) + (reverse (cons line lines)) )) - ))) - + )) + + +(define (wordwrap-markups layout props args justify) + (let* + ((baseline-skip (chain-assoc-get 'baseline-skip props)) + (line-width (chain-assoc-get 'linewidth props)) + (word-space (chain-assoc-get 'word-space props)) + (lines (wordwrap-stencils + (remove ly:stencil-empty? + (map (lambda (m) (interpret-markup layout props m)) args)) + justify word-space line-width) + )) + (stack-lines DOWN 0.0 baseline-skip lines))) (def-markup-command (justify layout props args) (markup-list?) + "Simple wordwrap" + + (wordwrap-markups layout props args #t)) + +(def-markup-command (wordwrap layout props args) (markup-list?) "Like wordwrap, but with lines stretched to justify the margins." - - (interpret-markup layout - (prepend-alist-chain 'word-wrap-justify #t props) - (list wordwrap-markup args) - )) + (wordwrap-markups layout props args #f)) + +(define (wordwrap-string layout props justify arg) + (let* + ((baseline-skip (chain-assoc-get 'baseline-skip props)) + (line-width (chain-assoc-get 'linewidth props)) + (word-space (chain-assoc-get 'word-space props)) + (para-strings (regexp-split arg "\n[ \t\n]*\n[ \t\n]*")) + + (list-para-words (map (lambda (str) + (regexp-split str "[ \t\n]+")) + para-strings)) + (para-lines (map (lambda (words) + (let* + ((stencils + (remove + ly:stencil-empty? (map + (lambda (x) + (interpret-markup layout props x)) + words))) + (lines (wordwrap-stencils stencils + justify word-space line-width))) + + lines)) + + list-para-words))) + + (stack-lines DOWN 0.0 baseline-skip (apply append para-lines)))) + + +(def-markup-command (wordwrap-string layout props arg) (string?) + "Wordwrap a string. Paragraphs may be separated with double newlines" + (wordwrap-string layout props #f arg)) + +(def-markup-command (justify-string layout props arg) (string?) + "Justify a string. Paragraphs may be separated with double newlines" + (wordwrap-string layout props #t arg)) + (def-markup-command (combine layout props m1 m2) (markup? markup?) "Print two markups on top of each other." (let* ((s1 (interpret-markup layout props m1)) Index: lilypond/scm/lily-library.scm diff -u lilypond/scm/lily-library.scm:1.37 lilypond/scm/lily-library.scm:1.38 --- lilypond/scm/lily-library.scm:1.37 Tue Jun 14 00:44:14 2005 +++ lilypond/scm/lily-library.scm Wed Jun 29 10:55:46 2005 @@ -314,6 +314,26 @@ (define-public (string-regexp-substitute a b str) (regexp-substitute/global #f a str 'pre b 'post)) + +(define (regexp-split str regex) + (define matches '()) + (define end-of-prev-match 0) + (define (notice match) + (set! matches (cons (substring (match:string match) + end-of-prev-match + (match:start match)) + matches)) + (set! end-of-prev-match (match:end match))) + + (regexp-substitute/global #f regex str notice 'post) + + (if (< end-of-prev-match (string-length str)) + (set! + matches + (cons (substring str end-of-prev-match (string-length str)) matches))) + + (reverse matches)) + ;;;;;;;;;;;;;;;; ; other (define (sign x) _______________________________________________ Lilypond-cvs mailing list Lilypond-cvs@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-cvs