]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/flag.cc
Merge branch 'translation' into 'master'
[lilypond.git] / lily / flag.cc
index f997d6fe457f44626cddc7bec2579788b4046a69..f4fcce8e0e96a8db468846208a8ab193ec7952b8 100644 (file)
@@ -33,6 +33,7 @@ class Flag
 {
 public:
   DECLARE_SCHEME_CALLBACK (print, (SCM));
+  DECLARE_SCHEME_CALLBACK (glyph_name, (SCM));
   DECLARE_SCHEME_CALLBACK (width, (SCM));
   DECLARE_SCHEME_CALLBACK (calc_y_offset, (SCM));
   DECLARE_SCHEME_CALLBACK (pure_calc_y_offset, (SCM, SCM, SCM));
@@ -61,9 +62,10 @@ Flag::width (SCM smob)
 
   return ly_interval2scm (sten->extent (X_AXIS) - stem->extent (stem, X_AXIS)[RIGHT]);
 }
-MAKE_SCHEME_CALLBACK (Flag, print, 1);
+
+MAKE_SCHEME_CALLBACK (Flag, glyph_name, 1);
 SCM
-Flag::print (SCM smob)
+Flag::glyph_name (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
   Grob *stem = me->get_parent (X_AXIS);
@@ -76,9 +78,6 @@ Flag::print (SCM smob)
   if (scm_is_symbol (flag_style_scm))
     flag_style = ly_symbol2string (flag_style_scm);
 
-  if (flag_style == "no-flag")
-    return Stencil ().smobbed_copy ();
-
   bool adjust = true;
 
   string staffline_offs;
@@ -106,9 +105,31 @@ Flag::print (SCM smob)
 
   char dir = (d == UP) ? 'u' : 'd';
   string font_char = flag_style
-                     + to_string (dir) + staffline_offs + to_string (log);
+                     + ::to_string (dir) + staffline_offs + ::to_string (log);
+  return ly_string2scm ("flags." + font_char);
+}
+
+MAKE_SCHEME_CALLBACK (Flag, print, 1);
+SCM
+Flag::print (SCM smob)
+{
+  Grob *me = unsmob_grob (smob);
+  Grob *stem = me->get_parent (X_AXIS);
+
+  Direction d = get_grob_direction (stem);
+  string flag_style;
+
+  SCM flag_style_scm = me->get_property ("style");
+  if (scm_is_symbol (flag_style_scm))
+    flag_style = ly_symbol2string (flag_style_scm);
+
+  if (flag_style == "no-flag")
+    return Stencil ().smobbed_copy ();
+
+  char dir = (d == UP) ? 'u' : 'd';
   Font_metric *fm = Font_interface::get_default_font (me);
-  Stencil flag = fm->find_by_name ("flags." + font_char);
+  string font_char = robust_scm2string (me->get_property ("glyph-name"), "");
+  Stencil flag = fm->find_by_name (font_char);
   if (flag.is_empty ())
     me->warning (_f ("flag `%s' not found", font_char));
 
@@ -122,11 +143,11 @@ Flag::print (SCM smob)
       string stroke_style = ly_scm2string (stroke_style_scm);
       if (!stroke_style.empty ())
         {
-          string font_char = flag_style + to_string (dir) + stroke_style;
+          string font_char = flag_style + ::to_string (dir) + stroke_style;
           Stencil stroke = fm->find_by_name ("flags." + font_char);
           if (stroke.is_empty ())
             {
-              font_char = to_string (dir) + stroke_style;
+              font_char = ::to_string (dir) + stroke_style;
               stroke = fm->find_by_name ("flags." + font_char);
             }
           if (stroke.is_empty ())
@@ -165,11 +186,13 @@ Flag::internal_calc_y_offset (SCM smob, bool pure)
   Real blot
     = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter"));
 
-  Real y2 = pure
-            ? stem->pure_height (stem, 0, INT_MAX)[d]
-            : stem->extent (stem, Y_AXIS)[d];
+  Interval stem_extent = pure
+                         ? stem->pure_height (stem, 0, INT_MAX)
+                         : stem->extent (stem, Y_AXIS);
 
-  return scm_from_double (y2 - d * blot / 2);
+  return scm_from_double (stem_extent.is_empty ()
+                          ? 0.0
+                          : stem_extent[d] - d * blot / 2);
 }
 
 MAKE_SCHEME_CALLBACK (Flag, calc_x_offset, 1);
@@ -190,6 +213,7 @@ ADD_INTERFACE (Flag,
                " @code{'no-flag}, which switches off the flag.",
 
                /* properties */
+               "glyph-name "
                "style "
                "stroke-style "
               );