#include "font.h"
#include "dcpomatic_assert.h"
#include "warnings.h"
+#include "util.h"
#include <dcp/raw_convert.h>
#include <fontconfig/fontconfig.h>
#include <cairomm/cairomm.h>
#ifndef DCPOMATIC_HAVE_SHOW_IN_CAIRO_CONTEXT
#include <pango/pangocairo.h>
#endif
-#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp>
#include <iostream>
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;
{
string out;
- BOOST_FOREACH (StringText const & i, subtitles) {
+ for (auto const& i: subtitles) {
out += "<span ";
if (i.italic()) {
out += "style=\"italic\" ";
fc_config = FcInitLoadConfig ();
}
- optional<boost::filesystem::path> font_file;
+ optional<boost::filesystem::path> font_file = default_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";
- }
-
- BOOST_FOREACH (shared_ptr<Font> i, fonts) {
+ for (auto i: fonts) {
if (i->id() == subtitle.font() && i->file()) {
font_file = i->file ();
}
{
int x = 0;
switch (first.h_align ()) {
- case dcp::HALIGN_LEFT:
+ case dcp::HAlign::LEFT:
/* h_position is distance between left of frame and left of subtitle */
x = first.h_position() * target_width;
break;
- case dcp::HALIGN_CENTER:
+ case dcp::HAlign::CENTER:
/* h_position is distance between centre of frame and centre of subtitle */
x = (0.5 + first.h_position()) * target_width - layout_width / 2;
break;
- case dcp::HALIGN_RIGHT:
+ case dcp::HAlign::RIGHT:
/* h_position is distance between right of frame and right of subtitle */
x = (1.0 - first.h_position()) * target_width - layout_width;
break;
{
int y = 0;
switch (first.v_align ()) {
- case dcp::VALIGN_TOP:
+ case dcp::VAlign::TOP:
/* SMPTE says that v_position is the distance between top
of frame and top of subtitle, but this doesn't always seem to be
the case in practice; Gunnar Ásgeirsson's Dolby server appears
- to put VALIGN_TOP subs with v_position as the distance between top
+ to put VAlign::TOP subs with v_position as the distance between top
of frame and bottom of subtitle.
*/
y = first.v_position() * target_height - layout_height;
break;
- case dcp::VALIGN_CENTER:
+ case dcp::VAlign::CENTER:
/* v_position is distance between centre of frame and centre of subtitle */
y = (0.5 + first.v_position()) * target_height - layout_height / 2;
break;
- case dcp::VALIGN_BOTTOM:
+ case dcp::VAlign::BOTTOM:
/* v_position is distance between bottom of frame and bottom of subtitle */
y = (1.0 - first.v_position()) * target_height - layout_height;
break;
create_layout()
{
PangoFontMap* c_font_map = pango_cairo_font_map_new ();
+ DCPOMATIC_ASSERT (c_font_map);
Glib::RefPtr<Pango::FontMap> font_map = Glib::wrap (c_font_map);
PangoContext* c_context = pango_font_map_create_context (c_font_map);
+ DCPOMATIC_ASSERT (c_context);
Glib::RefPtr<Pango::Context> context = Glib::wrap (c_context);
return Pango::Layout::create (context);
}
}
}
+ float const border_width = first.effect() == dcp::Effect::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;
context->scale (x_scale, y_scale);
layout->update_from_cairo_context (context);
- if (first.effect() == dcp::SHADOW) {
+ if (first.effect() == dcp::Effect::SHADOW) {
/* Drop-shadow effect */
set_source_rgba (context, first.effect_colour(), fade_factor);
context->move_to (x_offset + 4, y_offset + 4);
context->fill ();
}
- if (first.effect() == dcp::BORDER) {
- /* Border effect; stroke the subtitle with a large (arbitrarily chosen) line width */
+ if (first.effect() == dcp::Effect::BORDER) {
+ /* 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);
/* 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);
/** @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<PositionImage>
list<StringText> pending;
list<PositionImage> images;
- BOOST_FOREACH (StringText const & i, subtitles) {
+ for (auto const& i: subtitles) {
if (!pending.empty() && (i.v_align() != pending.back().v_align() || fabs(i.v_position() - pending.back().v_position()) > 1e-4)) {
images.push_back (render_line (pending, fonts, target, time, frame_rate));
pending.clear ();