2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2015 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"
32 Index_to_charcode_map const *
33 All_font_metrics::get_index_to_charcode_map (const string &filename,
37 string key = filename + String_convert::int_string (face_index);
38 if (filename_charcode_maps_map_.find (key)
39 == filename_charcode_maps_map_.end ())
40 filename_charcode_maps_map_[key] = make_index_to_charcode_map (face);
42 return &filename_charcode_maps_map_[key];
45 All_font_metrics::All_font_metrics (const string &path)
48 pango_dict_ = new Scheme_hash_table;
51 otf_dict_ = new Scheme_hash_table;
53 otf_dict_->unprotect ();
56 pango_dict_->unprotect ();
57 PangoFontMap *pfm = pango_ft2_font_map_new ();
59 pango_ft2_fontmap_ = PANGO_FT2_FONT_MAP (pfm);
61 pango_dpi_ = PANGO_RESOLUTION;
62 pango_ft2_font_map_set_resolution (pango_ft2_fontmap_,
63 pango_dpi_, pango_dpi_);
66 search_path_.parse_path (path);
69 All_font_metrics::~All_font_metrics ()
72 g_object_unref (pango_ft2_fontmap_);
77 All_font_metrics::mark_smob () const
81 scm_gc_mark (pango_dict_->self_scm ());
84 return otf_dict_->self_scm ();
91 All_font_metrics::find_pango_font (PangoFontDescription const *description,
95 gchar *pango_fn = pango_font_description_to_filename (description);
96 SCM key = ly_symbol2scm (pango_fn);
99 if (!pango_dict_->try_retrieve (key, &val))
101 debug_output ("[" + string (pango_fn), true); // start on a new line
103 Pango_font *pf = new Pango_font (pango_ft2_fontmap_,
108 val = pf->self_scm ();
109 pango_dict_->set (key, val);
112 debug_output ("]", false);
114 pf->description_ = scm_cons (SCM_BOOL_F,
115 scm_from_double (1.0));
118 return unsmob<Pango_font> (val);
124 All_font_metrics::find_otf (const string &name)
126 SCM sname = ly_symbol2scm (name.c_str ());
128 if (!otf_dict_->try_retrieve (sname, &val))
132 if (file_name.empty ())
133 file_name = search_path_.find (name + ".otf");
134 if (file_name.empty ())
137 debug_output ("[" + file_name, true); // start on a new line
139 val = Open_type_font::make_otf (file_name);
141 debug_output ("]", false);
143 unsmob<Font_metric> (val)->file_name_ = file_name;
144 SCM name_string = ly_string2scm (name);
145 unsmob<Font_metric> (val)->description_ = scm_cons (name_string,
146 scm_from_double (1.0));
147 otf_dict_->set (sname, val);
148 unsmob<Font_metric> (val)->unprotect ();
151 return unsmob<Open_type_font> (val);
155 All_font_metrics::find_font (const string &name)
157 Font_metric *f = find_otf (name);
161 error (_f ("cannot find font: `%s'", name.c_str ()));