From 9ed874e36a460342872761d61778994691894265 Mon Sep 17 00:00:00 2001 From: Valentin Villenave Date: Sun, 20 Apr 2008 16:07:15 +0200 Subject: [PATCH] New \rounded-box markup command This new command makes possible to enclose text within a box with rounded corners. (I had to make up a 'corner-radius prop to allow users to change the blot.) --- Documentation/topdocs/NEWS.tely | 4 ++++ scm/define-markup-commands.scm | 18 ++++++++++++++++++ scm/stencil.scm | 13 +++++++++++++ 3 files changed, 35 insertions(+) diff --git a/Documentation/topdocs/NEWS.tely b/Documentation/topdocs/NEWS.tely index 3428c521b5..6ca65b7e60 100644 --- a/Documentation/topdocs/NEWS.tely +++ b/Documentation/topdocs/NEWS.tely @@ -65,6 +65,10 @@ which scares away people. @end ignore +@item +Enclosing text within boxes with rounded corners is now possible, +using the @code{rounded-box} command. + @item @command{lilypond-book} can run any program instead of @command{latex} to guess the line width, thanks to @code{--latex} command line option. diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm index 6114e61626..9ddfa49820 100644 --- a/scm/define-markup-commands.scm +++ b/scm/define-markup-commands.scm @@ -200,6 +200,24 @@ circle of diameter@tie{}0 (i.e. sharp corners)." (ly:round-filled-box xext yext blot)) +(define-builtin-markup-command (rounded-box layout props arg) (markup?) + "@cindex enclosing text in a bow with rounded corners + @cindex drawing boxes with rounded corners around text +Draw a box with rounded corners around @var{arg}. Looks at @code{thickness}, +@code{box-padding} and @code{font-size} properties to determine line +thickness and padding around the markup; the @code{corner-radius} property +makes possible to define another shape for the corners (default is 1)." + (let* ((th (* + (ly:output-def-lookup layout 'line-thickness) + (chain-assoc-get 'thickness props 1))) + (rad (chain-assoc-get 'corner-radius props 1)) + (size (chain-assoc-get 'font-size props 0)) + (pad (* (magstep size) + (chain-assoc-get 'box-padding props 0.5))) + (m (interpret-markup layout props arg))) + (ly:stencil-add (rounded-box-stencil m th pad rad) + m))) + (define-builtin-markup-command (rotate layout props ang arg) (number? markup?) " @cindex rotating text diff --git a/scm/stencil.scm b/scm/stencil.scm index e4c15978b4..baa8fe8ccd 100644 --- a/scm/stencil.scm +++ b/scm/stencil.scm @@ -129,6 +129,19 @@ encloses the contents. (interval-center x-ext) (interval-center y-ext)))))) +(define-public (rounded-box-stencil stencil thickness padding blot) + "Add a rounded box around STENCIL, producing a new stencil." + + (let* ((xext (interval-widen (ly:stencil-extent stencil 0) padding)) + (yext (interval-widen (ly:stencil-extent stencil 1) padding)) + (outer (ly:round-filled-box + (interval-widen xext thickness) (interval-widen yext thickness) blot)) + (inner (ly:make-stencil (list 'color (x11-color 'white) (ly:stencil-expr (ly:round-filled-box + (cons (+ (car xext) thickness) (- (cdr xext) thickness)) + (cons (+ (car yext) thickness) (- (cdr yext) thickness)) (* blot 0.8))))))) + (set! stencil (ly:stencil-add outer inner)) + stencil)) + (define-public (fontify-text font-metric text) "Set TEXT with font FONT-METRIC, returning a stencil." -- 2.39.2