]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-item.cc
* lily/include/main.hh: rename format to backend.
[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 #include "ly-module.hh"
23
24
25 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3)
26 SCM
27 Text_interface::interpret_string (SCM layout_smob,
28                                   SCM props,
29                                   SCM markup)
30 {
31   Output_def *layout = unsmob_output_def (layout_smob);
32   
33   SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
34                    __FUNCTION__, "Layout definition");
35   SCM_ASSERT_TYPE (scm_is_string (markup), markup, SCM_ARG3,
36                    __FUNCTION__, "string");
37
38   String str = ly_scm2string (markup);
39
40 #if HAVE_PANGO_FT2
41   if (output_backend_global != "tex"
42       && output_backend_global != "texstr")
43     {
44       Font_metric *fm = select_pango_font (layout, props);
45       return fm->text_stencil (str).smobbed_copy ();
46     }
47 #endif
48   
49   Font_metric *fm = select_encoded_font (layout, props);
50   return fm->text_stencil (str).smobbed_copy();
51 }
52
53 MAKE_SCHEME_CALLBACK (Text_interface, interpret_markup, 3)
54 SCM
55 Text_interface::interpret_markup (SCM layout_smob, SCM props, SCM markup)
56 {
57   if (scm_is_string (markup))
58     return interpret_string (layout_smob, props, markup);
59   else if (scm_is_pair (markup))
60     {
61       SCM func = scm_car (markup);
62       SCM args = scm_cdr (markup);
63       if (!markup_p (markup))
64         programming_error ("Markup head has no markup signature.");
65       
66       return scm_apply_2 (func, layout_smob, props, args);
67     }
68   else
69     {
70       programming_error ("Is not a markup: ");
71       scm_display (markup, scm_current_error_port());
72       assert (false);
73       Box b;
74       b[X_AXIS].set_empty();
75       b[Y_AXIS].set_empty();
76       
77       Stencil s(b, SCM_EOL);
78       return s.smobbed_copy();
79     }
80 }
81
82 MAKE_SCHEME_CALLBACK (Text_interface,print,1);
83 SCM
84 Text_interface::print (SCM grob)
85 {
86   Grob *me = unsmob_grob (grob);
87   
88   SCM t = me->get_property ("text");
89   SCM chain = Font_interface::text_font_alist_chain (me);
90   return interpret_markup (me->get_layout ()->self_scm (), chain, t);
91 }
92
93 /* Ugh. Duplicated from Scheme.  */
94 bool
95 Text_interface::markup_p (SCM x)
96 {
97   return (scm_is_string (x)
98           || (scm_is_pair (x)
99               && SCM_BOOL_F
100               != scm_object_property (scm_car (x),
101                                       ly_symbol2scm ("markup-signature"))));
102 }
103
104 ADD_INTERFACE (Text_interface,"text-interface",
105                "A scheme markup text, see @usermanref{Text-markup}.",
106                "text baseline-skip word-space");
107
108
109
110