]> git.donarmstrong.com Git - lilypond.git/blob - lily/pango-select.cc
* lily/tie-column.cc (set_manual_tie_configuration): new function.
[lilypond.git] / lily / pango-select.cc
1 /*
2   pango-select.cc -- implement lily font selection for Pango_fonts.
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8 #include <cmath>
9 using namespace std;
10
11 #include "dimensions.hh"
12 #include "all-font-metrics.hh"
13 #include "output-def.hh"
14 #include "pango-font.hh"
15
16 PangoFontDescription *
17 properties_to_pango_description (SCM chain, Real text_size)
18 {
19   SCM name = ly_chain_assoc_get (ly_symbol2scm ("font-name"), chain, SCM_BOOL_F);
20
21   PangoFontDescription *description = 0;
22   if (scm_is_string (name))
23     {
24       String name_str = ly_scm2string (name);
25       description = pango_font_description_from_string (name_str.to_str0 ());
26     }
27   else
28     {
29       SCM family = ly_chain_assoc_get (ly_symbol2scm ("font-family"), chain,
30                                        SCM_BOOL_F);
31       SCM variant = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
32                                         SCM_BOOL_F);
33
34       SCM style = ly_chain_assoc_get (ly_symbol2scm ("font-shape"), chain,
35                                       SCM_BOOL_F);
36       SCM weight = ly_chain_assoc_get (ly_symbol2scm ("font-series"), chain,
37                                        SCM_BOOL_F);
38
39       description
40         = symbols_to_pango_font_description (family, style, variant, weight,
41                                              SCM_BOOL_F);
42     }
43
44   Real step = robust_scm2double (ly_chain_assoc_get (ly_symbol2scm ("font-size"), chain, SCM_BOOL_F),
45                                  0.0);
46   Real size = text_size * pow (2.0, step / 6.0);
47
48   pango_font_description_set_size (description,
49                                    gint (size * PANGO_SCALE));
50   return description;
51 }
52
53 Font_metric *
54 select_pango_font (Output_def *layout, SCM chain)
55 {
56   PangoFontDescription *pfd
57     = properties_to_pango_description (chain,
58                                        point_constant
59                                        * layout->get_dimension (ly_symbol2scm ("text-font-size")));
60
61   char *str = pango_font_description_to_string (pfd);
62   SCM scm_str = scm_makfrom0str (str);
63   g_free (str);
64
65   return find_pango_font (layout, scm_str, 1.0);
66 }
67
68 PangoStyle
69 symbol_to_pango_style (SCM style)
70 {
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;
77
78   return pstyle;
79 }
80
81 PangoVariant
82 symbol_to_pango_variant (SCM variant)
83 {
84   PangoVariant pvariant = PANGO_VARIANT_NORMAL;
85   if (variant == ly_symbol2scm ("caps"))
86     pvariant = PANGO_VARIANT_SMALL_CAPS;
87   return pvariant;
88 }
89
90 PangoWeight
91 symbol_to_pango_weight (SCM weight)
92 {
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;
104
105   return pw;
106 }
107
108 PangoStretch
109 symbol_to_pango_stretch (SCM) //  stretch)
110 {
111   PangoStretch ps = PANGO_STRETCH_NORMAL;
112
113   /*
114   // TODO
115
116   PANGO_STRETCH_ULTRA_CONDENSED,
117   PANGO_STRETCH_EXTRA_CONDENSED,
118   PANGO_STRETCH_CONDENSED,
119   PANGO_STRETCH_SEMI_CONDENSED,
120
121   PANGO_STRETCH_SEMI_EXPANDED,
122   PANGO_STRETCH_EXPANDED,
123   PANGO_STRETCH_EXTRA_EXPANDED,
124   PANGO_STRETCH_ULTRA_EXPANDED
125   */
126   return ps;
127 }
128
129 PangoFontDescription *
130 symbols_to_pango_font_description (SCM family,
131                                    SCM style,
132                                    SCM variant,
133                                    SCM weight,
134                                    SCM stretch)
135 {
136   PangoFontDescription *description = pango_font_description_new ();
137
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);
143
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));
154
155   return description;
156 }