2 output-def-scheme.cc -- implement Output_def bindings
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "output-def.hh"
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"
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.")
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);
27 SCM answer = op->lookup_variable (sym);
28 if (answer == SCM_UNDEFINED)
30 if (def == SCM_UNDEFINED)
39 LY_DEFINE (ly_output_def_scope, "ly:output-def-scope",
41 "Get the variable scope inside @var{def}.")
43 LY_ASSERT_SMOB (Output_def, def, 1);
44 Output_def *op = unsmob_output_def (def);
48 LY_DEFINE (ly_output_def_parent, "ly:output-def-parent",
50 "Get the parent output definition of @var{def}.")
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;
57 LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
59 "Clone output definition @var{def}.")
61 LY_ASSERT_SMOB (Output_def, def, 1);
62 Output_def *op = unsmob_output_def (def);
64 Output_def *clone = op->clone ();
65 return clone->unprotect ();
68 LY_DEFINE (ly_output_description, "ly:output-description",
69 1, 0, 0, (SCM output_def),
70 "Return the description of translators in @var{output-def}.")
72 Output_def *id = unsmob_output_def (output_def);
74 SCM al = ly_module_2_alist (id->scope_);
76 for (SCM s = al; scm_is_pair (s); s = scm_cdr (s))
78 Context_def *td = unsmob_context_def (scm_cdar (s));
79 SCM key = scm_caar (s);
80 if (td && key == td->get_context_name ())
81 ell = scm_cons (scm_cons (key, td->to_alist ()), ell);
86 LY_DEFINE (ly_output_def_p, "ly:output-def?",
88 "Is @var{def} a layout definition?")
90 return ly_bool2scm (unsmob_output_def (def));
93 LY_DEFINE (ly_paper_outputscale, "ly:paper-outputscale",
95 "Get output-scale for @var{bp}.")
97 LY_ASSERT_SMOB (Output_def, bp, 1);
98 Output_def *b = unsmob_output_def (bp);
99 return scm_from_double (output_scale (b));
102 LY_DEFINE (ly_make_output_def, "ly:make-output-def",
104 "Make an output definition.")
106 Output_def *bp = new Output_def;
107 return bp->unprotect ();
110 LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
111 (SCM paper_smob, SCM chain),
112 "Return a font metric satisfying the font-qualifiers"
113 " in the alist chain @var{chain}. (An alist chain is a"
114 " list of alists, containing grob properties.)")
116 LY_ASSERT_SMOB (Output_def, paper_smob, 1);
118 Output_def *paper = unsmob_output_def (paper_smob);
119 Font_metric *fm = select_font (paper, chain);
120 return fm->self_scm ();
123 LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
124 (SCM layout_smob, SCM name),
125 "Return the layout variable @var{name}.")
128 LY_ASSERT_SMOB (Output_def, layout_smob, 1);
129 Output_def *layout = unsmob_output_def (layout_smob);
130 return scm_from_double (layout->get_dimension (name));
133 LY_DEFINE (ly_paper_fonts, "ly:paper-fonts",
136 "Return fonts from the @code{\\paper} block @var{bp}.")
138 LY_ASSERT_SMOB (Output_def, bp, 1);
139 Output_def *b = unsmob_output_def (bp);
141 SCM tab1 = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
142 SCM tab2 = b->lookup_variable (ly_symbol2scm ("pango-fonts"));
144 SCM alist1 = SCM_EOL;
145 if (scm_hash_table_p (tab1) == SCM_BOOL_T)
147 alist1 = scm_append (ly_alist_vals (ly_hash2alist (tab1)));
149 alist1 = ly_alist_vals (alist1);
152 SCM alist2 = SCM_EOL;
153 if (scm_hash_table_p (tab2) == SCM_BOOL_T)
155 // strip original-fonts/pango-font-descriptions
156 alist2 = scm_append (ly_alist_vals (ly_hash2alist (tab2)));
158 // strip size factors
159 alist2 = ly_alist_vals (alist2);
162 SCM alist = scm_append (scm_list_2 (alist1, alist2));
163 SCM font_list = SCM_EOL;
164 for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
166 SCM entry = scm_car (s);
168 Font_metric *fm = unsmob_metrics (entry);
170 if (dynamic_cast<Modified_font_metric *> (fm)
171 || dynamic_cast<Pango_font *> (fm))
172 font_list = scm_cons (fm->self_scm (), font_list);