]> git.donarmstrong.com Git - lilypond.git/blob - input/regression/stencil-hacking.ly
Merge commit 'origin' into includes
[lilypond.git] / input / regression / stencil-hacking.ly
1
2 \version "2.12.0"
3
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.
7
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.
11 "
12         
13 }
14
15 #(define (parenthesize-callback callback)
16    "Construct a function that will do CALLBACK and add parentheses.
17 Example usage:
18
19   \\property NoteHead \\override #'print-function
20                    =
21                       #(parenthesize-callback ly:note-head::print)
22                     
23 "
24
25    
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.
29 "
30      
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))
35
36             ; remember old size
37             (subject-dim-x (ly:stencil-extent subject 0))
38             (subject-dim-y (ly:stencil-extent subject 1)))
39
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))
45
46         ; revert old size.
47        (ly:make-stencil
48         (ly:stencil-expr subject) subject-dim-x subject-dim-y)))
49    parenthesize-stencil)
50     
51
52 \layout { ragged-right = ##t }
53 \relative c' {
54     c4 e
55
56     \override NoteHead  #'stencil
57     =
58     #(parenthesize-callback ly:note-head::print)
59     g bes
60     \revert NoteHead #'stencil
61
62     \override Beam  #'stencil
63     =
64     #(parenthesize-callback ly:beam::print)
65
66     a8 gis8 a2.
67     
68 }
69
70
71