2 output-def-scheme.cc -- implement Output_def bindings
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "font-metric.hh"
10 #include "pango-font.hh"
11 #include "modified-font-metric.hh"
12 #include "output-def.hh"
13 #include "ly-module.hh"
14 #include "context-def.hh"
15 #include "lily-parser.hh"
17 LY_DEFINE (ly_layout_lookup, "ly:output-def-lookup",
18 2, 1, 0, (SCM pap, SCM sym, SCM def),
19 "Lookup @var{sym} in @var{pap}. "
20 "Return the value or @var{def} (which defaults to @code{'()}) if undefined.")
22 Output_def *op = unsmob_output_def (pap);
23 SCM_ASSERT_TYPE (op, pap, SCM_ARG1, __FUNCTION__, "Output_def");
24 SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
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 Output_def *op = unsmob_output_def (def);
43 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
47 LY_DEFINE (ly_output_def_parent, "ly:output-def-parent",
49 "Get the parent output-def of @var{def}.")
51 Output_def *op = unsmob_output_def (def);
52 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
53 return op->parent_ ? op->parent_->self_scm () : SCM_EOL;
56 LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
60 Output_def *op = unsmob_output_def (def);
61 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
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_module2alist (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_layout_def_p, "ly:layout-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 Output_def *b = unsmob_output_def (bp);
97 SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "paper");
98 return scm_from_double (output_scale (b));
102 Cannot put in scope, but need a separate function, since we don't
103 want to allow this in --safe.
105 LY_DEFINE (ly_output_def_parser, "ly:output-def-parser",
107 "Return the parser where @var{odef} is coming from.")
109 Output_def *b = unsmob_output_def (odef);
110 SCM_ASSERT_TYPE (b, odef, SCM_ARG1, __FUNCTION__, "paper");
112 return b->get_parser()->self_scm ();
116 LY_DEFINE (ly_make_output_def, "ly:make-output-def",
118 "Make a output def.")
120 Output_def *bp = new Output_def;
121 return bp->unprotect ();
124 LY_DEFINE (ly_paper_get_font, "ly:paper-get-font", 2, 0, 0,
125 (SCM paper_smob, SCM chain),
127 "Return a font metric satisfying the font-qualifiers "
128 "in the alist chain @var{chain}.\n"
129 "(An alist chain is a list of alists, "
130 "containing grob properties).\n")
132 Output_def *paper = unsmob_output_def (paper_smob);
133 SCM_ASSERT_TYPE (paper, paper_smob, SCM_ARG1,
134 __FUNCTION__, "paper definition");
136 Font_metric *fm = select_font (paper, chain);
137 return fm->self_scm ();
140 LY_DEFINE (ly_paper_get_number, "ly:paper-get-number", 2, 0, 0,
141 (SCM layout_smob, SCM name),
142 "Return the layout variable @var{name}.")
144 Output_def *layout = unsmob_output_def (layout_smob);
145 SCM_ASSERT_TYPE (layout, layout_smob, SCM_ARG1,
146 __FUNCTION__, "layout definition");
147 return scm_from_double (layout->get_dimension (name));
150 LY_DEFINE (ly_paper_fonts, "ly:paper-fonts",
153 "Return fonts from the @code{\\paper} block @var{bp}.")
155 Output_def *b = unsmob_output_def (bp);
157 SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "paper");
159 SCM tab1 = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
160 SCM tab2 = b->lookup_variable (ly_symbol2scm ("pango-fonts"));
162 SCM alist1 = SCM_EOL;
163 if (scm_hash_table_p (tab1) == SCM_BOOL_T)
165 alist1 = scm_append (ly_alist_vals (ly_hash2alist (tab1)));
167 alist1 = ly_alist_vals (alist1);
170 SCM alist2 = SCM_EOL;
171 if (scm_hash_table_p (tab2) == SCM_BOOL_T)
173 // strip original-fonts/pango-font-descriptions
174 alist2 = scm_append (ly_alist_vals (ly_hash2alist (tab2)));
176 // strip size factors
177 alist2 = ly_alist_vals (alist2);
180 SCM alist = scm_append (scm_list_2 (alist1, alist2));
181 SCM font_list = SCM_EOL;
182 for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
184 SCM entry = scm_car (s);
186 Font_metric *fm = unsmob_metrics (entry);
188 if (dynamic_cast<Modified_font_metric *> (fm)
189 || dynamic_cast<Pango_font *> (fm))
190 font_list = scm_cons (fm->self_scm (), font_list);