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,
53 ly_symbol2scm ("latin1"),
54 ly_symbol2scm ("latin1"));
59 symbol_to_pango_style (SCM style)
61 PangoStyle pstyle = PANGO_STYLE_NORMAL;
62 if (style == ly_symbol2scm ("italic"))
64 pstyle = PANGO_STYLE_NORMAL;
66 else if (style == ly_symbol2scm ("oblique")
67 || style == ly_symbol2scm ("slanted")
70 pstyle = PANGO_STYLE_OBLIQUE;
77 symbol_to_pango_variant (SCM variant)
79 PangoVariant pvariant;
80 if (variant == ly_symbol2scm ("caps"))
82 pvariant = PANGO_VARIANT_SMALL_CAPS;
89 symbol_to_pango_weight (SCM weight)
91 PangoWeight pw = PANGO_WEIGHT_NORMAL;
92 if (weight == ly_symbol2scm ("bold"))
94 pw = PANGO_WEIGHT_BOLD;
96 if (weight == ly_symbol2scm ("heavy"))
98 pw = PANGO_WEIGHT_HEAVY;
100 if (weight == ly_symbol2scm ("ultrabold"))
102 pw = PANGO_WEIGHT_ULTRABOLD;
104 if (weight == ly_symbol2scm ("light"))
106 pw = PANGO_WEIGHT_LIGHT;
108 if (weight == ly_symbol2scm ("ultralight"))
110 pw = PANGO_WEIGHT_ULTRALIGHT;
117 symbol_to_pango_stretch (SCM) // stretch)
119 PangoStretch ps = PANGO_STRETCH_NORMAL;
124 PANGO_STRETCH_ULTRA_CONDENSED,
125 PANGO_STRETCH_EXTRA_CONDENSED,
126 PANGO_STRETCH_CONDENSED,
127 PANGO_STRETCH_SEMI_CONDENSED,
129 PANGO_STRETCH_SEMI_EXPANDED,
130 PANGO_STRETCH_EXPANDED,
131 PANGO_STRETCH_EXTRA_EXPANDED,
132 PANGO_STRETCH_ULTRA_EXPANDED
139 PangoFontDescription*
140 symbols_to_pango_font_description(SCM family,
146 PangoFontDescription * description = pango_font_description_new ();
148 String family_str = scm_is_symbol (family)
149 ? ly_symbol2string (family)
151 pango_font_description_set_family (description,
152 family_str.to_str0 ());
153 pango_font_description_set_style (description,
154 symbol_to_pango_style (style));
155 pango_font_description_set_variant (description,
156 symbol_to_pango_variant (variant));
157 pango_font_description_set_weight (description,
158 symbol_to_pango_weight (weight));
159 pango_font_description_set_stretch (description,
160 symbol_to_pango_stretch (stretch));