Use `transform'.
[lilypond.git] / lily / all-font-metrics.cc
blob8a1143a537e2d33982506d4f7102e4c1e8590d28
1 /*
2 all-font-metrics.cc -- implement All_font_metrics
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "all-font-metrics.hh"
11 #include "international.hh"
12 #include "main.hh"
13 #include "open-type-font.hh"
14 #include "pango-font.hh"
15 #include "scm-hash.hh"
16 #include "warn.hh"
19 Index_to_charcode_map const *
20 All_font_metrics::get_index_to_charcode_map (string filename, FT_Face face)
22 if (filename_charcode_maps_map_.find (filename)
23 == filename_charcode_maps_map_.end ())
24 filename_charcode_maps_map_[filename] = make_index_to_charcode_map (face);
26 return &filename_charcode_maps_map_[filename];
30 All_font_metrics::All_font_metrics (string path)
32 otf_dict_ = new Scheme_hash_table;
34 #if HAVE_PANGO_FT2
35 PangoFontMap *pfm = pango_ft2_font_map_new ();
37 pango_ft2_fontmap_
38 = G_TYPE_CHECK_INSTANCE_CAST (pfm,
39 PANGO_TYPE_FT2_FONT_MAP,
40 PangoFT2FontMap);
41 pango_dpi_ = 1200;
42 pango_ft2_font_map_set_resolution (pango_ft2_fontmap_,
43 pango_dpi_, pango_dpi_);
45 pango_dict_ = new Scheme_hash_table;
46 #endif
48 search_path_.parse_path (path);
51 All_font_metrics::~All_font_metrics ()
53 otf_dict_->unprotect ();
55 #if HAVE_PANGO_FT2
56 pango_dict_->unprotect ();
57 g_object_unref (pango_ft2_fontmap_);
58 #endif
61 All_font_metrics::All_font_metrics (All_font_metrics const &)
65 #if HAVE_PANGO_FT2
67 Pango_font *
68 All_font_metrics::find_pango_font (PangoFontDescription const *description,
69 Real output_scale
72 gchar *pango_fn = pango_font_description_to_filename (description);
73 SCM key = ly_symbol2scm (pango_fn);
75 SCM val;
76 if (!pango_dict_->try_retrieve (key, &val))
78 if (be_verbose_global)
79 progress_indication ("[" + string (pango_fn));
81 Pango_font *pf = new Pango_font (pango_ft2_fontmap_,
82 description,
83 output_scale
86 val = pf->self_scm ();
87 pango_dict_->set (key, val);
88 pf->unprotect ();
90 if (be_verbose_global)
91 progress_indication ("]");
93 pf->description_ = scm_cons (SCM_BOOL_F,
94 scm_from_double (1.0));
96 g_free (pango_fn);
97 return dynamic_cast<Pango_font *> (unsmob_metrics (val));
100 #endif
103 Open_type_font *
104 All_font_metrics::find_otf (string name)
106 SCM sname = ly_symbol2scm (name.c_str ());
107 SCM name_string = ly_string2scm (name);
108 SCM val;
109 if (!otf_dict_->try_retrieve (sname, &val))
111 string file_name;
113 if (file_name.empty ())
114 file_name = search_path_.find (name + ".otf");
115 if (file_name.empty ())
116 return 0;
118 if (be_verbose_global)
119 progress_indication ("[" + file_name);
121 val = Open_type_font::make_otf (file_name);
123 if (be_verbose_global)
124 progress_indication ("]");
126 unsmob_metrics (val)->file_name_ = file_name;
127 unsmob_metrics (val)->description_ = scm_cons (name_string,
128 scm_from_double (1.0));
129 otf_dict_->set (sname, val);
130 unsmob_metrics (val)->unprotect ();
133 return dynamic_cast<Open_type_font *> (unsmob_metrics (val));
136 Font_metric *
137 All_font_metrics::find_font (string name)
139 Font_metric *f = find_otf (name);
141 if (!f)
143 error (_f ("cannot find font: `%s'", name.c_str ()));
146 return f;
149 All_font_metrics *all_fonts_global;