]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
*** empty log message ***
[lilypond.git] / lily / text-item.cc
1 /*   
2   text-item.cc -- implement Text_interface
3
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7                  Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "text-item.hh"
11
12 #include <math.h>
13
14 #include "main.hh" 
15 #include "config.hh"
16 #include "pango-font.hh"
17 #include "warn.hh"
18 #include "grob.hh"
19 #include "font-interface.hh"
20 #include "output-def.hh"
21 #include "modified-font-metric.hh"
22
23
24 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3)
25 SCM
26 Text_interface::interpret_string (SCM layout_smob,
27                                   SCM props,
28                                   SCM markup)
29 {
30   Output_def *layout = unsmob_output_def (layout_smob);
31   
32   SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
33                    __FUNCTION__, "Layout definition");
34   SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3,
35                    __FUNCTION__, "string");
36
37   String str = ly_scm2string (markup);
38
39 #if HAVE_PANGO_FT2
40   if (output_backend_global != "tex"
41       && output_backend_global != "texstr")
42     {
43       Font_metric *fm = select_pango_font (layout, props);
44       return fm->text_stencil (str).smobbed_copy ();
45     }
46 #endif
47   
48   Font_metric *fm = select_encoded_font (layout, props);
49   return fm->text_stencil (str).smobbed_copy();
50 }
51
52 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3)
53 SCM
54 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
55 {
56   if (scm_is_string (markup))
57     return interpret_string (layout_smob, props, markup);
58   else if (scm_is_pair (markup))
59     {
60       SCM func = scm_car (markup);
61       SCM args = scm_cdr (markup);
62       if (!markup_p (markup))
63         programming_error ("Markup head has no markup signature.");
64       
65       return scm_apply_2 (func, layout_smob, props, args);
66     }
67   else
68     {
69       programming_error ("Is not a markup: ");
70       scm_display (markup, scm_current_error_port());
71       assert (false);
72       Box b;
73       b[X_AXIS].set_empty();
74       b[Y_AXIS].set_empty();
75       
76       Stencil s(b, SCM_EOL);
77       return s.smobbed_copy();
78     }
79 }
80
81 MAKE_SCHEME_CALLBACK (Text_interface,print,1);
82 SCM
83 Text_interface::print (SCM grob)
84 {
85   Grob *me = unsmob_grob (grob);
86   
87   SCM t = me->get_property ("text");
88   SCM chain = Font_interface::text_font_alist_chain (me);
89   return interpret_markup (me->get_layout ()->self_scm (), chain, t);
90 }
91
92 /* Ugh. Duplicated from Scheme.  */
93 bool
94 Text_interface::markup_p (SCM x)
95 {
96   return (scm_is_string (x)
97           || (scm_is_pair (x)
98               && SCM_BOOL_F
99               != scm_object_property (scm_car (x),
100                                       ly_symbol2scm ("markup-signature"))));
101 }
102
103 ADD_INTERFACE (Text_interface,"text-interface",
104                "A scheme markup text, see @usermanref{Text-markup}.",
105                "text baseline-skip word-space");
106
107
108
109