[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

markups and extents

From: address@hidden
Subject: markups and extents
Date: Thu, 20 Oct 2011 11:00:57 +0200

Hey all,

I'm starting to work on a markup overhaul and I've been able to frame the 
problem with the code below.  There are two callbacks each for X and pure-Y:


my-*-callback-one gives minimal estimates for the given dimension, whereas 
my-*-callback-two gives maximal estimates.
The only code that doesn't lead to overlap is the use of maximal estimates for 
everything (my-*-callback-two, which I pasted below).  Subbing in 
my-*-callback-one for either value will lead to overlapping.  However, 
my-*-callback-two being very generous, the vertical spacing becomes too large.  
So, my question before I start fiddling with the C++ side is: is there a way to 
use non-pure-heights in LilyPond's vertical layout?

If not, my proposed game plan is the following (suggestions welcome!):

1) Create a variable in the Paper_column class called pure_x_offset_
2) From, run the spring and rods problem on an 
infinitely long line.  Give all paper columns a pure_x_offset_ that comes from 
this spring and rods problem (this, I'd argue, is the ideal horizontal spacing, 
unfettered by the length and width of a page).
3) Create a TextScriptSpanner
4) The pure height function of a text script spanner 
(Text_script_spanner::pure_height (SCM smob, SCM start, SCM end)) would go like 
---) if `start' is to the right of the TextScriptSpanner's left bound, return 0.
---) otherwise, find the distance between the pure_x_offset_ of the 
TextScriptSpanner's left bound and the pure_x_offset_ of the column at `end'
---) use this line-width to justify the text, then find the Y-extent of this 
stencil.  this is the pure-Y value between `start' and `end'.

Obviously, pure_x_offset_ will get progressively off as a piece continues, but 
for small ranges of columns, it will likely provide a good estimation of grobs' 

But, again, before I spend the 4ish hours necessary to do this, does anyone see 
any problems with it?


#(define (define-grob-property symbol type? description)
 (if (not (equal? (object-property symbol 'backend-doc) #f))
     (ly:error (_ "symbol ~S redefined") symbol))

 (set-object-property! symbol 'backend-type? type?)
 (set-object-property! symbol 'backend-doc description)

#(define (has-interface? grob interface)
 (member interface
      (assoc-get 'interfaces
                 (ly:grob-property grob 'meta))))

#(define-grob-property 'nuggets list? "List of text for a markup.")

#(define (my-max x y) (if (> (interval-length x) (interval-length y)) x y))

#(define (my-add x y) (cons (car x) (+ (cdr x) (interval-length y))))

#(define (my-x-callback-one grob)
 (reduce my-max -1000 (map (lambda (x) (ly:stencil-extent 
(grob-interpret-markup grob x) X))
                            (ly:grob-property grob 'nuggets))))

#(define (my-x-callback-two grob)
 (ly:stencil-extent (grob-interpret-markup grob (make-line-markup 
(ly:grob-property grob 'nuggets))) X))

#(define (my-y-callback-one grob start end)
 (ly:stencil-extent (grob-interpret-markup grob (make-line-markup 
(ly:grob-property grob 'nuggets))) Y))

#(define (my-y-callback-two grob start end)
 (reduce my-add '(0 . 0) (map (lambda (x) (ly:stencil-extent 
(grob-interpret-markup grob x) X))
                            (ly:grob-property grob 'nuggets))))

#(define (find-system grob)
(if (has-interface? grob 'system-interface)
  (find-system (ly:grob-parent grob X))))

#(define (my-stencil grob)
 (let* ((system (find-system grob))
        (mkups (map (lambda (x) (markup x)) (ly:grob-property grob 'nuggets)))
        (r-bound (ly:spanner-bound system RIGHT))
        (l-coord (ly:grob-relative-coordinate grob system X))
        (r-coord (ly:grob-relative-coordinate r-bound system X)))
   (grob-interpret-markup grob (markup #:override `(line-width . ,(- r-coord 
l-coord)) (make-justify-markup mkups)))))

foo =
#(define-music-function (parser location s) (string?)
 \once \override TextScript #'nuggets = #(string-split $s #\space)
 \once \override TextScript #'Y-extent = #(ly:make-unpure-pure-container 
ly:grob::stencil-height my-y-callback-two)
 \once \override TextScript #'X-extent = #my-x-callback-two
 \once \override TextScript #'stencil = #my-stencil

\relative c' {
 \override Score . PaperColumn #'keep-inside-line = ##f
 \repeat unfold 40 { \foo #"Hello world this is a test of a Scheme markup 
splitting system." d^\markup { \null } a b c d e f g }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]