Reviewers: ,

Description:
Table Of Contents crash with negative first-page-number

Issue 4494

Let \with-link point to the physical page-number

Please review this at https://codereview.appspot.com/258740043/

Affected files (+20, -11 lines):
  M scm/define-markup-commands.scm


Index: scm/define-markup-commands.scm
diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm
index 5a08facce20b7d8c040c43722028b010cfa82b35..63a2303ea69d18f25f6f8e11dbcefdd66449f5fb 100644
--- a/scm/define-markup-commands.scm
+++ b/scm/define-markup-commands.scm
@@ -528,19 +528,28 @@ only works in the PDF backend.
   (let* ((arg-stencil (interpret-markup layout props arg))
          (x-ext (ly:stencil-extent arg-stencil X))
          (y-ext (ly:stencil-extent arg-stencil Y)))
-    (ly:stencil-add
-     (ly:make-stencil
+    (ly:make-stencil
       `(delay-stencil-evaluation
- ,(delay (let* ((table (ly:output-def-lookup layout 'label-page-table))
-                       (page-number (if (list? table)
-                                        (assoc-get label table)
-                                        #f)))
-                  (list 'page-link page-number
-                        `(quote ,x-ext) `(quote ,y-ext)))))
+        ,(delay (ly:stencil-expr
+ (let* ((table (ly:output-def-lookup layout 'label-page-table))
+                        (table-page-number
+                          (if (list? table)
+                              (assoc-get label table)
+                              #f))
+                        (first-page-number
+                          (ly:output-def-lookup layout 'first-page-number))
+                        (current-page-number
+ (+ table-page-number (+ 1 (* -1 first-page-number))))
+                        (link-expr
+                          (list 'page-link
+                                current-page-number
+                                `(quote ,x-ext)
+                                `(quote ,y-ext))))
+                   (ly:stencil-add
+                     (ly:make-stencil link-expr x-ext y-ext)
+                     arg-stencil)))))
       x-ext
-      y-ext)
-     arg-stencil)))
-
+      y-ext)))

 (define-markup-command (beam layout props width slope thickness)
   (number? number? number?)



_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to