]> git.donarmstrong.com Git - lilypond.git/blob - input/lsr/three-sided-box.ly
lilypond-book robustness: ensure EOL at the end of @verbatim
[lilypond.git] / input / lsr / three-sided-box.ly
1 %% Do not edit this file; it is auto-generated from LSR http://lsr.dsi.unimi.it
2 %% This file is in the public domain.
3 \version "2.13.1"
4
5 \header {
6   lsrtags = "rhythms, text"
7
8   texidoc = "
9 This example shows how to add a markup command to get a three sided box
10 around some text (or other markup).
11
12 "
13   doctitle = "Three-sided box"
14 } % begin verbatim
15
16 % New command to add a three sided box, with sides north, west and south
17 % Based on the box-stencil command defined in scm/stencil.scm
18 % Note that ";" is used to comment a line in Scheme
19 #(define-public (NWS-box-stencil stencil thickness padding)
20   "Add a box around STENCIL, producing a new stencil."
21   (let* ((x-ext (interval-widen (ly:stencil-extent stencil 0) padding))
22          (y-ext (interval-widen (ly:stencil-extent stencil 1) padding))
23          (y-rule (make-filled-box-stencil (cons 0 thickness) y-ext))
24          (x-rule (make-filled-box-stencil
25                   (interval-widen x-ext thickness) (cons 0 thickness))))
26 ;    (set! stencil (ly:stencil-combine-at-edge stencil X 1 y-rule padding))
27     (set! stencil (ly:stencil-combine-at-edge stencil X -1 y-rule padding))
28     (set! stencil (ly:stencil-combine-at-edge stencil Y 1 x-rule 0.0))
29     (set! stencil (ly:stencil-combine-at-edge stencil Y -1 x-rule 0.0))
30     stencil))
31
32 % The corresponding markup command, based on the \box command defined 
33 % in scm/define-markup-commands.scm
34 #(define-markup-command (NWS-box layout props arg) (markup?)
35   "Draw a box round @var{arg}.  Looks at @code{thickness},
36 @code{box-padding} and @code{font-size} properties to determine line
37 thickness and padding around the markup."  
38   (let* ((th (chain-assoc-get 'thickness props  0.1))
39          (size (chain-assoc-get 'font-size props 0))
40          (pad (* (magstep size)
41                  (chain-assoc-get 'box-padding props 0.2)))
42          (m (interpret-markup layout props arg)))
43     (NWS-box-stencil m th pad)))
44
45 % Test it:
46
47 \layout { ragged-right = ##f }
48 \relative c' {
49   c2^\markup { \NWS-box ABCD }
50   c2^\markup { \NWS-box \note #"4" #1.0 }
51 }
52