]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-markup-commands.scm
Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / scm / define-markup-commands.scm
index 9a576439fbd1386b35cf71c7eb85de52cf659b01..125a34339ff726c533fa915d96ad9fa023890a03 100644 (file)
@@ -143,17 +143,27 @@ A simple line.
   ()
   #:category graphic
   #:properties ((draw-line-markup)
-                (line-width))
+                (line-width)
+                (span-factor 1))
   "
 @cindex drawing a line across a page
 
-Draws a line across a page.
+Draws a line across a page, where the property @code{span-factor}
+controls what fraction of the page is taken up.
 @lilypond[verbatim,quote]
 \\markup {
-  \\draw-hline
+  \\column {
+    \\draw-hline
+    \\override #'(span-factor . 1/3)
+    \\draw-hline
+  }
 }
 @end lilypond"
-  (interpret-markup layout props (make-draw-line-markup (cons line-width 0))))
+  (interpret-markup layout
+                    props
+                    (markup #:draw-line (cons (* line-width
+                                                  span-factor)
+                                               0))))
 
 (define-markup-command (draw-circle layout props radius thickness filled)
   (number? number? boolean?)
@@ -254,6 +264,60 @@ the PDF backend.
 
     (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
 
+(define-markup-command (page-link layout props page-number arg)
+  (number? markup?)
+  #:category other
+  "
+@cindex referencing page numbers in text
+
+Add a link to the page @var{page-number} around @var{arg}. This only works in
+the PDF backend.
+
+@lilypond[verbatim,quote]
+\\markup {
+  \\page-link #2  { \\italic { This links to page 2... } }
+}
+@end lilypond"
+  (let* ((stil (interpret-markup layout props arg))
+        (xextent (ly:stencil-extent stil X))
+        (yextent (ly:stencil-extent stil Y))
+        (old-expr (ly:stencil-expr stil))
+        (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
+
+    (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
+
+(define-markup-command (with-link layout props label arg)
+  (symbol? markup?)
+  #:category other
+  "
+@cindex referencing page labels in text
+
+Add a link to the page holding label @var{label} around @var{arg}. This
+only works in the PDF backend.
+
+@lilypond[verbatim,quote]
+\\markup {
+  \\with-link #\"label\" { \\italic { This links to the page containing the label... } }
+}
+@end lilypond"
+  (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:make-stencil
+     `(delay-stencil-evaluation
+       ,(delay (ly:stencil-expr
+                (let* ((table (ly:output-def-lookup layout 'label-page-table))
+                       (page-number (if (list? table)
+                                        (assoc-get label table)
+                                        #f))
+                       (link-expr (list 'page-link 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)))
+
+
 (define-markup-command (beam layout props width slope thickness)
   (number? number? number?)
   #:category graphic