lilypond-user
[Top][All Lists]
Advanced

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

Re: Stencil rubber


From: Aaron Hill
Subject: Re: Stencil rubber
Date: Sat, 12 Dec 2020 19:05:23 -0800
User-agent: Roundcube Webmail/1.4.9

On 2020-12-12 1:18 pm, Jean Abou Samra wrote:
Hi,

Is there a way to restrict the drawing of a stencil to certain parts?

For example, suppose that I want to join the letters A and B in a
custom letter that is half an A in the left half and half a B in the
right half. How can I do that in a markup?

I can add a white box to hide part of the A, getting half an A. I can
do the same for B. But if I \combine the two, the white half of the B
get printed over the A...

This only works for PostScript output at the moment, but here's a potential way to do this:

%%%%
\version "2.20.0"

#(define-markup-command
  (clip layout props rel-xex rel-yex args)
  (number-pair? number-pair? markup?)
  (let* ((sten (interpret-markup layout props args))
         (orig-xex (ly:stencil-extent sten X))
         (orig-yex (ly:stencil-extent sten Y))
         (clip-xex (cons (interval-index orig-xex (car rel-xex))
                         (interval-index orig-xex (cdr rel-xex))))
         (clip-yex (cons (interval-index orig-yex (car rel-yex))
                         (interval-index orig-yex (cdr rel-yex))))
         (expr (ly:stencil-expr sten)))
    (ly:make-stencil
      `(combine-stencil
        (embedded-ps
        ,(ly:format
          "gsave currentpoint ~a ~a vector_add ~a ~a rectclip"
          (car clip-xex) (car clip-yex)
          (interval-length clip-xex)
          (interval-length clip-yex)))
        (delay-stencil-evaluation ,(delay expr))
        (embedded-ps "grestore"))
      clip-xex clip-yex)))

markupA = \markup \huge \circle \italic "A"
markupB = \markup \huge \box \bold "B"

\markup \pad-around #0.5 {
  \markupA
  \put-adjacent #X #RIGHT
    \with-color #red \clip #'(-1 . 0) #'(-1 . 1) \markupA
    \with-color #blue \clip #'(0 . 1) #'(-1 . 1) \markupA
  \put-adjacent #Y #DOWN
    \with-color #red \clip #'(-1 . 0.75) #'(-0.25 . 1) \markupA
    \with-color #blue \clip #'(-0.75 . 1) #'(-1 . -0.25) \markupA
  \put-adjacent #X #RIGHT
    \with-color #red \clip #'(-1 . 0) #'(-1 . 1) \markupB
    \with-color #blue \clip #'(0 . 1) #'(-1 . 1) \markupB
  \put-adjacent #Y #DOWN
    \with-color #red \clip #'(-0.75 . 1) #'(0.33 . 1) \markupB
    \with-color #blue \clip #'(-1 . 0.75) #'(-1 . 0.33) \markupB
  \markupB
}
%%%%

The arguments for \clip assume relative coordinates (e.g. LEFT/DOWN = -1, CENTER = 0, RIGHT/UP = 1). This seemed easier to work with than absolute extents.


-- Aaron Hill

Attachment: clip-stencil.cropped.png
Description: PNG image


reply via email to

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