]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-grobs.scm
* Unify fetaDynamic and fetaNumber into one fetaText encoding
[lilypond.git] / scm / define-grobs.scm
index 5b54ad835a35815c3db755290c2bd5375b904584..8251fec8192086a91a9bd347105376c4de17856f 100644 (file)
@@ -1,9 +1,20 @@
-;;;; define-grobs.scm --
+;;;; This file is part of LilyPond, the GNU music typesetter.
 ;;;;
-;;;;  source file of the GNU LilyPond music typesetter
-;;;;
-;;;; (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
+;;;; Copyright (C) 1998--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
 ;;;;                 Jan Nieuwenhuizen <janneke@gnu.org>
+;;;;
+;;;; LilyPond is free software: you can redistribute it and/or modify
+;;;; it under the terms of the GNU General Public License as published by
+;;;; the Free Software Foundation, either version 3 of the License, or
+;;;; (at your option) any later version.
+;;;;
+;;;; LilyPond is distributed in the hope that it will be useful,
+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;;; GNU General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU General Public License
+;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;;; distances are given in line-thickness (thicknesses) and
 ;;;; staff-space (distances)
        (stencil . ,ly:arpeggio::print)
        (X-extent . ,ly:arpeggio::width)
        (X-offset . ,ly:side-position-interface::x-aligned-side)
-       (Y-extent . ,ly:arpeggio::height)
        (Y-offset . ,ly:staff-symbol-referencer::callback)
        (meta . ((class . Item)
                 (interfaces . (arpeggio-interface
        (direction . ,UP)
        (extra-spacing-width . (+inf.0 . -inf.0))
        (font-series . bold)
+       (outside-staff-priority . 450)
        (padding . 0.5)
        (script-priority . 200)
        (side-axis . ,Y)
     (DoublePercentRepeatCounter
      . (
        (direction . ,UP)
-       (font-encoding . fetaNumber)
+       (font-encoding . fetaText)
        (font-size . -2)
        (padding . 0.2)
        (self-alignment-X . ,CENTER)
 
        (direction . ,ly:script-interface::calc-direction)
        (extra-spacing-width . (+inf.0 . -inf.0))
-       (font-encoding . fetaDynamic)
+       (font-encoding . fetaText)
        (font-series . bold)
        (font-shape . italic)
        (outside-staff-priority . 250)
        (positioning-done . ,ly:script-interface::calc-positioning-done)
+       (right-padding . 0.5)
        (self-alignment-X . ,CENTER)
        (self-alignment-Y . ,CENTER)
        (stencil . ,ly:text-interface::print)
        (Y-offset . ,ly:self-alignment-interface::y-aligned-on-self)
        (meta . ((class . Item)
                 (interfaces . (dynamic-interface
+                               dynamic-text-interface
                                font-interface
                                script-interface
                                self-alignment-interface
 
     (DynamicTextSpanner
      . (
+       (before-line-breaking . ,dynamic-text-spanner::before-line-breaking)
        (bound-details . ((right . ((attach-dir .  ,LEFT)
                                    (Y . 0)
                                    (padding . 0.75)
 
                          (left . ((attach-dir .  ,LEFT)
                                   (Y . 0)
-                                  (stencil-offset . (0 . -0.5))
-                                  (padding . 0.5)
+                                  (stencil-offset . (-0.75 . -0.5))
+                                  (padding . 0.75)
                                   ))
                          (left-broken . ((attach-dir .  ,RIGHT)
                                   ))
                                text-interface))))))
 
 
+    (Episema
+     . (
+       (bound-details . ((left . ((Y . 0)
+                                  (padding . 0)
+                                  (attach-dir . ,LEFT)
+                                  ))
+                         (right . ((Y . 0)
+                                   (padding . 0)
+                                   (attach-dir . ,RIGHT)
+                                   ))
+                         ))
+       (direction . ,UP)
+       (left-bound-info . ,ly:line-spanner::calc-left-bound-info)
+       (quantize-position . #t)
+       (right-bound-info . ,ly:line-spanner::calc-right-bound-info)
+       (side-axis . ,Y)
+       (stencil . ,ly:line-spanner::print)
+       (style . line)
+       (Y-offset . ,ly:side-position-interface::y-aligned-side)
+       (meta . ((class . Spanner)
+                (interfaces . (episema-interface
+                               font-interface
+                               line-interface
+                               line-spanner-interface
+                               side-position-interface))))))
+
+
     (Fingering
      . (
 
        (avoid-slur . around)
        (cross-staff . ,ly:side-position-interface::calc-cross-staff)
        (direction . ,ly:script-interface::calc-direction)
-       (font-encoding . fetaNumber)
+       (font-encoding . fetaText)
        (font-size . -5)                ; don't overlap when next to heads.
        (padding . 0.5)
        (positioning-done . ,ly:script-interface::calc-positioning-done)
        (stencil . ,ly:hairpin::print)
        (thickness . 1.0)
        (to-barline . #t)
-       (Y-extent . ,ly:hairpin::height)
        (Y-offset . ,ly:self-alignment-interface::y-aligned-on-self)
        (meta . ((class . Spanner)
                 (interfaces . (dynamic-interface
      . (
        (bound-padding  . 2.0)
        (direction . ,UP)
-       (font-encoding . fetaNumber)
+       (font-encoding . fetaText)
        (padding . 0.4)
        (self-alignment-X . ,CENTER)
        (side-axis . ,Y)
     (PercentRepeatCounter
      . (
        (direction . ,UP)
-       (font-encoding . fetaNumber)
+       (font-encoding . fetaText)
        (font-size . -2)
        (padding . 0.2)
        (self-alignment-X . ,CENTER)
     (StringNumber
      . (
        (avoid-slur . around)
-       (font-encoding . fetaNumber)
+       (font-encoding . fetaText)
        (font-size . -5)                ; don't overlap when next to heads.
        (padding . 0.5)
        (script-priority . 100)
        (font-size . -2)
        (stem-attachment . (0.0 . 1.35))
        (stencil . ,ly:text-interface::print)
+       (whiteout . #t)
        (X-offset . ,ly:self-alignment-interface::x-aligned-on-self)
        (Y-offset . ,ly:staff-symbol-referencer::callback)
        (meta . ((class . Item)
                                   (padding . 0.25)
                                   (attach-dir . ,LEFT)
                                   ))
+                         (left-broken . ((end-on-note . #t)))
                          (right . ((Y . 0)
                                    (padding . 0.25)
                                    ))
     (TrillSpanner
      . (
        (after-line-breaking . ,ly:spanner::kill-zero-spanned-time)
-       (bound-details . ((left . ((text . ,(make-translate-scaled-markup
-                                            '(0.0 . -1.0)
-                                            (make-musicglyph-markup "scripts.trill")))
+       (bound-details . ((left . ((text . ,(make-musicglyph-markup "scripts.trill"))
                                   (Y . 0)
-                                  (stencil-offset . (-0.5 . 0))
-                                  (padding . 1.5)
+                                  (stencil-offset . (-0.5 . -1))
+                                  (padding . 0.5)
                                   (attach-dir . ,CENTER)
-                                  ;; this isn't CENTER because the trill glyph's origin
-                                  ;; is not centered in its extent; to have the trill
-                                  ;; spanner aligned the same as a trill, we need a slight offset
-                                  (anchor-alignment . 0.15)
                                   ))
                          (left-broken . ((end-on-note . #t)))
                          (right . ((Y . 0)))
      . (
        (direction . ,UP)
        (edge-height . (2.0 . 2.0)) ;; staff-space;
-       (font-encoding . fetaNumber)
+       (font-encoding . fetaText)
        (font-size . -4)
        (stencil . ,ly:volta-bracket-interface::print)
-       (thickness . 1.6)  ;;  line-thickness
+       (thickness . 1.6) ;; line-thickness
        (word-space . 0.6)
        (meta . ((class . Spanner)
                 (interfaces . (font-interface
                                line-interface
                                side-position-interface
                                text-interface
-                               volta-bracket-interface))))))
+                               volta-bracket-interface
+                               volta-interface))))))
 
     (VoltaBracketSpanner
      . (
        (after-line-breaking . ,ly:side-position-interface::move-to-extremal-staff)
        (axes . (,Y))
        (direction . ,UP)
-       (no-alignment . ,#t)
+       (no-alignment . #t)
        (outside-staff-priority . 600)
        (padding . 1)
        (side-axis . ,Y)
        (Y-offset . ,ly:side-position-interface::y-aligned-side)
        (meta . ((class . Spanner)
                 (interfaces . (axis-group-interface
-                               side-position-interface))))))
+                               side-position-interface
+                               volta-interface))))))
 
 ))
 
 
 (set! all-grob-descriptions (sort all-grob-descriptions alist<?))
 
+(define (volta-bracket-interface::pure-height grob start end)
+  (let ((edge-height (ly:grob-property grob 'edge-height)))
+    (if (number-pair? edge-height)
+       (let ((smaller (min (car edge-height) (cdr edge-height)))
+             (larger (max (car edge-height) (cdr edge-height))))
+         (interval-union '(0 . 0) (cons smaller larger)))
+       '(0 . 0))))
+
 (define pure-print-callbacks
   (list
    fret-board::calc-stencil
+   note-head::brew-ez-stencil
    print-circled-text-callback
    lyric-text::print
-   ly:arpeggio::print
-   ly:arpeggio::brew-chord-bracket
    ly:bar-line::print
    ly:mensural-ligature::brew-ligature-primitive
    ly:note-head::print
    ly:text-interface::print
    ly:script-interface::print))
 
-;; ly:grob::stencil-extent is safe iff the print callback is safe too
+;; Sometimes we have grobs with (Y-extent . ,ly:grob::stencil-height)
+;; and the print function is not pure, but there is a easy way to
+;; figure out the Y-extent from the print function.
+(define pure-print-to-height-conversions
+  `(
+    (,ly:arpeggio::print . ,ly:arpeggio::pure-height)
+    (,ly:arpeggio::brew-chord-bracket . ,ly:arpeggio::pure-height)
+    (,ly:hairpin::print . ,ly:hairpin::pure-height)
+    (,ly:volta-bracket-interface::print . ,volta-bracket-interface::pure-height)))
+
+;; ly:grob::stencil-extent is safe if the print callback is safe too
 (define (pure-stencil-height grob start stop)
-  (let ((sten (ly:grob-property-data grob 'stencil)))
-    (if (or
-        (ly:stencil? sten)
-        (memq sten pure-print-callbacks))
-       (ly:grob::stencil-height grob)
-       '(0 . 0))))
+  (let* ((sten (ly:grob-property-data grob 'stencil))
+        (pure-height-callback (assoc-get sten pure-print-to-height-conversions)))
+    (cond ((or
+           (ly:stencil? sten)
+           (memq sten pure-print-callbacks))
+          (ly:grob::stencil-height grob))
+         ((procedure? pure-height-callback)
+          (pure-height-callback grob start stop))
+         (else
+          '(0 . 0)))))
 
 (define pure-conversions-alist
   `(
     (,ly:accidental-interface::height . ,ly:accidental-interface::pure-height)
-    (,ly:arpeggio::height . ,ly:arpeggio::pure-height)
     (,ly:slur::outside-slur-callback . ,ly:slur::pure-outside-slur-callback)
-    (,ly:hairpin::height . ,ly:hairpin::pure-height)
     (,ly:stem::height . ,ly:stem::pure-height)
     (,ly:rest::height . ,ly:rest::pure-height)
     (,ly:grob::stencil-height . ,pure-stencil-height)
               (memq extent-callback pure-functions)
               (and
                (pair? (assq extent-callback pure-conversions-alist))
-               (begin
+               (let ((stencil (ly:grob-property-data grob 'stencil)))
                  (or
                   (not (eq? extent-callback ly:grob::stencil-height))
-                  (memq (ly:grob-property-data grob 'stencil) pure-print-callbacks)
-                  (ly:stencil? (ly:grob-property-data grob 'stencil))
-
-                  ))))))))
+                  (memq stencil pure-print-callbacks)
+                  (assq stencil pure-print-to-height-conversions)
+                  (ly:stencil? stencil)))))))))
 
 (define-public (call-pure-function unpure args start end)
   (if (ly:simple-closure? unpure)