2 pango-select.cc -- implement lily font selection for Pango_fonts.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 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 PangoFontDescription *
18 properties_to_pango_description (SCM chain, Real text_size)
20 SCM name = ly_chain_assoc (ly_symbol2scm ("font-name"), chain);
22 PangoFontDescription *description = 0;
23 if (scm_is_pair (name) && scm_is_string (scm_cdr (name)))
25 String name_str = ly_scm2string (scm_cdr (name));
26 description = pango_font_description_from_string (name_str.to_str0 ());
30 SCM family = ly_chain_assoc_get (ly_symbol2scm ("font-family"), chain,
32 SCM variant = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
35 SCM style = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
37 SCM weight = ly_chain_assoc_get (ly_symbol2scm ("font-series"), chain,
41 = symbols_to_pango_font_description (family, style, variant, weight,
45 Real step = robust_scm2double (ly_symbol2scm ("font-size"), 0.0);
46 Real size = text_size * pow (2.0, step / 6.0);
48 pango_font_description_set_size (description,
49 gint (size * PANGO_SCALE));
54 select_pango_font (Output_def *layout, SCM chain)
56 PangoFontDescription *pfd = properties_to_pango_description (chain,
57 point_constant * layout->get_dimension (ly_symbol2scm ("text-font-size")));
59 return all_fonts_global->find_pango_font (pfd, 1.0, output_scale (layout));
63 symbol_to_pango_style (SCM style)
65 PangoStyle pstyle = PANGO_STYLE_NORMAL;
66 if (style == ly_symbol2scm ("italic"))
68 pstyle = PANGO_STYLE_ITALIC;
70 else if (style == ly_symbol2scm ("oblique")
71 || style == ly_symbol2scm ("slanted")
74 pstyle = PANGO_STYLE_OBLIQUE;
81 symbol_to_pango_variant (SCM variant)
83 PangoVariant pvariant = PANGO_VARIANT_NORMAL;
84 if (variant == ly_symbol2scm ("caps"))
86 pvariant = PANGO_VARIANT_SMALL_CAPS;
93 symbol_to_pango_weight (SCM weight)
95 PangoWeight pw = PANGO_WEIGHT_NORMAL;
96 if (weight == ly_symbol2scm ("bold"))
98 pw = PANGO_WEIGHT_BOLD;
100 if (weight == ly_symbol2scm ("heavy"))
102 pw = PANGO_WEIGHT_HEAVY;
104 if (weight == ly_symbol2scm ("ultrabold"))
106 pw = PANGO_WEIGHT_ULTRABOLD;
108 if (weight == ly_symbol2scm ("light"))
110 pw = PANGO_WEIGHT_LIGHT;
112 if (weight == ly_symbol2scm ("ultralight"))
114 pw = PANGO_WEIGHT_ULTRALIGHT;
121 symbol_to_pango_stretch (SCM) // stretch)
123 PangoStretch ps = PANGO_STRETCH_NORMAL;
128 PANGO_STRETCH_ULTRA_CONDENSED,
129 PANGO_STRETCH_EXTRA_CONDENSED,
130 PANGO_STRETCH_CONDENSED,
131 PANGO_STRETCH_SEMI_CONDENSED,
133 PANGO_STRETCH_SEMI_EXPANDED,
134 PANGO_STRETCH_EXPANDED,
135 PANGO_STRETCH_EXTRA_EXPANDED,
136 PANGO_STRETCH_ULTRA_EXPANDED
143 PangoFontDescription*
144 symbols_to_pango_font_description(SCM family,
150 PangoFontDescription * description = pango_font_description_new ();
152 String family_str = "roman";
153 if (scm_is_symbol (family))
154 family_str = ly_symbol2string (family);
155 else if (scm_is_string (family))
156 family_str = ly_scm2string (family);
158 pango_font_description_set_family (description,
159 family_str.to_str0 ());
160 pango_font_description_set_style (description,
161 symbol_to_pango_style (style));
162 pango_font_description_set_variant (description,
163 symbol_to_pango_variant (variant));
164 pango_font_description_set_weight (description,
165 symbol_to_pango_weight (weight));
166 pango_font_description_set_stretch (description,
167 symbol_to_pango_stretch (stretch));