2 pango-select.cc -- implement lily font selection for Pango_fonts.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "all-font-metrics.hh"
12 #include "output-def.hh"
13 #include "pango-font.hh"
16 select_pango_font (Output_def *layout, SCM chain)
18 SCM name = ly_chain_assoc (ly_symbol2scm ("font-name"), chain);
20 PangoFontDescription *description = 0;
21 if (scm_is_pair (name) && scm_is_string (scm_cdr (name)))
23 String name_str = ly_scm2string (scm_cdr (name));
24 description = pango_font_description_from_string (name_str.to_str0 ());
28 SCM family = ly_chain_assoc_get (ly_symbol2scm ("font-family"), chain,
30 SCM variant = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
33 SCM style = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
35 SCM weight = ly_chain_assoc_get (ly_symbol2scm ("font-series"), chain,
38 Real step = robust_scm2double (ly_symbol2scm ("font-size"), 0.0);
39 Real size = layout->get_dimension (ly_symbol2scm ("text-font-size"))
40 * pow (2.0, step / 6.0);
43 = symbols_to_pango_font_description (family, style, variant, weight,
48 Font_metric * fm = all_fonts_global->find_pango_font (description);
51 Klutz the pango font into font table, otherwise it doesn't show up
54 SCM font_table = get_font_table (layout);
55 SCM sizes = scm_hashq_ref (font_table, fm->self_scm (), SCM_BOOL_F);
56 if (sizes != SCM_BOOL_F)
58 SCM met = scm_assoc (scm_make_real (1.0), sizes);
59 if (scm_is_pair (met))
60 return unsmob_metrics (scm_cdr (met));
65 sizes = scm_acons (scm_make_real (1.0), fm->self_scm(), sizes);
66 scm_hashq_set_x (font_table, fm->self_scm (), sizes);
73 symbol_to_pango_style (SCM style)
75 PangoStyle pstyle = PANGO_STYLE_NORMAL;
76 if (style == ly_symbol2scm ("italic"))
78 pstyle = PANGO_STYLE_NORMAL;
80 else if (style == ly_symbol2scm ("oblique")
81 || style == ly_symbol2scm ("slanted")
84 pstyle = PANGO_STYLE_OBLIQUE;
91 symbol_to_pango_variant (SCM variant)
93 PangoVariant pvariant;
94 if (variant == ly_symbol2scm ("caps"))
96 pvariant = PANGO_VARIANT_SMALL_CAPS;
103 symbol_to_pango_weight (SCM weight)
105 PangoWeight pw = PANGO_WEIGHT_NORMAL;
106 if (weight == ly_symbol2scm ("bold"))
108 pw = PANGO_WEIGHT_BOLD;
110 if (weight == ly_symbol2scm ("heavy"))
112 pw = PANGO_WEIGHT_HEAVY;
114 if (weight == ly_symbol2scm ("ultrabold"))
116 pw = PANGO_WEIGHT_ULTRABOLD;
118 if (weight == ly_symbol2scm ("light"))
120 pw = PANGO_WEIGHT_LIGHT;
122 if (weight == ly_symbol2scm ("ultralight"))
124 pw = PANGO_WEIGHT_ULTRALIGHT;
131 symbol_to_pango_stretch (SCM) // stretch)
133 PangoStretch ps = PANGO_STRETCH_NORMAL;
138 PANGO_STRETCH_ULTRA_CONDENSED,
139 PANGO_STRETCH_EXTRA_CONDENSED,
140 PANGO_STRETCH_CONDENSED,
141 PANGO_STRETCH_SEMI_CONDENSED,
143 PANGO_STRETCH_SEMI_EXPANDED,
144 PANGO_STRETCH_EXPANDED,
145 PANGO_STRETCH_EXTRA_EXPANDED,
146 PANGO_STRETCH_ULTRA_EXPANDED
153 PangoFontDescription*
154 symbols_to_pango_font_description(SCM family,
161 PangoFontDescription * description = pango_font_description_new ();
163 String family_str = scm_is_symbol (family)
164 ? ly_symbol2string (family)
166 pango_font_description_set_family (description,
167 family_str.to_str0 ());
168 pango_font_description_set_style (description,
169 symbol_to_pango_style (style));
170 pango_font_description_set_variant (description,
171 symbol_to_pango_variant (variant));
172 pango_font_description_set_weight (description,
173 symbol_to_pango_weight (weight));
174 pango_font_description_set_stretch (description,
175 symbol_to_pango_stretch (stretch));
176 pango_font_description_set_size (description,
177 gint (size * PANGO_SCALE));