]> git.donarmstrong.com Git - lilypond.git/blob - lily/pango-select.cc
* scm/framework-ps.scm (output-variables): separately scale the
[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 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9 #include <math.h>
10
11 #include "dimensions.hh"
12 #include "all-font-metrics.hh"
13 #include "output-def.hh"
14 #include "pango-font.hh"
15
16 Font_metric *
17 select_pango_font (Output_def *layout, SCM chain)
18 {
19   SCM name = ly_chain_assoc (ly_symbol2scm ("font-name"), chain);
20
21   PangoFontDescription *description = 0;
22   if (scm_is_pair (name) && scm_is_string (scm_cdr (name)))
23     {
24       String name_str = ly_scm2string (scm_cdr (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_symbol2scm ("font-size"), 0.0);
45   Real size = layout->get_dimension (ly_symbol2scm ("text-font-size"))
46     * pow (2.0, step / 6.0) * point_constant;
47   pango_font_description_set_size (description,
48                                    gint (size * PANGO_SCALE));
49   
50   Font_metric * fm = all_fonts_global->find_pango_font (description);
51
52   return find_scaled_font (layout, fm, 1.0,
53                            ly_symbol2scm ("latin1"),
54                            ly_symbol2scm ("latin1")); 
55 }
56
57
58 PangoStyle
59 symbol_to_pango_style (SCM style)
60 {
61   PangoStyle pstyle = PANGO_STYLE_NORMAL;
62   if (style == ly_symbol2scm ("italic"))
63     {
64       pstyle = PANGO_STYLE_NORMAL;
65     }
66   else if (style == ly_symbol2scm ("oblique")
67            || style == ly_symbol2scm ("slanted")
68            )
69     {
70       pstyle = PANGO_STYLE_OBLIQUE;
71     }
72
73   return pstyle;
74 }
75
76 PangoVariant
77 symbol_to_pango_variant (SCM variant)
78 {
79   PangoVariant pvariant;
80   if (variant == ly_symbol2scm ("caps"))
81     {
82       pvariant = PANGO_VARIANT_SMALL_CAPS;
83     }
84   return pvariant;
85 }
86
87
88 PangoWeight
89 symbol_to_pango_weight (SCM weight)
90 {
91   PangoWeight pw = PANGO_WEIGHT_NORMAL;
92   if (weight == ly_symbol2scm ("bold"))
93     {
94       pw = PANGO_WEIGHT_BOLD;
95     }
96   if (weight == ly_symbol2scm ("heavy"))
97     {
98       pw = PANGO_WEIGHT_HEAVY;
99     }
100   if (weight == ly_symbol2scm ("ultrabold"))
101     {
102       pw = PANGO_WEIGHT_ULTRABOLD;
103     }
104   if (weight == ly_symbol2scm ("light"))
105     {
106       pw = PANGO_WEIGHT_LIGHT;
107     }
108   if (weight == ly_symbol2scm ("ultralight"))
109     {
110       pw = PANGO_WEIGHT_ULTRALIGHT;
111     }
112
113   return pw;
114 }
115
116 PangoStretch
117 symbol_to_pango_stretch (SCM) //  stretch)
118 {
119   PangoStretch ps = PANGO_STRETCH_NORMAL;
120
121   /*
122     // TODO
123     
124   PANGO_STRETCH_ULTRA_CONDENSED,
125   PANGO_STRETCH_EXTRA_CONDENSED,
126   PANGO_STRETCH_CONDENSED,
127   PANGO_STRETCH_SEMI_CONDENSED,
128   
129   PANGO_STRETCH_SEMI_EXPANDED,
130   PANGO_STRETCH_EXPANDED,
131   PANGO_STRETCH_EXTRA_EXPANDED,
132   PANGO_STRETCH_ULTRA_EXPANDED
133   */ 
134   return ps;
135 }
136
137
138
139 PangoFontDescription* 
140 symbols_to_pango_font_description(SCM family,
141                                   SCM style,
142                                   SCM variant,
143                                   SCM weight,
144                                   SCM stretch)
145 {
146   PangoFontDescription * description = pango_font_description_new ();
147
148   String family_str = scm_is_symbol (family)
149     ? ly_symbol2string (family)
150     : String("roman");
151   pango_font_description_set_family (description,
152                                      family_str.to_str0 ());
153   pango_font_description_set_style (description,
154                                     symbol_to_pango_style (style));
155   pango_font_description_set_variant (description,
156                                       symbol_to_pango_variant (variant));
157   pango_font_description_set_weight (description,
158                                      symbol_to_pango_weight (weight));
159   pango_font_description_set_stretch (description,
160                                       symbol_to_pango_stretch (stretch));
161
162   return description;
163 }