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