2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2011 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 "all-font-metrics.hh"
22 #include "string-convert.hh"
23 #include "international.hh"
25 #include "open-type-font.hh"
26 #include "pango-font.hh"
27 #include "scm-hash.hh"
30 Index_to_charcode_map const *
31 All_font_metrics::get_index_to_charcode_map (string filename,
35 string key = filename + String_convert::int_string (face_index);
36 if (filename_charcode_maps_map_.find (key)
37 == filename_charcode_maps_map_.end ())
38 filename_charcode_maps_map_[key] = make_index_to_charcode_map (face);
40 return &filename_charcode_maps_map_[key];
43 All_font_metrics::All_font_metrics (string path)
45 otf_dict_ = new Scheme_hash_table;
48 PangoFontMap *pfm = pango_ft2_font_map_new ();
50 pango_ft2_fontmap_ = PANGO_FT2_FONT_MAP (pfm);
52 pango_dpi_ = PANGO_RESOLUTION;
53 pango_ft2_font_map_set_resolution (pango_ft2_fontmap_,
54 pango_dpi_, pango_dpi_);
56 pango_dict_ = new Scheme_hash_table;
59 search_path_.parse_path (path);
62 All_font_metrics::~All_font_metrics ()
64 otf_dict_->unprotect ();
67 pango_dict_->unprotect ();
68 g_object_unref (pango_ft2_fontmap_);
72 All_font_metrics::All_font_metrics (All_font_metrics const &)
79 All_font_metrics::find_pango_font (PangoFontDescription const *description,
83 gchar *pango_fn = pango_font_description_to_filename (description);
84 SCM key = ly_symbol2scm (pango_fn);
87 if (!pango_dict_->try_retrieve (key, &val))
89 if (be_verbose_global)
90 progress_indication ("\n[" + string (pango_fn));
92 Pango_font *pf = new Pango_font (pango_ft2_fontmap_,
97 val = pf->self_scm ();
98 pango_dict_->set (key, val);
101 if (be_verbose_global)
102 progress_indication ("]");
104 pf->description_ = scm_cons (SCM_BOOL_F,
105 scm_from_double (1.0));
108 return dynamic_cast<Pango_font *> (unsmob_metrics (val));
114 All_font_metrics::find_otf (string name)
116 SCM sname = ly_symbol2scm (name.c_str ());
118 if (!otf_dict_->try_retrieve (sname, &val))
122 if (file_name.empty ())
123 file_name = search_path_.find (name + ".otf");
124 if (file_name.empty ())
127 if (be_verbose_global)
128 progress_indication ("\n[" + file_name);
130 val = Open_type_font::make_otf (file_name);
132 if (be_verbose_global)
133 progress_indication ("]");
135 unsmob_metrics (val)->file_name_ = file_name;
136 SCM name_string = ly_string2scm (name);
137 unsmob_metrics (val)->description_ = scm_cons (name_string,
138 scm_from_double (1.0));
139 otf_dict_->set (sname, val);
140 unsmob_metrics (val)->unprotect ();
143 return dynamic_cast<Open_type_font *> (unsmob_metrics (val));
147 All_font_metrics::find_font (string name)
149 Font_metric *f = find_otf (name);
153 error (_f ("cannot find font: `%s'", name.c_str ()));
159 All_font_metrics *all_fonts_global;