From: Reinhold Kainhofer Date: Sun, 17 Aug 2008 23:45:17 +0000 (+0200) Subject: Add a make-line-stencil function, which correctly sets stencil extents X-Git-Tag: release/2.11.57-1~34^2~16 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5a5ac06f4f6e8b737a59a25aae0663a32f8215e3;p=lilypond.git Add a make-line-stencil function, which correctly sets stencil extents 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 --- diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm index 18112b874c..a63dba2995 100644 --- a/scm/define-markup-commands.scm +++ b/scm/define-markup-commands.scm @@ -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 diff --git a/scm/fret-diagrams.scm b/scm/fret-diagrams.scm index fb986f91b9..1ffa530d65 100644 --- a/scm/fret-diagrams.scm +++ b/scm/fret-diagrams.scm @@ -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 diff --git a/scm/stencil.scm b/scm/stencil.scm index 6a4b88d7b2..19303ae691 100644 --- a/scm/stencil.scm +++ b/scm/stencil.scm @@ -70,6 +70,17 @@ (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."