]> git.donarmstrong.com Git - lilypond.git/blob - input/regression/stencil-hacking.ly
Issue 5167/6: Changes: show \markup xxx = ... \etc assignments
[lilypond.git] / input / regression / stencil-hacking.ly
1 \version "2.19.21"
2
3 \header { texidoc=" You can write stencil callbacks in Scheme, thus
4 providing custom glyphs for notation elements.  A simple example is
5 adding parentheses to existing stencil callbacks.
6
7 The parenthesized beam is less successful due to implementation of the
8 Beam. The note head is also rather naive, since the extent of the
9 parens are also not seen by accidentals.
10 "
11         
12 }
13
14 #(define (parenthesize-callback callback)
15    "Construct a function that will do CALLBACK and add parentheses.
16 Example usage:
17
18   \\override NoteHead.stencil
19   =
20   #(parenthesize-callback ly:note-head::print)"
21    
22    (define (parenthesize-stencil grob)
23      "This function adds parentheses to the original callback for
24 GROB.  It does not affect the dimensions of the stencil.
25 "
26      
27      (let* ((fn (ly:grob-default-font grob))
28             (pclose (ly:font-get-glyph fn "accidentals.rightparen"))
29             (popen (ly:font-get-glyph fn "accidentals.leftparen"))
30             (subject (callback grob))
31
32             ; remember old size
33             (subject-dim-x (ly:stencil-extent subject X))
34             (subject-dim-y (ly:stencil-extent subject Y)))
35
36         ;; add parens
37         (set! subject
38              (ly:stencil-combine-at-edge 
39               (ly:stencil-combine-at-edge subject X RIGHT pclose 0.2)
40               X LEFT popen  0.2))
41
42         ; revert old size.
43        (ly:make-stencil
44         (ly:stencil-expr subject) subject-dim-x subject-dim-y)))
45    parenthesize-stencil)
46     
47
48 \layout { ragged-right = ##t }
49 \relative {
50     c'4 e
51
52     \override NoteHead.stencil
53     =
54     #(parenthesize-callback ly:note-head::print)
55     g bes
56     \revert NoteHead.stencil
57
58     \override Beam.stencil
59     =
60     #(parenthesize-callback ly:beam::print)
61
62     a8 gis8 a2.
63     
64 }
65
66
67