1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
9 ;;; * each markup function should have a doc string with
10 ;; syntax, description and example.
12 (use-modules (ice-9 regex))
14 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
15 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
17 (def-markup-command (stencil layout props stil) (ly:stencil?)
21 (def-markup-command (draw-circle layout props radius thickness)
23 "A circle of radius @var{radius} and thickness @var{thickness}"
24 (make-circle-stencil radius thickness))
26 (def-markup-command (circle layout props arg) (markup?)
27 "Draw a circle around @var{arg}. Use @code{thickness},
28 @code{circle-padding} and @code{font-size} properties to determine line
29 thickness and padding around the markup."
30 (let* ((th (chain-assoc-get 'thickness props 0.1))
31 (size (chain-assoc-get 'font-size props 0))
34 (chain-assoc-get 'circle-padding props 0.2)))
35 (m (interpret-markup layout props arg)))
36 (circle-stencil m th pad)))
38 (def-markup-command (with-url layout props url arg) (string? markup?)
39 "Add a link to URL @var{url} around @var{arg}. This only works in
41 (let* ((stil (interpret-markup layout props arg))
42 (xextent (ly:stencil-extent stil X))
43 (yextent (ly:stencil-extent stil Y))
44 (old-expr (ly:stencil-expr stil))
45 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
46 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
48 (def-markup-command (score layout props score) (ly:score?)
49 "Inline an image of music."
50 (let* ((systems (ly:score-embedded-format score layout)))
52 (if (= 0 (vector-length systems))
54 (ly:warn (_"No systems found in \\score markup. Does it have a \\layout? block"))
56 (let* ((stencil (ly:paper-system-stencil (vector-ref systems 0))))
58 (ly:stencil-aligned-to stencil Y CENTER)))))
60 (def-markup-command (simple layout props str) (string?)
61 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
62 @code{\\markup @{ \\simple #\"foo\" @}}."
63 (interpret-markup layout props str))
65 (def-markup-command (encoded-simple layout props sym str) (symbol? string?)
66 "A text string, encoded with encoding @var{sym}. See
67 @usermanref{Text encoding} for more information."
68 (Text_interface::interpret_string layout props sym str))
71 ;; TODO: use font recoding.
73 ;; (map make-word-markup (string-tokenize str)))))
75 (define-public empty-markup
76 (make-simple-markup ""))
79 (def-markup-command (postscript layout props str) (string?)
80 "This inserts @var{str} directly into the output as a PostScript
81 command string. Due to technicalities of the output backends,
82 different scales should be used for the @TeX{} and PostScript backend,
83 selected with @code{-f}.
86 For the TeX backend, the following string prints a rotated text
91 0 0 moveto /ecrm10 findfont
92 1.75 scalefont setfont 90 rotate (hello) show
96 The magical constant 1.75 scales from LilyPond units (staff spaces) to
99 For the postscript backend, use the following
102 gsave /ecrm10 findfont
103 10.0 output-scale div
104 scalefont setfont 90 rotate (hello) show grestore
109 (list 'embedded-ps str)
112 ;;(def-markup-command (fill-line layout props line-width markups)
113 ;; (number? markup-list?)
114 ;; no parser tag -- should make number? markuk-list? thingy
115 (def-markup-command (fill-line layout props markups)
117 "Put @var{markups} in a horizontal line of width @var{line-width}.
118 The markups are spaced/flushed to fill the entire line.
119 If there are no arguments, return an empty stencil.
121 (let* ((orig-stencils
122 (map (lambda (x) (interpret-markup layout props x))
126 (if (ly:stencil-empty? stc)
128 stc)) orig-stencils))
131 (if (ly:stencil-empty? stc)
133 (interval-length (ly:stencil-extent stc X))))
135 (text-width (apply + text-widths))
136 (word-count (length stencils))
137 (word-space (chain-assoc-get 'word-space props))
138 (line-width (chain-assoc-get 'linewidth props))
143 (/ (- line-width text-width) 2)
144 (/ (- line-width text-width) 2)))
147 (- line-width text-width)))
149 (get-fill-space word-count line-width text-widths))))
157 (line-stencils (if (= word-count 1)
164 (if (null? (remove ly:stencil-empty? orig-stencils))
166 (stack-stencils-padding-list X RIGHT fill-space-normal line-stencils))))
168 (define (get-fill-space word-count line-width text-widths)
169 "Calculate the necessary paddings between each two adjacent texts.
170 The lengths of all texts are stored in @var{text-widths}.
171 The normal formula for the padding between texts a and b is:
172 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
173 The first and last padding have to be calculated specially using the
174 whole length of the first or last text.
175 Return a list of paddings.
178 ;; special case first padding
179 ((= (length text-widths) word-count)
181 (- (- (/ line-width (1- word-count)) (car text-widths))
182 (/ (car (cdr text-widths)) 2))
183 (get-fill-space word-count line-width (cdr text-widths))))
184 ;; special case last padding
185 ((= (length text-widths) 2)
186 (list (- (/ line-width (1- word-count))
187 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
190 (- (/ line-width (1- word-count))
191 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
192 (get-fill-space word-count line-width (cdr text-widths))))))
194 (define (font-markup qualifier value)
195 (lambda (layout props arg)
196 (interpret-markup layout (prepend-alist-chain qualifier value props) arg)))
198 (def-markup-command (line layout props args) (markup-list?)
199 "Put @var{args} in a horizontal line. The property @code{word-space}
200 determines the space between each markup in @var{args}."
202 (chain-assoc-get 'word-space props)
203 (remove ly:stencil-empty?
204 (map (lambda (m) (interpret-markup layout props m)) args))))
206 (def-markup-command (fromproperty layout props symbol) (symbol?)
207 "Read the @var{symbol} from property settings, and produce a stencil
208 from the markup contained within. If @var{symbol} is not defined, it
209 returns an empty markup"
210 (let* ((m (chain-assoc-get symbol props)))
212 (interpret-markup layout props m)
213 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
216 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
217 "Apply the @var{procedure} markup command to
218 @var{arg}. @var{procedure} should take a single argument."
219 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
220 (set-object-property! anonymous-with-signature
223 (interpret-markup layout props (list anonymous-with-signature arg))))
226 (def-markup-command (combine layout props m1 m2) (markup? markup?)
227 "Print two markups on top of each other."
228 (let* ((s1 (interpret-markup layout props m1))
229 (s2 (interpret-markup layout props m2)))
230 (ly:stencil-add s1 s2)))
232 (def-markup-command (finger layout props arg) (markup?)
233 "Set the argument as small numbers."
234 (interpret-markup layout
235 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
238 (def-markup-command (fontsize layout props mag arg) (number? markup?)
239 "Set the relative font size, e.g.
241 A \\fontsize #2 @{ B C @} D
245 This will enlarge the B and the C by two steps.
249 (prepend-alist-chain 'font-size mag props)
252 (def-markup-command (magnify layout props sz arg) (number? markup?)
253 "Set the font magnification for the its argument. In the following
254 example, the middle A will be 10% larger:
256 A \\magnify #1.1 @{ A @} A
259 Note: magnification only works if a font-name is explicitly selected.
260 Use @code{\\fontsize} otherwise."
263 (prepend-alist-chain 'font-magnification sz props)
266 (def-markup-command (bold layout props arg) (markup?)
267 "Switch to bold font-series"
268 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
270 (def-markup-command (sans layout props arg) (markup?)
271 "Switch to the sans serif family"
272 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
274 (def-markup-command (number layout props arg) (markup?)
275 "Set font family to @code{number}, which yields the font used for
276 time signatures and fingerings. This font only contains numbers and
277 some punctuation. It doesn't have any letters. "
278 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
280 (def-markup-command (roman layout props arg) (markup?)
281 "Set font family to @code{roman}."
282 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
284 (def-markup-command (huge layout props arg) (markup?)
285 "Set font size to +2."
286 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
288 (def-markup-command (large layout props arg) (markup?)
289 "Set font size to +1."
290 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
292 (def-markup-command (normalsize layout props arg) (markup?)
293 "Set font size to default."
294 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
296 (def-markup-command (small layout props arg) (markup?)
297 "Set font size to -1."
298 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
300 (def-markup-command (tiny layout props arg) (markup?)
301 "Set font size to -2."
302 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
304 (def-markup-command (teeny layout props arg) (markup?)
305 "Set font size to -3."
306 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
308 (def-markup-command (caps layout props arg) (markup?)
309 "Set @code{font-shape} to @code{caps}."
310 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
312 ;(def-markup-command (latin-i layout props arg) (markup?)
313 ; "TEST latin1 encoding."
314 ; (interpret-markup layout (prepend-alist-chain 'font-shape 'latin1 props) arg))
316 (def-markup-command (dynamic layout props arg) (markup?)
317 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
318 @b{z}, @b{p}, and @b{r}. When producing phrases, like ``pi@`{u} @b{f}'', the
319 normal words (like ``pi@`{u}'') should be done in a different font. The
320 recommend font for this is bold and italic"
322 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
324 (def-markup-command (italic layout props arg) (markup?)
325 "Use italic @code{font-shape} for @var{arg}. "
326 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
328 (def-markup-command (typewriter layout props arg) (markup?)
329 "Use @code{font-family} typewriter for @var{arg}."
331 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
333 (def-markup-command (upright layout props arg) (markup?)
334 "Set font shape to @code{upright}."
336 layout (prepend-alist-chain 'font-shape 'upright props) arg))
338 (def-markup-command (doublesharp layout props) ()
339 "Draw a double sharp symbol."
341 (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
342 (def-markup-command (sesquisharp layout props) ()
343 "Draw a 3/2 sharp symbol."
344 (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
346 (def-markup-command (sharp layout props) ()
347 "Draw a sharp symbol."
348 (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
350 (def-markup-command (semisharp layout props) ()
351 "Draw a semi sharp symbol."
352 (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
354 (def-markup-command (natural layout props) ()
355 "Draw a natural symbol."
356 (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
358 (def-markup-command (semiflat layout props) ()
360 (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
362 (def-markup-command (flat layout props) ()
363 "Draw a flat symbol."
364 (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
366 (def-markup-command (sesquiflat layout props) ()
367 "Draw a 3/2 flat symbol."
368 (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
370 (def-markup-command (doubleflat layout props) ()
371 "Draw a double flat symbol."
372 (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
376 ;; TODO: should extract baseline-skip from each argument somehow..
378 (def-markup-command (column layout props args) (markup-list?)
379 "Stack the markups in @var{args} vertically. The property
380 @code{baseline-skip} determines the space between each markup in @var{args}."
382 -1 0.0 (chain-assoc-get 'baseline-skip props)
383 (remove ly:stencil-empty?
384 (map (lambda (m) (interpret-markup layout props m)) args))))
386 (def-markup-command (dir-column layout props args) (markup-list?)
387 "Make a column of args, going up or down, depending on the setting
388 of the @code{#'direction} layout property."
389 (let* ((dir (chain-assoc-get 'direction props)))
391 (if (number? dir) dir -1)
393 (chain-assoc-get 'baseline-skip props)
394 (map (lambda (x) (interpret-markup layout props x)) args))))
396 (def-markup-command (center-align layout props args) (markup-list?)
397 "Put @code{args} in a centered column. "
398 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
399 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
400 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
402 (def-markup-command (vcenter layout props arg) (markup?)
403 "Align @code{arg} to its Y center. "
404 (let* ((mol (interpret-markup layout props arg)))
405 (ly:stencil-aligned-to mol Y CENTER)))
407 (def-markup-command (hcenter layout props arg) (markup?)
408 "Align @code{arg} to its X center. "
409 (let* ((mol (interpret-markup layout props arg)))
410 (ly:stencil-aligned-to mol X CENTER)))
412 (def-markup-command (right-align layout props arg) (markup?)
413 "Align @var{arg} on its right edge. "
414 (let* ((m (interpret-markup layout props arg)))
415 (ly:stencil-aligned-to m X RIGHT)))
417 (def-markup-command (left-align layout props arg) (markup?)
418 "Align @var{arg} on its left edge. "
419 (let* ((m (interpret-markup layout props arg)))
420 (ly:stencil-aligned-to m X LEFT)))
422 (def-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
423 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
424 (let* ((m (interpret-markup layout props arg)))
425 (ly:stencil-aligned-to m axis dir)))
427 (def-markup-command (halign layout props dir arg) (number? markup?)
428 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
429 left-aligned, while @code{+1} is right. Values in between interpolate
430 alignment accordingly."
431 (let* ((m (interpret-markup layout props arg)))
432 (ly:stencil-aligned-to m X dir)))
434 (def-markup-command (musicglyph layout props glyph-name) (string?)
435 "This is converted to a musical symbol, e.g. @code{\\musicglyph
436 #\"accidentals.0\"} will select the natural sign from the music font.
437 See @usermanref{The Feta font} for a complete listing of the possible glyphs."
439 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
443 (def-markup-command (lookup layout props glyph-name) (string?)
444 "Lookup a glyph by name."
445 (ly:font-get-glyph (ly:paper-get-font layout props)
448 (def-markup-command (char layout props num) (integer?)
449 "Produce a single character, e.g. @code{\\char #65} produces the
451 (ly:get-glyph (ly:paper-get-font layout props) num))
453 (def-markup-command (raise layout props amount arg) (number? markup?)
455 This raises @var{arg}, by the distance @var{amount}.
456 A negative @var{amount} indicates lowering:
458 @lilypond[verbatim,fragment,relative=1]
459 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
461 The argument to @code{\\raise} is the vertical displacement amount,
462 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
463 raise objects in relation to their surrounding markups.
465 If the text object itself is positioned above or below the staff, then
466 @code{\\raise} cannot be used to move it, since the mechanism that
467 positions it next to the staff cancels any shift made with
468 @code{\\raise}. For vertical positioning, use the @code{padding}
469 and/or @code{extra-offset} properties. "
470 (ly:stencil-translate-axis (interpret-markup layout props arg)
473 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
474 "Make a fraction of two markups."
475 (let* ((m1 (interpret-markup layout props arg1))
476 (m2 (interpret-markup layout props arg2)))
477 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
478 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
479 (let* ((x1 (ly:stencil-extent m1 X))
480 (x2 (ly:stencil-extent m2 X))
481 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
482 ;; should stack mols separately, to maintain LINE on baseline
483 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
485 (ly:stencil-aligned-to stack Y CENTER))
487 (ly:stencil-aligned-to stack X LEFT))
488 ;; should have EX dimension
490 (ly:stencil-translate-axis stack 0.75 Y))))
493 ;; TODO: better syntax.
495 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
496 "Construct a note symbol, with stem. By using fractional values for
497 @var{dir}, you can obtain longer or shorter stems."
498 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
499 (size (chain-assoc-get 'font-size props 0))
500 (stem-length (* (magstep size) (max 3 (- log 1))))
501 (head-glyph (ly:font-get-glyph
503 (string-append "noteheads.s" (number->string (min log 2)))))
504 (stem-thickness 0.13)
505 (stemy (* dir stem-length))
506 (attachx (if (> dir 0)
507 (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
509 (attachy (* dir 0.28))
510 (stem-glyph (and (> log 0)
512 (cons attachx (+ attachx stem-thickness))
513 (cons (min stemy attachy)
515 (/ stem-thickness 3))))
516 (dot (ly:font-get-glyph font "dots.dot"))
517 (dotwid (interval-length (ly:stencil-extent dot X)))
518 (dots (and (> dot-count 0)
519 (apply ly:stencil-add
521 (ly:stencil-translate-axis
522 dot (* (+ 1 (* 2 x)) dotwid) X))
523 (iota dot-count 1)))))
524 (flaggl (and (> log 2)
525 (ly:stencil-translate
526 (ly:font-get-glyph font
527 (string-append "flags."
528 (if (> dir 0) "u" "d")
529 (number->string log)))
530 (cons (+ attachx (/ stem-thickness 2)) stemy)))))
532 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
533 (if (ly:stencil? stem-glyph)
534 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
535 (set! stem-glyph head-glyph))
536 (if (ly:stencil? dots)
539 (ly:stencil-translate-axis
541 (+ (if (and (> dir 0) (> log 2))
544 ;; huh ? why not necessary?
545 ;;(cdr (ly:stencil-extent head-glyph X))
552 (let ((divisor (log 2)))
553 (lambda (z) (inexact->exact (/ (log z) divisor)))))
555 (define (parse-simple-duration duration-string)
556 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
557 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
558 (if (and match (string=? duration-string (match:substring match 0)))
559 (let ((len (match:substring match 1))
560 (dots (match:substring match 2)))
561 (list (cond ((string=? len "breve") -1)
562 ((string=? len "longa") -2)
563 ((string=? len "maxima") -3)
564 (else (log2 (string->number len))))
565 (if dots (string-length dots) 0)))
566 (error "This is not a valid duration string:" duration-string))))
568 (def-markup-command (note layout props duration dir) (string? number?)
569 "This produces a note with a stem pointing in @var{dir} direction, with
570 the @var{duration} for the note head type and augmentation dots. For
571 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
572 a shortened down stem."
573 (let ((parsed (parse-simple-duration duration)))
574 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
576 (def-markup-command (normal-size-super layout props arg) (markup?)
577 "Set @var{arg} in superscript with a normal font size."
578 (ly:stencil-translate-axis
579 (interpret-markup layout props arg)
580 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
582 (def-markup-command (super layout props arg) (markup?)
585 @cindex lowering text
587 @cindex translating text
589 @cindex @code{\\super}
592 Raising and lowering texts can be done with @code{\\super} and
595 @lilypond[verbatim,fragment,relative=1]
596 c1^\\markup { E \"=\" mc \\super \"2\" }
600 (ly:stencil-translate-axis
603 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
605 (* 0.5 (chain-assoc-get 'baseline-skip props))
608 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
609 "This translates an object. Its first argument is a cons of numbers
611 A \\translate #(cons 2 -3) @{ B C @} D
613 This moves `B C' 2 spaces to the right, and 3 down, relative to its
614 surroundings. This command cannot be used to move isolated scripts
615 vertically, for the same reason that @code{\\raise} cannot be used for
619 (ly:stencil-translate (interpret-markup layout props arg)
622 (def-markup-command (sub layout props arg) (markup?)
623 "Set @var{arg} in subscript."
624 (ly:stencil-translate-axis
627 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
629 (* -0.5 (chain-assoc-get 'baseline-skip props))
632 (def-markup-command (beam layout props width slope thickness)
633 (number? number? number?)
634 "Create a beam with the specified parameters."
635 (let* ((y (* slope width))
636 (yext (cons (min 0 y) (max 0 y)))
637 (half (/ thickness 2)))
643 (ly:output-def-lookup layout 'blotdiameter))
645 (cons (+ (- half) (car yext))
646 (+ half (cdr yext))))))
648 (def-markup-command (normal-size-sub layout props arg) (markup?)
649 "Set @var{arg} in subscript, in a normal font size."
650 (ly:stencil-translate-axis
651 (interpret-markup layout props arg)
652 (* -0.5 (chain-assoc-get 'baseline-skip props))
655 (def-markup-command (hbracket layout props arg) (markup?)
656 "Draw horizontal brackets around @var{arg}."
657 (let ((th 0.1) ;; todo: take from GROB.
658 (m (interpret-markup layout props arg)))
659 (bracketify-stencil m X th (* 2.5 th) th)))
661 (def-markup-command (bracket layout props arg) (markup?)
662 "Draw vertical brackets around @var{arg}."
663 (let ((th 0.1) ;; todo: take from GROB.
664 (m (interpret-markup layout props arg)))
665 (bracketify-stencil m Y th (* 2.5 th) th)))
667 ;; todo: fix negative space
668 (def-markup-command (hspace layout props amount) (number?)
669 "This produces a invisible object taking horizontal space.
671 \\markup @{ A \\hspace #2.0 B @}
673 will put extra space between A and B, on top of the space that is
674 normally inserted before elements on a line.
677 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
678 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
680 (def-markup-command (override layout props new-prop arg) (pair? markup?)
681 "Add the first argument in to the property list. Properties may be
682 any sort of property supported by @internalsref{font-interface} and
683 @internalsref{text-interface}, for example
686 \\override #'(font-family . married) \"bla\"
690 (interpret-markup layout (cons (list new-prop) props) arg))
693 (def-markup-command (fontsize layout props increment arg) (number? markup?)
694 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
696 (let* ((fs (chain-assoc-get 'font-size props 0))
697 (bs (chain-assoc-get 'baseline-skip props 2))
699 (cons 'baseline-skip (* bs (magstep increment)))
700 (cons 'font-size (+ fs increment )))))
702 (interpret-markup layout (cons entries props) arg)))
704 (def-markup-command (bigger layout props arg) (markup?)
705 "Increase the font size relative to current setting"
706 (interpret-markup layout props
707 `(,fontsize-markup 1 ,arg)))
709 (def-markup-command (smaller layout props arg) (markup?)
710 "Decrease the font size relative to current setting"
711 (interpret-markup layout props
712 `(,fontsize-markup -1 ,arg)))
714 (def-markup-command larger (markup?) bigger-markup)
716 (def-markup-command (box layout props arg) (markup?)
717 "Draw a box round @var{arg}. Looks at @code{thickness},
718 @code{box-padding} and @code{font-size} properties to determine line
719 thickness and padding around the markup."
720 (let* ((th (chain-assoc-get 'thickness props 0.1))
721 (size (chain-assoc-get 'font-size props 0))
722 (pad (* (magstep size)
723 (chain-assoc-get 'box-padding props 0.2)))
724 (m (interpret-markup layout props arg)))
725 (box-stencil m th pad)))
727 ;;FIXME: is this working?
728 (def-markup-command (strut layout props) ()
729 "Create a box of the same height as the space in the current font."
730 (let ((m (Text_interface::interpret_markup layout props " ")))
731 (ly:make-stencil (ly:stencil-expr m)
732 (ly:stencil-extent m X)
735 (define number->mark-letter-vector (make-vector 25 #\A))
740 (if (= i (- (char->integer #\I) (char->integer #\A)))
742 (vector-set! number->mark-letter-vector j
743 (integer->char (+ i (char->integer #\A)))))
745 (define number->mark-alphabet-vector (list->vector
746 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
748 (define (number->markletter-string vec n)
749 "Double letters for big marks."
750 (let* ((lst (vector-length vec)))
753 (string-append (number->markletter-string vec (1- (quotient n lst)))
754 (number->markletter-string vec (remainder n lst)))
755 (make-string 1 (vector-ref vec n)))))
757 (def-markup-command (markletter layout props num) (integer?)
758 "Make a markup letter for @var{num}. The letters start with A to Z
759 (skipping I), and continues with double letters."
760 (Text_interface::interpret_markup layout props
761 (number->markletter-string number->mark-letter-vector num)))
763 (def-markup-command (markalphabet layout props num) (integer?)
764 "Make a markup letter for @var{num}. The letters start with A to Z
765 and continues with double letters."
766 (Text_interface::interpret_markup layout props
767 (number->markletter-string number->mark-alphabet-vector num)))
769 (def-markup-command (bracketed-y-column layout props indices args)
771 "Make a column of the markups in @var{args}, putting brackets around
772 the elements marked in @var{indices}, which is a list of numbers."
773 (define (sublist lst start stop)
774 (take (drop lst start) (- (1+ stop) start)))
776 (define (stencil-list-extent ss axis)
778 (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
779 (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
781 (define (stack-stencils stencils bskip last-stencil)
783 ((null? stencils) '())
784 ((not (ly:stencil? last-stencil))
786 (stack-stencils (cdr stencils) bskip (car stencils))))
788 (let* ((orig (car stencils))
789 (dir (chain-assoc-get 'direction props DOWN))
790 (new (ly:stencil-moved-to-edge last-stencil Y dir
794 (cons new (stack-stencils (cdr stencils) bskip new))))))
796 (define (make-brackets stencils indices acc)
799 (pair? (cdr indices)))
800 (let* ((encl (sublist stencils (car indices) (cadr indices)))
801 (x-ext (stencil-list-extent encl X))
802 (y-ext (stencil-list-extent encl Y))
805 (protusion (* 2.5 thick))
807 (ly:stencil-translate-axis
808 (ly:bracket Y y-ext thick protusion)
809 (- (car x-ext) pad) X))
810 (rb (ly:stencil-translate-axis
811 (ly:bracket Y y-ext thick (- protusion))
812 (+ (cdr x-ext) pad) X)))
815 stencils (cddr indices)
828 (chain-assoc-get 'baseline-skip props))
829 (stacked (stack-stencils
830 (remove ly:stencil-empty? stencils) 1.25 #f))
831 (brackets (make-brackets stacked indices '())))
833 (apply ly:stencil-add
834 (append stacked brackets))))