lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: box-stencil (was: Drawing boxes around grobs)


From: Paolo Prete
Subject: Re: box-stencil (was: Drawing boxes around grobs)
Date: Sun, 23 Feb 2020 01:26:09 +0100

I just checked that this unwanted behavior happens in the default make-stencil-boxer function too.

Is there a fix for this?
Thanks

%%%%%%%%%%%%%%%%
{
  \override DynamicText.stencil =
    #(make-stencil-boxer 0.4 0 ly:text-interface::print)
    c'_\mf
}

%%%%%%%%%%%%%%%%

On Sun, Feb 23, 2020 at 1:19 AM Paolo Prete <address@hidden> wrote:
(This is for Aaron (and anyone who shows interest...)

Hi Aaron,

I need a little fix on the wonderful function you implemented.
As you can see, in case of dynamic, the box has a little unwanted overlay.
How we could avoid this?

Thanks,
Best
P

%%%%
\version "2.19.83"

#(define (box-stencil stencil thickness padding color expand?)
  "Add a box around @var{stencil}, producing a new stencil."
  (define (css-style-padding padding)
    ;; padding => (top right bottom left)
    (cond
      ((or (null? padding) (eqv? #f padding)) '(0 0 0 0))
      ((number? padding) (make-list 4 padding))
      ((number-pair? padding)
        (list (car padding) (cdr padding)
              (car padding) (cdr padding)))
      ((and (number-list? padding) (<= (length padding) 4))
        (case (length padding)
          ((1) (make-list 4 (first padding)))
          ((2) (list (first padding) (second padding)
                     (first padding) (second padding)))
          ((3) (list (first padding) (second padding)
                     (third padding) (second padding)))
          (else padding)))
      (else
        (begin (ly:warning "Ignoring invalid padding: ~a" padding)
               '(0 0 0 0)))))
  (let* ((padding (css-style-padding padding))
         (padding-top (first padding))
         (padding-right (second padding))
         (padding-bottom (third padding))
         (padding-left (fourth padding))

         (x-ext-orig (ly:stencil-extent stencil X))
         (y-ext-orig (ly:stencil-extent stencil Y))
         (x-ext-inner
           (cons (- (interval-start x-ext-orig) padding-left)
                 (+ (interval-end x-ext-orig) padding-right)))
         (y-ext-inner
           (cons (- (interval-start y-ext-orig) padding-bottom)
                 (+ (interval-end y-ext-orig) padding-top)))
         (x-ext-outer (interval-widen x-ext-inner thickness))
         (y-ext-outer (interval-widen y-ext-inner thickness))
         (x-ext-new (if expand? x-ext-outer x-ext-orig))
         (y-ext-new (if expand? y-ext-outer y-ext-orig))

(x-rule (make-filled-box-stencil (cons 0 thickness) y-ext-inner)) (y-rule (make-filled-box-stencil x-ext-outer (cons 0 thickness)))
         (box (stencil-with-color
           (ly:stencil-add
(ly:stencil-translate-axis y-rule (interval-end y-ext-inner) Y) (ly:stencil-translate-axis x-rule (interval-end x-ext-inner) X) (ly:stencil-translate-axis y-rule (interval-start y-ext-outer) Y) (ly:stencil-translate-axis x-rule (interval-start x-ext-outer) X))
           color)))
    (ly:make-stencil
      (ly:stencil-expr (ly:stencil-add stencil box))
      x-ext-new y-ext-new)))

#(define* (make-stencil-boxer thickness padding callback
           #:optional (color red) (expand? #t))
  "Return function that adds a box around the grob passed as argument."
  (lambda (grob)
    (box-stencil (callback grob) thickness padding color expand?)))

{
  \override DynamicText.stencil =
    #(make-stencil-boxer 0.4 0 ly:text-interface::print)
    c'_\mf
}
%%%%

reply via email to

[Prev in Thread] Current Thread [Next in Thread]