]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/text-item.cc
release: 1.3.110
[lilypond.git] / lily / text-item.cc
index e1085702f950a8fc3e653eb43e2c9c4a2c9099a2..34c710db9dbc055a39eabcf16b0c6e1bfabf6893 100644 (file)
@@ -11,7 +11,7 @@
 #include "debug.hh"
 #include "text-item.hh"
 #include "paper-def.hh"
-#include "font-metric.hh"
+#include "font-interface.hh"
 #include "staff-symbol-referencer.hh"
 #include "staff-symbol-referencer.hh"
 #include "main.hh"
@@ -54,7 +54,7 @@
  */
 
 Molecule
-Text_item::text2molecule (Score_element *me, SCM text, SCM alist_chain) 
+Text_item::text2molecule (Grob *me, SCM text, SCM alist_chain) 
 {
   if (gh_string_p (text))
     return string2molecule (me, text, alist_chain);
@@ -67,97 +67,77 @@ Text_item::text2molecule (Score_element *me, SCM text, SCM alist_chain)
     }
   return Molecule ();
 }
-
-SCM
-ly_assoc_chain (SCM key, SCM achain)
-{
-  if (gh_pair_p (achain))
-    {
-      SCM handle = scm_assoc (key, gh_car (achain));
-      if (gh_pair_p (handle))
-       return handle;
-      else
-       return ly_assoc_chain (key, gh_cdr (achain));
-    }
-  else
-    return SCM_BOOL_F;
-}
             
 Molecule
-Text_item::string2molecule (Score_element *me, SCM text, SCM alist_chain)
+Text_item::string2molecule (Grob *me, SCM text, SCM alist_chain)
 {
   SCM style = ly_assoc_chain (ly_symbol2scm ("font-style"),
                              alist_chain);
-  if  (gh_pair_p (style))
-    style = gh_cdr (style);
-  
-  SCM sheet = me->paper_l ()->style_sheet_;
-  
-  if (gh_symbol_p (style))
-    {
-      SCM style_alist = gh_cdr (scm_assoc (ly_symbol2scm ("style-alist"), sheet));
-      SCM entry = scm_assoc (style, style_alist);
-      entry = gh_pair_p (entry) ? gh_cdr (entry) : SCM_EOL;
-      alist_chain = gh_cons (entry, alist_chain);
-    }
-
-  SCM fonts = gh_cdr (scm_assoc (ly_symbol2scm ("fonts"), sheet));
-  SCM proc  = gh_cdr (scm_assoc (ly_symbol2scm ("properties-to-font"), sheet));
-  SCM font_name = gh_call2 (proc, fonts, alist_chain);
+  if  (gh_pair_p (style) && gh_symbol_p (gh_cdr (style)))
+    alist_chain = Font_interface::add_style (me, gh_cdr(style), alist_chain);
 
+  Font_metric *fm = Font_interface::get_font (me, alist_chain);
+  
   SCM lookup = ly_assoc_chain (ly_symbol2scm ("lookup"), alist_chain);
-
+    
   Molecule mol;
-  if (gh_pair_p (lookup) && ly_symbol2string (gh_cdr (lookup)) == "name")
-    mol = lookup_character (me, font_name, text);
+  if (gh_pair_p (lookup) && gh_cdr (lookup) ==ly_symbol2scm ("name"))
+    mol = lookup_character (me, fm, text);
   else
-    mol = lookup_text (me, font_name, text);
+    mol = lookup_text (me, fm, text);
   
   return mol;
 }
 
 Molecule
-Text_item::lookup_character (Score_element *me, SCM font_name, SCM char_name)
+Text_item::lookup_character (Grob *, Font_metric*fm, SCM char_name)
 {
-  Adobe_font_metric *afm = all_fonts_global_p->find_afm (ly_scm2string (font_name));
-  
-  if (!afm)
-    {
-      warning (_f ("can't find font: `%s'", ly_scm2string (font_name)));
-      warning (_f ("(search path: `%s')", global_path.str ().ch_C()));
-      error (_ ("Aborting"));
-    }
-  Font_metric * fm = afm;
-  
   return fm->find_by_name (ly_scm2string (char_name));
 }
 
 
 Molecule
-Text_item::lookup_text (Score_element *me, SCM font_name, SCM text)
+Text_item::lookup_text (Grob *me, Font_metric*fm, SCM text)
 {
-  SCM magnification = me->get_elt_property ("font-magnification");
+#if 0
+  /*
+    Fixme; should be done differently, move to font-interface?
+   */
+
+  SCM magnification = me->get_grob_property ("font-magnification");
+
   Font_metric* metric = 0;
   if (gh_number_p (magnification))
     {
+
       Real realmag = pow (1.2, gh_scm2int (magnification));
       metric = all_fonts_global_p->find_scaled (ly_scm2string (font_name), realmag);
+
+      assert (false);
     }
-  else
-    metric = all_fonts_global_p->find_font (ly_scm2string (font_name));
-  
+
+#endif
+
   SCM list = gh_list (ly_symbol2scm ("text"), text, SCM_UNDEFINED);
-  list = fontify_atom (metric, list);
+  list = fontify_atom (fm, list);
   
-  return Molecule (metric->text_dimension (ly_scm2string (text)), list);
+  return Molecule (fm->text_dimension (ly_scm2string (text)), list);
 }
 
 Molecule
-Text_item::markup_sentence2molecule (Score_element *me, SCM markup_sentence,
+Text_item::markup_sentence2molecule (Grob *me, SCM markup_sentence,
                                     SCM alist_chain)
 {
+  /*
+    FIXME
+
+    huh?
+   */
+  // return Molecule ();
+  
   SCM sheet = me->paper_l ()->style_sheet_;
   SCM f = gh_cdr (scm_assoc (ly_symbol2scm ("markup-to-properties"), sheet));
+  
   SCM markup = gh_car (markup_sentence);
   SCM sentence = gh_cdr (markup_sentence);
   
@@ -200,16 +180,14 @@ MAKE_SCHEME_CALLBACK (Text_item, brew_molecule, 1);
 SCM 
 Text_item::brew_molecule (SCM smob)
 {
-  Score_element *me = unsmob_element (smob);
+  Grob *me = unsmob_grob (smob);
   
-  SCM text = me->get_elt_property ("text");
-
-  SCM properties = gh_list (me->immutable_property_alist_,
-                           me->mutable_property_alist_, SCM_UNDEFINED);
+  SCM text = me->get_grob_property ("text");
 
+  SCM properties = Font_interface::font_alist_chain (me);
   Molecule mol = Text_item::text2molecule (me, text, properties);
 
-  SCM space = me->get_elt_property ("word-space");
+  SCM space = me->get_grob_property ("word-space");
   if (gh_number_p (space))
     {
       Molecule m;
@@ -217,6 +195,6 @@ Text_item::brew_molecule (SCM smob)
       mol.add_at_edge (X_AXIS, RIGHT, m, gh_scm2double (space)
                       * Staff_symbol_referencer::staff_space (me));
     }
-  return mol.create_scheme (); 
+  return mol.smobbed_copy (); 
 }