From: Mike Solomon Date: Tue, 24 Jan 2012 05:17:21 +0000 (+0100) Subject: Adds an ID property to grobs. X-Git-Tag: release/2.15.27-1~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ad3a9e6531e32c4403f1bdc6d203d3c94c6d411e;p=lilypond.git Adds an ID property to grobs. 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 tag with its `id' attribute set to `id.' --- diff --git a/input/regression/id.ly b/input/regression/id.ly new file mode 100644 index 0000000000..10c628f3a8 --- /dev/null +++ b/input/regression/id.ly @@ -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 } diff --git a/lily/grob.cc b/lily/grob.cc index 6c2eba1710..ed96f1d13a 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -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 " diff --git a/lily/stencil-interpret.cc b/lily/stencil-interpret.cc index 1d89e032ba..8214af5dcc 100644 --- a/lily/stencil-interpret.cc +++ b/lily/stencil-interpret.cc @@ -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")) diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 4e0cc6af8e..28443694a6 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -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 () +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?") diff --git a/scm/define-stencil-commands.scm b/scm/define-stencil-commands.scm index d7e930cd7e..c8a6b17962 100644 --- a/scm/define-stencil-commands.scm +++ b/scm/define-stencil-commands.scm @@ -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 diff --git a/scm/output-ps.scm b/scm/output-ps.scm index 82fe77d140..0b4405072e 100644 --- a/scm/output-ps.scm +++ b/scm/output-ps.scm @@ -77,6 +77,12 @@ "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 diff --git a/scm/output-svg.scm b/scm/output-svg.scm index 5d1c09c99d..27b6118483 100644 --- a/scm/output-svg.scm +++ b/scm/output-svg.scm @@ -70,6 +70,12 @@ "c = close" (format #f "\n" entity)) +(define (start-enclosing-id-node s) + (string-append "\n")) + +(define (end-enclosing-id-node) + "\n") + (define-public (comment s) (string-append "\n"))