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 "modified-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 val = Modified_font_metric::make_scaled_font_metric (input_enc_name,
85 sizes = scm_acons (scm_make_real (lookup_mag), val, sizes);
86 scm_gc_unprotect_object (val);
87 scm_hashq_set_x (font_table, f->self_scm (), sizes);
88 return unsmob_metrics (val);
91 /* TODO: this is a nasty interface. During formatting,
92 the Output_def should be scaled to the output_scale_
93 specified in the toplevel Output_def. */
95 scale_output_def (Output_def *o, Real amount)
97 SCM proc = ly_scheme_function ("scale-paper");
98 SCM new_pap = scm_call_2 (proc, o->self_scm (), scm_double2num (amount));
99 scm_gc_protect_object (new_pap);
101 return unsmob_output_def (new_pap);
104 LY_DEFINE (ly_bookpaper_fonts, "ly:bookpaper-fonts",
107 "Return fonts scaled up BP")
109 Output_def *b = unsmob_output_def (bp);
111 SCM font_table = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
113 SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper");
116 if (scm_hash_table_p (font_table) == SCM_BOOL_T)
118 SCM func = ly_scheme_function ("hash-table->alist");
120 for (SCM s = scm_call_1 (func, font_table); ly_c_pair_p (s);
123 SCM entry = ly_car (s);
124 for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t = ly_cdr (t))
126 Font_metric *fm = unsmob_metrics (ly_cdar (t));
128 if (dynamic_cast<Modified_font_metric*> (fm))
129 ell = scm_cons (fm->self_scm (), ell);