- /* Hack: try the debian/ubuntu locations if getting the shared path failed */
-
- if (!font_file || !boost::filesystem::exists(*font_file)) {
- font_file = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf";
- }
-
- BOOST_FOREACH (shared_ptr<Font> i, fonts) {
- if (i->id() == subtitle.font() && i->file()) {
- font_file = i->file ();
- }
- }
-
- list<pair<boost::filesystem::path, string> >::const_iterator existing = fc_config_fonts.begin ();
- while (existing != fc_config_fonts.end() && existing->first != *font_file) {
- ++existing;
- }
-
- string font_name;
- if (existing != fc_config_fonts.end ()) {
- font_name = existing->second;
- } else {
- /* Make this font available to DCP-o-matic */
- FcConfigAppFontAddFile (fc_config, reinterpret_cast<FcChar8 const *>(font_file->string().c_str()));
- FcPattern* pattern = FcPatternBuild (
- 0, FC_FILE, FcTypeString, font_file->string().c_str(), static_cast<char *> (0)
- );
- FcObjectSet* object_set = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_LANG, FC_FILE, static_cast<char *> (0));
- FcFontSet* font_set = FcFontList (fc_config, pattern, object_set);
- if (font_set) {
- for (int i = 0; i < font_set->nfont; ++i) {
- FcPattern* font = font_set->fonts[i];
- FcChar8* file;
- FcChar8* family;
- FcChar8* style;
- if (
- FcPatternGetString (font, FC_FILE, 0, &file) == FcResultMatch &&
- FcPatternGetString (font, FC_FAMILY, 0, &family) == FcResultMatch &&
- FcPatternGetString (font, FC_STYLE, 0, &style) == FcResultMatch
- ) {
- font_name = reinterpret_cast<char const *> (family);
- }
- }
-
- FcFontSetDestroy (font_set);
- }
-
- FcObjectSetDestroy (object_set);
- FcPatternDestroy (pattern);
-
- fc_config_fonts.push_back (make_pair(*font_file, font_name));
- }
-
- FcConfigSetCurrent (fc_config);
- return font_name;