Skip to content
Snippets Groups Projects
Commit d15756b9 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Make the toc file work with bookparts, too

parent 1b94ab73
No related branches found
No related tags found
No related merge requests found
...@@ -830,12 +830,17 @@ keepcuefilter = #(define-music-function (parser location music) (ly:music?) ...@@ -830,12 +830,17 @@ keepcuefilter = #(define-music-function (parser location music) (ly:music?)
removecuefilter = #(define-music-function (parser location music) (ly:music?) removecuefilter = #(define-music-function (parser location music) (ly:music?)
((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music))) ((ly:music-function-extract removeWithTag) parser location 'cued ((ly:music-function-extract killCues) parser location music)))
%% The page numbers are pages counts in the pdf file, not visible page number!
%% So we have to offset them if the first page is not page #1
%% unfortunately this means we have to store the first-page-number of the first
%% bookpart in a global variable, because in later layouts we don't have that
%% information available any more (first-page-number will be the first page
%% number of the currently processed bookpart!)
#(define oly:first-page-offset #f)
#(define (oly:create-toc-file layout pages) #(define (oly:create-toc-file layout pages)
(let* ((label-table (ly:output-def-lookup layout 'label-page-table)) (if (not oly:first-page-offset)
;; The page numbers are pages counts in the pdf file, not visible page number! (set! oly:first-page-offset (1- (ly:output-def-lookup layout 'first-page-number))))
;; So we have to offset them if the first page is not page #1 (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
(first-page-offset (1- (ly:output-def-lookup layout 'first-page-number))))
(if (not (null? label-table)) (if (not (null? label-table))
(let* ((format-line (lambda (toc-item) (let* ((format-line (lambda (toc-item)
(let* ((label (car toc-item)) (let* ((label (car toc-item))
...@@ -843,9 +848,12 @@ removecuefilter = #(define-music-function (parser location music) (ly:music?) ...@@ -843,9 +848,12 @@ removecuefilter = #(define-music-function (parser location music) (ly:music?)
(label-page (and (list? label-table) (label-page (and (list? label-table)
(assoc label label-table))) (assoc label label-table)))
(page (and label-page (cdr label-page)))) (page (and label-page (cdr label-page))))
(format #f "~a, section, 1, {~a}, ~a" (- page first-page-offset) text label)))) (if page
(format #f "~a, section, 1, {~a}, ~a" (- page oly:first-page-offset) text label)
;; label came from a different bookpart, so ignore it!
#f))))
(formatted-toc-items (map format-line (toc-items))) (formatted-toc-items (map format-line (toc-items)))
(whole-string (string-join formatted-toc-items ",\n")) (whole-string (string-join (filter (lambda (i) i) formatted-toc-items) ",\n"))
(output-name (ly:parser-output-name parser)) (output-name (ly:parser-output-name parser))
(outfilename (format "~a.toc" output-name)) (outfilename (format "~a.toc" output-name))
(outfile (open-output-file outfilename))) (outfile (open-output-file outfilename)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment