lilypond-devel
[Top][All Lists]

## Oval stencil and oval markup suggestions

 From: Pierre Perol-Schneider Subject: Oval stencil and oval markup suggestions Date: Thu, 4 Apr 2019 17:33:39 +0200

Hi Dev Team,
Here's some thougts:

%%%%%%
\version "2.19.83"

%% The oval stencil commands uses beziers curves that cause some side
effects:
\markuplist {
\line\vcenter {
"Circle, radius = 2 : "
\stencil #(make-circle-stencil 2 .13 #f)
}
\line\vcenter {
\stencil #(make-oval-stencil 2 2 .13 #f)
}
\line\vcenter {
\box\stencil #(make-oval-stencil 2 2 .13 #f)
}
}

%% Here's a suggestion with a corrected y-radius in order to reach a quasi
circle:
defined by @code{fill}."
(let*
(y-max (* y-radius (+ 1 (/ 1 3)))) ; <= max deviation < 1%
(y-min (* (- y-radius) (+ 1 (/ 1 3)))) ; <= max deviation < 1%
(commands (,(list 'moveto x-max 0)
,(list 'curveto x-max y-max x-min y-max x-min 0)
,(list 'curveto x-min y-min x-max y-min x-max 0)
,(list 'closepath)
))
(command-list (fold-right append '() commands)))
(ly:make-stencil
(path ,thickness (,@',command-list) 'round 'round ,fill)

\markuplist {
% Test #1:
\line\vcenter {
"make-oval-stencil-var: "
\box\stencil #(make-oval-stencil-var 2 2 .13 #f)
" v.s. make-circle-stencil: "
\box\stencil #(make-circle-stencil 2 .13 #f)
}
% Test #2:
\vspace #1 "make-oval-stencil-var & make-circle-stencil combined:"
\vspace #.3
\translate #'(8 . 0)
\line {
\scale #'(5 . 5) {
\combine
\with-color #blue
\draw-circle #2 #.13 ##f
\with-color #red
\stencil #(make-oval-stencil-var 2 2 .13 #f)
}
\scale #'(5 . 5) {
\combine
\with-color #red
\stencil #(make-oval-stencil-var 2 2 .13 #f)
\with-color #blue
\draw-circle #2 #.13 ##f
}
}
\vspace #1
}

%% Here comes a suggestion for the markup command:
producing a var stencil."
(let* ((x-ext (ly:stencil-extent stencil X))
(y-ext (ly:stencil-extent stencil Y))
(x-length (+ (interval-length x-ext) x-padding thickness))
(y-length (+ (interval-length y-ext) y-padding thickness))

stencil
(ly:stencil-translate oval
(cons
(interval-center x-ext)
(interval-center y-ext))))))

#(define-markup-command (oval-var layout props arg)
(markup?)
#:category graphic
#:properties ((thickness 1)
(font-size 0)
"
@cindex drawing oval around text

Draw an oval around @var{arg}.  Use @code{thickness},
determine
line thickness and padding around the markup.

@lilypond[verbatim,quote]
\\markup {
\\oval-var {
Hi
}
}
@end lilypond"
(let ((th (* (ly:output-def-lookup layout 'line-thickness)
thickness))
(m (interpret-markup layout props arg)))

%% Comparative test:
\markup {
"oval: "
\box\oval "Hi"
" v.s. oval-var markups: "
\box\oval-var "Hi"
}

%%%%%

Cheers,
Pierre

`