2 paper-def.cc -- implement Paper_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 "ly-module.hh"
11 #include "output-def.hh"
12 #include "modified-font-metric.hh"
13 #include "virtual-font-metric.hh"
16 output_scale (Output_def *od)
18 return scm_to_double (od->lookup_variable (ly_symbol2scm ("outputscale")));
21 /* TODO: should add nesting for Output_def here too. */
23 find_scaled_font (Output_def *mod, Font_metric *f, Real m,
24 SCM font_encoding, SCM input_encoding)
27 return find_scaled_font (mod->parent_, f, m, font_encoding, input_encoding);
30 if (!dynamic_cast<Virtual_font_metric*> (f))
31 lookup_mag /= output_scale (mod);
33 SCM font_table = mod->lookup_variable (ly_symbol2scm ("scaled-fonts"));
34 if (scm_hash_table_p (font_table) != SCM_BOOL_T)
36 font_table = scm_c_make_hash_table (11);
37 mod->set_variable (ly_symbol2scm ("scaled-fonts"), font_table);
40 SCM sizes = scm_hashq_ref (font_table, f->self_scm (), SCM_BOOL_F);
41 if (sizes != SCM_BOOL_F)
43 SCM met = scm_assoc (scm_make_real (lookup_mag), sizes);
44 if (scm_is_pair (met))
45 return unsmob_metrics (scm_cdr (met));
50 /* Hmm. We're chaining font - metrics. Should consider whether to
51 merge virtual-font and scaled_font. */
53 if (Virtual_font_metric * vf = dynamic_cast<Virtual_font_metric*> (f))
55 /* For fontify_atom (), the magnification and name must be known
56 at the same time. That's impossible for
58 Scaled (Virtual_font (Font1,Font2))
62 Virtual_font (Scaled (Font1), Scaled (Font2)) */
65 for (SCM s = vf->get_font_list (); scm_is_pair (s); s = scm_cdr (s))
68 = find_scaled_font (mod, unsmob_metrics (scm_car (s)), m,
69 font_encoding, input_encoding);
70 *t = scm_cons (scaled->self_scm (), SCM_EOL);
74 vf = new Virtual_font_metric (lst);
75 val = vf->self_scm ();
78 val = Modified_font_metric::make_scaled_font_metric (f, lookup_mag,
82 sizes = scm_acons (scm_make_real (lookup_mag), val, sizes);
83 scm_gc_unprotect_object (val);
84 scm_hashq_set_x (font_table, f->self_scm (), sizes);
85 return unsmob_metrics (val);
88 /* TODO: this is a nasty interface. During formatting,
89 the Output_def should be scaled to the output_scale_
90 specified in the toplevel Output_def. */
92 scale_output_def (Output_def *o, Real amount)
94 SCM proc = ly_scheme_function ("scale-layout");
95 SCM new_pap = scm_call_2 (proc, o->self_scm (), scm_double2num (amount));
96 scm_gc_protect_object (new_pap);
98 return unsmob_output_def (new_pap);
101 LY_DEFINE (ly_paper_fonts, "ly:paper-fonts",
104 "Return fonts scaled up BP")
106 Output_def *b = unsmob_output_def (bp);
108 SCM font_table = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
110 SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "paper");
113 if (scm_hash_table_p (font_table) == SCM_BOOL_T)
115 SCM func = ly_scheme_function ("hash-table->alist");
117 for (SCM s = scm_call_1 (func, font_table); scm_is_pair (s);
120 SCM entry = scm_car (s);
121 for (SCM t = scm_cdr (entry); scm_is_pair (t); t = scm_cdr (t))
123 Font_metric *fm = unsmob_metrics (scm_cdar (t));
125 if (dynamic_cast<Modified_font_metric*> (fm))
126 ell = scm_cons (fm->self_scm (), ell);