+#include "font-interface.hh"
+#include "staff-symbol-referencer.hh"
+#include "staff-symbol-referencer.hh"
+#include "main.hh"
+#include "all-font-metrics.hh"
+#include "afm.hh"
+
+
+/*
+ TEXT : STRING | (MARKUP SENTENCE)
+ MARKUP: PROPERTY | ABBREV
+ SENTENCE: TEXT | SENTENCE TEXT
+ PROPERTY: (key . value)
+ ABBREV: rows lines roman music bold italic named super sub text, or any font-style
+ */
+
+/*
+ TODO:
+
+ rewrite routines and syntax to be like
+
+ TEXT: STRING
+ | (head-expression* TEXT*)
+ ;
+
+ head-expression is a list, containing a tag and a variable number of
+ arguments. If necessary, the number of arguments can be stored in a alist,
+
+ '(
+ (tag1 . argcount1)
+ (tag2 . argcount2)
+
+ ... etc
+
+ )
+
+ or even entries like
+
+ (tag . (argcount function-to-handle-the-tag ))
+
+ */
+
+Molecule
+Text_item::text2molecule (Score_element *me, SCM text, SCM alist_chain)
+{
+ if (gh_string_p (text))
+ return string2molecule (me, text, alist_chain);
+ else if (gh_list_p (text))
+ {
+ if (!gh_pair_p (gh_car (text)) && gh_string_p (gh_car (text)))
+ return string2molecule (me, gh_car (text), alist_chain);
+ else
+ return markup_sentence2molecule (me, text, 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)
+{
+ SCM style = ly_assoc_chain (ly_symbol2scm ("font-style"),
+ 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) && gh_cdr (lookup) ==ly_symbol2scm ("name"))
+ mol = lookup_character (me, fm, text);
+ else
+ mol = lookup_text (me, fm, text);
+
+ return mol;
+}