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 "dimensions.hh"
12 #include "all-font-metrics.hh"
13 #include "output-def.hh"
14 #include "pango-font.hh"
17 select_pango_font (Output_def *layout, SCM chain)
19 SCM name = ly_chain_assoc (ly_symbol2scm ("font-name"), chain);
21 PangoFontDescription *description = 0;
22 if (scm_is_pair (name) && scm_is_string (scm_cdr (name)))
24 String name_str = ly_scm2string (scm_cdr (name));
25 description = pango_font_description_from_string (name_str.to_str0 ());
29 SCM family = ly_chain_assoc_get (ly_symbol2scm ("font-family"), chain,
31 SCM variant = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
34 SCM style = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
36 SCM weight = ly_chain_assoc_get (ly_symbol2scm ("font-series"), chain,
40 = symbols_to_pango_font_description (family, style, variant, weight,
44 Real step = robust_scm2double (ly_symbol2scm ("font-size"), 0.0);
45 Real size = layout->get_dimension (ly_symbol2scm ("text-font-size"))
46 * pow (2.0, step / 6.0) * point_constant;
47 pango_font_description_set_size (description,
48 gint (size * PANGO_SCALE));
50 Font_metric * fm = all_fonts_global->find_pango_font (description);
52 return find_scaled_font (layout, fm, 1.0);
57 symbol_to_pango_style (SCM style)
59 PangoStyle pstyle = PANGO_STYLE_NORMAL;
60 if (style == ly_symbol2scm ("italic"))
62 pstyle = PANGO_STYLE_NORMAL;
64 else if (style == ly_symbol2scm ("oblique")
65 || style == ly_symbol2scm ("slanted")
68 pstyle = PANGO_STYLE_OBLIQUE;
75 symbol_to_pango_variant (SCM variant)
77 PangoVariant pvariant;
78 if (variant == ly_symbol2scm ("caps"))
80 pvariant = PANGO_VARIANT_SMALL_CAPS;
87 symbol_to_pango_weight (SCM weight)
89 PangoWeight pw = PANGO_WEIGHT_NORMAL;
90 if (weight == ly_symbol2scm ("bold"))
92 pw = PANGO_WEIGHT_BOLD;
94 if (weight == ly_symbol2scm ("heavy"))
96 pw = PANGO_WEIGHT_HEAVY;
98 if (weight == ly_symbol2scm ("ultrabold"))
100 pw = PANGO_WEIGHT_ULTRABOLD;
102 if (weight == ly_symbol2scm ("light"))
104 pw = PANGO_WEIGHT_LIGHT;
106 if (weight == ly_symbol2scm ("ultralight"))
108 pw = PANGO_WEIGHT_ULTRALIGHT;
115 symbol_to_pango_stretch (SCM) // stretch)
117 PangoStretch ps = PANGO_STRETCH_NORMAL;
122 PANGO_STRETCH_ULTRA_CONDENSED,
123 PANGO_STRETCH_EXTRA_CONDENSED,
124 PANGO_STRETCH_CONDENSED,
125 PANGO_STRETCH_SEMI_CONDENSED,
127 PANGO_STRETCH_SEMI_EXPANDED,
128 PANGO_STRETCH_EXPANDED,
129 PANGO_STRETCH_EXTRA_EXPANDED,
130 PANGO_STRETCH_ULTRA_EXPANDED
137 PangoFontDescription*
138 symbols_to_pango_font_description(SCM family,
144 PangoFontDescription * description = pango_font_description_new ();
146 String family_str = scm_is_symbol (family)
147 ? ly_symbol2string (family)
149 pango_font_description_set_family (description,
150 family_str.to_str0 ());
151 pango_font_description_set_style (description,
152 symbol_to_pango_style (style));
153 pango_font_description_set_variant (description,
154 symbol_to_pango_variant (variant));
155 pango_font_description_set_weight (description,
156 symbol_to_pango_weight (weight));
157 pango_font_description_set_stretch (description,
158 symbol_to_pango_stretch (stretch));