From 3cdd12b8c6c729b703831a763a9a6f2a9182d146 Mon Sep 17 00:00:00 2001
From: Valentin Villenave <valentin@villenave.net>
Date: Mon, 21 Apr 2008 16:59:41 +0200
Subject: [PATCH] \rounded-box corrections

Added an example, and corrected a bit the algorithm.
---
 scm/define-markup-commands.scm |  7 ++++++-
 scm/stencil.scm                | 12 +++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm
index 9ddfa49820..e5d7196cd1 100644
--- a/scm/define-markup-commands.scm
+++ b/scm/define-markup-commands.scm
@@ -206,7 +206,12 @@ circle of diameter@tie{}0 (i.e. sharp corners)."
 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)." 
+makes possible to define another shape for the corners (default is 1).
+
+@lilypond[quote,verbatim,fragment,relative=2]
+c^\markup{ \rounded-box Overtura }
+c,8. c16 c4 r
+@end lilypond" 
   (let* ((th (*
 	      (ly:output-def-lookup layout 'line-thickness)
 	      (chain-assoc-get 'thickness props 1)))
diff --git a/scm/stencil.scm b/scm/stencil.scm
index baa8fe8ccd..3256d49f61 100644
--- a/scm/stencil.scm
+++ b/scm/stencil.scm
@@ -134,11 +134,17 @@ encloses the contents.
 
   (let* ((xext (interval-widen (ly:stencil-extent stencil 0) padding))
 	 (yext (interval-widen (ly:stencil-extent stencil 1) padding))
+   (min-ext (min (-(cdr xext) (car xext)) (-(cdr yext) (car yext))))
+   (ideal-blot (min blot (/ min-ext 2)))
+   (ideal-thickness (min thickness (/ min-ext 2)))
 	 (outer (ly:round-filled-box
-		  (interval-widen xext thickness) (interval-widen yext thickness) blot))
+		   (interval-widen xext ideal-thickness) 
+       (interval-widen yext ideal-thickness) 
+            ideal-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)))))))
+       (cons (+ (car xext) ideal-thickness) (- (cdr xext) ideal-thickness)) 
+       (cons (+ (car yext) ideal-thickness) (- (cdr yext) ideal-thickness)) 
+            (- ideal-blot (* ideal-thickness 2))))))))
     (set! stencil (ly:stencil-add outer inner))
     stencil))
 
-- 
2.39.5