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