From 8df18ed7b493871d72e52650022fee129789d176 Mon Sep 17 00:00:00 2001 From: Paul Morris Date: Wed, 10 Jun 2015 00:16:16 -0400 Subject: [PATCH] Issue 4418/2 add and use new whiteout function scm/stencil.scm: redefine the whiteout function so that it approximates the stencil's outline by creating multiple displaced copies of the stencil. Rename the previous whiteout function 'whiteout-box'. scm/define-grob-properties.scm: define two properties to go with the two whiteout functions. lily/grob.cc: use the new whiteout functions and properties. scm/define-markup-commands.scm: define markup commands to go with the two whiteout functions. --- lily/grob.cc | 43 +++++++++++++++--------- scm/define-grob-properties.scm | 12 +++++-- scm/define-markup-commands.scm | 25 ++++++++++++-- scm/stencil.scm | 61 ++++++++++++++++++++++++++++++---- 4 files changed, 115 insertions(+), 26 deletions(-) diff --git a/lily/grob.cc b/lily/grob.cc index 2377a5d963..2f5357a0ae 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -141,15 +141,38 @@ Grob::get_print_stencil () const retval = *m; bool transparent = to_boolean (get_property ("transparent")); + /* Process whiteout before color and grob-cause to prevent colored */ + /* whiteout background and larger file sizes with \pointAndClickOn. */ + /* A grob has to be visible, otherwise the whiteout property has no effect. */ + /* Calls the scheme procedure stencil-whiteout in scm/stencils.scm */ + if (!transparent && (scm_is_number (get_property("whiteout")) + || to_boolean (get_property ("whiteout")))) + { + SCM wh_proc = ly_lily_module_constant ("stencil-whiteout"); + Real thickness = robust_scm2double (get_property("whiteout"), 3.0) + * layout ()->get_dimension (ly_symbol2scm ("line-thickness")); + retval = *unsmob (scm_call_2 (wh_proc, + retval.smobbed_copy (), + scm_from_double (thickness))); + } + + /* Calls the scheme procedure stencil-whiteout-box in scm/stencils.scm */ + if (!transparent && to_boolean (get_property ("whiteout-box"))) + { + SCM wh_proc = ly_lily_module_constant ("stencil-whiteout-box"); + retval = *unsmob (scm_call_1 (wh_proc, + retval.smobbed_copy ())); + } + if (transparent) retval = Stencil (m->extent_box (), SCM_EOL); else { - SCM expr = m->expr (); - expr = scm_list_3 (ly_symbol2scm ("grob-cause"), - self_scm (), expr); + SCM expr = scm_list_3 (ly_symbol2scm ("grob-cause"), + self_scm (), + retval.expr ()); - retval = Stencil (m->extent_box (), expr); + retval = Stencil (retval.extent_box (), expr); } SCM rot = get_property ("rotation"); @@ -173,17 +196,6 @@ Grob::get_print_stencil () const retval = Stencil (retval.extent_box (), expr); } - /* process whiteout */ - /* a grob has to be visible, otherwise the whiteout property has no effect */ - if (!transparent && to_boolean (get_property ("whiteout"))) - { - /* Call the scheme procedure stencil-whiteout in scm/stencils.scm */ - /* to add a round-filled-box stencil to the stencil list */ - retval - = *unsmob (scm_call_1 (ly_lily_module_constant ("stencil-whiteout"), - retval.smobbed_copy ())); - } - SCM id = get_property ("id"); if (scm_is_string (id)) { @@ -828,6 +840,7 @@ ADD_INTERFACE (Grob, "transparent " "vertical-skylines " "whiteout " + "whiteout-box " ); /**************************************************************** diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index bbd2405541..8649a67117 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -1140,9 +1140,15 @@ one below this grob.") ;;; w ;;; (when ,ly:moment? "Global time step associated with this column.") - (whiteout ,boolean? "If true, the grob is printed over a white -background to white-out underlying material, if the grob is visible. - Usually #f by default.") + (whiteout ,boolean-or-number? "If a number or true, the grob is +printed over a white background that follows the outline of the stencil, +if the grob is visible. A number sets the thickness of the outline as a +multiple of the staff-line thickness. For compatibility with former +behavior (now available with @code{whiteout-box}) the value @code{#t} is +treated as @code{3.0}. Usually @code{#f} by default.") + (whiteout-box ,boolean? "If true, the grob is printed over a +rounded rectangular white background to white-out underlying material, +if the grob is visible. Usually @code{#f} by default.") (width ,ly:dimension? "The width of a grob measured in staff space.") (word-space ,ly:dimension? "Space to insert between words in diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm index 4844dcd75e..5a08facce2 100644 --- a/scm/define-markup-commands.scm +++ b/scm/define-markup-commands.scm @@ -707,6 +707,7 @@ Rotate object with @var{ang} degrees around its center. (define-markup-command (whiteout layout props arg) (markup?) #:category other + #:properties ((thickness 3)) " @cindex adding a white background to text @@ -716,10 +717,30 @@ Provide a white background for @var{arg}. \\markup { \\combine \\filled-box #'(-1 . 10) #'(-3 . 4) #1 - \\whiteout whiteout + \\override #'(thickness . 1.5) \\whiteout whiteout } @end lilypond" - (stencil-whiteout (interpret-markup layout props arg))) + (stencil-whiteout + (interpret-markup layout props arg) + (* thickness + (ly:output-def-lookup layout 'line-thickness)))) + +(define-markup-command (whiteout-box layout props arg) + (markup?) + #:category other + " +@cindex adding a rounded rectangular white background to text + +Provide a rounded rectangular white background for @var{arg}. + +@lilypond[verbatim,quote] +\\markup { + \\combine + \\filled-box #'(-1 . 10) #'(-3 . 4) #1 + \\whiteout-box whiteout-box +} +@end lilypond" + (stencil-whiteout-box (interpret-markup layout props arg))) (define-markup-command (pad-markup layout props amount arg) (number? markup?) diff --git a/scm/stencil.scm b/scm/stencil.scm index 03259cc3f5..75efde39d9 100644 --- a/scm/stencil.scm +++ b/scm/stencil.scm @@ -685,18 +685,67 @@ box, remains the same." (ly:stencil-extent stencil X) (ly:stencil-extent stencil Y))) -(define-public (stencil-whiteout stencil) +(define*-public (stencil-whiteout + stil #:optional (thickness 0.3) (color white) + (angle-increments 16) (radial-increments 1)) + "This function works by creating a series of white or @var{color} +stencils radially offset from the original stencil with angles from +0 to 2*pi, at an increment of @code{angle-inc}, and with radii +from @code{radial-inc} to @var{thickness}. @var{thickness} is how big +the white outline is in staff-spaces. @var{radial-increments} is how +many copies of the white stencil we make on our way out to thickness. +@var{angle-increments} is how many copies of the white stencil +we make between 0 and 2*pi." + (if (or (not (positive? angle-increments)) + (not (positive? radial-increments))) + (begin + (ly:warning "Both angle-increments and radial-increments must be positive numbers.") + stil) + (let* ((2pi 6.283185307) + (angle-inc (/ 2pi angle-increments)) + (radial-inc (/ thickness radial-increments))) + + (define (circle-plot ang dec radius original-stil new-stil) + ;; ang (angle) and dec (decrement) are in radians, not degrees + (if (<= ang 0) + new-stil + (circle-plot (- ang dec) dec radius original-stil + (ly:stencil-add + new-stil + (ly:stencil-translate original-stil + (cons + (* radius (cos ang)) + (* radius (sin ang)))))))) + + (define (radial-plot radius original-stil new-stil) + (if (<= radius 0) + new-stil + (ly:stencil-add new-stil + (radial-plot + (- radius radial-inc) + original-stil + (circle-plot 2pi angle-inc + radius original-stil empty-stencil))))) + + (let ((whiteout-expr + (ly:stencil-expr + (stencil-with-color + (radial-plot thickness stil empty-stencil) + color)))) + (ly:stencil-add + (ly:make-stencil + `(delay-stencil-evaluation ,(delay whiteout-expr))) + stil))))) + +(define-public (stencil-whiteout-box stencil) (let* ((x-ext (ly:stencil-extent stencil X)) - (y-ext (ly:stencil-extent stencil Y)) - - ) + (y-ext (ly:stencil-extent stencil Y))) (ly:stencil-add (stencil-with-color (ly:round-filled-box x-ext y-ext 0.0) white) - stencil) - )) + stencil))) (define-public (arrow-stencil-maker start? end?) "Return a function drawing a line from current point to @code{destination}, -- 2.39.2