2 book-paper-def.cc -- implement Output_def
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "ly-module.hh"
11 #include "output-def.hh"
12 #include "dimensions.hh"
13 #include "ly-smobs.icc"
14 #include "font-metric.hh"
15 #include "virtual-font-metric.hh"
16 #include "scaled-font-metric.hh"
19 output_scale (Output_def * od)
21 return ly_scm2double (od->lookup_variable (ly_symbol2scm ("outputscale")));
25 TODO: should add nesting for Output_def here too.
28 find_scaled_font (Output_def * mod,
29 Font_metric *f, Real m, SCM input_enc_name)
33 return find_scaled_font (mod->parent_,
34 f, m, input_enc_name);
38 if (!dynamic_cast<Virtual_font_metric*> (f))
39 lookup_mag /= output_scale (mod);
41 SCM font_table = mod->lookup_variable (ly_symbol2scm ("scaled-fonts"));
42 if (scm_hash_table_p (font_table) != SCM_BOOL_T)
44 font_table = scm_c_make_hash_table (11);
45 mod->set_variable (ly_symbol2scm ("scaled-fonts"), font_table);
49 SCM sizes = scm_hashq_ref (font_table, f->self_scm (), SCM_BOOL_F);
50 if (sizes != SCM_BOOL_F)
52 SCM met = scm_assoc (scm_make_real (lookup_mag), sizes);
53 if (ly_c_pair_p (met))
54 return unsmob_metrics (ly_cdr (met));
59 /* Hmm. We're chaining font - metrics. Should consider whether to
60 merge virtual-font and scaled_font. */
62 if (Virtual_font_metric * vf = dynamic_cast<Virtual_font_metric*> (f))
65 For fontify_atom (), the magnification and name must be known
66 at the same time. That's impossible for
68 Scaled (Virtual_font (Font1,Font2))
72 Virtual_font (Scaled (Font1), Scaled (Font2))
78 for (SCM s = vf->get_font_list (); ly_c_pair_p (s); s = ly_cdr (s))
80 Font_metric *scaled = find_scaled_font (mod,
81 unsmob_metrics (ly_car (s)),
83 *t = scm_cons (scaled->self_scm (), SCM_EOL);
87 vf = new Virtual_font_metric (lst);
88 val = vf->self_scm ();
92 if (!ly_c_symbol_p (input_enc_name))
94 SCM var = ly_module_lookup (mod->scope_, ly_symbol2scm ("inputencoding"));
95 if (var != SCM_BOOL_F)
96 input_enc_name = scm_variable_ref (var);
97 if (!ly_c_symbol_p (input_enc_name))
98 input_enc_name = ly_symbol2scm ("latin1");
101 val = Modified_font_metric::make_scaled_font_metric (input_enc_name,
105 sizes = scm_acons (scm_make_real (lookup_mag), val, sizes);
106 scm_gc_unprotect_object (val);
107 scm_hashq_set_x (font_table, f->self_scm (), sizes);
108 return unsmob_metrics (val);
112 TODO: this is a nasty interface. During formatting,
113 the Output_def should be scaled to the output_scale_
114 specified in the toplevel Output_def.
117 scale_output_def (Output_def * o, Real amount)
119 SCM proc = ly_scheme_function ("scale-paper");
120 SCM new_pap = scm_call_2 (proc, o->self_scm (),
121 scm_double2num (amount));
122 scm_gc_protect_object (new_pap);
124 return unsmob_output_def (new_pap);
127 LY_DEFINE (ly_bookpaper_fonts, "ly:bookpaper-fonts",
130 "Return fonts scaled up BP")
132 Output_def *b = unsmob_output_def (bp);
134 SCM font_table = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
136 SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper");
139 if (scm_hash_table_p (font_table) == SCM_BOOL_T)
141 SCM func = ly_scheme_function ("hash-table->alist");
143 for (SCM s = scm_call_1 (func, font_table); ly_c_pair_p (s);
146 SCM entry = ly_car (s);
147 for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t))
149 Font_metric *fm = unsmob_metrics (ly_cdar (t));
151 if (dynamic_cast<Modified_font_metric*> (fm))
152 ell = scm_cons (fm->self_scm (), ell);