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 "Lookup @var{sym} in the Output_def @var{pap}. "
20 "Return the value or @var{def} (which defaults to @code{'()}) if undefined.")
22 LY_ASSERT_FIRST_SMOB (Output_def, pap);
23 Output_def *op = unsmob_output_def (pap);
24 LY_ASSERT_TYPE (ly_is_symbol, 2);
26 SCM answer = op->lookup_variable (sym);
27 if (answer == SCM_UNDEFINED)
29 if (def == SCM_UNDEFINED)
38 LY_DEFINE (ly_output_def_scope, "ly:output-def-scope",
40 "Get the variable scope inside @var{def}.")
42 LY_ASSERT_FIRST_SMOB (Output_def, def);
43 Output_def *op = unsmob_output_def (def);
47 LY_DEFINE (ly_output_def_parent, "ly:output-def-parent",
49 "Get the parent output-def of @var{def}.")
51 LY_ASSERT_FIRST_SMOB (Output_def, def);
52 Output_def *op = unsmob_output_def (def);
53 return op->parent_ ? op->parent_->self_scm () : SCM_EOL;
56 LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
60 LY_ASSERT_FIRST_SMOB (Output_def, def);
61 Output_def *op = unsmob_output_def (def);
63 Output_def *clone = op->clone ();
64 return clone->unprotect ();
67 LY_DEFINE (ly_output_description, "ly:output-description",
68 1, 0, 0, (SCM output_def),
69 "Return the description of translators in @var{output-def}.")
71 Output_def *id = unsmob_output_def (output_def);
73 SCM al = ly_module_2_alist (id->scope_);
75 for (SCM s = al; scm_is_pair (s); s = scm_cdr (s))
77 Context_def *td = unsmob_context_def (scm_cdar (s));
78 SCM key = scm_caar (s);
79 if (td && key == td->get_context_name ())
80 ell = scm_cons (scm_cons (key, td->to_alist ()), ell);
85 LY_DEFINE (ly_output_def_p, "ly:output-def?",
87 "Is @var{def} a layout definition?")
89 return ly_bool2scm (unsmob_output_def (def));
92 LY_DEFINE (ly_paper_outputscale, "ly:paper-outputscale",
94 "Get output-scale for BP.")
96 LY_ASSERT_FIRST_SMOB (Output_def, bp);
97 Output_def *b = unsmob_output_def (bp);
98 return scm_from_double (output_scale (b));
101 LY_DEFINE (ly_make_output_def, "ly:make-output-def",
103 "Make a output def.")
105 Output_def *bp = new Output_def;
106 return bp->unprotect ();
109 LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
110 (SCM paper_smob, SCM chain),
112 "Return a font metric satisfying the font-qualifiers "
113 "in the alist chain @var{chain}.\n"
114 "(An alist chain is a list of alists, "
115 "containing grob properties).\n")
117 LY_ASSERT_FIRST_SMOB (Output_def, paper_smob);
119 Output_def *paper = unsmob_output_def (paper_smob);
120 Font_metric *fm = select_font (paper, chain);
121 return fm->self_scm ();
124 LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
125 (SCM layout_smob, SCM name),
126 "Return the layout variable @var{name}.")
129 LY_ASSERT_FIRST_SMOB (Output_def, layout_smob);
130 Output_def *layout = unsmob_output_def (layout_smob);
131 return scm_from_double (layout->get_dimension (name));
134 LY_DEFINE (ly_paper_fonts, "ly:paper-fonts",
137 "Return fonts from the @code{\\paper} block @var{bp}.")
139 LY_ASSERT_FIRST_SMOB (Output_def, bp);
140 Output_def *b = unsmob_output_def (bp);
142 SCM tab1 = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
143 SCM tab2 = b->lookup_variable (ly_symbol2scm ("pango-fonts"));
145 SCM alist1 = SCM_EOL;
146 if (scm_hash_table_p (tab1) == SCM_BOOL_T)
148 alist1 = scm_append (ly_alist_vals (ly_hash2alist (tab1)));
150 alist1 = ly_alist_vals (alist1);
153 SCM alist2 = SCM_EOL;
154 if (scm_hash_table_p (tab2) == SCM_BOOL_T)
156 // strip original-fonts/pango-font-descriptions
157 alist2 = scm_append (ly_alist_vals (ly_hash2alist (tab2)));
159 // strip size factors
160 alist2 = ly_alist_vals (alist2);
163 SCM alist = scm_append (scm_list_2 (alist1, alist2));
164 SCM font_list = SCM_EOL;
165 for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
167 SCM entry = scm_car (s);
169 Font_metric *fm = unsmob_metrics (entry);
171 if (dynamic_cast<Modified_font_metric *> (fm)
172 || dynamic_cast<Pango_font *> (fm))
173 font_list = scm_cons (fm->self_scm (), font_list);