2 pango-select.cc -- implement lily font selection for Pango_fonts.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "dimensions.hh"
10 #include "all-font-metrics.hh"
11 #include "output-def.hh"
12 #include "pango-font.hh"
14 PangoFontDescription *
15 properties_to_pango_description (SCM chain, Real text_size)
17 SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F);
19 PangoFontDescription *description = 0;
20 if (scm_is_string (name))
22 string name_str = ly_scm2string (name);
23 description = pango_font_description_from_string (name_str.c_str ());
27 SCM family = ly_chain_assoc_get (ly_symbol2scm ("font-family"), chain,
29 SCM variant = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
32 SCM style = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
34 SCM weight = ly_chain_assoc_get (ly_symbol2scm ("font-series"), chain,
38 = symbols_to_pango_font_description (family, style, variant, weight,
42 Real step = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F),
44 Real size = text_size * pow (2.0, step / 6.0);
46 pango_font_description_set_size (description, gint (size * PANGO_SCALE));
51 select_pango_font (Output_def *layout, SCM chain)
53 PangoFontDescription *pfd
54 = properties_to_pango_description (chain,
56 * layout->get_dimension (ly_symbol2scm ("text-font-size")));
58 char *str = pango_font_description_to_string (pfd);
59 SCM scm_str = scm_makfrom0str (str);
62 return find_pango_font (layout, scm_str, 1.0);
66 symbol_to_pango_style (SCM style)
68 PangoStyle pstyle = PANGO_STYLE_NORMAL;
69 if (style == ly_symbol2scm ("italic"))
70 pstyle = PANGO_STYLE_ITALIC;
71 else if (style == ly_symbol2scm ("oblique")
72 || style == ly_symbol2scm ("slanted"))
73 pstyle = PANGO_STYLE_OBLIQUE;
79 symbol_to_pango_variant (SCM variant)
81 PangoVariant pvariant = PANGO_VARIANT_NORMAL;
82 if (variant == ly_symbol2scm ("caps"))
83 pvariant = PANGO_VARIANT_SMALL_CAPS;
88 symbol_to_pango_weight (SCM weight)
90 PangoWeight pw = PANGO_WEIGHT_NORMAL;
91 if (weight == ly_symbol2scm ("bold"))
92 pw = PANGO_WEIGHT_BOLD;
93 if (weight == ly_symbol2scm ("heavy"))
94 pw = PANGO_WEIGHT_HEAVY;
95 if (weight == ly_symbol2scm ("ultrabold"))
96 pw = PANGO_WEIGHT_ULTRABOLD;
97 if (weight == ly_symbol2scm ("light"))
98 pw = PANGO_WEIGHT_LIGHT;
99 if (weight == ly_symbol2scm ("ultralight"))
100 pw = PANGO_WEIGHT_ULTRALIGHT;
106 symbol_to_pango_stretch (SCM) // stretch)
108 PangoStretch ps = PANGO_STRETCH_NORMAL;
113 PANGO_STRETCH_ULTRA_CONDENSED,
114 PANGO_STRETCH_EXTRA_CONDENSED,
115 PANGO_STRETCH_CONDENSED,
116 PANGO_STRETCH_SEMI_CONDENSED,
118 PANGO_STRETCH_SEMI_EXPANDED,
119 PANGO_STRETCH_EXPANDED,
120 PANGO_STRETCH_EXTRA_EXPANDED,
121 PANGO_STRETCH_ULTRA_EXPANDED
126 PangoFontDescription *
127 symbols_to_pango_font_description (SCM family,
133 PangoFontDescription *description = pango_font_description_new ();
135 string family_str = "roman";
136 if (scm_is_symbol (family))
137 family_str = ly_symbol2string (family);
138 else if (scm_is_string (family))
139 family_str = ly_scm2string (family);
141 pango_font_description_set_family (description,
142 family_str.c_str ());
143 pango_font_description_set_style (description,
144 symbol_to_pango_style (style));
145 pango_font_description_set_variant (description,
146 symbol_to_pango_variant (variant));
147 pango_font_description_set_weight (description,
148 symbol_to_pango_weight (weight));
149 pango_font_description_set_stretch (description,
150 symbol_to_pango_stretch (stretch));