]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-def.cc
* mf/GNUmakefile: remove SAUTER_FONTS.
[lilypond.git] / lily / paper-def.cc
1 /* 
2   paper-def.cc -- implement Paper_def
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "dimensions.hh"
10 #include "ly-module.hh"
11 #include "output-def.hh"
12 #include "modified-font-metric.hh"
13
14 Real
15 output_scale (Output_def *od)
16 {
17   return scm_to_double (od->lookup_variable (ly_symbol2scm ("outputscale")));
18 }
19
20 /* TODO: should add nesting for Output_def here too. */
21 Font_metric *
22 find_scaled_font (Output_def *mod, Font_metric *f, Real m,
23                   SCM font_encoding, SCM input_encoding)
24 {
25   if (mod->parent_)
26     return find_scaled_font (mod->parent_, f, m, font_encoding, input_encoding);
27   
28   Real lookup_mag = m / output_scale (mod);
29
30
31   SCM font_table = mod->lookup_variable (ly_symbol2scm ("scaled-fonts"));
32   if (scm_hash_table_p (font_table) != SCM_BOOL_T)
33     {
34       font_table = scm_c_make_hash_table (11);
35       mod->set_variable (ly_symbol2scm ("scaled-fonts"), font_table);
36     }
37   
38   SCM sizes = scm_hashq_ref (font_table, f->self_scm (), SCM_BOOL_F);
39   if (sizes != SCM_BOOL_F)
40     {
41       SCM met = scm_assoc (scm_make_real (lookup_mag), sizes);
42       if (scm_is_pair (met))
43         return unsmob_metrics (scm_cdr (met));
44     }
45   else
46     sizes = SCM_EOL;
47   
48   SCM val = Modified_font_metric::make_scaled_font_metric (f, lookup_mag,
49                                                            font_encoding,
50                                                            input_encoding);
51
52   sizes = scm_acons (scm_make_real (lookup_mag), val, sizes);
53   scm_gc_unprotect_object (val);
54   scm_hashq_set_x (font_table, f->self_scm (), sizes);
55   return unsmob_metrics (val);
56 }
57
58 /* TODO: this is a nasty interface. During formatting,
59    the Output_def should be scaled to the output_scale_
60    specified in the toplevel Output_def.  */
61 Output_def * 
62 scale_output_def (Output_def *o, Real amount)
63 {
64   SCM proc = ly_scheme_function ("scale-layout");
65   SCM new_pap = scm_call_2 (proc, o->self_scm (), scm_double2num (amount));
66   scm_gc_protect_object (new_pap);
67
68   return unsmob_output_def (new_pap);
69 }
70
71 LY_DEFINE (ly_paper_fonts, "ly:paper-fonts",
72            1, 0, 0,
73            (SCM bp),
74            "Return fonts scaled up BP")
75 {
76   Output_def *b = unsmob_output_def (bp);
77
78   SCM font_table = b->lookup_variable (ly_symbol2scm ("scaled-fonts"));
79   
80   SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "paper");
81
82   SCM ell = SCM_EOL;
83   if (scm_hash_table_p (font_table) == SCM_BOOL_T)
84     {
85       SCM func = ly_scheme_function ("hash-table->alist");
86
87       for (SCM s = scm_call_1 (func, font_table); scm_is_pair (s);
88            s = scm_cdr (s))
89         {
90           SCM entry = scm_car (s);
91           for (SCM t = scm_cdr (entry); scm_is_pair (t); t = scm_cdr (t))
92             {
93               Font_metric *fm = unsmob_metrics (scm_cdar (t));
94
95               if (dynamic_cast<Modified_font_metric*> (fm))
96                 ell = scm_cons (fm->self_scm (), ell);
97             }
98         }
99     }
100   return ell;
101 }