]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/text-item.cc
remove TEXMF from variables.
[lilypond.git] / lily / text-item.cc
index ee10d5e873b393749176d872fc75338038ce899d..a45a3c84b873699ec3e1056750e4c3c379cd499c 100644 (file)
@@ -1,75 +1,96 @@
 /*
-  textitem.cc -- implement Text_item
+  text-item.cc -- implement Text_interface
 
-  source file of the LilyPond music typesetter
+  source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
-
-#include "musical-request.hh"
-#include "paper-def.hh"
 #include "text-item.hh"
-#include "stem.hh"
-#include "molecule.hh"
-#include "lookup.hh"
 
-Text_item::Text_item(Text_def *tdef_l)
-    : Staff_side(this)
-{
-    dir_i_ =-1;
-    init(tdef_l);  
-}
+#include <math.h>
 
-Text_def*
-Text_item::tdef_l()
-{
-    return tdef_p_;
-}
+#include "main.hh"
+#include "config.hh"
+#include "pango-font.hh"
+#include "warn.hh"
+#include "grob.hh"
+#include "font-interface.hh"
+#include "output-def.hh"
+#include "modified-font-metric.hh"
 
-Text_item::~Text_item()
+MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3);
+SCM
+Text_interface::interpret_string (SCM layout_smob,
+                                 SCM props,
+                                 SCM markup)
 {
-    delete tdef_p_;
-}
+  Output_def *layout = unsmob_output_def (layout_smob);
 
-void
-Text_item::init(Text_def *tdef_l)
-{
-    tdef_p_ = new Text_def (*tdef_l);
-}
+  SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
+                  __FUNCTION__, "Layout definition");
+  SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3,
+                  __FUNCTION__, "string");
 
-Text_item::Text_item(Text_req* treq_l)
-    : Staff_side(this)
-{
-    init(treq_l->tdef_p_);
-    dir_i_ = treq_l->dir_i_;
-    if (!dir_i_)
-       dir_i_ = -1;
+  String str = ly_scm2string (markup);
+
+  Font_metric *fm = select_encoded_font (layout, props);
+  return fm->text_stencil (str).smobbed_copy ();
 }
 
-void
-Text_item::set_default_index()
+MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3);
+SCM
+Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
 {
-    pos_i_  = get_position_i();
+  if (scm_is_string (markup))
+    return interpret_string (layout_smob, props, markup);
+  else if (scm_is_pair (markup))
+    {
+      SCM func = scm_car (markup);
+      SCM args = scm_cdr (markup);
+      if (!markup_p (markup))
+       programming_error ("Markup head has no markup signature.");
+
+      return scm_apply_2 (func, layout_smob, props, args);
+    }
+  else
+    {
+      programming_error ("Is not a markup: ");
+      scm_display (markup, scm_current_error_port ());
+      assert (false);
+      Box b;
+      b[X_AXIS].set_empty ();
+      b[Y_AXIS].set_empty ();
+
+      Stencil s (b, SCM_EOL);
+      return s.smobbed_copy ();
+    }
 }
 
-void
-Text_item::do_pre_processing()
+MAKE_SCHEME_CALLBACK (Text_interface, print, 1);
+SCM
+Text_interface::print (SCM grob)
 {
-    set_default_index();
+  Grob *me = unsmob_grob (grob);
+
+  SCM t = me->get_property ("text");
+  SCM chain = Font_interface::text_font_alist_chain (me);
+  return interpret_markup (me->get_layout ()->self_scm (), chain, t);
 }
 
-    
-Molecule*
-Text_item::brew_molecule_p() const
+/* Ugh. Duplicated from Scheme.  */
+bool
+Text_interface::markup_p (SCM x)
 {
-    Molecule* mol_p = new Molecule(tdef_p_->create_atom(paper()));
-
-    if(dir_i_<0 )              // should do something better anyway.
-       mol_p->translate(Offset(0, -mol_p->extent().y.left ));
-    mol_p->translate(Offset(0, pos_i_ * paper()->internote()));
-    
-    return mol_p;
+  return (scm_is_string (x)
+         || (scm_is_pair (x)
+             && SCM_BOOL_F
+             != scm_object_property (scm_car (x),
+                                     ly_symbol2scm ("markup-signature"))));
 }
 
-IMPLEMENT_STATIC_NAME(Text_item);
+ADD_INTERFACE (Text_interface, "text-interface",
+              "A scheme markup text, see @usermanref{Text-markup}.",
+              "text baseline-skip word-space");
+