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