- (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
- line-stencils))))
-
- (line-word-space (cond
- ((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)
- ((null? (cdr line-stencils)) 0.0)
- (else (/ space-left (1- (length line-stencils))))))
-
- (line (stack-stencil-line
- line-word-space
- (if (= text-dir RIGHT)
- (reverse line-stencils)
- line-stencils))))
-
- (if (pair? (cdr line-break))
- (loop (cons line lines)
- (cdr line-break))
-
- (begin
- (if (= text-dir LEFT)
- (set! line
- (ly:stencil-translate-axis line
- (- line-width (interval-end (ly:stencil-extent line X)))
- X)))
- (reverse (cons line lines))
-
- )))
-
- ))
-
-
-(define (wordwrap-markups layout props args justify)
- (let*
- ((baseline-skip (chain-assoc-get 'baseline-skip props))
- (prop-line-width (chain-assoc-get 'line-width props #f))
- (line-width (if prop-line-width prop-line-width
- (ly:output-def-lookup layout 'line-width)))
- (word-space (chain-assoc-get 'word-space props))
- (text-dir (chain-assoc-get 'text-direction props RIGHT))
- (lines (wordwrap-stencils
- (remove ly:stencil-empty?
- (map (lambda (m) (interpret-markup layout props m)) args))
- justify word-space line-width
- text-dir)
- ))
-
- (stack-lines DOWN 0.0 baseline-skip lines)))
-
-(define-builtin-markup-command (justify layout props args) (markup-list?)
- "Like wordwrap, but with lines stretched to justify the margins.
-Use @code{\\override #'(line-width . X)} to set line-width, where X
-is the number of staff spaces."
-
- (wordwrap-markups layout props args #t))
-
-(define-builtin-markup-command (wordwrap layout props args) (markup-list?)
- "Simple wordwrap. Use @code{\\override #'(line-width . X)} to set
-line-width, where X is the number of staff spaces."
-
- (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 'line-width props))
- (word-space (chain-assoc-get 'word-space props))
-
- (para-strings (regexp-split
- (string-regexp-substitute "\r" "\n"
- (string-regexp-substitute "\r\n" "\n" arg))
- "\n[ \t\n]*\n[ \t\n]*"))
-
- (text-dir (chain-assoc-get 'text-direction props RIGHT))
- (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 text-dir
- )))
-
- lines))
-
- list-para-words)))
-
- (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
-
-
-(define-builtin-markup-command (wordwrap-string layout props arg) (string?)
- "Wordwrap a string. Paragraphs may be separated with double newlines"
- (wordwrap-string layout props #f arg))
+ (space-left (- line-width
+ (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
+ line-stencils))))
+ (line-word-space (cond ((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)
+ ((null? (cdr line-stencils)) 0.0)
+ (else (/ space-left (1- (length line-stencils))))))
+ (line (stack-stencil-line line-word-space
+ (if (= text-dir RIGHT)
+ (reverse line-stencils)
+ line-stencils))))
+ (if (pair? (cdr line-break))
+ (loop (cons line lines)
+ (cdr line-break))
+ (begin
+ (if (= text-dir LEFT)
+ (set! line
+ (ly:stencil-translate-axis
+ line
+ (- line-width (interval-end (ly:stencil-extent line X)))
+ X)))
+ (reverse (cons line lines)))))))
+
+(define-builtin-markup-list-command (wordwrap-internal layout props justify args)
+ (boolean? markup-list?)
+ ((line-width #f)
+ (word-space)
+ (text-direction RIGHT))
+ "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
+ (wordwrap-stencils (remove ly:stencil-empty?
+ (interpret-markup-list layout props args))
+ justify
+ word-space
+ (or line-width
+ (ly:output-def-lookup layout 'line-width))
+ text-direction))
+
+(define-builtin-markup-command (justify layout props args)
+ (markup-list?)
+ align
+ ((baseline-skip)
+ wordwrap-internal-markup-list)
+ "
+@cindex justifying text
+
+Like @code{\\wordwrap}, but with lines stretched to justify the margins.
+Use @code{\\override #'(line-width . @var{X})} to set the line width;
+@var{X}@tie{}is the number of staff spaces.
+
+@lilypond[verbatim,quote]
+\\markup {
+ \\justify {
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
+ do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ Ut enim ad minim veniam, quis nostrud exercitation ullamco
+ laboris nisi ut aliquip ex ea commodo consequat.
+ }
+}
+@end lilypond"
+ (stack-lines DOWN 0.0 baseline-skip
+ (wordwrap-internal-markup-list layout props #t args)))
+
+(define-builtin-markup-command (wordwrap layout props args)
+ (markup-list?)
+ align
+ ((baseline-skip)
+ wordwrap-internal-markup-list)
+ "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
+the line width, where @var{X} is the number of staff spaces.
+
+@lilypond[verbatim,quote]
+\\markup {
+ \\wordwrap {
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
+ do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ Ut enim ad minim veniam, quis nostrud exercitation ullamco
+ laboris nisi ut aliquip ex ea commodo consequat.
+ }
+}
+@end lilypond"
+ (stack-lines DOWN 0.0 baseline-skip
+ (wordwrap-internal-markup-list layout props #f args)))
+
+(define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
+ (boolean? string?)
+ ((line-width)
+ (word-space)
+ (text-direction RIGHT))
+ "Internal markup list command used to define @code{\\justify-string} and
+@code{\\wordwrap-string}."
+ (let* ((para-strings (regexp-split
+ (string-regexp-substitute
+ "\r" "\n"
+ (string-regexp-substitute "\r\n" "\n" 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))))
+ (wordwrap-stencils stencils
+ justify word-space
+ line-width text-direction)))
+ list-para-words)))
+ (apply append para-lines)))
+
+(define-builtin-markup-command (wordwrap-string layout props arg)
+ (string?)
+ align
+ ((baseline-skip)
+ wordwrap-string-internal-markup-list)
+ "Wordwrap a string. Paragraphs may be separated with double newlines.