+(define-markup-command (triangle layout props filled) (boolean?)
+ "A triangle, filled or not"
+ (let*
+ ((th (chain-assoc-get 'thickness props 0.1))
+ (size (chain-assoc-get 'font-size props 0))
+ (ex (* (magstep size)
+ 0.8
+ (chain-assoc-get 'baseline-skip props 2))))
+
+ (ly:make-stencil
+ `(polygon '(0.0 0.0
+ ,ex 0.0
+ ,(* 0.5 ex)
+ ,(* 0.86 ex))
+ ,th
+ ,filled)
+
+ (cons 0 ex)
+ (cons 0 (* .86 ex))
+ )))
+
+(define-markup-command (circle layout props arg) (markup?)
+ "Draw a circle around @var{arg}. Use @code{thickness},
+@code{circle-padding} and @code{font-size} properties to determine line
+thickness and padding around the markup."
+ (let* ((th (chain-assoc-get 'thickness props 0.1))
+ (size (chain-assoc-get 'font-size props 0))
+ (pad
+ (* (magstep size)
+ (chain-assoc-get 'circle-padding props 0.2)))
+ (m (interpret-markup layout props arg)))
+ (circle-stencil m th pad)))
+
+(define-markup-command (with-url layout props url arg) (string? markup?)
+ "Add a link to URL @var{url} around @var{arg}. This only works in
+the PDF backend."
+ (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))
+ (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
+ (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
+
+
+(define-markup-command (beam layout props width slope thickness)
+ (number? number? number?)
+ "Create a beam with the specified parameters."
+ (let* ((y (* slope width))
+ (yext (cons (min 0 y) (max 0 y)))
+ (half (/ thickness 2)))
+
+ (ly:make-stencil
+ `(polygon ',(list
+ 0 (/ thickness -2)
+ width (+ (* width slope) (/ thickness -2))
+ width (+ (* width slope) (/ thickness 2))
+ 0 (/ thickness 2))
+ ,(ly:output-def-lookup layout 'blot-diameter)
+ #t)
+ (cons 0 width)
+ (cons (+ (- half) (car yext))
+ (+ half (cdr yext))))))
+
+(define-markup-command (box layout props arg) (markup?)
+ "Draw a box round @var{arg}. Looks at @code{thickness},
+@code{box-padding} and @code{font-size} properties to determine line
+thickness and padding around the markup."
+
+ (let* ((th (chain-assoc-get 'thickness props 0.1))
+ (size (chain-assoc-get 'font-size props 0))
+ (pad (* (magstep size)
+ (chain-assoc-get 'box-padding props 0.2)))
+ (m (interpret-markup layout props arg)))
+ (box-stencil m th pad)))
+
+(define-markup-command (filled-box layout props xext yext blot)
+ (number-pair? number-pair? number?)
+ "Draw a box with rounded corners of dimensions @var{xext} and
+@var{yext}. For example,
+@verbatim
+\\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
+@end verbatim
+create a box extending horizontally from -0.3 to 1.8 and
+vertically from -0.3 up to 1.8, with corners formed from a
+circle of diameter 0 (ie sharp corners)."
+ (ly:round-filled-box
+ xext yext blot))
+
+(define-markup-command (whiteout layout props arg) (markup?)
+ "Provide a white underground for @var{arg}"
+ (let* ((stil (interpret-markup layout props
+ (make-with-color-markup black arg)))
+ (white
+ (interpret-markup layout props
+ (make-with-color-markup
+ white
+ (make-filled-box-markup
+ (ly:stencil-extent stil X)
+ (ly:stencil-extent stil Y)
+ 0.0)))))
+
+ (ly:stencil-add white stil)))
+
+(define-markup-command (pad-markup layout props padding arg) (number? markup?)
+ "Add space around a markup object."
+
+ (let*
+ ((stil (interpret-markup layout props arg))
+ (xext (ly:stencil-extent stil X))
+ (yext (ly:stencil-extent stil Y)))
+
+ (ly:make-stencil
+ (ly:stencil-expr stil)
+ (interval-widen xext padding)
+ (interval-widen yext padding))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; space
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;FIXME: is this working?
+(define-markup-command (strut layout props) ()
+ "Create a box of the same height as the space in the current font."
+ (let ((m (ly:text-interface::interpret-markup layout props " ")))
+ (ly:make-stencil (ly:stencil-expr m)
+ '(1000 . -1000)
+ (ly:stencil-extent m X)
+ )))
+
+
+;; todo: fix negative space
+(define-markup-command (hspace layout props amount) (number?)
+ "This produces a invisible object taking horizontal space.
+@example
+\\markup @{ A \\hspace #2.0 B @}
+@end example
+will put extra space between A and B, on top of the space that is
+normally inserted before elements on a line.
+"
+ (if (> amount 0)
+ (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
+ (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; importing graphics.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define-markup-command (stencil layout props stil) (ly:stencil?)