Merge branch 'fret-diagram-details'
[lilypond/csorensen.git] / lily / output-def-scheme.cc
blob91a7933d00f20ebec81e6b2ecdc8e2c85683a3b9
1 /*
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>
7 */
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)
31 def = SCM_EOL;
33 answer = def;
36 return answer;
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}.")
43 LY_ASSERT_SMOB (Output_def, def, 1);
44 Output_def *op = unsmob_output_def (def);
45 return op->scope_;
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}.")
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_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}.")
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;
68 LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
69 1, 0, 0, (SCM def),
70 "Clone output definition @var{def}.")
72 LY_ASSERT_SMOB (Output_def, def, 1);
73 Output_def *op = unsmob_output_def (def);
75 Output_def *clone = op->clone ();
76 return clone->unprotect ();
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}.")
83 Output_def *id = unsmob_output_def (output_def);
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))
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);
94 return ell;
97 LY_DEFINE (ly_output_def_p, "ly:output-def?",
98 1, 0, 0, (SCM def),
99 "Is @var{def} a layout definition?")
101 return ly_bool2scm (unsmob_output_def (def));
104 LY_DEFINE (ly_paper_outputscale, "ly:paper-outputscale",
105 1, 0, 0, (SCM bp),
106 "Get output-scale for @var{bp}.")
108 LY_ASSERT_SMOB (Output_def, bp, 1);
109 Output_def *b = unsmob_output_def (bp);
110 return scm_from_double (output_scale (b));
113 LY_DEFINE (ly_make_output_def, "ly:make-output-def",
114 0, 0, 0, (),
115 "Make an output definition.")
117 Output_def *bp = new Output_def;
118 return bp->unprotect ();
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.)")
127 LY_ASSERT_SMOB (Output_def, paper_smob, 1);
129 Output_def *paper = unsmob_output_def (paper_smob);
130 Font_metric *fm = select_font (paper, chain);
131 return fm->self_scm ();
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}.")
139 LY_ASSERT_SMOB (Output_def, layout_smob, 1);
140 Output_def *layout = unsmob_output_def (layout_smob);
141 return scm_from_double (layout->get_dimension (name));
144 LY_DEFINE (ly_paper_fonts, "ly:paper-fonts",
145 1, 0, 0,
146 (SCM bp),
147 "Return fonts from the @code{\\paper} block @var{bp}.")
149 LY_ASSERT_SMOB (Output_def, bp, 1);
150 Output_def *b = unsmob_output_def (bp);
152 SCM tab1 = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
153 SCM tab2 = b->lookup_variable (ly_symbol2scm ("pango-fonts"));
155 SCM alist1 = SCM_EOL;
156 if (scm_hash_table_p (tab1) == SCM_BOOL_T)
158 alist1 = scm_append (ly_alist_vals (ly_hash2alist (tab1)));
160 alist1 = ly_alist_vals (alist1);
163 SCM alist2 = SCM_EOL;
164 if (scm_hash_table_p (tab2) == SCM_BOOL_T)
166 // strip original-fonts/pango-font-descriptions
167 alist2 = scm_append (ly_alist_vals (ly_hash2alist (tab2)));
169 // strip size factors
170 alist2 = ly_alist_vals (alist2);
173 SCM alist = scm_append (scm_list_2 (alist1, alist2));
174 SCM font_list = SCM_EOL;
175 for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
177 SCM entry = scm_car (s);
179 Font_metric *fm = unsmob_metrics (entry);
181 if (dynamic_cast<Modified_font_metric *> (fm)
182 || dynamic_cast<Pango_font *> (fm))
183 font_list = scm_cons (fm->self_scm (), font_list);
186 return font_list;