]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-def-scheme.cc
Run `make grand-replace'.
[lilypond.git] / lily / output-def-scheme.cc
1 /*
2   output-def-scheme.cc -- implement Output_def bindings
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "output-def.hh"
10
11 #include "pango-font.hh"
12 #include "modified-font-metric.hh"
13 #include "ly-module.hh"
14 #include "context-def.hh"
15 #include "lily-parser.hh"
16
17 LY_DEFINE (ly_output_def_lookup, "ly:output-def-lookup",
18            2, 1, 0, (SCM pap, SCM sym, SCM def),
19            "Look up @var{sym} in the @var{pap} output definition"
20            " (e.g., @code{\\paper}).  Return the value or @var{def}"
21            " (which defaults to @code{'()}) if undefined.")
22 {
23   LY_ASSERT_SMOB (Output_def, pap, 1);
24   Output_def *op = unsmob_output_def (pap);
25   LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
26
27   SCM answer = op->lookup_variable (sym);
28   if (answer == SCM_UNDEFINED)
29     {
30       if (def == SCM_UNDEFINED)
31         def = SCM_EOL;
32
33       answer = def;
34     }
35
36   return answer;
37 }
38
39 LY_DEFINE (ly_output_def_scope, "ly:output-def-scope",
40            1, 0, 0, (SCM def),
41            "Get the variable scope inside @var{def}.")
42 {
43   LY_ASSERT_SMOB (Output_def, def, 1);
44   Output_def *op = unsmob_output_def (def);
45   return op->scope_;
46 }
47
48 LY_DEFINE (ly_output_def_parent, "ly:output-def-parent",
49            1, 0, 0, (SCM def),
50            "Get the parent output definition of @var{def}.")
51 {
52   LY_ASSERT_SMOB (Output_def, def, 1);
53   Output_def *op = unsmob_output_def (def);
54   return op->parent_ ? op->parent_->self_scm () : SCM_EOL;
55 }
56
57 LY_DEFINE (ly_output_def_set_variable_x, "ly:output-def-set-variable!",
58            3, 0, 0, (SCM def, SCM sym, SCM val),
59            "Set an output definition @var{def} variable @var{sym} to @var{val}.")
60 {
61   LY_ASSERT_SMOB (Output_def, def, 1);
62   Output_def *output_def = unsmob_output_def (def);
63   LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
64   output_def->set_variable (sym, val);
65   return SCM_UNSPECIFIED;
66 }
67
68 LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
69            1, 0, 0, (SCM def),
70            "Clone output definition @var{def}.")
71 {
72   LY_ASSERT_SMOB (Output_def, def, 1);
73   Output_def *op = unsmob_output_def (def);
74
75   Output_def *clone = op->clone ();
76   return clone->unprotect ();
77 }
78
79 LY_DEFINE (ly_output_description, "ly:output-description",
80            1, 0, 0, (SCM output_def),
81            "Return the description of translators in @var{output-def}.")
82 {
83   Output_def *id = unsmob_output_def (output_def);
84
85   SCM al = ly_module_2_alist (id->scope_);
86   SCM ell = SCM_EOL;
87   for (SCM s = al; scm_is_pair (s); s = scm_cdr (s))
88     {
89       Context_def *td = unsmob_context_def (scm_cdar (s));
90       SCM key = scm_caar (s);
91       if (td && key == td->get_context_name ())
92         ell = scm_cons (scm_cons (key, td->to_alist ()), ell);
93     }
94   return ell;
95 }
96
97 LY_DEFINE (ly_output_def_p, "ly:output-def?",
98            1, 0, 0, (SCM def),
99            "Is @var{def} a layout definition?")
100 {
101   return ly_bool2scm (unsmob_output_def (def));
102 }
103
104 LY_DEFINE (ly_paper_outputscale, "ly:paper-outputscale",
105            1, 0, 0, (SCM bp),
106            "Get output-scale for @var{bp}.")
107 {
108   LY_ASSERT_SMOB (Output_def, bp, 1);
109   Output_def *b = unsmob_output_def (bp);
110   return scm_from_double (output_scale (b));
111 }
112
113 LY_DEFINE (ly_make_output_def, "ly:make-output-def",
114            0, 0, 0, (),
115            "Make an output definition.")
116 {
117   Output_def *bp = new Output_def;
118   return bp->unprotect ();
119 }
120
121 LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
122            (SCM paper_smob, SCM chain),
123            "Return a font metric satisfying the font-qualifiers"
124            " in the alist chain @var{chain}.  (An alist chain is a"
125            " list of alists, containing grob properties.)")
126 {
127   LY_ASSERT_SMOB (Output_def, paper_smob, 1);
128
129   Output_def *paper = unsmob_output_def (paper_smob);
130   Font_metric *fm = select_font (paper, chain);
131   return fm->self_scm ();
132 }
133
134 LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
135            (SCM layout_smob, SCM name),
136            "Return the layout variable @var{name}.")
137 {
138   LY_ASSERT_SMOB (Output_def, layout_smob, 1);
139   Output_def *layout = unsmob_output_def (layout_smob);
140   return scm_from_double (layout->get_dimension (name));
141 }
142
143 LY_DEFINE (ly_paper_fonts, "ly:paper-fonts",
144            1, 0, 0,
145            (SCM bp),
146            "Return fonts from the @code{\\paper} block @var{bp}.")
147 {
148   LY_ASSERT_SMOB (Output_def, bp, 1);
149   Output_def *b = unsmob_output_def (bp);
150
151   SCM tab1 = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
152   SCM tab2 = b->lookup_variable (ly_symbol2scm ("pango-fonts"));
153
154   SCM alist1 = SCM_EOL;
155   if (scm_hash_table_p (tab1) == SCM_BOOL_T)
156     {
157       alist1 = scm_append (ly_alist_vals (ly_hash2alist (tab1)));
158
159       alist1 = ly_alist_vals (alist1);
160     }
161
162   SCM alist2 = SCM_EOL;
163   if (scm_hash_table_p (tab2) == SCM_BOOL_T)
164     {
165       // strip original-fonts/pango-font-descriptions
166       alist2 = scm_append (ly_alist_vals (ly_hash2alist (tab2)));
167
168       // strip size factors
169       alist2 = ly_alist_vals (alist2);
170     }
171
172   SCM alist = scm_append (scm_list_2 (alist1, alist2));
173   SCM font_list = SCM_EOL;
174   for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
175     {
176       SCM entry = scm_car (s);
177
178       Font_metric *fm = unsmob_metrics (entry);
179
180       if (dynamic_cast<Modified_font_metric *> (fm)
181           || dynamic_cast<Pango_font *> (fm))
182         font_list = scm_cons (fm->self_scm (), font_list);
183     }
184
185   return font_list;
186 }