]> git.donarmstrong.com Git - lilypond.git/commitdiff
Implements annotations for footnotes.
authorMike Solomon <mike@apollinemike.com>
Wed, 9 Mar 2011 08:17:41 +0000 (09:17 +0100)
committerMike Solomon <mike@apollinemike.com>
Wed, 9 Mar 2011 08:17:41 +0000 (09:17 +0100)
The annotations are carried by two grobs: FootnoteItem and FootnoteSpanner.

FootnoteItems inherit break visibility from their Y parents. This break
visibility can be overrided.

The annotation on a broken spanner is placed using the parameter
spanner-placement.  Check out the documentation in define-grob-properties
for this property.

lily/balloon.cc
lily/system.cc
scm/define-grob-properties.scm
scm/define-grobs.scm

index f4efd4c4894a7b827e62b4a203a312daa8da0c28..1dfab523a8bc54cc77dfe60a69b049344e6627cb 100644 (file)
 
 #include "text-interface.hh"
 #include "grob.hh"
+#include "item.hh"
 #include "line-interface.hh"
 #include "lookup.hh"
 #include "font-interface.hh"
 #include "lily-guile.hh"
 #include "output-def.hh"
 #include "misc.hh"
+#include "spanner.hh"
 
 class Balloon_interface
 {
 public:
   DECLARE_SCHEME_CALLBACK (print, (SCM));
+  DECLARE_SCHEME_CALLBACK (print_spanner, (SCM));
   DECLARE_GROB_INTERFACE ();
+
+  static SCM internal_balloon_print (Grob *me, Grob *p, Offset off);
 };
 
 MAKE_SCHEME_CALLBACK (Balloon_interface, print, 1);
@@ -39,19 +44,67 @@ Balloon_interface::print (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
 
+  if (Item *item = dynamic_cast<Item *> (me))
+    if (!Item::break_visible (item))
+      return SCM_EOL;
+
   Grob *p = me->get_parent (X_AXIS);
-  
+
   Offset off (me->relative_coordinate (p, X_AXIS),
              me->relative_coordinate (p, Y_AXIS));
 
+  return internal_balloon_print (me, p, off);
+}
+
+// ugh...code dup...hopefully can be consolidated w/ above one day
+MAKE_SCHEME_CALLBACK (Balloon_interface, print_spanner, 1);
+SCM
+Balloon_interface::print_spanner (SCM smob)
+{
+  Spanner *me = unsmob_spanner (smob);
+  Grob *orig = me->original ();
+
+  if (orig)
+    {
+      // TODO : consolidate code dup from System::get_footnote_grobs_in_range
+      int pos = orig->spanned_rank_interval ()[LEFT];
+      Real spanner_placement = min (1.0,
+                                    max (robust_scm2double (me->get_property ("spanner-placement"), -1.0),
+                                         -1.0));
+
+      spanner_placement = (spanner_placement + 1.0) / 2.0;
+      int rpos = orig->spanned_rank_interval ()[RIGHT];
+      pos = (int)((rpos - pos) * spanner_placement + pos + 0.5);
+
+      if (pos < me->spanned_rank_interval () [LEFT])
+        return SCM_EOL;
+      if (pos >= me->spanned_rank_interval () [RIGHT] && (me->spanned_rank_interval () [RIGHT] != orig->spanned_rank_interval () [RIGHT]))
+        return SCM_EOL;
+    }
+
+
+  Spanner *p = dynamic_cast<Spanner *> (me->get_parent (Y_AXIS));
+
+  if (!p)
+    return SCM_EOL;
+
+  Offset off (me->relative_coordinate (me->get_bound (LEFT), X_AXIS),
+             me->relative_coordinate (p, Y_AXIS));
+  return internal_balloon_print (me, p, off);
+}
+
+SCM
+Balloon_interface::internal_balloon_print (Grob *me, Grob *p, Offset off)
+{
   Box b (p->extent (p, X_AXIS),
         p->extent (p, Y_AXIS));
-
   Real padding = robust_scm2double (me->get_property ("padding"), .1);
   b.widen (padding, padding);
 
   // FIXME
-  Stencil fr = Lookup::frame (b, 0.1, 0.05);
+  Stencil fr;
+  if (to_boolean (me->get_property ("annotation-balloon")))
+    fr = Lookup::frame (b, 0.1, 0.05);
 
   SCM bt = me->get_property ("text");
   SCM chain = Font_interface::text_font_alist_chain (me);
@@ -71,7 +124,8 @@ Balloon_interface::print (SCM smob)
 
   Offset z2 = z1 + off;
 
-  fr.add_stencil (Line_interface::line (me, z1, z2));
+  if (to_boolean (me->get_property ("annotation-line")))
+    fr.add_stencil (Line_interface::line (me, z1, z2));
 
   text_stil->translate (z2);
   fr.add_stencil (*text_stil);
@@ -85,7 +139,10 @@ ADD_INTERFACE (Balloon_interface,
               " object.",
 
               /* properties */
+              "annotation-balloon "
+              "annotation-line "
               "padding "
+              "spanner-placement "
               "text "
               );
 
index 6bf428206d2481882108720405ef89e51d345beb..574dce56c9de8e54869b164e772dc702707663d0 100644 (file)
@@ -254,11 +254,9 @@ System::get_footnote_grobs_in_range (vector<Grob *> &out, vsize start, vsize end
       bool end_of_line_visible = true;
       if (Spanner *s = dynamic_cast<Spanner *>(footnote_grobs_[i]))
         {
-          Real spanner_placement = robust_scm2double (s->get_property ("spanner-placement"), -1.0);
-          if (spanner_placement < -1.0)
-            spanner_placement = -1.0;
-          if (spanner_placement > 1.0)
-            spanner_placement = 1.0;
+          Real spanner_placement = min (1.0,
+                                        max (robust_scm2double (s->get_property ("spanner-placement"), -1.0),
+                                             -1.0));
 
           spanner_placement = (spanner_placement + 1.0) / 2.0;
           int rpos = s->spanned_rank_interval ()[RIGHT];
index 9a6ba22d8b44130b7e12648d1007dd06bdd2998d..aa6ce82cb7ff1c2bad24b65a9f06369ae50959a4 100644 (file)
@@ -48,6 +48,9 @@ be created below this bar line.")
      (alteration-alist ,list? "List of @code{(@var{pitch}
 . @var{accidental})} pairs for key signature.")
      (annotation ,string? "Annotate a grob for debug purposes.")
+     (annotation-balloon ,boolean? "Print the balloon around an annotation.")
+     (annotation-line ,boolean? "Print the line from an annotation to the
+grob that it annotates.")
      (arpeggio-direction ,ly:dir? "If set, put an arrow on the
 arpeggio squiggly line.")
      (arrow-length ,number? "Arrow length.")
index ac75852215a03d5cde2ab83815e16b2ec172c2d7..e5658a8384d4c2745f709ea49917d440196048c8 100644 (file)
 
     (BalloonTextItem
      . (
+       (annotation-balloon . #t)
+       (annotation-line . #t)
        (stencil . ,ly:balloon-interface::print)
        (text . ,(grob::calc-property-by-copy 'text))
        (X-offset . ,(grob::calc-property-by-copy 'X-offset))
 
     (FootnoteItem
      . (
+       (annotation-balloon . #f)
+       (annotation-line . #t)
        (break-visibility . ,inherit-y-parent-visibility)
        (footnote-text . ,(grob::calc-property-by-copy 'footnote-text))
-       (stencil . #f)
+       (stencil . ,ly:balloon-interface::print)
        (text . ,(grob::calc-property-by-copy 'text))
-       (Y-extent . 0.0)
+       (Y-extent . #f)
        (X-offset . ,(grob::calc-property-by-copy 'X-offset))
        (Y-offset . ,(grob::calc-property-by-copy 'Y-offset))
        (meta . ((class . Item)
 
     (FootnoteSpanner
      . (
+       (annotation-balloon . #f)
+       (annotation-line . #t)
        (footnote-text . ,(grob::calc-property-by-copy 'footnote-text))
        (spanner-placement . -1.0)
-       (stencil . #f)
+       (stencil . ,ly:balloon-interface::print-spanner)
        (text . ,(grob::calc-property-by-copy 'text))
-       (Y-extent . 0.0)
+       (Y-extent . #f)
        (X-offset . ,(grob::calc-property-by-copy 'X-offset))
        (Y-offset . ,(grob::calc-property-by-copy 'Y-offset))
        (meta . ((class . Spanner)