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 ());
27 Real step = robust_scm2double (ly_symbol2scm ("font-size"), 0.0);
28 Real size = layout->get_dimension (ly_symbol2scm ("text-font-size"))
29 * pow (2.0, step / 6.0);
30 pango_font_description_set_size (description,
31 gint (size * PANGO_SCALE));
35 SCM family = ly_chain_assoc_get (ly_symbol2scm ("font-family"), chain,
37 SCM variant = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
40 SCM style = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
42 SCM weight = ly_chain_assoc_get (ly_symbol2scm ("font-series"), chain,
45 Real step = robust_scm2double (ly_symbol2scm ("font-size"), 0.0);
46 Real size = layout->get_dimension (ly_symbol2scm ("text-font-size"))
47 * pow (2.0, step / 6.0);
50 = symbols_to_pango_font_description (family, style, variant, weight,
55 Font_metric * fm = all_fonts_global->find_pango_font (description);
57 return find_scaled_font (layout, fm, 1.0,
58 ly_symbol2scm ("latin1"),
59 ly_symbol2scm ("latin1"));
64 symbol_to_pango_style (SCM style)
66 PangoStyle pstyle = PANGO_STYLE_NORMAL;
67 if (style == ly_symbol2scm ("italic"))
69 pstyle = PANGO_STYLE_NORMAL;
71 else if (style == ly_symbol2scm ("oblique")
72 || style == ly_symbol2scm ("slanted")
75 pstyle = PANGO_STYLE_OBLIQUE;
82 symbol_to_pango_variant (SCM variant)
84 PangoVariant pvariant;
85 if (variant == ly_symbol2scm ("caps"))
87 pvariant = PANGO_VARIANT_SMALL_CAPS;
94 symbol_to_pango_weight (SCM weight)
96 PangoWeight pw = PANGO_WEIGHT_NORMAL;
97 if (weight == ly_symbol2scm ("bold"))
99 pw = PANGO_WEIGHT_BOLD;
101 if (weight == ly_symbol2scm ("heavy"))
103 pw = PANGO_WEIGHT_HEAVY;
105 if (weight == ly_symbol2scm ("ultrabold"))
107 pw = PANGO_WEIGHT_ULTRABOLD;
109 if (weight == ly_symbol2scm ("light"))
111 pw = PANGO_WEIGHT_LIGHT;
113 if (weight == ly_symbol2scm ("ultralight"))
115 pw = PANGO_WEIGHT_ULTRALIGHT;
122 symbol_to_pango_stretch (SCM) // stretch)
124 PangoStretch ps = PANGO_STRETCH_NORMAL;
129 PANGO_STRETCH_ULTRA_CONDENSED,
130 PANGO_STRETCH_EXTRA_CONDENSED,
131 PANGO_STRETCH_CONDENSED,
132 PANGO_STRETCH_SEMI_CONDENSED,
134 PANGO_STRETCH_SEMI_EXPANDED,
135 PANGO_STRETCH_EXPANDED,
136 PANGO_STRETCH_EXTRA_EXPANDED,
137 PANGO_STRETCH_ULTRA_EXPANDED
144 PangoFontDescription*
145 symbols_to_pango_font_description(SCM family,
152 PangoFontDescription * description = pango_font_description_new ();
154 String family_str = scm_is_symbol (family)
155 ? ly_symbol2string (family)
157 pango_font_description_set_family (description,
158 family_str.to_str0 ());
159 pango_font_description_set_style (description,
160 symbol_to_pango_style (style));
161 pango_font_description_set_variant (description,
162 symbol_to_pango_variant (variant));
163 pango_font_description_set_weight (description,
164 symbol_to_pango_weight (weight));
165 pango_font_description_set_stretch (description,
166 symbol_to_pango_stretch (stretch));
167 pango_font_description_set_size (description,
168 gint (size * PANGO_SCALE));