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"
16 PangoFontDescription *
17 properties_to_pango_description (SCM chain, Real text_size)
19 SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F);
21 PangoFontDescription *description = 0;
22 if (scm_is_string (name))
24 String name_str = ly_scm2string (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_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F),
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
57 = properties_to_pango_description (chain,
59 * layout->get_dimension (ly_symbol2scm ("text-font-size")));
61 char *str = pango_font_description_to_string (pfd);
62 SCM scm_str = scm_makfrom0str (str);
65 return find_pango_font (layout, scm_str, 1.0);
69 symbol_to_pango_style (SCM style)
71 PangoStyle pstyle = PANGO_STYLE_NORMAL;
72 if (style == ly_symbol2scm ("italic"))
73 pstyle = PANGO_STYLE_ITALIC;
74 else if (style == ly_symbol2scm ("oblique")
75 || style == ly_symbol2scm ("slanted"))
76 pstyle = PANGO_STYLE_OBLIQUE;
82 symbol_to_pango_variant (SCM variant)
84 PangoVariant pvariant = PANGO_VARIANT_NORMAL;
85 if (variant == ly_symbol2scm ("caps"))
86 pvariant = PANGO_VARIANT_SMALL_CAPS;
91 symbol_to_pango_weight (SCM weight)
93 PangoWeight pw = PANGO_WEIGHT_NORMAL;
94 if (weight == ly_symbol2scm ("bold"))
95 pw = PANGO_WEIGHT_BOLD;
96 if (weight == ly_symbol2scm ("heavy"))
97 pw = PANGO_WEIGHT_HEAVY;
98 if (weight == ly_symbol2scm ("ultrabold"))
99 pw = PANGO_WEIGHT_ULTRABOLD;
100 if (weight == ly_symbol2scm ("light"))
101 pw = PANGO_WEIGHT_LIGHT;
102 if (weight == ly_symbol2scm ("ultralight"))
103 pw = PANGO_WEIGHT_ULTRALIGHT;
109 symbol_to_pango_stretch (SCM) // stretch)
111 PangoStretch ps = PANGO_STRETCH_NORMAL;
116 PANGO_STRETCH_ULTRA_CONDENSED,
117 PANGO_STRETCH_EXTRA_CONDENSED,
118 PANGO_STRETCH_CONDENSED,
119 PANGO_STRETCH_SEMI_CONDENSED,
121 PANGO_STRETCH_SEMI_EXPANDED,
122 PANGO_STRETCH_EXPANDED,
123 PANGO_STRETCH_EXTRA_EXPANDED,
124 PANGO_STRETCH_ULTRA_EXPANDED
129 PangoFontDescription *
130 symbols_to_pango_font_description (SCM family,
136 PangoFontDescription *description = pango_font_description_new ();
138 String family_str = "roman";
139 if (scm_is_symbol (family))
140 family_str = ly_symbol2string (family);
141 else if (scm_is_string (family))
142 family_str = ly_scm2string (family);
144 pango_font_description_set_family (description,
145 family_str.to_str0 ());
146 pango_font_description_set_style (description,
147 symbol_to_pango_style (style));
148 pango_font_description_set_variant (description,
149 symbol_to_pango_variant (variant));
150 pango_font_description_set_weight (description,
151 symbol_to_pango_weight (weight));
152 pango_font_description_set_stretch (description,
153 symbol_to_pango_stretch (stretch));