2 pango-select.cc -- implement lily font selection for Pango_fonts.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2007 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_from_locale_string (str
);
61 pango_font_description_free (pfd
);
63 return find_pango_font (layout
, scm_str
, 1.0);
67 symbol_to_pango_style (SCM style
)
69 PangoStyle pstyle
= PANGO_STYLE_NORMAL
;
70 if (style
== ly_symbol2scm ("italic"))
71 pstyle
= PANGO_STYLE_ITALIC
;
72 else if (style
== ly_symbol2scm ("oblique")
73 || style
== ly_symbol2scm ("slanted"))
74 pstyle
= PANGO_STYLE_OBLIQUE
;
80 symbol_to_pango_variant (SCM variant
)
82 PangoVariant pvariant
= PANGO_VARIANT_NORMAL
;
83 if (variant
== ly_symbol2scm ("caps"))
84 pvariant
= PANGO_VARIANT_SMALL_CAPS
;
89 symbol_to_pango_weight (SCM weight
)
91 PangoWeight pw
= PANGO_WEIGHT_NORMAL
;
92 if (weight
== ly_symbol2scm ("bold"))
93 pw
= PANGO_WEIGHT_BOLD
;
94 if (weight
== ly_symbol2scm ("heavy"))
95 pw
= PANGO_WEIGHT_HEAVY
;
96 if (weight
== ly_symbol2scm ("ultrabold"))
97 pw
= PANGO_WEIGHT_ULTRABOLD
;
98 if (weight
== ly_symbol2scm ("light"))
99 pw
= PANGO_WEIGHT_LIGHT
;
100 if (weight
== ly_symbol2scm ("ultralight"))
101 pw
= PANGO_WEIGHT_ULTRALIGHT
;
107 symbol_to_pango_stretch (SCM
) // stretch)
109 PangoStretch ps
= PANGO_STRETCH_NORMAL
;
114 PANGO_STRETCH_ULTRA_CONDENSED,
115 PANGO_STRETCH_EXTRA_CONDENSED,
116 PANGO_STRETCH_CONDENSED,
117 PANGO_STRETCH_SEMI_CONDENSED,
119 PANGO_STRETCH_SEMI_EXPANDED,
120 PANGO_STRETCH_EXPANDED,
121 PANGO_STRETCH_EXTRA_EXPANDED,
122 PANGO_STRETCH_ULTRA_EXPANDED
127 PangoFontDescription
*
128 symbols_to_pango_font_description (SCM family
,
134 PangoFontDescription
*description
= pango_font_description_new ();
136 string family_str
= "roman";
137 if (scm_is_symbol (family
))
138 family_str
= ly_symbol2string (family
);
139 else if (scm_is_string (family
))
140 family_str
= ly_scm2string (family
);
142 pango_font_description_set_family (description
,
143 family_str
.c_str ());
144 pango_font_description_set_style (description
,
145 symbol_to_pango_style (style
));
146 pango_font_description_set_variant (description
,
147 symbol_to_pango_variant (variant
));
148 pango_font_description_set_weight (description
,
149 symbol_to_pango_weight (weight
));
150 pango_font_description_set_stretch (description
,
151 symbol_to_pango_stretch (stretch
));