X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fflag.cc;h=4b90be8be01a2395624067d2d64d04d9e230048d;hb=8659a99f233f5c4684292728e7ad4206669b35b0;hp=e4621c58a1b55ec64e5a57c4e71d694968585633;hpb=0c61221b46addec50e2406e04af44a7d460443d4;p=lilypond.git diff --git a/lily/flag.cc b/lily/flag.cc index e4621c58a1..4b90be8be0 100644 --- a/lily/flag.cc +++ b/lily/flag.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1996--2011 Han-Wen Nienhuys + Copyright (C) 1996--2015 Han-Wen Nienhuys Jan Nieuwenhuizen LilyPond is free software: you can redistribute it and/or modify @@ -33,18 +33,21 @@ 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)); DECLARE_SCHEME_CALLBACK (calc_x_offset, (SCM)); - DECLARE_GROB_INTERFACE (); + + static SCM internal_calc_y_offset (SCM smob, bool pure); }; MAKE_SCHEME_CALLBACK (Flag, width, 1); SCM Flag::width (SCM smob) { - Grob *me = unsmob_grob (smob); - Stencil *sten = unsmob_stencil (me->get_property ("stencil")); + Grob *me = unsmob (smob); + Stencil *sten = unsmob (me->get_property ("stencil")); if (!sten) return ly_interval2scm (Interval (0.0, 0.0)); @@ -58,11 +61,12 @@ 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 *me = unsmob (smob); Grob *stem = me->get_parent (X_AXIS); Direction d = get_grob_direction (stem); @@ -73,9 +77,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; @@ -103,9 +104,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 (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)); @@ -119,11 +142,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 ()) @@ -136,27 +159,46 @@ Flag::print (SCM smob) return flag.smobbed_copy (); } +MAKE_SCHEME_CALLBACK (Flag, pure_calc_y_offset, 3); +SCM +Flag::pure_calc_y_offset (SCM smob, + SCM /* beg */, + SCM /* end */) +{ + return internal_calc_y_offset (smob, true); +} + MAKE_SCHEME_CALLBACK (Flag, calc_y_offset, 1); SCM Flag::calc_y_offset (SCM smob) { - Grob *me = unsmob_grob (smob); + return internal_calc_y_offset (smob, false); +} + +SCM +Flag::internal_calc_y_offset (SCM smob, bool pure) +{ + Grob *me = unsmob (smob); Grob *stem = me->get_parent (X_AXIS); Direction d = get_grob_direction (stem); Real blot = me->layout ()->get_dimension (ly_symbol2scm ("blot-diameter")); - Real y2 = stem->extent (stem, Y_AXIS)[d]; + Interval stem_extent = pure + ? stem->pure_y_extent (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); SCM Flag::calc_x_offset (SCM smob) { - Grob *me = unsmob_grob (smob); + Grob *me = unsmob (smob); Grob *stem = me->get_parent (X_AXIS); return scm_from_double (stem->extent (stem, X_AXIS)[RIGHT]); } @@ -170,6 +212,7 @@ ADD_INTERFACE (Flag, " @code{'no-flag}, which switches off the flag.", /* properties */ + "glyph-name " "style " "stroke-style " );