From fbf273dae953c2549d8f1ac2806df644e2681d11 Mon Sep 17 00:00:00 2001 From: tux Date: Wed, 9 Aug 2023 16:39:17 +0200 Subject: [PATCH] smarter breaks in toc columns closes #2 --- toc_include.ly | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/toc_include.ly b/toc_include.ly index 3b98c1a..483125c 100644 --- a/toc_include.ly +++ b/toc_include.ly @@ -19,13 +19,21 @@ (map (lambda (foo) (make-general-align-markup Y UP (make-override-markup '(baseline-skip . 1) (make-column-markup (let add-to-col ((lines restlines) (height-left height)) - (let* ((finished (null? lines)) - (linestencil (if (not finished) (interpret-markup layout (cons (list (cons 'line-width line-width) (cons 'baseline-skip 1)) props) (markup #:center-align (car lines))))) - (calc-height (- height-left (if finished 0 (interval-length (ly:stencil-extent linestencil Y)))))) - (set! restlines lines) - (if (or (< calc-height 0) (null? lines)) - (list) - (cons (markup #:stencil linestencil) (add-to-col (cdr lines) calc-height))))))))) + (set! restlines lines) + (if (null? lines) + '() + (let* ((line-to-stencil (lambda (line) (interpret-markup layout (cons (list (cons 'line-width line-width) (cons 'baseline-skip 1)) props) (markup line)))) + (stencil-height (lambda (stencil) (interval-length (ly:stencil-extent stencil Y)))) + (linestencil (line-to-stencil (car lines))) + (calc-height (- height-left (stencil-height linestencil))) + (calc-width (interval-length (ly:stencil-extent linestencil X))) + (is-less-than-half-line-width (< calc-width (/ line-width 2.0))) + (next-line-height (if (null? (cdr lines)) 0 (stencil-height (line-to-stencil (cadr lines))))) + (no-space-for-next-line (and is-less-than-half-line-width (< (- calc-height next-line-height) 0))) + ) + (if (or (< calc-height 0) no-space-for-next-line) + '() + (cons (markup #:stencil linestencil) (add-to-col (cdr lines) calc-height)))))))))) (make-list cols)))) (if (null? restlines) (list) @@ -182,8 +190,8 @@ indexItemMarkup = \markup \with-link-symbol-ref #'index:label { \index-item-with-pattern } - indexSectionMarkup = \markup \override #'(baseline-skip . 1.5) \column { - \fill-line { \sans \bold \fontsize #3 \fromproperty #'index:text \null } + indexSectionMarkup = \markup \override #'(baseline-skip . 1.5) \left-column { + \sans \bold \fontsize #3 \fromproperty #'index:text \null } indexCategoryMarkup = \markup \override #'(baseline-skip . 1.5) \column {