/*
- text-item.cc -- implement Item
+ text-item.cc -- implement Text_item
source file of the GNU LilyPond music typesetter
- (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
+ (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ Jan Nieuwenhuizen <janneke@gnu.org>
*/
+#include <math.h>
-#include "debug.hh"
-#include "molecule.hh"
+#include "warn.hh"
+#include "grob.hh"
+#include "text-item.hh"
+#include "font-interface.hh"
+#include "virtual-font-metric.hh"
#include "paper-def.hh"
-#include "lookup.hh"
-#include "staff-symbol-referencer.hh"
+#include "scaled-font-metric.hh"
-struct Text_item
+MAKE_SCHEME_CALLBACK (Text_item, interpret_string, 4)
+SCM
+Text_item::interpret_string (SCM paper, SCM props, SCM encoding, SCM markup)
{
- static SCM brew_molecule (SCM);
-};
+ Paper_def *pap = unsmob_paper (paper);
+
+ SCM_ASSERT_TYPE(pap, paper, SCM_ARG1, __FUNCTION__, "Paper definition");
+ SCM_ASSERT_TYPE(ly_c_string_p (markup), markup, SCM_ARG3, __FUNCTION__, "string");
+ SCM_ASSERT_TYPE(encoding == SCM_EOL
+ || ly_c_symbol_p (encoding), encoding, SCM_ARG2, __FUNCTION__, "symbol");
+
+ String str = ly_scm2string (markup);
+ Font_metric *fm = select_encoded_font (pap, props, encoding);
+ SCM lst = SCM_EOL;
+ Box b;
+ if (Modified_font_metric* mf = dynamic_cast<Modified_font_metric*> (fm))
+ {
+ lst = scm_list_3 (ly_symbol2scm ("text"),
+ mf->self_scm (),
+ markup);
+
+ b = mf->text_dimension (str);
+ }
+ else
+ {
+ /* ARGH. */
+ programming_error ("Must have Modified_font_metric for text.");
+ }
+
+ return Stencil (b, lst).smobbed_copy ();
+}
-MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Text_item,brew_molecule)
-SCM
-Text_item::brew_molecule (SCM sm)
+MAKE_SCHEME_CALLBACK (Text_item, interpret_markup, 3)
+SCM
+Text_item::interpret_markup (SCM paper, SCM props, SCM markup)
{
- Score_element * s = unsmob_element (sm);
+ if (ly_c_string_p (markup))
+ return interpret_string (paper, props, SCM_EOL, markup);
+ else if (ly_c_pair_p (markup))
+ {
+ SCM func = ly_car (markup);
+ SCM args = ly_cdr (markup);
+ if (!markup_p (markup))
+ programming_error ("Markup head has no markup signature.");
+
+ return scm_apply_2 (func, paper, props, args);
+ }
+ return SCM_EOL;
+}
+
+MAKE_SCHEME_CALLBACK (Text_item,print,1);
+SCM
+Text_item::print (SCM grob)
+{
+ Grob *me = unsmob_grob (grob);
- SCM style = s->get_elt_property ("style");
- String st = gh_string_p (style) ? ly_scm2string (style) : "";
- SCM txt = s-> get_elt_property ("text");
- String t = gh_string_p (txt) ? ly_scm2string (txt) : "";
+ SCM t = me->get_property ("text");
+ SCM chain = Font_interface::text_font_alist_chain (me);
+ return interpret_markup (me->get_paper ()->self_scm (), chain, t);
+}
- Molecule mol = s->paper_l ()->lookup_l(0)->text (st, t, s->paper_l ());
- SCM space = s->get_elt_property ("word-space");
- if (gh_number_p (space))
- {
- Molecule m;
- m.set_empty (false);
- mol.add_at_edge (X_AXIS, RIGHT, m, gh_scm2double (space)*
- Staff_symbol_referencer_interface (s).staff_space ());
- }
- return mol.create_scheme ();
+/*
+ Ugh. Duplicated from Scheme.
+ */
+bool
+Text_item::markup_p (SCM x)
+{
+ return
+ ly_c_string_p (x) ||
+ (ly_c_pair_p (x)
+ && SCM_BOOL_F != scm_object_property (ly_car (x), ly_symbol2scm ("markup-signature")));
}
+ADD_INTERFACE (Text_item,"text-interface",
+ "A scheme markup text, see @usermanref{Text-markup}.",
+ "text baseline-skip word-space");
+
+
+