From: Patrick McCarty Date: Wed, 15 Jul 2009 16:54:28 +0000 (-0700) Subject: Change API to filter music fonts in text-interface X-Git-Tag: release/2.13.4-1~294 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;ds=sidebyside;h=c5db146c701720c3dbef76a0da1e1dc537f78ddc;p=lilypond.git Change API to filter music fonts in text-interface Currently, some grobs using the text-interface require the music fonts (Emmentaler and Aybabtu). The new changes for the SVG backend require special handling for these cases, thus the API change. Now the SVG backend will use "glyph-string" to output text in the music fonts, and "utf-8-string" for all other text. --- diff --git a/lily/font-metric-scheme.cc b/lily/font-metric-scheme.cc index bb4dbd401c..cf351b2628 100644 --- a/lily/font-metric-scheme.cc +++ b/lily/font-metric-scheme.cc @@ -120,7 +120,7 @@ LY_DEFINE (ly_text_dimension, "ly:text-dimension", LY_ASSERT_SMOB (Font_metric, font, 1); LY_ASSERT_TYPE (scm_is_string, text, 2); - Stencil stc (fm->text_stencil (ly_scm2string (text))); + Stencil stc (fm->text_stencil (ly_scm2string (text), false)); return scm_cons (ly_interval2scm (stc.extent (X_AXIS)), ly_interval2scm (stc.extent (Y_AXIS))); } diff --git a/lily/font-metric.cc b/lily/font-metric.cc index 12d8807831..928adef851 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -179,15 +179,15 @@ Font_metric::sub_fonts () const } Stencil -Font_metric::word_stencil (string str) const +Font_metric::word_stencil (string str, bool feta) const { - return text_stencil (str); + return text_stencil (str, feta); } Stencil -Font_metric::text_stencil (string /* str */) const +Font_metric::text_stencil (string, bool) const { - programming_error("Cannot get a text stencil from this font"); + programming_error ("Cannot get a text stencil from this font"); return Stencil (Box (), SCM_EOL); } diff --git a/lily/include/font-metric.hh b/lily/include/font-metric.hh index 8346b4378a..5c1eb50be3 100644 --- a/lily/include/font-metric.hh +++ b/lily/include/font-metric.hh @@ -28,8 +28,8 @@ public: SCM description_; string file_name_; - virtual Stencil text_stencil (string) const; - virtual Stencil word_stencil (string) const; + virtual Stencil text_stencil (string, bool) const; + virtual Stencil word_stencil (string, bool) const; // ugh. virtual Box text_dimension (string) const; diff --git a/lily/include/modified-font-metric.hh b/lily/include/modified-font-metric.hh index 101949674c..8b5b244fa1 100644 --- a/lily/include/modified-font-metric.hh +++ b/lily/include/modified-font-metric.hh @@ -17,7 +17,7 @@ struct Modified_font_metric : public Font_metric public: Box text_dimension (string) const; Box word_dimension (string) const; - Stencil text_stencil (string) const; + Stencil text_stencil (string, bool) const; static SCM make_scaled_font_metric (Font_metric *fm, Real magnification); size_t count () const; diff --git a/lily/include/pango-font.hh b/lily/include/pango-font.hh index 09f3ff7fad..f36adffb3b 100644 --- a/lily/include/pango-font.hh +++ b/lily/include/pango-font.hh @@ -38,12 +38,12 @@ public: string description_string () const; SCM font_file_name () const; void register_font_file (string, string, int); - Stencil text_stencil (string, bool tight) const; + Stencil text_stencil (string, bool, bool) const; - Stencil pango_item_string_stencil (PangoItem const *, string, bool tight) const; + Stencil pango_item_string_stencil (PangoItem const *, string, bool) const; - virtual Stencil word_stencil (string) const; - virtual Stencil text_stencil (string) const; + virtual Stencil word_stencil (string, bool) const; + virtual Stencil text_stencil (string, bool) const; virtual void derived_mark () const; }; diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc index 6972b44f92..71b532d618 100644 --- a/lily/modified-font-metric.cc +++ b/lily/modified-font-metric.cc @@ -102,12 +102,12 @@ Modified_font_metric::derived_mark () const } Stencil -Modified_font_metric::text_stencil (string text) const +Modified_font_metric::text_stencil (string text, bool feta) const { Box b; if (Pango_font *pf = dynamic_cast (orig_)) { - Stencil stc = pf->text_stencil (text); + Stencil stc = pf->text_stencil (text, feta); Box b = stc.extent_box (); @@ -116,7 +116,7 @@ Modified_font_metric::text_stencil (string text) const return scaled; } - return Font_metric::text_stencil (text); + return Font_metric::text_stencil (text, feta); } Box diff --git a/lily/pango-font.cc b/lily/pango-font.cc index d02b63ae7a..14ceadf438 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -285,19 +285,20 @@ Pango_font::physical_font_tab () const } Stencil -Pango_font::word_stencil (string str) const +Pango_font::word_stencil (string str, bool feta) const { - return text_stencil (str, true); + return text_stencil (str, feta, true); } Stencil -Pango_font::text_stencil (string str) const +Pango_font::text_stencil (string str, bool feta) const { - return text_stencil (str, false); + return text_stencil (str, feta, false); } Stencil Pango_font::text_stencil (string str, + bool feta, bool tight) const { GList *items @@ -346,10 +347,27 @@ Pango_font::text_stencil (string str, dest.add_stencil (item_stencil); } - // UGH. Should have flags per output format signifying supported - // options. string name = get_output_backend_name (); - if (name != "ps" && name != "eps") + string output_mod = "scm output-" + name; + SCM mod = scm_c_resolve_module (output_mod.c_str ()); + + bool has_utf8_string = false; + + if (ly_is_module (mod)) + { + SCM utf8_string = ly_module_lookup (mod, ly_symbol2scm ("utf-8-string")); + if (utf8_string != SCM_BOOL_F) + has_utf8_string = true; + } + + /* + The SVG backend only uses utf-8-string for the non-music + fonts, hence the check here. --pmccarty + + TODO: use a program option (-dmusic-strings-to-paths) here + instead that is enabled only when -dbackend=svg. + */ + if ((name == "svg" && !feta) || (name != "svg" && has_utf8_string)) { // For Pango based backends, we take a shortcut. SCM exp = scm_list_3 (ly_symbol2scm ("utf-8-string"), diff --git a/lily/text-interface.cc b/lily/text-interface.cc index 8b55618521..1c88d97cb3 100644 --- a/lily/text-interface.cc +++ b/lily/text-interface.cc @@ -64,7 +64,22 @@ Text_interface::interpret_string (SCM layout_smob, Font_metric *fm = select_encoded_font (layout, props); replace_whitespace (&str); - return fm->word_stencil (str).smobbed_copy (); + + /* + We want to use "glyph-string" in the SVG backend for all + music fonts (Emmentaler and Aybabtu) that pass through the + text interface. Here the font encoding is checked to see if + it matches one of the music font encodings. --pmccarty + */ + SCM encoding = ly_chain_assoc_get (ly_symbol2scm ("font-encoding"), + props, + SCM_BOOL_F); + SCM music_encodings = ly_lily_module_constant ("all-music-font-encodings"); + + if (scm_memq (encoding, music_encodings) != SCM_BOOL_F) + return fm->word_stencil (str, true).smobbed_copy (); + else + return fm->word_stencil (str, false).smobbed_copy (); } MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Text_interface, interpret_markup, 3, 0,