X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftext-item.cc;h=84a006243daf7f0a90053dc2a229d6c247f48031;hb=98ba77f9a972c75e431f29a47df18676c3d65621;hp=d51a1363852da12891b018dff849c01f66d125cb;hpb=48f2b9351f93d0161c675cfb60e95bf919041df2;p=lilypond.git diff --git a/lily/text-item.cc b/lily/text-item.cc index d51a136385..7203d7b8e0 100644 --- a/lily/text-item.cc +++ b/lily/text-item.cc @@ -1,29 +1,121 @@ /* - text-item.cc -- implement Text_item + text-item.cc -- implement Text_interface source file of the GNU LilyPond music typesetter - (c) 1998--1999 Han-Wen Nienhuys - - */ + (c) 1998--2004 Han-Wen Nienhuys + Jan Nieuwenhuizen +*/ #include "text-item.hh" -#include "debug.hh" -#include "molecule.hh" -#include "paper-def.hh" -#include "lookup.hh" -Molecule* -Text_item::do_brew_molecule_p () const +#include + +#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" +#include "ly-module.hh" + + +MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 4) +SCM +Text_interface::interpret_string (SCM layout_smob, + SCM props, SCM input_encoding, SCM markup) +{ + Output_def *layout = unsmob_output_def (layout_smob); + + SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1, + __FUNCTION__, "Layout definition"); + SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3, + __FUNCTION__, "string"); + + String str = ly_scm2string (markup); + +#if HAVE_PANGO_FT2 + if (output_format_global != "tex") + { + Font_metric *fm = select_pango_font (layout, props); + return fm->text_stencil (str).smobbed_copy (); + } +#endif + + SCM_ASSERT_TYPE (input_encoding == SCM_EOL || scm_is_symbol (input_encoding), + input_encoding, SCM_ARG2, __FUNCTION__, "symbol"); + + if (!scm_is_symbol (input_encoding)) + { + SCM enc = layout->lookup_variable (ly_symbol2scm ("inputencoding")); + if (scm_is_string (enc)) + input_encoding = scm_string_to_symbol (enc); + else if (scm_is_symbol (enc)) + input_encoding = enc; + } + + Font_metric *fm = select_encoded_font (layout, props, input_encoding); + + return fm->text_stencil (str).smobbed_copy(); +} + +MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3) +SCM +Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup) +{ + if (scm_is_string (markup)) + return interpret_string (layout_smob, props, SCM_EOL, 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(); + } +} + +MAKE_SCHEME_CALLBACK (Text_interface,print,1); +SCM +Text_interface::print (SCM grob) { - SCM style = get_elt_property ("style"); - String st = gh_string_p (style) ? ly_scm2string (style) : ""; - SCM txt = get_elt_property ("text"); - String t = gh_string_p (txt) ? ly_scm2string (txt) : ""; + Grob *me = unsmob_grob (grob); - Molecule a= paper_l ()->lookup_l(0)->text (st, t, paper_l ()); + 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); +} - return new Molecule (a); +/* Ugh. Duplicated from Scheme. */ +bool +Text_interface::markup_p (SCM x) +{ + return (scm_is_string (x) + || (scm_is_pair (x) + && SCM_BOOL_F + != scm_object_property (scm_car (x), + ly_symbol2scm ("markup-signature")))); } +ADD_INTERFACE (Text_interface,"text-interface", + "A scheme markup text, see @usermanref{Text-markup}.", + "text baseline-skip word-space"); + + +