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>
10 #include "dimensions.hh"
11 #include "all-font-metrics.hh"
12 #include "output-def.hh"
13 #include "pango-font.hh"
15 PangoFontDescription *
16 properties_to_pango_description (SCM chain, Real text_size)
18 SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F);
20 PangoFontDescription *description = 0;
21 if (scm_is_string (name))
23 String name_str = ly_scm2string (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,
39 = symbols_to_pango_font_description (family, style, variant, weight,
43 Real step = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F),
45 Real size = text_size * pow (2.0, step / 6.0);
47 pango_font_description_set_size (description,
48 gint (size * PANGO_SCALE));
53 select_pango_font (Output_def *layout, SCM chain)
55 PangoFontDescription *pfd
56 = properties_to_pango_description (chain,
58 * layout->get_dimension (ly_symbol2scm ("text-font-size")));
60 char *str = pango_font_description_to_string (pfd);
61 SCM scm_str = scm_makfrom0str (str);
64 return find_pango_font (layout, scm_str, 1.0);
68 symbol_to_pango_style (SCM style)
70 PangoStyle pstyle = PANGO_STYLE_NORMAL;
71 if (style == ly_symbol2scm ("italic"))
73 pstyle = PANGO_STYLE_ITALIC;
75 else if (style == ly_symbol2scm ("oblique")
76 || style == ly_symbol2scm ("slanted"))
78 pstyle = PANGO_STYLE_OBLIQUE;
85 symbol_to_pango_variant (SCM variant)
87 PangoVariant pvariant = PANGO_VARIANT_NORMAL;
88 if (variant == ly_symbol2scm ("caps"))
90 pvariant = PANGO_VARIANT_SMALL_CAPS;
96 symbol_to_pango_weight (SCM weight)
98 PangoWeight pw = PANGO_WEIGHT_NORMAL;
99 if (weight == ly_symbol2scm ("bold"))
101 pw = PANGO_WEIGHT_BOLD;
103 if (weight == ly_symbol2scm ("heavy"))
105 pw = PANGO_WEIGHT_HEAVY;
107 if (weight == ly_symbol2scm ("ultrabold"))
109 pw = PANGO_WEIGHT_ULTRABOLD;
111 if (weight == ly_symbol2scm ("light"))
113 pw = PANGO_WEIGHT_LIGHT;
115 if (weight == ly_symbol2scm ("ultralight"))
117 pw = PANGO_WEIGHT_ULTRALIGHT;
124 symbol_to_pango_stretch (SCM) // stretch)
126 PangoStretch ps = PANGO_STRETCH_NORMAL;
131 PANGO_STRETCH_ULTRA_CONDENSED,
132 PANGO_STRETCH_EXTRA_CONDENSED,
133 PANGO_STRETCH_CONDENSED,
134 PANGO_STRETCH_SEMI_CONDENSED,
136 PANGO_STRETCH_SEMI_EXPANDED,
137 PANGO_STRETCH_EXPANDED,
138 PANGO_STRETCH_EXTRA_EXPANDED,
139 PANGO_STRETCH_ULTRA_EXPANDED
144 PangoFontDescription *
145 symbols_to_pango_font_description (SCM family,
151 PangoFontDescription *description = pango_font_description_new ();
153 String family_str = "roman";
154 if (scm_is_symbol (family))
155 family_str = ly_symbol2string (family);
156 else if (scm_is_string (family))
157 family_str = ly_scm2string (family);
159 pango_font_description_set_family (description,
160 family_str.to_str0 ());
161 pango_font_description_set_style (description,
162 symbol_to_pango_style (style));
163 pango_font_description_set_variant (description,
164 symbol_to_pango_variant (variant));
165 pango_font_description_set_weight (description,
166 symbol_to_pango_weight (weight));
167 pango_font_description_set_stretch (description,
168 symbol_to_pango_stretch (stretch));