[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lilypond-user
Subject:    Vertically filling a markup list
From:       Valentin Petzel <valentin () petzel ! at>
Date:       2023-02-19 13:54:31
Message-ID: 2698883.iZASKD2KPV () archbox
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hello Pondmates,

a while ago I did a small function for filling a markup list onto a given 
height or the whole page. The intended use for this is designing titlepages 
and such directly within Lilypond.

I've now buffed up the function a bit, allowing to use unequal distribution of 
the additional space. This can be done by adjusting the weight of each space 
by annotating the lower markup with

markup1
\annotate #'((weight . someweight))
markup2

or by directly specifying a ratio the same way:

markup1
\annotate #'((ratio . someratio))
markup2

And yes, the publisher is a fictional counterpart to UE.

Cheers,
Valentin
["vertical-fill.ly" (vertical-fill.ly)]

\header {
  tagline = ##f
}

\paper {
  % Remove headers
  oddHeaderMarkup = ##f
  evenHeaderMarkup = ##f
  oddFooterMarkup = ##f
  evenFooterMarkup = ##f
}

#(define (printable-height layout props)
   (let*
    ((height (ly:output-def-lookup layout 'paper-height))
     (tm (ly:output-def-lookup layout 'top-margin))
     (bm (ly:output-def-lookup layout 'bottom-margin))
     (tms (ly:output-def-lookup layout 'top-markup-spacing))
     (tms (+ (assoc-get 'minimum-distance tms 0) (assoc-get 'padding tms 0))))
    (- height tm bm tms)))

#(define-markup-command (annotate layout props annot mu) (list? markup?)
   (interpret-markup layout props mu))

#(define* (markup-property m sym #:optional (default '()))
   (if (and (list? m) (equal? (procedure-name (car m)) 'annotate-markup))
       (let ((props (cadr m)))
         (assoc-get sym props default))
       default))

#(define-markup-command (vertical-fill layout props height mups) (number? markup-list?)
   (let*
    ((realheight (if (>= height 0) height (printable-height layout props)))
     (stcs (interpret-markup-list layout props mups))
     (tmu (stack-stencils Y DOWN 0 stcs))
     (muext (ly:stencil-extent tmu Y))
     (muheight (interval-length muext))
     (noels (length mups))
     (ratios (map (lambda (m) (markup-property m 'ratio)) (cdr mups)))
     (sumrats (fold (lambda (x prev) (+ prev (if (null? x) 0 x))) 0 ratios))
     (weights (map (lambda (m) (markup-property m 'weight 1)) (cdr mups)))
     (restratweight (fold (lambda (w r prev) (+ prev (if (null? r) w 0))) 0 weights ratios))
     (restratfac (if (> restratweight 0) (/ (- 1 sumrats) restratweight) 0))
     (ratios (map (lambda (r w) (if (null? r) (* w restratfac) r)) ratios weights))
     (space (- realheight muheight))
     (mu (if (> noels 1)
             (fold (lambda (stc ratio prev)
                     (ly:stencil-stack prev Y DOWN stc (* space ratio)))
                   (car stcs) (cdr stcs) ratios)
             (if (= noels 0) empty-stencil
               (interpret-markup layout props (car mups))))))
    mu))

\markup \fill-line {
  \vertical-fill #50  { a b \column { c d e } }
  \vertical-fill #100 { a \annotate #'((ratio . 0.2)) b \column { c d e } }
  \vertical-fill #-1  { a \annotate #'((weight . 2)) b \column { c d e } }
}

\pageBreak

\markup \vertical-fill #-1 {
  \fill-line { \null \fontsize #2 "LILY BOGUS FESTIVAL 2312" }

  \annotate #'((ratio . 0.25))
  \vertical-fill #22 {
    \fill-line { \null \fontsize #7 "John Henry Decomposer" \null }

    \override #'(baseline-skip . 5)
    \column {
      \fill-line { \null \fontsize #9 "Missa solenelle" \null }
      \fill-line { \null \fontsize #6 "per tre elefanti ed organo" \null }
    }
  }

  \annotate #'((ratio . 0.3))
  \fill-line { \null \fontsize #9 \musicglyph #"clefs.C" \null }

  \fill-line { \null \fontsize #2 "VerySpecificEdition" \null }
}

\pageBreak

\markup \vertical-fill #-1 {
  \fill-line { \null \fontsize #2 "LILY BOGUS FESTIVAL 2312" }

  \annotate #'((weight . 0.55))
  \vertical-fill #22 {
    \fill-line { \null \fontsize #7 "John Henry Decomposer" \null }

    \override #'(baseline-skip . 5)
    \column {
      \fill-line { \null \fontsize #9 "Missa solenelle" \null }
      \fill-line { \null \fontsize #6 "per tre elefanti ed organo" \null }
    }
  }

  \annotate #'((weight . 0.66))
  \fill-line { \null \fontsize #9 \musicglyph #"clefs.C" \null }

  \fill-line { \null \fontsize #2 "VerySpecificEdition" \null }
}
["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic