Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / input / regression / stencil-hacking.ly
blobb95fffb857b9f7c44ad65c8ed07f38299097b309
2 \version "2.12.0"
4 \header { texidoc=" You can write stencil callbacks in Scheme, thus
5 providing custom glyphs for notation elements. A simple example is
6 adding parentheses to existing stencil callbacks.
8 The parenthesized beam is less successful due to implementation of the
9 Beam. The note head is also rather naive, since the extent of the
10 parens are also not seen by accidentals.
15 #(define (parenthesize-callback callback)
16 "Construct a function that will do CALLBACK and add parentheses.
17 Example usage:
19 \\property NoteHead \\override #'print-function
21 #(parenthesize-callback ly:note-head::print)
26 (define (parenthesize-stencil grob)
27 "This function adds parentheses to the original callback for
28 GROB. The dimensions of the stencil is not affected.
31 (let* ((fn (ly:grob-default-font grob))
32 (pclose (ly:font-get-glyph fn "accidentals.rightparen"))
33 (popen (ly:font-get-glyph fn "accidentals.leftparen"))
34 (subject (callback grob))
36 ; remember old size
37 (subject-dim-x (ly:stencil-extent subject 0))
38 (subject-dim-y (ly:stencil-extent subject 1)))
40 ;; add parens
41 (set! subject
42 (ly:stencil-combine-at-edge
43 (ly:stencil-combine-at-edge subject 0 1 pclose 0.2)
44 0 -1 popen 0.2))
46 ; revert old size.
47 (ly:make-stencil
48 (ly:stencil-expr subject) subject-dim-x subject-dim-y)))
49 parenthesize-stencil)
52 \layout { ragged-right = ##t }
53 \relative c' {
54 c4 e
56 \override NoteHead #'stencil
58 #(parenthesize-callback ly:note-head::print)
59 g bes
60 \revert NoteHead #'stencil
62 \override Beam #'stencil
64 #(parenthesize-callback ly:beam::print)
66 a8 gis8 a2.