lilypond-user
[Top][All Lists]
Advanced

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

Re: Drawing boxes around grobs


From: Thomas Morley
Subject: Re: Drawing boxes around grobs
Date: Sat, 8 Feb 2020 22:36:46 +0100

Am Sa., 8. Feb. 2020 um 22:20 Uhr schrieb Paolo Prete <address@hidden>:
>
>
>
> On Sat, Feb 8, 2020 at 9:06 PM Thomas Morley <address@hidden> wrote:
>>
>> Am Sa., 8. Feb. 2020 um 19:26 Uhr schrieb Paolo Prete <address@hidden>:
>> >
>
>
>
>
>
>>
>> {
>> \override TextScript.stencil =
>>   #(make-stencil-boxer 0.1 0.3 ly:text-interface::print)
>>
>> \override Script.stencil =
>>   #(make-stencil-boxer 0.1 0.3 ly:script-interface::print)
>>
>> \override NoteHead.stencil =
>>   #(make-stencil-boxer 0.1 0.3 ly:note-head::print)
>>   c'4^"foo"->
>>
>> \override TupletBracket.stencil =
>>   #(make-stencil-boxer 0.1 0.8 ly:tuplet-bracket::print)
>>   \tuplet 3/2 { b4 4 4 }
>> }
>>
>> The boxed NoteHead is wider, the stem-attachment does as before, i.e.
>> the Stem is placed at the border...
>> In this case tackle stem-attachment or better, don't let the boxed
>> stencil be wider. Which may lead to probably unwished collisions, if
>> done for with grobs.
>>
>> Cheers,
>>   Harm
>
>
>
> Thank you harm.
> Is it possible to override/tweak the color of the boxer?
>
> Best,
> P
>
>

You could redefine box-stencil to take an additional color-argument.
Also stencil-boxer to take an optional color-argument:

#(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))

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

{
\override TextScript.stencil =
  #(make-stencil-boxer 0.1 0.3 ly:text-interface::print)

\override Script.stencil =
  #(make-stencil-boxer 0.1 0.3 ly:script-interface::print)

\override NoteHead.stencil =
  #(make-stencil-boxer 0.1 0.3 ly:note-head::print cyan)
  c'4^"foo"->

\override TupletBracket.stencil =
  #(make-stencil-boxer 0.1 0.8 ly:tuplet-bracket::print)
  \tuplet 3/2 { b4 4 4 }
}

Cheers,
  Harm



reply via email to

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