]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4418/2 add and use new whiteout function
authorPaul Morris <paulwmorris@gmail.com>
Wed, 10 Jun 2015 04:16:16 +0000 (00:16 -0400)
committerJames Lowe <pkx166h@gmail.com>
Thu, 18 Jun 2015 04:16:03 +0000 (05:16 +0100)
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
scm/define-grob-properties.scm
scm/define-markup-commands.scm
scm/stencil.scm

index 2377a5d963f92d794916185c6518b395fcf29aca..2f5357a0aedfda212475b987322a0085022bac35 100644 (file)
@@ -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<Stencil> (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<Stencil> (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<Stencil> (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 "
               );
 
 /****************************************************************
index bbd24055415bdc4cb931a0db3b897ae6a1ad6aca..8649a67117190ed03523651b06dd0002d5e16859 100644 (file)
@@ -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
index 4844dcd75e321d60b5adec7849900bbfdf1be344..5a08facce20b7d8c040c43722028b010cfa82b35 100644 (file)
@@ -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?)
index 03259cc3f53e90a9e1057a1e84a128964d003730..75efde39d9886e9e4718cffe07a3b9f22f3eff5a 100644 (file)
@@ -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},