+#include "main.hh"
+#include "all-font-metrics.hh"
+#include "afm.hh"
+#include "lookup.hh"
+#include "virtual-font-metric.hh"
+
+/*
+
+ TEXT: STRING
+ | (MARKUP? TEXT+)
+ ;
+
+ HEAD: MARKUP-ITEM | (MARKUP-ITEM+)
+
+ MARKUP-ITEM: PROPERTY | ABBREV | FONT-STYLE
+ PROPERTY: (key . value)
+ ABBREV: rows lines roman music bold italic named super sub text
+
+*/
+
+Molecule
+Text_item::text2molecule (Grob *me, SCM text, SCM alist_chain)
+{
+ if (gh_string_p (text))
+ return string2molecule (me, text, alist_chain);
+ else if (gh_pair_p (text))
+ {
+ /* urg, why not just do this in markup_text2molecule ? */
+ if (gh_string_p (ly_car (text)))
+ return markup_text2molecule (me,
+ gh_append2 (scm_list_n (SCM_EOL,
+ SCM_UNDEFINED),
+ text),
+ alist_chain);
+ /*
+ Allow (faulty) texts that are in an extra list:
+ #'(("foo"))
+ */
+ else if (scm_ilength (text) <= 1)
+ return text2molecule (me, ly_car (text), alist_chain);
+ else
+ return markup_text2molecule (me, text, alist_chain);
+ }
+ return Molecule ();
+}
+
+
+MAKE_SCHEME_CALLBACK(Text_item,text_to_molecule,3);
+SCM
+Text_item::text_to_molecule (SCM grob, SCM props, SCM markup)
+{
+ Grob *me = unsmob_grob (grob);
+
+ return Text_item::text2molecule (me, markup, props).smobbed_copy();
+}
+
+
+Molecule
+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) && gh_symbol_p (ly_cdr (style)))
+ alist_chain = Font_interface::add_style (me, ly_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_cdr (lookup) ==ly_symbol2scm ("name"))
+ mol = lookup_character (me, fm, text);
+ else
+ mol = lookup_text (me, fm, text);
+
+ return mol;
+}
+
+Molecule
+Text_item::lookup_character (Grob *, Font_metric*fm, SCM char_name)
+{
+ return fm->find_by_name (ly_scm2string (char_name));
+}
+
+
+
+Molecule
+Text_item::lookup_text (Grob *, Font_metric*fm, SCM text)
+{
+ SCM list = scm_list_n (ly_symbol2scm ("text"), text, SCM_UNDEFINED);
+
+ if (dynamic_cast<Virtual_font_metric*> (fm))
+ {
+ /*
+ ARGH.
+ */
+ programming_error ("Can't use virtual font for text.");
+ }
+ else
+ list = fontify_atom (fm, list);
+
+ return Molecule (fm->text_dimension (ly_scm2string (text)), list);
+}
+
+
+/*
+ TODO: