]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add a make-line-stencil function, which correctly sets stencil extents
authorReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 17 Aug 2008 23:45:17 +0000 (01:45 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 19 Aug 2008 17:08:12 +0000 (19:08 +0200)
So far, one had to create line stencils manually using
   (ly:make-stencil (list 'draw-line ...) xext yext)
Unfortunately that meant that one had to specify the x- and y- coordinates
twice. This new make-line-stencil function takes the coordinates once,
creates the stencil and properly sets its extent (adding half the line
width to all coordinates of the x- and y-intervals).

Signed-off-by: Reinhold Kainhofer <reinhold@kainhofer.com>
scm/define-markup-commands.scm
scm/fret-diagrams.scm
scm/stencil.scm

index 18112b874c1336b0130133c184da85e904ccddac..a63dba2995e376dc8374dc6eeceb4d6675a4fef0 100644 (file)
@@ -42,13 +42,7 @@ A simple line.
                thickness))
         (x (car dest))
         (y (cdr dest)))
-    (ly:make-stencil
-     `(draw-line
-       ,th
-       0 0
-       ,x ,y)
-     (cons (min x 0) (max x 0))
-     (cons (min y 0) (max y 0)))))
+    (make-line-stencil th 0 0 x y)))
 
 (define-builtin-markup-command (draw-circle layout props radius thickness fill)
   (number? number? boolean?)
@@ -206,10 +200,7 @@ thickness and y offset.
          (x1 (car (ly:stencil-extent markup X)))
          (x2 (cdr (ly:stencil-extent markup X)))
          (y (* thick -2))
-         (line (ly:make-stencil
-                `(draw-line ,thick ,x1 ,y ,x2 ,y)
-                (cons (min x1 0) (max x2 0))
-                (cons thick thick))))
+         (line (make-line-stencil thick x1 y x2 y)))
     (ly:stencil-add markup line)))
 
 (define-builtin-markup-command (box layout props arg)
@@ -2530,11 +2521,9 @@ and continue with double letters.
          (num-y (interval-widen (cons center center) (abs dy)))
          (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
          (slash-stencil (if is-sane
-                            (ly:make-stencil
-                             `(draw-line ,thickness
-                                         ,(car num-x) ,(- (interval-center num-y) dy)
-                                         ,(cdr num-x) ,(+ (interval-center num-y) dy))
-                             num-x num-y)
+                            (make-line-stencil thickness 
+                                         (car num-x) (- (interval-center num-y) dy)
+                                         (cdr num-x) (+ (interval-center num-y) dy))
                             #f)))
     (if (ly:stencil? slash-stencil)
       (begin
index fb986f91b990f3589d48d05f883017aa2a559220..1ffa530d65df4186a14c19af513174f0907f246c 100644 (file)
@@ -70,18 +70,11 @@ Line thickness is given by @var{th}, fret & string spacing by
   (let* ((fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
          (sl (* (+ fret-count 1) size))
          (sth (* size th))
-         (half-thickness (* sth 0.5))
          (gap (- size sth))
          (string-stencil
           (if (eq? orientation 'normal)
-              (ly:make-stencil
-               (list 'draw-line sth 0 0 0 sl)
-               (cons (- half-thickness) half-thickness)
-               (cons (- half-thickness) (+ sl half-thickness)))
-              (ly:make-stencil
-               (list 'draw-line sth 0 0 sl 0)
-               (cons (- half-thickness) (+ sl half-thickness))
-               (cons (- half-thickness) half-thickness)))))
+              (make-line-stencil sth 0 0 0 sl)
+              (make-line-stencil sth 0 0 sl 0))))
     (if (= string-count 1)
         string-stencil
         (if (eq? orientation 'normal)
@@ -125,16 +118,10 @@ fret & string spacing by @var{size}. Orientation is given by @var{orientation}"
          (sth (* size th))
          (half-thickness (* sth 0.5)))
     (if (eq? orientation 'normal)
-        (ly:make-stencil
-         (list 'draw-line sth half-thickness size
+        (make-line-stencil sth half-thickness size
                (- fret-length half-thickness) size)
-         (cons 0 fret-length)
-         (cons (- half-thickness) half-thickness))
-        (ly:make-stencil
-         (list 'draw-line sth 0 half-thickness
-               0 (- fret-length half-thickness))
-         (cons (- half-thickness) half-thickness)
-         (cons 0 fret-length)))))
+        (make-line-stencil sth 0 half-thickness
+               0 (- fret-length half-thickness)))))
 
 (define (draw-thick-zero-fret details string-count th size orientation)
   "Draw a thick zeroth fret for a fret diagram whose base fret is not 1."
@@ -381,25 +368,13 @@ Line thickness is given by @var{th}, fret & string spacing by
              (barre-stencil
               (if (eq? barre-type 'straight)
                   (if (eq? orientation 'normal)
-                      (ly:make-stencil
-                       (list
-                        'draw-line (* size dot-radius) left dot-center-y
-                        right dot-center-y)
-                       (cons left right)
-                       (cons (- dot-center-y scale-dot-radius)
-                             (+ dot-center-y scale-dot-radius)))
-                      (ly:make-stencil
-                       (list 'draw-line (* size dot-radius)
+                      (make-line-stencil scale-dot-radius left dot-center-y
+                                         right dot-center-y)
+                      (make-line-stencil scale-dot-radius
                              (* size barre-fret-coordinate)
                              (* size barre-start-string-coordinate)
                              (* size barre-fret-coordinate)
-                             (* size barre-end-string-coordinate))
-                       (cons (- (* size barre-fret-coordinate)
-                                scale-dot-radius)
-                             (+ (* size barre-fret-coordinate)
-                                scale-dot-radius))
-                       (cons (* size barre-start-string-coordinate)
-                             (* size barre-end-string-coordinate))))
+                             (* size barre-end-string-coordinate)))
                   (if (eq? orientation 'normal)
                       (ly:make-stencil
                        (list 'bezier-sandwich
index 6a4b88d7b2c24a3f0d22e351cb277f2c68d4f2ec..19303ae691bc85d1499de93ae24b19dc01161244 100644 (file)
          (ly:stencil-combine-at-edge stil (other-axis axis) -1 rb padding))
     stil))
 
+(define-public (make-line-stencil width startx starty endx endy)
+  "Make a line stencil of given linewidth and set its extents accordingly"
+  (let ((xext (cons (min startx endx) (max startx endx)))
+        (yext (cons (min starty endy) (max starty endy))))
+    (ly:make-stencil
+      (list 'draw-line width startx starty endx endy)
+      ; Since the line has rounded edges, we have to / can safely add half the 
+      ; width to all coordinates!
+      (interval-widen xext (/ width 2))
+      (interval-widen yext (/ width 2)))))
+
 (define-public (make-filled-box-stencil xext yext)
   "Make a filled box."