Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / all-font-metrics.cc
blob344d3a3e7548023c9b7a16b52f187f9fc61674d6
1 /*
2 all-font-metrics.cc -- implement All_font_metrics
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "all-font-metrics.hh"
11 #include "string-convert.hh"
12 #include "international.hh"
13 #include "main.hh"
14 #include "open-type-font.hh"
15 #include "pango-font.hh"
16 #include "scm-hash.hh"
17 #include "warn.hh"
20 Index_to_charcode_map const *
21 All_font_metrics::get_index_to_charcode_map (string filename,
22 int face_index,
23 FT_Face face)
25 string key = filename + String_convert::int_string (face_index);
26 if (filename_charcode_maps_map_.find (key)
27 == filename_charcode_maps_map_.end ())
28 filename_charcode_maps_map_[key] = make_index_to_charcode_map (face);
30 return &filename_charcode_maps_map_[key];
34 All_font_metrics::All_font_metrics (string path)
36 otf_dict_ = new Scheme_hash_table;
38 #if HAVE_PANGO_FT2
39 PangoFontMap *pfm = pango_ft2_font_map_new ();
41 pango_ft2_fontmap_
42 = G_TYPE_CHECK_INSTANCE_CAST (pfm,
43 PANGO_TYPE_FT2_FONT_MAP,
44 PangoFT2FontMap);
45 pango_dpi_ = 1200;
46 pango_ft2_font_map_set_resolution (pango_ft2_fontmap_,
47 pango_dpi_, pango_dpi_);
49 pango_dict_ = new Scheme_hash_table;
50 #endif
52 search_path_.parse_path (path);
55 All_font_metrics::~All_font_metrics ()
57 otf_dict_->unprotect ();
59 #if HAVE_PANGO_FT2
60 pango_dict_->unprotect ();
61 g_object_unref (pango_ft2_fontmap_);
62 #endif
65 All_font_metrics::All_font_metrics (All_font_metrics const &)
69 #if HAVE_PANGO_FT2
71 Pango_font *
72 All_font_metrics::find_pango_font (PangoFontDescription const *description,
73 Real output_scale
76 gchar *pango_fn = pango_font_description_to_filename (description);
77 SCM key = ly_symbol2scm (pango_fn);
79 SCM val;
80 if (!pango_dict_->try_retrieve (key, &val))
82 if (be_verbose_global)
83 progress_indication ("\n[" + string (pango_fn));
85 Pango_font *pf = new Pango_font (pango_ft2_fontmap_,
86 description,
87 output_scale
90 val = pf->self_scm ();
91 pango_dict_->set (key, val);
92 pf->unprotect ();
94 if (be_verbose_global)
95 progress_indication ("]");
97 pf->description_ = scm_cons (SCM_BOOL_F,
98 scm_from_double (1.0));
100 g_free (pango_fn);
101 return dynamic_cast<Pango_font *> (unsmob_metrics (val));
104 #endif
107 Open_type_font *
108 All_font_metrics::find_otf (string name)
110 SCM sname = ly_symbol2scm (name.c_str ());
111 SCM val;
112 if (!otf_dict_->try_retrieve (sname, &val))
114 string file_name;
116 if (file_name.empty ())
117 file_name = search_path_.find (name + ".otf");
118 if (file_name.empty ())
119 return 0;
121 if (be_verbose_global)
122 progress_indication ("\n[" + file_name);
124 val = Open_type_font::make_otf (file_name);
126 if (be_verbose_global)
127 progress_indication ("]");
129 unsmob_metrics (val)->file_name_ = file_name;
130 SCM name_string = ly_string2scm (name);
131 unsmob_metrics (val)->description_ = scm_cons (name_string,
132 scm_from_double (1.0));
133 otf_dict_->set (sname, val);
134 unsmob_metrics (val)->unprotect ();
137 return dynamic_cast<Open_type_font *> (unsmob_metrics (val));
140 Font_metric *
141 All_font_metrics::find_font (string name)
143 Font_metric *f = find_otf (name);
145 if (!f)
147 error (_f ("cannot find font: `%s'", name.c_str ()));
150 return f;
153 All_font_metrics *all_fonts_global;