2 paper-def.cc -- implement Paper_def
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "dimensions.hh"
10 #include "output-def.hh"
11 #include "modified-font-metric.hh"
12 #include "pango-font.hh"
13 #include "all-font-metrics.hh"
16 output_scale (Output_def
*od
)
18 return scm_to_double (od
->lookup_variable (ly_symbol2scm ("outputscale")));
22 get_font_table (Output_def
*def
)
24 SCM font_table
= def
->lookup_variable (ly_symbol2scm ("scaled-fonts"));
25 if (scm_hash_table_p (font_table
) != SCM_BOOL_T
)
27 font_table
= scm_c_make_hash_table (11);
28 def
->set_variable (ly_symbol2scm ("scaled-fonts"), font_table
);
34 get_pango_font_table (Output_def
*def
)
36 SCM font_table
= def
->lookup_variable (ly_symbol2scm ("pango-fonts"));
37 if (scm_hash_table_p (font_table
) != SCM_BOOL_T
)
39 font_table
= scm_c_make_hash_table (11);
40 def
->set_variable (ly_symbol2scm ("pango-fonts"), font_table
);
45 /* TODO: should add nesting for Output_def here too. */
47 find_scaled_font (Output_def
*mod
, Font_metric
*f
, Real m
)
50 return find_scaled_font (mod
->parent_
, f
, m
);
52 Real lookup_mag
= m
/ output_scale (mod
);
54 SCM font_table
= get_font_table (mod
);
55 SCM sizes
= scm_hashq_ref (font_table
, f
->self_scm (), SCM_EOL
);
56 SCM handle
= scm_assoc (scm_make_real (lookup_mag
), sizes
);
57 if (scm_is_pair (handle
))
58 return unsmob_metrics (scm_cdr (handle
));
60 SCM val
= Modified_font_metric::make_scaled_font_metric (f
, lookup_mag
);
62 sizes
= scm_acons (scm_make_real (lookup_mag
), val
, sizes
);
63 scm_gc_unprotect_object (val
);
64 scm_hashq_set_x (font_table
, f
->self_scm (), sizes
);
65 return unsmob_metrics (val
);
69 find_pango_font (Output_def
*layout
, SCM descr
, Real factor
)
72 return find_pango_font (layout
->parent_
, descr
, factor
);
74 SCM table
= get_pango_font_table (layout
);
75 SCM sizes
= scm_hash_ref (table
, descr
, SCM_EOL
);
76 SCM size_key
= scm_from_double (factor
);
77 SCM handle
= scm_assoc (size_key
, sizes
);
78 if (scm_is_pair (handle
))
80 return unsmob_metrics (scm_cdr (handle
));
83 PangoFontDescription
*description
84 = pango_font_description_from_string (scm_i_string_chars (descr
));
85 Font_metric
*fm
= all_fonts_global
->find_pango_font (description
,
87 output_scale (layout
));
89 sizes
= scm_acons (size_key
, fm
->self_scm (), sizes
);
90 scm_hash_set_x (table
, descr
, sizes
);
95 /* TODO: this is a nasty interface. During formatting,
96 the Output_def should be scaled to the output_scale_
97 specified in the toplevel Output_def. */
99 scale_output_def (Output_def
*o
, Real amount
)
101 SCM proc
= ly_lily_module_constant ("scale-layout");
102 SCM new_pap
= scm_call_2 (proc
, o
->self_scm (), scm_double2num (amount
));
103 scm_gc_protect_object (new_pap
);
105 return unsmob_output_def (new_pap
);