X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Frender_text.cc;h=3129c220f8f5f56ee5f7618e7df368f064bb439b;hb=dd9be86db6cde0afa5da0d1d1ac43b42e05dca26;hp=b0a958c16d194cd15b0a65d5ec72030a29a8f519;hpb=2da4caba7871455c097c0ed940dd6f2332dbda5d;p=dcpomatic.git diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index b0a958c16..3129c220f 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -25,6 +25,7 @@ #include "font.h" #include "dcpomatic_assert.h" #include "warnings.h" +#include "util.h" #include #include #include @@ -47,7 +48,7 @@ using std::max; using std::pair; using std::cerr; using std::make_pair; -using boost::shared_ptr; +using std::shared_ptr; using boost::optional; using boost::algorithm::replace_all; using namespace dcpomatic; @@ -139,19 +140,7 @@ setup_font (StringText const& subtitle, list > const& fonts) fc_config = FcInitLoadConfig (); } - optional font_file; - - try { - font_file = shared_path () / "LiberationSans-Regular.ttf"; - } catch (boost::filesystem::filesystem_error& e) { - - } - - /* 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"; - } + optional font_file = default_font_file (); BOOST_FOREACH (shared_ptr i, fonts) { if (i->id() == subtitle.font() && i->file()) { @@ -300,8 +289,10 @@ static Glib::RefPtr create_layout() { PangoFontMap* c_font_map = pango_cairo_font_map_new (); + DCPOMATIC_ASSERT (c_font_map); Glib::RefPtr font_map = Glib::wrap (c_font_map); PangoContext* c_context = pango_font_map_create_context (c_font_map); + DCPOMATIC_ASSERT (c_context); Glib::RefPtr context = Glib::wrap (c_context); return Pango::Layout::create (context); } @@ -343,13 +334,15 @@ render_line (list subtitles, list > fonts, dcp::Siz } } + float const border_width = first.effect() == dcp::BORDER ? (first.outline_width * target.width / 2048.0) : 0; + size.width += 2 * ceil (border_width); + size.height += 2 * ceil (border_width); + size.width *= x_scale; size.height *= y_scale; - /* Shuffle the subtitle over very slightly if it has a border so that the left-hand - side of the first character's border is not cut off. - */ - int const x_offset = first.effect() == dcp::BORDER ? (target.width / 600.0) : 0; + /* Shuffle the subtitle over by the border width (if we have any) so it's not cut off */ + int const x_offset = ceil (border_width); /* Move down a bit so that accents on capital letters can be seen */ int const y_offset = target.height / 100.0; @@ -373,9 +366,9 @@ render_line (list subtitles, list > fonts, dcp::Siz } if (first.effect() == dcp::BORDER) { - /* Border effect; stroke the subtitle with a large (arbitrarily chosen) line width */ + /* Border effect */ set_source_rgba (context, first.effect_colour(), fade_factor); - context->set_line_width (first.outline_width * target.width / 2048.0); + context->set_line_width (border_width); context->set_line_join (Cairo::LINE_JOIN_ROUND); context->move_to (x_offset, y_offset); layout->add_to_cairo_context (context); @@ -384,13 +377,16 @@ render_line (list subtitles, list > fonts, dcp::Siz /* The actual subtitle */ - context->set_line_width (0); + set_source_rgba (context, first.colour(), fade_factor); + context->move_to (x_offset, y_offset); -#ifdef DCPOMATIC_HAVE_SHOW_IN_CAIRO_CONTEXT - layout->show_in_cairo_context (context); -#else - pango_cairo_show_layout (context->cobj(), layout->gobj()); -#endif + layout->add_to_cairo_context (context); + context->fill (); + + context->set_line_width (0.5); + context->move_to (x_offset, y_offset); + layout->add_to_cairo_context (context); + context->stroke (); int const x = x_position (first, target.width, size.width); int const y = y_position (first, target.height, size.height); @@ -399,6 +395,7 @@ render_line (list subtitles, list > fonts, dcp::Siz /** @param time Time of the frame that these subtitles are going on. + * @param target Size of the container that this subtitle will end up in. * @param frame_rate DCP frame rate. */ list