lilypond-user
[Top][All Lists]
Advanced

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

Boxed text with rounded corners


From: Valentin Villenave
Subject: Boxed text with rounded corners
Date: Fri, 28 Mar 2008 15:50:21 +0100

Hi everybody,

There are two features (among others) I appreciate very much In
LilyPond: \box and \filled-box.

Would there be any possibility to somehow mix these two commands?

For instance, is it possible to add an optionnal "blot" argument to
the make-stencil-boxer function? If specified, the corners will be
rounded; if not, the corners will be sharp.

I tried to have a look at stencil.scm, define-markup-commands.scm,
lookup.cc and text-interface.cc, but I am definitely not a programmer
(see below).

Here are some questions I couldn't solve:

1-how to obtain a non-filled rounded box? The only solution I can see would to:
    -draw a black-filled box slightly too large
    -then draw a white-filled box on top of it (#:whiteout or something?)
    -then print the text on the white box (#:combine or something?)

It's complicated; however I found that some objects are already
printed using this "dirty way:
http://lists.gnu.org/archive/html/lilypond-devel/2006-04/msg00264.html

2-how exactly does ly:stencil-extent work? is it possible to obtain
the width and length of an object *prior* to drawing it?

3-Here's some code to demonstrate my idea. It's very dirty but perhaps
you'll see what I'm trying to achieve.

#(define-markup-command (rbox layout props radius text) (number?) (markup?)
"Add a rounded box around the text"
  (let* ((th (*
              (ly:output-def-lookup layout 'line-thickness)
              (chain-assoc-get 'thickness props 1)))
         (size (chain-assoc-get 'font-size props 0))
         (pad (* (magstep size)
                 (chain-assoc-get 'box-padding props 0.2)))
         (m (interpret-markup layout props text)))
   (let* ((x-ext (interval-widen (ly:stencil-extent m 0) (+ pad th)))
     (y-ext (interval-widen (ly:stencil-extent m 1) (+ pad th)))
     (xext (cons (- (/ x-ext 2)) (/ x-ext 2)))
     (yext (cons (- (/ y-ext 2)) (/ y-ext 2)))
     (blot radius))
     (markup (ly:round-filled-box xext yext blot)))
   (let* ((x-ext (interval-widen (ly:stencil-extent m 0) pad))
     (y-ext (interval-widen (ly:stencil-extent m 1) pad))
     (xext (cons (- (/ x-ext 2)) (/ x-ext 2)))
     (yext (cons (- (/ y-ext 2)) (/ y-ext 2)))
     (blot radius))
     (markup #:with-color (rgb-color 1 1 1) #:filled-box xext yext blot))
   (markup m)))

Besides, this could allow interesting Editorial uses: this way
\balloonText could look like "real" balloons :)

Cheers,
Valentin




reply via email to

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