Comment.
[dcpomatic.git] / src / lib / render_subtitles.cc
index e2e5745cf262fb441dc496ab172f61f3ba4e7a4c..e22c8c44fb19acac05131422d4302ccafb0d2488 100644 (file)
@@ -25,6 +25,7 @@
 #include <cairomm/cairomm.h>
 #include <pangomm.h>
 #include <boost/foreach.hpp>
+#include <iostream>
 
 using std::list;
 using std::cout;
@@ -37,8 +38,6 @@ using std::make_pair;
 using boost::shared_ptr;
 using boost::optional;
 
-#define DEBUG_FONTS 1
-
 static FcConfig* fc_config = 0;
 static list<pair<boost::filesystem::path, string> > fc_config_fonts;
 
@@ -88,7 +87,14 @@ render_subtitle (dcp::SubtitleString const & subtitle, list<shared_ptr<Font> > f
                fc_config = FcConfigCreate ();
        }
 
-       boost::filesystem::path font_file = shared_path () / "LiberationSans-Regular.ttf";
+       boost::filesystem::path font_file;
+       try {
+               font_file = shared_path () / "LiberationSans-Regular.ttf";
+       } catch (boost::filesystem::filesystem_error& e) {
+               /* Hack: try the debian/ubuntu location if getting the shared path failed */
+               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().get ();
@@ -105,11 +111,7 @@ render_subtitle (dcp::SubtitleString const & subtitle, list<shared_ptr<Font> > f
                font_name = existing->second;
        } else {
                /* Make this font available to DCP-o-matic */
-               if (FcConfigAppFontAddFile (fc_config, reinterpret_cast<FcChar8 const *> (font_file.string().c_str ())) == FcFalse) {
-#if defined(DEBUG_FONTS)
-                       cerr << "FcConfigAppFontAddFile failed to load " << font_file << "\n";
-#endif
-               }
+               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));
@@ -148,9 +150,6 @@ render_subtitle (dcp::SubtitleString const & subtitle, list<shared_ptr<Font> > f
 
        /* Render the subtitle at the top left-hand corner of image */
 
-#if defined(DEBUG_FONTS)
-       cerr << "Font name is " << font_name << "\n";
-#endif
        Pango::FontDescription font (font_name);
        font.set_absolute_size (subtitle.size_in_pixels (target.height) * PANGO_SCALE);
        if (subtitle.italic ()) {