;;; * each markup function should have a doc string with
;; syntax, description and example.
+(use-modules (ice-9 regex))
+
(define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
(define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
"Stencil as markup"
stil)
+(def-markup-command (draw-circle layout props radius thickness)
+ (number? number?)
+ "A circle of radius @var{radius} and thickness @var{thickness}"
+ (make-circle-stencil radius thickness))
+
+(def-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)))
(def-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 X))
- (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)))
+ (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)))
(def-markup-command (score layout props score) (ly:score?)
"Inline an image of music."
(if (= 0 (vector-length systems))
(begin
- (ly:warn "No systems found in \\score markup. Did you forget \\layout?")
+ (ly:warn (_"No systems found in \\score markup. Does it have a \\layout? block"))
empty-markup)
- (begin
- (let* ((stencil (ly:paper-system-stencil (vector-ref systems 0))))
-
- (ly:stencil-align-to! stencil Y CENTER)
- stencil)))))
+ (let* ((stencil (ly:paper-system-stencil (vector-ref systems 0))))
+
+ (ly:stencil-aligned-to stencil Y CENTER)))))
(def-markup-command (simple layout props str) (string?)
"A simple text string; @code{\\markup @{ foo @}} is equivalent with
(def-markup-command (encoded-simple layout props sym str) (symbol? string?)
"A text string, encoded with encoding @var{sym}. See
@usermanref{Text encoding} for more information."
- (Text_interface::interpret_string layout
- props sym str))
+ (Text_interface::interpret_string layout props sym str))
;; TODO: use font recoding.
(stack-stencils-padding-list X RIGHT fill-space-normal line-stencils))))
(define (get-fill-space word-count line-width text-widths)
- "Calculates the necessary paddings between each two adjacent texts.
+ "Calculate the necessary paddings between each two adjacent texts.
The lengths of all texts are stored in @var{text-widths}.
The normal formula for the padding between texts a and b is:
padding = line-width/(word-count - 1) - (length(a) + length(b))/2
The first and last padding have to be calculated specially using the
whole length of the first or last text.
- Returns a list of paddings.
+ Return a list of paddings.
"
(cond
- ;; special case first padding
- ((= (length text-widths) word-count)
- (cons
- (- (- (/ line-width (1- word-count)) (car text-widths)) (/ (car (cdr text-widths)) 2))
- (get-fill-space word-count line-width (cdr text-widths))))
- ;; special case last padding
- ((= (length text-widths) 2)
- (list (- (/ line-width (1- word-count)) (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
- (else
- (cons
- (- (/ line-width (1- word-count)) (/ (+ (car text-widths) (car (cdr text-widths))) 2))
- (get-fill-space word-count line-width (cdr text-widths))))))
+ ;; special case first padding
+ ((= (length text-widths) word-count)
+ (cons
+ (- (- (/ line-width (1- word-count)) (car text-widths))
+ (/ (car (cdr text-widths)) 2))
+ (get-fill-space word-count line-width (cdr text-widths))))
+ ;; special case last padding
+ ((= (length text-widths) 2)
+ (list (- (/ line-width (1- word-count))
+ (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
+ (else
+ (cons
+ (- (/ line-width (1- word-count))
+ (/ (+ (car text-widths) (car (cdr text-widths))) 2))
+ (get-fill-space word-count line-width (cdr text-widths))))))
(define (font-markup qualifier value)
(lambda (layout props arg)
- (interpret-markup layout
- (prepend-alist-chain qualifier value props)
- arg)))
-
+ (interpret-markup layout (prepend-alist-chain qualifier value props) arg)))
(def-markup-command (line layout props args) (markup-list?)
"Put @var{args} in a horizontal line. The property @code{word-space}
arg))
(def-markup-command (fontsize layout props mag arg) (number? markup?)
- "This sets the relative font size, e.g.
+ "Set the relative font size, e.g.
@example
A \\fontsize #2 @{ B C @} D
@end example
arg))
(def-markup-command (magnify layout props sz arg) (number? markup?)
- "This sets the font magnification for the its argument. In the following
+ "Set the font magnification for the its argument. In the following
example, the middle A will be 10% larger:
@example
A \\magnify #1.1 @{ A @} A
"Draw a double flat symbol."
(interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
+
+;;
+;; TODO: should extract baseline-skip from each argument somehow..
+;;
(def-markup-command (column layout props args) (markup-list?)
"Stack the markups in @var{args} vertically. The property
@code{baseline-skip} determines the space between each markup in @var{args}."
(def-markup-command (center-align layout props args) (markup-list?)
"Put @code{args} in a centered column. "
(let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
- (cmols (map (lambda (x) (ly:stencil-align-to! x X CENTER)) mols)))
+ (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
(stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
(def-markup-command (vcenter layout props arg) (markup?)
"Align @code{arg} to its Y center. "
(let* ((mol (interpret-markup layout props arg)))
- (ly:stencil-align-to! mol Y CENTER)
- mol))
+ (ly:stencil-aligned-to mol Y CENTER)))
(def-markup-command (hcenter layout props arg) (markup?)
"Align @code{arg} to its X center. "
(let* ((mol (interpret-markup layout props arg)))
- (ly:stencil-align-to! mol X CENTER)
- mol))
+ (ly:stencil-aligned-to mol X CENTER)))
(def-markup-command (right-align layout props arg) (markup?)
"Align @var{arg} on its right edge. "
(let* ((m (interpret-markup layout props arg)))
- (ly:stencil-align-to! m X RIGHT)
- m))
+ (ly:stencil-aligned-to m X RIGHT)))
(def-markup-command (left-align layout props arg) (markup?)
"Align @var{arg} on its left edge. "
(let* ((m (interpret-markup layout props arg)))
- (ly:stencil-align-to! m X LEFT)
- m))
+ (ly:stencil-aligned-to m X LEFT)))
(def-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
"Align @var{arg} in @var{axis} direction to the @var{dir} side."
(let* ((m (interpret-markup layout props arg)))
- (ly:stencil-align-to! m axis dir)
- m))
+ (ly:stencil-aligned-to m axis dir)))
(def-markup-command (halign layout props dir arg) (number? markup?)
"Set horizontal alignment. If @var{dir} is @code{-1}, then it is
left-aligned, while @code{+1} is right. Values in between interpolate
alignment accordingly."
(let* ((m (interpret-markup layout props arg)))
- (ly:stencil-align-to! m X dir)
- m))
+ (ly:stencil-aligned-to m X dir)))
(def-markup-command (musicglyph layout props glyph-name) (string?)
"This is converted to a musical symbol, e.g. @code{\\musicglyph
"Make a fraction of two markups."
(let* ((m1 (interpret-markup layout props arg1))
(m2 (interpret-markup layout props arg2)))
- (ly:stencil-align-to! m1 X CENTER)
- (ly:stencil-align-to! m2 X CENTER)
+ (set! m1 (ly:stencil-aligned-to m1 X CENTER))
+ (set! m2 (ly:stencil-aligned-to m2 X CENTER))
(let* ((x1 (ly:stencil-extent m1 X))
(x2 (ly:stencil-extent m2 X))
(line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
;; should stack mols separately, to maintain LINE on baseline
(stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
- (ly:stencil-align-to! stack Y CENTER)
- (ly:stencil-align-to! stack X LEFT)
+ (set! stack
+ (ly:stencil-aligned-to stack Y CENTER))
+ (set! stack
+ (ly:stencil-aligned-to stack X LEFT))
;; should have EX dimension
;; empirical anyway
(ly:stencil-translate-axis stack 0.75 Y))))
(if (ly:stencil? dots)
(set! stem-glyph
(ly:stencil-add
- (ly:stencil-translate-axis dots
- (+ (if (and (> dir 0) (> log 2))
- (* 1.5 dotwid)
- 0)
- ;; huh ? why not necessary?
- ;;(cdr (ly:stencil-extent head-glyph X))
- dotwid)
- X)
+ (ly:stencil-translate-axis
+ dots
+ (+ (if (and (> dir 0) (> log 2))
+ (* 1.5 dotwid)
+ 0)
+ ;; huh ? why not necessary?
+ ;;(cdr (ly:stencil-extent head-glyph X))
+ dotwid)
+ X)
stem-glyph)))
stem-glyph))
-(use-modules (ice-9 regex))
-
(define-public log2
(let ((divisor (log 2)))
(lambda (z) (inexact->exact (/ (log z) divisor)))))
(if (and match (string=? duration-string (match:substring match 0)))
(let ((len (match:substring match 1))
(dots (match:substring match 2)))
- (list (cond ((string=? len "breve") -1)
- ((string=? len "longa") -2)
+ (list (cond ((string=? len "breve") -1)
+ ((string=? len "longa") -2)
((string=? len "maxima") -3)
(else (log2 (string->number len))))
(if dots (string-length dots) 0)))
(def-markup-command (normal-size-super layout props arg) (markup?)
"Set @var{arg} in superscript with a normal font size."
- (ly:stencil-translate-axis (interpret-markup
- layout
- props arg)
- (* 0.5 (chain-assoc-get 'baseline-skip props))
- Y))
+ (ly:stencil-translate-axis
+ (interpret-markup layout props arg)
+ (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
(def-markup-command (super layout props arg) (markup?)
"
(* -0.5 (chain-assoc-get 'baseline-skip props))
Y))
-(def-markup-command (beam layout props width slope thickness) (number? number? number?)
+(def-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)))
- (let*
- ((y (* slope width))
- (yext (cons (min 0 y) (max 0 y)))
- (half (/ thickness 2)))
-
(ly:make-stencil
(list 'beam width
slope
(ly:output-def-lookup layout 'blotdiameter))
(cons 0 width)
(cons (+ (- half) (car yext))
- (+ half (cdr yext))))
-
- ))
-
+ (+ half (cdr yext))))))
(def-markup-command (normal-size-sub layout props arg) (markup?)
"Set @var{arg} in subscript, in a normal font size."
"
(interpret-markup layout (cons (list new-prop) props) arg))
-(def-markup-command (smaller layout props arg) (markup?)
- "Decrease the font size relative to current setting"
+
+(def-markup-command (fontsize layout props increment arg) (number? markup?)
+ "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
+
(let* ((fs (chain-assoc-get 'font-size props 0))
- (entry (cons 'font-size (- fs 1))))
- (interpret-markup layout (cons (list entry) props) arg)))
+ (bs (chain-assoc-get 'baseline-skip props 2))
+ (entries (list
+ (cons 'baseline-skip (* bs (magstep increment)))
+ (cons 'font-size (+ fs increment )))))
+ (interpret-markup layout (cons entries props) arg)))
+
(def-markup-command (bigger layout props arg) (markup?)
"Increase the font size relative to current setting"
- (let* ((fs (chain-assoc-get 'font-size props 0))
- (entry (cons 'font-size (+ fs 1))))
- (interpret-markup layout (cons (list entry) props) arg)))
+ (interpret-markup layout props
+ `(,fontsize-markup 1 ,arg)))
+
+(def-markup-command (smaller layout props arg) (markup?)
+ "Decrease the font size relative to current setting"
+ (interpret-markup layout props
+ `(,fontsize-markup -1 ,arg)))
(def-markup-command larger (markup?) bigger-markup)
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)))
+ (pad (* (magstep size)
+ (chain-assoc-get 'box-padding props 0.2)))
(m (interpret-markup layout props arg)))
(box-stencil m th pad)))
(def-markup-command (strut layout props) ()
"Create a box of the same height as the space in the current font."
(let ((m (Text_interface::interpret_markup layout props " ")))
- (ly:stencil-set-extent! m X '(1000 . -1000))
- m))
+ (ly:make-stencil (ly:stencil-expr m)
+ (ly:stencil-extent m X)
+ '(1000 . -1000))))
(define number->mark-letter-vector (make-vector 25 #\A))