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>
9 #include "dimensions.hh"
10 #include "font-metric.hh"
11 #include "ly-module.hh"
12 #include "output-def.hh"
13 #include "scaled-font-metric.hh"
14 #include "virtual-font-metric.hh"
17 output_scale (Output_def *od)
19 return ly_scm2double (od->lookup_variable (ly_symbol2scm ("outputscale")));
22 /* TODO: should add nesting for Output_def here too. */
24 find_scaled_font (Output_def *mod,
25 Font_metric *f, Real m, SCM input_enc_name)
28 return find_scaled_font (mod->parent_, f, m, input_enc_name);
31 if (!dynamic_cast<Virtual_font_metric*> (f))
32 lookup_mag /= output_scale (mod);
34 SCM font_table = mod->lookup_variable (ly_symbol2scm ("scaled-fonts"));
35 if (scm_hash_table_p (font_table) != SCM_BOOL_T)
37 font_table = scm_c_make_hash_table (11);
38 mod->set_variable (ly_symbol2scm ("scaled-fonts"), font_table);
42 SCM sizes = scm_hashq_ref (font_table, f->self_scm (), SCM_BOOL_F);
43 if (sizes != SCM_BOOL_F)
45 SCM met = scm_assoc (scm_make_real (lookup_mag), sizes);
46 if (ly_c_pair_p (met))
47 return unsmob_metrics (ly_cdr (met));
52 /* Hmm. We're chaining font - metrics. Should consider whether to
53 merge virtual-font and scaled_font. */
55 if (Virtual_font_metric * vf = dynamic_cast<Virtual_font_metric*> (f))
57 /* For fontify_atom (), the magnification and name must be known
58 at the same time. That's impossible for
60 Scaled (Virtual_font (Font1,Font2))
64 Virtual_font (Scaled (Font1), Scaled (Font2)) */
67 for (SCM s = vf->get_font_list (); ly_c_pair_p (s); s = ly_cdr (s))
69 Font_metric *scaled = find_scaled_font (mod,
70 unsmob_metrics (ly_car (s)),
72 *t = scm_cons (scaled->self_scm (), SCM_EOL);
76 vf = new Virtual_font_metric (lst);
77 val = vf->self_scm ();
81 if (!ly_c_symbol_p (input_enc_name))
83 SCM var = ly_module_lookup (mod->scope_,
84 ly_symbol2scm ("inputencoding"));
85 if (var != SCM_BOOL_F)
86 input_enc_name = scm_variable_ref (var);
87 if (!ly_c_symbol_p (input_enc_name))
88 input_enc_name = ly_symbol2scm ("latin1");
91 val = Modified_font_metric::make_scaled_font_metric (input_enc_name,
95 sizes = scm_acons (scm_make_real (lookup_mag), val, sizes);
96 scm_gc_unprotect_object (val);
97 scm_hashq_set_x (font_table, f->self_scm (), sizes);
98 return unsmob_metrics (val);
101 /* TODO: this is a nasty interface. During formatting,
102 the Output_def should be scaled to the output_scale_
103 specified in the toplevel Output_def. */
105 scale_output_def (Output_def *o, Real amount)
107 SCM proc = ly_scheme_function ("scale-paper");
108 SCM new_pap = scm_call_2 (proc, o->self_scm (), scm_double2num (amount));
109 scm_gc_protect_object (new_pap);
111 return unsmob_output_def (new_pap);
114 LY_DEFINE (ly_bookpaper_fonts, "ly:bookpaper-fonts",
117 "Return fonts scaled up BP")
119 Output_def *b = unsmob_output_def (bp);
121 SCM font_table = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
123 SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper");
126 if (scm_hash_table_p (font_table) == SCM_BOOL_T)
128 SCM func = ly_scheme_function ("hash-table->alist");
130 for (SCM s = scm_call_1 (func, font_table); ly_c_pair_p (s);
133 SCM entry = ly_car (s);
134 for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t))
136 Font_metric *fm = unsmob_metrics (ly_cdar (t));
138 if (dynamic_cast<Modified_font_metric*> (fm))
139 ell = scm_cons (fm->self_scm (), ell);