]> git.donarmstrong.com Git - lilypond.git/commitdiff
Change API to filter music fonts in text-interface
authorPatrick McCarty <pnorcks@gmail.com>
Wed, 15 Jul 2009 16:54:28 +0000 (09:54 -0700)
committerPatrick McCarty <pnorcks@gmail.com>
Sun, 26 Jul 2009 03:35:38 +0000 (20:35 -0700)
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.

lily/font-metric-scheme.cc
lily/font-metric.cc
lily/include/font-metric.hh
lily/include/modified-font-metric.hh
lily/include/pango-font.hh
lily/modified-font-metric.cc
lily/pango-font.cc
lily/text-interface.cc

index bb4dbd401c74a93bd43895f138dd11c29248ecc5..cf351b2628b013627e35810f4668abc28b7665a5 100644 (file)
@@ -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)));
 }
index 12d8807831d5d57023ef905de5bdb501a8d46972..928adef851a93454ed0c44e6a3ec10d8552f7548 100644 (file)
@@ -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);
 }
 
index 8346b4378a8c459a0b861a561c780552e25ce40e..5c1eb50be3e06e8e54d9003c69eb838f069a1cbd 100644 (file)
@@ -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;
index 101949674cd4d0680a775b4d60578baffe045aee..8b5b244fa108978e2d991f3833cce20e576bfd07 100644 (file)
@@ -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;
index 09f3ff7fadf27cf84642322e9d0d539c8306d01b..f36adffb3b38d1841d8593653bdc3a3f12626c2a 100644 (file)
@@ -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;
 };
 
index 6972b44f926b95f6b9487ce3864aade4fb2f9cb6..71b532d61883fb64d2ca4fc1906686c7d008bfc8 100644 (file)
@@ -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<Pango_font *> (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
index d02b63ae7a01ac0a63358f637616d4733af0f4a6..14ceadf438a530c5e851e5754164b1ee1918d218 100644 (file)
@@ -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"),
index 8b55618521af2ae9bc9bc5df032a1a6cfec1459b..1c88d97cb30c7789c068030c93d255f8a28e1efa 100644 (file)
@@ -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,