]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/stencil.scm
Merge with master
[lilypond.git] / scm / stencil.scm
index 5f3413df8f64a24395a3334f207dd397446cd4c9..463a082fd337e63e25230fc4fe89f70c3091206f 100644 (file)
@@ -2,7 +2,7 @@
 ;;;;
 ;;;;  source file of the GNU LilyPond music typesetter
 ;;;; 
-;;;; (c) 2003--2006 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+;;;; (c) 2003--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
 (define-public (stack-stencils axis dir padding stils)
   "Stack stencils STILS in direction AXIS, DIR, using PADDING."
 
 (define-public (stack-lines dir padding baseline stils)
   "Stack vertically with a baseline-skip."
-  (if (null? stils)
-      empty-stencil
-      (if (null? (cdr stils))
-         (car stils)
-         (ly:stencil-combine-at-edge
-          (car stils) Y dir 
-          (stack-lines dir padding baseline (cdr stils))
-          padding baseline))))
+  (define result empty-stencil)
+  (define last-y #f)
+  (do
+      ((last-stencil #f (car p))
+       (p stils (cdr p)))
+      
+      ((null? p))
+
+    (if (number? last-y)
+       (begin
+         (let* ((dy (max (+ (* dir (interval-bound (ly:stencil-extent last-stencil Y) dir))
+                            padding
+                            (* (- dir) (interval-bound (ly:stencil-extent (car p) Y) (- dir))))
+                         baseline))
+                (y (+ last-y  (* dir dy))))
+           
+                         
+           
+           (set! result
+                 (ly:stencil-add result (ly:stencil-translate-axis (car p) y Y)))
+           (set! last-y y)))
+       (begin
+         (set! last-y 0)
+         (set! result (car p)))))
+
+  result)
+    
 
 (define-public (bracketify-stencil stil axis thick protusion padding)
   "Add brackets around STIL, producing a new stencil."
@@ -100,9 +119,16 @@ encloses the contents.
         (y-ext (ly:stencil-extent stencil 1))
         (diameter (max (- (cdr x-ext) (car x-ext))
                        (- (cdr y-ext) (car y-ext))))
-        (radius (+ (/ diameter 2) padding thickness)))
+        (radius (+ (/ diameter 2) padding thickness))
+        (circle (make-circle-stencil radius thickness #f)))
+
     (ly:stencil-add
-     (centered-stencil stencil) (make-circle-stencil radius thickness #f))))
+     stencil
+     (ly:stencil-translate circle
+                          (cons
+                           (interval-center x-ext)
+                           (interval-center y-ext))))))
+
 
 (define-public (fontify-text font-metric text)
   "Set TEXT with font FONT-METRIC, returning a stencil."
@@ -111,13 +137,32 @@ encloses the contents.
      `(text ,font-metric ,text) (car b) (cdr b))))
      
 (define-public (fontify-text-white scale font-metric text)
-  "Set TEXT with scale factor s"
+  "Set TEXT with scale factor SCALE"
   (let* ((b (ly:text-dimension font-metric text))
         ;;urg -- workaround for using ps font
          (c `(white-text ,(* 2 scale) ,text)))
     ;;urg -- extent is not from ps font, but we hope it's close
     (ly:make-stencil c (car b) (cdr b))))
 
+(define-public (stencil-with-color stencil color)
+  (ly:make-stencil
+   (list 'color color (ly:stencil-expr stencil))
+   (ly:stencil-extent stencil X)
+   (ly:stencil-extent stencil Y)))
+  
+(define-public (stencil-whiteout stencil)
+  (let*
+      ((x-ext (ly:stencil-extent stencil X))
+       (y-ext (ly:stencil-extent stencil Y))
+
+       )
+    
+    (ly:stencil-add
+     (stencil-with-color (ly:round-filled-box x-ext y-ext 0.0)
+                        white)
+     stencil)
+    ))
+
 (define-public (dimension-arrows destination) 
   "Draw twosided arrow from here to @var{destination}"
   
@@ -214,11 +259,11 @@ encloses the contents.
          (set! annotation
                 (center-stencil-on-extent text-stencil))
          (set! annotation
-               (ly:stencil-combine-at-edge arrows X RIGHT annotation 0.5 0))
+               (ly:stencil-combine-at-edge arrows X RIGHT annotation 0.5))
          (set! annotation
                (ly:stencil-combine-at-edge annotation X LEFT
                                             (center-stencil-on-extent dim-stencil)
-                                            0.5 0))
+                                            0.5))
          (set! annotation
                (ly:make-stencil (list 'color color (ly:stencil-expr annotation))
                                 (ly:stencil-extent annotation X)
@@ -279,6 +324,7 @@ grestore
          (write-system-signatures basename (cdr paper-systems) (1+ count))))))
 
 
+(use-modules (scm paper-system))
 (define-public (write-system-signature filename paper-system)
   (define (float? x)
     (and (number? x) (inexact? x)))
@@ -309,14 +355,6 @@ grestore
              rest))
        expr))
   
-  (define (music-cause grob)
-    (let*
-       ((cause (ly:grob-property  grob 'cause)))
-      
-      (cond
-       ((ly:music? cause) cause)
-       ((ly:grob? cause) (music-cause cause))
-       (else #f))))
 
   (define (pythonic-string expr)
     "escape quotes and slashes for python consumption"
@@ -325,14 +363,23 @@ grestore
   (define (pythonic-pair expr)
     (format "(~a,~a)"
            (car expr) (cdr expr)))
-                   
+
+
+  (define (raw-string expr)
+    "escape quotes and slashes for python consumption"
+    (regexp-substitute/global #f "[@\n]" (format "~a" expr) 'pre " " 'post))
+
+  (define (raw-pair expr)
+    (format "~a ~a"
+           (car expr) (cdr expr)))
+  
   (define (found-grob expr)
     (let*
        ((grob (car expr))
         (rest (cdr expr))
         (collected '())
-        (cause (music-cause grob))
-        (input (if (ly:music? cause) (ly:music-property cause 'origin) #f))
+        (cause (event-cause grob))
+        (input (if (ly:stream-event? cause) (ly:event-property cause 'origin) #f))
         (location (if (ly:input-location? input) (ly:input-file-line-char-column input) '()))
 
         (x-ext (ly:grob-extent grob system-grob X))
@@ -344,12 +391,12 @@ grestore
                               rest)
 
       (format output
-             "['~a', '~a', ~a, ~a, '~a'],\n"
+             "~a@~a@~a@~a@~a\n"
              (cdr (assq 'name (ly:grob-property grob 'meta) ))
-             (pythonic-string location)
-             (pythonic-pair (if (interval-empty? x-ext) '(1 . -1) x-ext))
-             (pythonic-pair (if (interval-empty? y-ext) '(1 . -1) y-ext))
-             (pythonic-string collected))
+             (raw-string location)
+             (raw-pair (if (interval-empty? x-ext) '(1 . -1) x-ext))
+             (raw-pair (if (interval-empty? y-ext) '(1 . -1) y-ext))
+             (raw-string collected))
       ))
 
   (define (interpret-for-signature escape collect expr)