2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "dimensions.hh"
21 #include "all-font-metrics.hh"
22 #include "libc-extension.hh"
23 #include "output-def.hh"
24 #include "pango-font.hh"
28 PangoFontDescription *
29 properties_to_pango_description (SCM chain, Real text_size)
31 SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F);
33 PangoFontDescription *description = 0;
34 if (scm_is_string (name))
36 string name_str = ly_scm2string (name);
37 description = pango_font_description_from_string (name_str.c_str ());
41 SCM family = ly_chain_assoc_get (ly_symbol2scm ("font-family"), chain,
43 SCM variant = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
46 SCM style = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
48 SCM weight = ly_chain_assoc_get (ly_symbol2scm ("font-series"), chain,
52 = symbols_to_pango_font_description (family, style, variant, weight,
56 Real step = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F),
58 Real size = text_size * pow (2.0, step / 6.0);
60 pango_font_description_set_size (description,
61 gint (my_round (size * PANGO_SCALE)));
66 select_pango_font (Output_def *layout, SCM chain)
68 PangoFontDescription *pfd
69 = properties_to_pango_description (chain,
71 * layout->get_dimension (ly_symbol2scm ("text-font-size")));
73 char *str = pango_font_description_to_string (pfd);
74 SCM scm_str = scm_from_locale_string (str);
76 pango_font_description_free (pfd);
78 return find_pango_font (layout, scm_str, 1.0);
82 symbol_to_pango_style (SCM style)
84 PangoStyle pstyle = PANGO_STYLE_NORMAL;
85 if (scm_is_eq (style, ly_symbol2scm ("italic")))
86 pstyle = PANGO_STYLE_ITALIC;
87 else if (scm_is_eq (style, ly_symbol2scm ("oblique"))
88 || scm_is_eq (style, ly_symbol2scm ("slanted")))
89 pstyle = PANGO_STYLE_OBLIQUE;
95 symbol_to_pango_variant (SCM variant)
97 PangoVariant pvariant = PANGO_VARIANT_NORMAL;
98 if (scm_is_eq (variant, ly_symbol2scm ("caps")))
99 pvariant = PANGO_VARIANT_SMALL_CAPS;
104 symbol_to_pango_weight (SCM weight)
106 PangoWeight pw = PANGO_WEIGHT_NORMAL;
107 if (scm_is_eq (weight, ly_symbol2scm ("bold")))
108 pw = PANGO_WEIGHT_BOLD;
109 if (scm_is_eq (weight, ly_symbol2scm ("heavy")))
110 pw = PANGO_WEIGHT_HEAVY;
111 if (scm_is_eq (weight, ly_symbol2scm ("ultrabold")))
112 pw = PANGO_WEIGHT_ULTRABOLD;
113 if (scm_is_eq (weight, ly_symbol2scm ("light")))
114 pw = PANGO_WEIGHT_LIGHT;
115 if (scm_is_eq (weight, ly_symbol2scm ("ultralight")))
116 pw = PANGO_WEIGHT_ULTRALIGHT;
122 symbol_to_pango_stretch (SCM) // stretch)
124 PangoStretch ps = PANGO_STRETCH_NORMAL;
129 PANGO_STRETCH_ULTRA_CONDENSED,
130 PANGO_STRETCH_EXTRA_CONDENSED,
131 PANGO_STRETCH_CONDENSED,
132 PANGO_STRETCH_SEMI_CONDENSED,
134 PANGO_STRETCH_SEMI_EXPANDED,
135 PANGO_STRETCH_EXPANDED,
136 PANGO_STRETCH_EXTRA_EXPANDED,
137 PANGO_STRETCH_ULTRA_EXPANDED
142 PangoFontDescription *
143 symbols_to_pango_font_description (SCM family,
149 PangoFontDescription *description = pango_font_description_new ();
151 string family_str = "roman";
152 if (scm_is_symbol (family))
153 family_str = ly_symbol2string (family);
154 else if (scm_is_string (family))
155 family_str = ly_scm2string (family);
157 pango_font_description_set_family (description,
158 family_str.c_str ());
159 pango_font_description_set_style (description,
160 symbol_to_pango_style (style));
161 pango_font_description_set_variant (description,
162 symbol_to_pango_variant (variant));
163 pango_font_description_set_weight (description,
164 symbol_to_pango_weight (weight));
165 pango_font_description_set_stretch (description,
166 symbol_to_pango_stretch (stretch));