]> git.donarmstrong.com Git - lilypond.git/commitdiff
Adds an ID property to grobs.
authorMike Solomon <mike@apollinemike.com>
Tue, 24 Jan 2012 05:17:21 +0000 (06:17 +0100)
committerMike Solomon <mike@apollinemike.com>
Tue, 24 Jan 2012 05:17:21 +0000 (06:17 +0100)
This property is intended to group visual elements of a grob in a given
backend into a container that has `id' as its id.  Currently, it is only
implemented for svg, where grobs are wrapped in a <g> tag with its `id'
attribute set to `id.'

input/regression/id.ly [new file with mode: 0644]
lily/grob.cc
lily/stencil-interpret.cc
scm/define-grob-properties.scm
scm/define-stencil-commands.scm
scm/output-ps.scm
scm/output-svg.scm

diff --git a/input/regression/id.ly b/input/regression/id.ly
new file mode 100644 (file)
index 0000000..10c628f
--- /dev/null
@@ -0,0 +1,9 @@
+\version "2.15.27"
+
+\header {
+  texidoc = "Shows the id property of a grob being set.  This should have
+no effect in the PS backend.
+"
+}
+
+{ \override NoteHead #'id = #"foo" c }
index 6c2eba1710fb15a283f5ecd50249f3ee7f11320f..ed96f1d13a9b1386a4c64912c2d823684b397097 100644 (file)
@@ -170,6 +170,17 @@ Grob::get_print_stencil () const
             = *unsmob_stencil (scm_call_1 (ly_lily_module_constant ("stencil-whiteout"),
                                            retval.smobbed_copy ()));
         }
+
+      SCM id = get_property ("id");
+      if (scm_is_string (id))
+        {
+          SCM expr = scm_list_3 (ly_symbol2scm ("id"),
+                                 id,
+                                 retval.expr ());
+
+          retval = Stencil (retval.extent_box (), expr);
+        }
+
     }
 
   return retval;
@@ -784,6 +795,7 @@ ADD_INTERFACE (Grob,
                "cause "
                "color "
                "cross-staff "
+               "id "
                "extra-X-extent "
                "extra-Y-extent "
                "extra-offset "
index 1d89e032ba2559051bc8d489fc339eacc7450df2..8214af5dcc8e40a427dcd80212a0931a74bcef6f 100644 (file)
@@ -72,6 +72,16 @@ interpret_stencil_expression (SCM expr,
           interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
           (*func) (func_arg, scm_list_1 (ly_symbol2scm ("resetcolor")));
 
+          return;
+        }
+      else if (head == ly_symbol2scm ("id"))
+        {
+          SCM id = scm_cadr (expr);
+
+          (*func) (func_arg, scm_list_2 (ly_symbol2scm ("start-enclosing-id-node"), id));
+          interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
+          (*func) (func_arg, scm_list_1 (ly_symbol2scm ("end-enclosing-id-node")));
+
           return;
         }
       else if (head == ly_symbol2scm ("rotate-stencil"))
index 4e0cc6af8e6899a154a84fb73c5282fef4e6a92d..28443694a686e457542c77af7d9f9db74acf46d7 100644 (file)
@@ -483,6 +483,13 @@ left and one to the right of this grob.")
 ;;
 ;; i
 ;;
+     (id ,string? "An id string for the grob.  Depending on the typestting
+backend being used, this id will be assigned to a group containing all of
+the stencils that comprise a given grob.  For example, in the svg backend,
+the string will be assigned to the @code{id} attribute of a group (<g>)
+that encloses the stencils that comprise the grob.  In the Postscript
+backend, as there is no way to group items, the setting of the id property
+will have no effect.")
      (ignore-collision ,boolean? "If set, don't do note collision
 resolution on this @code{NoteColumn}.")
      (implicit ,boolean? "Is this an implicit bass figure?")
index d7e930cd7e0415a41b9f8c33c2c59f0b9f7f8672..c8a6b179622d6b071064edb6a3e3afbb5d9bfa9a 100644 (file)
@@ -34,6 +34,7 @@ defined in the output modules (@file{output-*.scm})."
     ellipse
     embedded-ps
     embedded-svg
+    end-enclosing-id-node
     glyph-string
     grob-cause
     named-glyph
@@ -52,6 +53,7 @@ defined in the output modules (@file{output-*.scm})."
     setcolor
     setrotation
     setscale
+    start-enclosing-id-node
     text
     unknown
     url-link
@@ -69,6 +71,7 @@ are used internally in @file{lily/@/stencil-interpret.cc}."
     combine-stencil
     delay-stencil-evaluation
     footnote
+    id
     rotate-stencil
     scale-stencil
     translate-stencil
index 82fe77d14042a4987e650d3915fa8487db42ce77..0b4405072ea2a6edc370e8ca140a327c59cf4dfe 100644 (file)
      "false")
    radius thick))
 
+(define (start-enclosing-id-node s)
+  "")
+
+(define (end-enclosing-id-node)
+  "")
+
 (define (dashed-line thick on off dx dy phase)
   (ly:format "~4f ~4f ~4f [ ~4f ~4f ] ~4f draw_dashed_line"
    dx
index 5d1c09c99d5fa2ddc554072b5f5e38f80c1628f8..27b6118483ccdb05cfcb1fce79e805a037637d2f 100644 (file)
   "c = close"
   (format #f "</~S>\n" entity))
 
+(define (start-enclosing-id-node s)
+  (string-append "<g id=\"" s "\">\n"))
+
+(define (end-enclosing-id-node)
+  "</g>\n")
+
 (define-public (comment s)
   (string-append "<!-- " s " -->\n"))