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>
9 #include "all-font-metrics.hh"
11 #include "string-convert.hh"
12 #include "international.hh"
14 #include "open-type-font.hh"
15 #include "pango-font.hh"
16 #include "scm-hash.hh"
20 Index_to_charcode_map
const *
21 All_font_metrics::get_index_to_charcode_map (string filename
,
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
;
39 PangoFontMap
*pfm
= pango_ft2_font_map_new ();
42 = G_TYPE_CHECK_INSTANCE_CAST (pfm
,
43 PANGO_TYPE_FT2_FONT_MAP
,
46 pango_ft2_font_map_set_resolution (pango_ft2_fontmap_
,
47 pango_dpi_
, pango_dpi_
);
49 pango_dict_
= new Scheme_hash_table
;
52 search_path_
.parse_path (path
);
55 All_font_metrics::~All_font_metrics ()
57 otf_dict_
->unprotect ();
60 pango_dict_
->unprotect ();
61 g_object_unref (pango_ft2_fontmap_
);
65 All_font_metrics::All_font_metrics (All_font_metrics
const &)
72 All_font_metrics::find_pango_font (PangoFontDescription
const *description
,
76 gchar
*pango_fn
= pango_font_description_to_filename (description
);
77 SCM key
= ly_symbol2scm (pango_fn
);
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_
,
90 val
= pf
->self_scm ();
91 pango_dict_
->set (key
, val
);
94 if (be_verbose_global
)
95 progress_indication ("]");
97 pf
->description_
= scm_cons (SCM_BOOL_F
,
98 scm_from_double (1.0));
101 return dynamic_cast<Pango_font
*> (unsmob_metrics (val
));
108 All_font_metrics::find_otf (string name
)
110 SCM sname
= ly_symbol2scm (name
.c_str ());
112 if (!otf_dict_
->try_retrieve (sname
, &val
))
116 if (file_name
.empty ())
117 file_name
= search_path_
.find (name
+ ".otf");
118 if (file_name
.empty ())
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
));
141 All_font_metrics::find_font (string name
)
143 Font_metric
*f
= find_otf (name
);
147 error (_f ("cannot find font: `%s'", name
.c_str ()));
153 All_font_metrics
*all_fonts_global
;