On 2020-02-08 1:36 pm, Thomas Morley wrote:
#(define (box-stencil stencil thickness padding color)
"Add a box around @var{stencil}, producing a new stencil."
(let* ((x-ext (interval-widen (ly:stencil-extent stencil 0) padding))
(y-ext (interval-widen (ly:stencil-extent stencil 1) padding))
(y-rule
(stencil-with-color
(make-filled-box-stencil (cons 0 thickness) y-ext) color))
(x-rule
(stencil-with-color
(make-filled-box-stencil
(interval-widen x-ext thickness) (cons 0 thickness))
color)))
(set! stencil (ly:stencil-combine-at-edge stencil X 1 y-rule
padding))
(set! stencil (ly:stencil-combine-at-edge stencil X -1 y-rule
padding))
(set! stencil (ly:stencil-combine-at-edge stencil Y 1 x-rule 0.0))
(set! stencil (ly:stencil-combine-at-edge stencil Y -1 x-rule 0.0))
stencil))
You can restore the behavior of things like stem attachment by
outputting the modified stencil with the original extents:
%%%%
#(define (box-stencil stencil thickness padding color)
"Add a box around @var{stencil}, producing a new stencil."
(let* ((x-ext-orig (ly:stencil-extent stencil X))
(y-ext-orig (ly:stencil-extent stencil Y))
(x-ext (interval-widen x-ext-orig padding))
(y-ext (interval-widen y-ext-orig padding))
(y-rule
(stencil-with-color
(make-filled-box-stencil (cons 0 thickness) y-ext) color))
(x-rule
(stencil-with-color
(make-filled-box-stencil
(interval-widen x-ext thickness) (cons 0 thickness))
color)))
(set! stencil (ly:stencil-combine-at-edge stencil X 1 y-rule
padding))
(set! stencil (ly:stencil-combine-at-edge stencil X -1 y-rule
padding))
(set! stencil (ly:stencil-combine-at-edge stencil Y 1 x-rule 0.0))
(set! stencil (ly:stencil-combine-at-edge stencil Y -1 x-rule 0.0))
(ly:make-stencil (ly:stencil-expr stencil) x-ext-orig y-ext-orig)))
%%%%
Users of the function might want to choose between using the original
dimensions and the larger ones, so an additional parameter would
probably be necessary.
-- Aaron Hill