]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/stencil.scm
Merge branch 'master' into lilypond/translation
[lilypond.git] / scm / stencil.scm
index 3e1de989492d157634a1e937de1f4e54a705e610..4a0a26bd6cd342186fc6150e679d5e69bc541071 100644 (file)
@@ -291,7 +291,7 @@ the more angular the shape of the parenthesis."
       (cons (min-max-crawler min cddr possible-extrema)
             (min-max-crawler max cddr possible-extrema)))))
 
-(define (connected-shape-min-max pointlist)
+(define (path-min-max origin pointlist)
 
   (define (line-part-min-max x1 x2)
     (list (min x1 x2) (max x1 x2)))
@@ -353,26 +353,52 @@ the more angular the shape of the parenthesis."
               (apply line-min-max x)))
         (map (lambda (x y)
                (append (list (cadr (reverse x)) (car (reverse x))) y))
-             (append (list (list 0 0))
+             (append (list origin)
                      (reverse (cdr (reverse pointlist)))) pointlist))))
 
-(define-public (make-connected-shape-stencil pointlist thickness
-                                             x-scale y-scale connect fill)
-  "Make a connected shape described by the list @var{pointlist}, with
+(define-public (make-connected-path-stencil pointlist thickness
+                                           x-scale y-scale connect fill)
+  "Make a connected path described by the list @var{pointlist}, with
 thickness @var{thickness}, and scaled by @var{x-scale} in the X direction
 and @var{y-scale} in the Y direction.  @var{connect} and @var{fill} are
-boolean arguments that specify if the shape should be connected or filled,
+boolean arguments that specify if the path should be connected or filled,
 respectively."
 
-  (let* ((boundlist (connected-shape-min-max pointlist)))
+  ;; paths using this routine are designed to begin at point '(0 . 0)
+  (let* ((origin (list 0 0))
+        (boundlist (path-min-max origin pointlist))
+        ;; modify pointlist to scale the coordinates
+        (path (map (lambda (x)
+                     (apply
+                       (if (eq? 6 (length x))
+                           (lambda (x1 x2 x3 x4 x5 x6)
+                             (list 'curveto
+                                   (* x1 x-scale)
+                                   (* x2 y-scale)
+                                   (* x3 x-scale)
+                                   (* x4 y-scale)
+                                   (* x5 x-scale)
+                                   (* x6 y-scale)))
+                           (lambda (x1 x2)
+                             (list 'lineto
+                                   (* x1 x-scale)
+                                   (* x2 y-scale))))
+                       x))
+                   pointlist))
+        ;; a path must begin with a `moveto'
+        (prepend-origin (apply list (cons 'moveto origin) path))
+        ;; if this path is connected, add closepath to the end
+        (final-path (if connect
+                        (append prepend-origin (list 'closepath))
+                        prepend-origin))
+        (command-list (fold-right append '() final-path)))
+
   (ly:make-stencil
-    `(connected-shape
-      ',pointlist
-      ',thickness
-      ',x-scale
-      ',y-scale
-      ',connect
-      ',fill)
+    `(path ,thickness
+          `(,@',command-list)
+          'round
+          'round
+          ,(if fill #t #f))
     (coord-translate
       ((if (< x-scale 0) reverse-interval identity)
         (cons (* x-scale (list-ref boundlist 0))