]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-interface.cc
* lily/text-item.cc (interpret_string): new file, select font with
[lilypond.git] / lily / grob-interface.cc
1 /*
2   grob-interface.cc -- implement graphic objects interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "protected-scm.hh"
10 #include "grob-interface.hh"
11 #include "lily-guile.hh"
12 #include "grob.hh"
13 #include "warn.hh"
14
15 Protected_scm all_ifaces;
16
17 void add_interface (const char * symbol,
18                     const char * descr,
19                     const char * vars)
20 {
21   SCM s = ly_symbol2scm (symbol);
22   SCM d = scm_makfrom0str (descr);
23   SCM l = parse_symbol_list (vars);
24
25   ly_add_interface (s,d,l);
26 }
27
28
29 LY_DEFINE (ly_add_interface, "ly:add-interface", 3,0,0, (SCM a, SCM b, SCM c),
30           "Add an interface description.")
31 {
32   SCM_ASSERT_TYPE (is_symbol (a), a, SCM_ARG1, __FUNCTION__, "symbol");
33   SCM_ASSERT_TYPE (is_string (b), b, SCM_ARG2, __FUNCTION__, "string");  
34   SCM_ASSERT_TYPE (is_list (c), c, SCM_ARG3, __FUNCTION__, "list of syms");    
35   if (!is_vector (all_ifaces))
36     all_ifaces = scm_make_vector (scm_int2num (40), SCM_EOL);
37
38   SCM entry = scm_list_n (a, b, c, SCM_UNDEFINED);
39
40   scm_hashq_set_x (all_ifaces, a, entry);
41
42   return SCM_UNSPECIFIED;
43 }
44
45
46 LY_DEFINE (ly_all_grob_interfaces, "ly:all-grob-interfaces",
47           0,0,0, (),
48           "Get a hash table with all interface descriptions.")
49 {
50   return all_ifaces;
51 }
52
53
54 void
55 check_interfaces_for_property (Grob const *me, SCM sym)
56 {
57   if (sym == ly_symbol2scm ("meta"))
58     {
59       /*
60         otherwise we get in a nasty recursion loop.
61        */
62       return ;
63
64     }
65   SCM ifs = me->get_property ("interfaces");
66
67   bool found = false;
68   for (; !found && is_pair (ifs); ifs =ly_cdr (ifs))
69     {
70       SCM iface = scm_hashq_ref (all_ifaces , ly_car (ifs), SCM_BOOL_F);
71       if (iface == SCM_BOOL_F)
72         {
73           String msg = to_string (_f ("Unknown interface `%s'",
74                                       ly_symbol2string (ly_car (ifs)).to_str0 ()));
75           programming_error (msg);
76           continue;
77         }
78
79       found= found || (scm_c_memq (sym, ly_caddr (iface)) != SCM_BOOL_F);
80     }
81
82   if (!found)
83     {
84       String str = to_string (_f ("Grob `%s' has no interface for property `%s'",
85                                   me->name ().to_str0 (),
86                                   ly_symbol2string (sym).to_str0 ()));
87       programming_error (str);
88     }
89 }