]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/stencil.scm
\rounded-box corrections
[lilypond.git] / scm / stencil.scm
index e4c15978b4fb6288b589a96f5648a8fa9a42637d..3256d49f61e6140b229cf0d721548d0966348648 100644 (file)
@@ -129,6 +129,25 @@ 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))
+   (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 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) 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))
+
 
 (define-public (fontify-text font-metric text)
   "Set TEXT with font FONT-METRIC, returning a stencil."