--- /dev/null
+/*
+ Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef DCPOMATIC_BITMAP_TEXT_H
+#define DCPOMATIC_BITMAP_TEXT_H
+
+#include "rect.h"
+#include <boost/shared_ptr.hpp>
+
+class Image;
+
+class BitmapText
+{
+public:
+ BitmapText (boost::shared_ptr<Image> i, dcpomatic::Rect<double> r)
+ : image (i)
+ , rectangle (r)
+ {}
+
+ boost::shared_ptr<Image> image;
+ /** Area that the subtitle covers on its corresponding video, expressed in
+ * proportions of the image size; e.g. rectangle.x = 0.5 would mean that
+ * the rectangle starts half-way across the video.
+ *
+ * This rectangle may or may not have had a TextContent's offsets and
+ * scale applied to it, depending on context.
+ */
+ dcpomatic::Rect<double> rectangle;
+};
+
+#endif
#include "dcpomatic_time.h"
#include "rect.h"
-#include "image_subtitle.h"
+#include "bitmap_text.h"
#include <dcp/subtitle_string.h>
#include <list>
ContentTime _from;
};
-class ContentImageSubtitle : public ContentSubtitle
+class ContentBitmapText : public ContentSubtitle
{
public:
- ContentImageSubtitle (ContentTime f, boost::shared_ptr<Image> im, dcpomatic::Rect<double> r)
+ ContentBitmapText (ContentTime f, boost::shared_ptr<Image> im, dcpomatic::Rect<double> r)
: ContentSubtitle (f)
, sub (im, r)
{}
/* Our subtitle, with its rectangle unmodified by any offsets or scales that the content specifies */
- ImageSubtitle sub;
+ BitmapText sub;
};
/** A text subtitle. We store the time period separately (as well as in the dcp::SubtitleStrings)
if (is) {
list<dcp::SubtitleString> s;
s.push_back (*is);
- subtitle->emit_text (
+ subtitle->emit_plain (
ContentTimePeriod (
ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (i->in().as_seconds ()),
ContentTime::from_frames (_offset - entry_point, vfr) + ContentTime::from_seconds (i->out().as_seconds ())
/* Gather all subtitles with the same time period that are next
on the list. We must emit all subtitles for the same time
- period with the same text_subtitle() call otherwise the
+ period with the same plain_text() call otherwise the
TextDecoder will assume there is nothing else at the
time of emit the first.
*/
/* XXX: image subtitles */
}
- subtitle->emit_text (p, s);
+ subtitle->emit_plain (p, s);
return false;
}
static_cast<double> (rect->h) / target_height
);
- subtitle->emit_image_start (from, image, scaled_rect);
+ subtitle->emit_bitmap_start (from, image, scaled_rect);
}
void
);
BOOST_FOREACH (sub::Subtitle const & i, sub::collect<list<sub::Subtitle> > (raw)) {
- subtitle->emit_text_start (from, i);
+ subtitle->emit_plain_start (from, i);
}
}
class Image;
-class ImageSubtitle
+class BitmapText
{
public:
- ImageSubtitle (boost::shared_ptr<Image> i, dcpomatic::Rect<double> r)
+ BitmapText (boost::shared_ptr<Image> i, dcpomatic::Rect<double> r)
: image (i)
, rectangle (r)
{}
--- /dev/null
+/*
+ Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "plain_text.h"
+#include "cross.h"
+#include "exceptions.h"
+#include "plain_text_content.h"
+#include <sub/subrip_reader.h>
+#include <sub/ssa_reader.h>
+#include <sub/collect.h>
+#include <unicode/ucsdet.h>
+#include <unicode/ucnv.h>
+#include <iostream>
+
+#include "i18n.h"
+
+using std::vector;
+using std::cout;
+using std::string;
+using boost::shared_ptr;
+using boost::scoped_array;
+using boost::optional;
+using dcp::Data;
+
+TextSubtitle::TextSubtitle (shared_ptr<const PlainText> content)
+{
+ Data in (content->path (0));
+
+ UErrorCode status = U_ZERO_ERROR;
+ UCharsetDetector* detector = ucsdet_open (&status);
+ ucsdet_setText (detector, reinterpret_cast<const char *> (in.data().get()), in.size(), &status);
+
+ UCharsetMatch const * match = ucsdet_detect (detector, &status);
+ char const * in_charset = ucsdet_getName (match, &status);
+
+ UConverter* to_utf16 = ucnv_open (in_charset, &status);
+ /* This is a guess; I think we should be able to encode any input in 4 times its input size */
+ scoped_array<uint16_t> utf16 (new uint16_t[in.size() * 2]);
+ int const utf16_len = ucnv_toUChars (
+ to_utf16, reinterpret_cast<UChar*>(utf16.get()), in.size() * 2,
+ reinterpret_cast<const char *> (in.data().get()), in.size(),
+ &status
+ );
+
+ UConverter* to_utf8 = ucnv_open ("UTF-8", &status);
+ /* Another guess */
+ scoped_array<char> utf8 (new char[utf16_len * 2]);
+ ucnv_fromUChars (to_utf8, utf8.get(), utf16_len * 2, reinterpret_cast<UChar*>(utf16.get()), utf16_len, &status);
+
+ /* Fix OS X line endings */
+ size_t utf8_len = strlen (utf8.get ());
+ for (size_t i = 0; i < utf8_len; ++i) {
+ if (utf8[i] == '\r' && ((i == utf8_len - 1) || utf8[i + 1] != '\n')) {
+ utf8[i] = '\n';
+ }
+ }
+
+ ucsdet_close (detector);
+ ucnv_close (to_utf16);
+ ucnv_close (to_utf8);
+
+ sub::Reader* reader = 0;
+
+ string ext = content->path(0).extension().string();
+ transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+
+ if (ext == ".srt") {
+ reader = new sub::SubripReader (utf8.get());
+ } else if (ext == ".ssa" || ext == ".ass") {
+ reader = new sub::SSAReader (utf8.get());
+ }
+
+ if (reader) {
+ _subtitles = sub::collect<vector<sub::Subtitle> > (reader->subtitles ());
+ }
+
+ delete reader;
+}
+
+/** @return time of first subtitle, if there is one */
+optional<ContentTime>
+TextSubtitle::first () const
+{
+ if (_subtitles.empty()) {
+ return optional<ContentTime>();
+ }
+
+ return ContentTime::from_seconds(_subtitles[0].from.all_as_seconds());
+}
+
+ContentTime
+TextSubtitle::length () const
+{
+ if (_subtitles.empty ()) {
+ return ContentTime ();
+ }
+
+ return ContentTime::from_seconds (_subtitles.back().to.all_as_seconds ());
+}
--- /dev/null
+/*
+ Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef DCPOMATIC_TEXT_SUBTITLE_H
+#define DCPOMATIC_TEXT_SUBTITLE_H
+
+#include "dcpomatic_time.h"
+#include <sub/subtitle.h>
+#include <boost/shared_ptr.hpp>
+#include <vector>
+
+class PlainText;
+class plain_text_time_test;
+class plain_text_coordinate_test;
+class plain_text_content_test;
+class plain_text_parse_test;
+
+class TextSubtitle
+{
+public:
+ explicit TextSubtitle (boost::shared_ptr<const PlainText>);
+
+ boost::optional<ContentTime> first () const;
+ ContentTime length () const;
+
+protected:
+ std::vector<sub::Subtitle> _subtitles;
+};
+
+#endif
#include "plain_text_content.h"
#include "util.h"
-#include "text_subtitle.h"
+#include "plain_text.h"
#include "film.h"
#include "font.h"
#include "text_content.h"
}
ContentTimePeriod const p = content_time_period (_subtitles[_next]);
- subtitle->emit_text (p, _subtitles[_next]);
+ subtitle->emit_plain (p, _subtitles[_next]);
++_next;
return false;
#define DCPOMATIC_TEXT_SUBTITLE_DECODER_H
#include "text_decoder.h"
-#include "text_subtitle.h"
+#include "plain_text.h"
class PlainText;
#include "raw_image_proxy.h"
#include "ratio.h"
#include "log.h"
-#include "render_subtitles.h"
+#include "render_text.h"
#include "config.h"
#include "content_video.h"
#include "player_video.h"
}
if (decoder->subtitle) {
- decoder->subtitle->ImageStart.connect (bind (&Player::image_subtitle_start, this, weak_ptr<Piece> (piece), _1));
- decoder->subtitle->TextStart.connect (bind (&Player::text_subtitle_start, this, weak_ptr<Piece> (piece), _1));
+ decoder->subtitle->BitmapStart.connect (bind (&Player::bitmap_text_start, this, weak_ptr<Piece> (piece), _1));
+ decoder->subtitle->PlainStart.connect (bind (&Player::plain_text_start, this, weak_ptr<Piece> (piece), _1));
decoder->subtitle->Stop.connect (bind (&Player::subtitle_stop, this, weak_ptr<Piece> (piece), _1));
}
}
}
list<PositionImage>
-Player::transform_image_subtitles (list<ImageSubtitle> subs) const
+Player::transform_bitmap_texts (list<BitmapText> subs) const
{
list<PositionImage> all;
- for (list<ImageSubtitle>::const_iterator i = subs.begin(); i != subs.end(); ++i) {
+ for (list<BitmapText>::const_iterator i = subs.begin(); i != subs.end(); ++i) {
if (!i->image) {
continue;
}
BOOST_FOREACH (PlayerSubtitles i, _active_subtitles.get_burnt (DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_subtitles)) {
/* Image subtitles */
- list<PositionImage> c = transform_image_subtitles (i.image);
+ list<PositionImage> c = transform_bitmap_texts (i.image);
copy (c.begin(), c.end(), back_inserter (subtitles));
/* Text subtitles (rendered to an image) */
if (!i.text.empty ()) {
- list<PositionImage> s = render_subtitles (i.text, i.fonts, _video_container_size, time, vfr);
+ list<PositionImage> s = render_text (i.text, i.fonts, _video_container_size, time, vfr);
copy (s.begin(), s.end(), back_inserter (subtitles));
}
}
}
void
-Player::image_subtitle_start (weak_ptr<Piece> wp, ContentImageSubtitle subtitle)
+Player::bitmap_text_start (weak_ptr<Piece> wp, ContentBitmapText subtitle)
{
shared_ptr<Piece> piece = wp.lock ();
if (!piece) {
}
void
-Player::text_subtitle_start (weak_ptr<Piece> wp, ContentTextSubtitle subtitle)
+Player::plain_text_start (weak_ptr<Piece> wp, ContentTextSubtitle subtitle)
{
shared_ptr<Piece> piece = wp.lock ();
if (!piece) {
void film_changed (Film::Property);
void playlist_changed ();
void playlist_content_changed (boost::weak_ptr<Content>, int, bool);
- std::list<PositionImage> transform_image_subtitles (std::list<ImageSubtitle>) const;
+ std::list<PositionImage> transform_bitmap_texts (std::list<BitmapText>) const;
Frame dcp_to_content_video (boost::shared_ptr<const Piece> piece, DCPTime t) const;
DCPTime content_video_to_dcp (boost::shared_ptr<const Piece> piece, Frame f) const;
Frame dcp_to_resampled_audio (boost::shared_ptr<const Piece> piece, DCPTime t) const;
boost::shared_ptr<PlayerVideo> black_player_video_frame (Eyes eyes) const;
void video (boost::weak_ptr<Piece>, ContentVideo);
void audio (boost::weak_ptr<Piece>, AudioStreamPtr, ContentAudio);
- void image_subtitle_start (boost::weak_ptr<Piece>, ContentImageSubtitle);
- void text_subtitle_start (boost::weak_ptr<Piece>, ContentTextSubtitle);
+ void bitmap_text_start (boost::weak_ptr<Piece>, ContentBitmapText);
+ void plain_text_start (boost::weak_ptr<Piece>, ContentTextSubtitle);
void subtitle_stop (boost::weak_ptr<Piece>, ContentTime);
DCPTime one_video_frame () const;
void fill_audio (DCPTimePeriod period);
#ifndef DCPOMATIC_PLAYER_SUBTITLES_H
#define DCPOMATIC_PLAYER_SUBTITLES_H
-#include "image_subtitle.h"
+#include "bitmap_text.h"
#include "dcpomatic_time.h"
#include "subtitle_string.h"
void add_fonts (std::list<boost::shared_ptr<Font> > fonts_);
std::list<boost::shared_ptr<Font> > fonts;
- /** ImageSubtitles, with their rectangles transformed as specified by their content */
- std::list<ImageSubtitle> image;
+ /** BitmapTexts, with their rectangles transformed as specified by their content */
+ std::list<BitmapText> image;
std::list<SubtitleString> text;
};
_subtitle_asset->add (shared_ptr<dcp::Subtitle>(new dcp::SubtitleString(i)));
}
- BOOST_FOREACH (ImageSubtitle i, subs.image) {
+ BOOST_FOREACH (BitmapText i, subs.image) {
_subtitle_asset->add (
shared_ptr<dcp::Subtitle>(
new dcp::SubtitleImage(
+++ /dev/null
-/*
- Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
-
- This file is part of DCP-o-matic.
-
- DCP-o-matic is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- DCP-o-matic is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "render_subtitles.h"
-#include "types.h"
-#include "image.h"
-#include "cross.h"
-#include "font.h"
-#include "dcpomatic_assert.h"
-#include <dcp/raw_convert.h>
-#include <fontconfig/fontconfig.h>
-#include <cairomm/cairomm.h>
-#include <pangomm.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::list;
-using std::cout;
-using std::string;
-using std::min;
-using std::max;
-using std::pair;
-using std::cerr;
-using std::make_pair;
-using boost::shared_ptr;
-using boost::optional;
-using boost::algorithm::replace_all;
-
-static FcConfig* fc_config = 0;
-static list<pair<FontFiles, string> > fc_config_fonts;
-
-string
-marked_up (list<SubtitleString> subtitles, int target_height, float fade_factor)
-{
- string out;
-
- BOOST_FOREACH (SubtitleString const & i, subtitles) {
- out += "<span ";
- if (i.italic()) {
- out += "style=\"italic\" ";
- }
- if (i.bold()) {
- out += "weight=\"bold\" ";
- }
- if (i.underline()) {
- out += "underline=\"single\" ";
- }
- out += "size=\"" + dcp::raw_convert<string>(i.size_in_pixels(target_height) * 72 * 1024 / 96) + "\" ";
- /* Between 1-65535 inclusive, apparently... */
- out += "alpha=\"" + dcp::raw_convert<string>(int(floor(fade_factor * 65534)) + 1) + "\" ";
- out += "color=\"#" + i.colour().to_rgb_string() + "\">";
-
- string t = i.text();
- replace_all(t, "&", "&");
- out += t;
-
- out += "</span>";
- }
-
- return out;
-}
-
-static void
-set_source_rgba (Cairo::RefPtr<Cairo::Context> context, dcp::Colour colour, float fade_factor)
-{
- context->set_source_rgba (float(colour.r) / 255, float(colour.g) / 255, float(colour.b) / 255, fade_factor);
-}
-
-/** @param subtitles A list of subtitles that are all on the same line,
- * at the same time and with the same fade in/out.
- */
-static PositionImage
-render_line (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate)
-{
- /* XXX: this method can only handle italic / bold changes mid-line,
- nothing else yet.
- */
-
- DCPOMATIC_ASSERT (!subtitles.empty ());
-
- /* Calculate x and y scale factors. These are only used to stretch
- the font away from its normal aspect ratio.
- */
- float xscale = 1;
- float yscale = 1;
- if (fabs (subtitles.front().aspect_adjust() - 1.0) > dcp::ASPECT_ADJUST_EPSILON) {
- if (subtitles.front().aspect_adjust() < 1) {
- xscale = max (0.25f, subtitles.front().aspect_adjust ());
- yscale = 1;
- } else {
- xscale = 1;
- yscale = 1 / min (4.0f, subtitles.front().aspect_adjust ());
- }
- }
-
- /* Make an empty bitmap as wide as target and at
- least tall enough for this subtitle.
- */
-
- int largest = 0;
- BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
- largest = max (largest, i.size());
- }
- /* Basic guess on height... */
- int height = largest * target.height / (11 * 72);
- /* ...scaled... */
- height *= yscale;
- /* ...and add a bit more for luck */
- height += target.height / 11;
-
- /* FFmpeg BGRA means first byte blue, second byte green, third byte red, fourth byte alpha */
- shared_ptr<Image> image (new Image (AV_PIX_FMT_BGRA, dcp::Size (target.width, height), false));
- image->make_black ();
-
-#ifdef DCPOMATIC_HAVE_FORMAT_STRIDE_FOR_WIDTH
- Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
- image->data()[0],
- Cairo::FORMAT_ARGB32,
- image->size().width,
- image->size().height,
- /* Cairo ARGB32 means first byte blue, second byte green, third byte red, fourth byte alpha */
- Cairo::ImageSurface::format_stride_for_width (Cairo::FORMAT_ARGB32, image->size().width)
- );
-#else
- /* Centos 5 does not have Cairo::ImageSurface::format_stride_for_width, so just use width * 4
- which I hope is safe (if slow)
- */
- Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
- image->data()[0],
- Cairo::FORMAT_ARGB32,
- image->size().width,
- image->size().height,
- image->size().width * 4
- );
-#endif
-
- Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (surface);
-
- if (!fc_config) {
- fc_config = FcConfigCreate ();
- }
-
- FontFiles font_files;
-
- try {
- font_files.set (FontFiles::NORMAL, shared_path () / "LiberationSans-Regular.ttf");
- font_files.set (FontFiles::ITALIC, shared_path () / "LiberationSans-Italic.ttf");
- font_files.set (FontFiles::BOLD, shared_path () / "LiberationSans-Bold.ttf");
- } catch (boost::filesystem::filesystem_error& e) {
-
- }
-
- /* Hack: try the debian/ubuntu locations if getting the shared path failed */
-
- if (!font_files.get(FontFiles::NORMAL) || !boost::filesystem::exists(font_files.get(FontFiles::NORMAL).get())) {
- font_files.set (FontFiles::NORMAL, "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf");
- }
- if (!font_files.get(FontFiles::ITALIC) || !boost::filesystem::exists(font_files.get(FontFiles::ITALIC).get())) {
- font_files.set (FontFiles::ITALIC, "/usr/share/fonts/truetype/liberation/LiberationSans-Italic.ttf");
- }
- if (!font_files.get(FontFiles::BOLD) || !boost::filesystem::exists(font_files.get(FontFiles::BOLD).get())) {
- font_files.set (FontFiles::BOLD, "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf");
- }
-
- BOOST_FOREACH (shared_ptr<Font> i, fonts) {
- if (i->id() == subtitles.front().font() && i->file(FontFiles::NORMAL)) {
- font_files = i->files ();
- }
- }
-
- list<pair<FontFiles, string> >::const_iterator existing = fc_config_fonts.begin ();
- while (existing != fc_config_fonts.end() && existing->first != font_files) {
- ++existing;
- }
-
- string font_name;
- if (existing != fc_config_fonts.end ()) {
- font_name = existing->second;
- } else {
- /* Make this font available to DCP-o-matic */
- for (int i = 0; i < FontFiles::VARIANTS; ++i) {
- if (font_files.get(static_cast<FontFiles::Variant>(i))) {
- FcConfigAppFontAddFile (
- fc_config,
- reinterpret_cast<FcChar8 const *> (font_files.get(static_cast<FontFiles::Variant>(i)).get().string().c_str())
- );
- }
- }
-
- FcPattern* pattern = FcPatternBuild (
- 0, FC_FILE, FcTypeString, font_files.get(FontFiles::NORMAL).get().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_files, font_name));
- }
-
- FcConfigSetCurrent (fc_config);
-
- Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
-
- layout->set_alignment (Pango::ALIGN_LEFT);
-
- context->set_line_width (1);
- context->set_antialias (Cairo::ANTIALIAS_GRAY);
- Cairo::FontOptions fo;
- context->get_font_options (fo);
- fo.set_antialias (Cairo::ANTIALIAS_GRAY);
- context->set_font_options (fo);
-
- /* Compute fade factor */
- float fade_factor = 1;
-
- /* Round the fade start/end to the nearest frame start. Otherwise if a subtitle starts just after
- the start of a frame it will be faded out.
- */
- DCPTime const fade_in_start = DCPTime::from_seconds(subtitles.front().in().as_seconds()).round(frame_rate);
- DCPTime const fade_in_end = fade_in_start + DCPTime::from_seconds (subtitles.front().fade_up_time().as_seconds ());
- DCPTime const fade_out_end = DCPTime::from_seconds (subtitles.front().out().as_seconds()).round(frame_rate);
- DCPTime const fade_out_start = fade_out_end - DCPTime::from_seconds (subtitles.front().fade_down_time().as_seconds ());
-
- if (fade_in_start <= time && time <= fade_in_end && fade_in_start != fade_in_end) {
- fade_factor *= DCPTime(time - fade_in_start).seconds() / DCPTime(fade_in_end - fade_in_start).seconds();
- }
- if (fade_out_start <= time && time <= fade_out_end && fade_out_start != fade_out_end) {
- fade_factor *= 1 - DCPTime(time - fade_out_start).seconds() / DCPTime(fade_out_end - fade_out_start).seconds();
- }
- if (time < fade_in_start || time > fade_out_end) {
- fade_factor = 0;
- }
-
- /* Render the subtitle at the top left-hand corner of image */
-
- Pango::FontDescription font (font_name);
- layout->set_font_description (font);
- layout->set_markup (marked_up (subtitles, target.height, fade_factor));
-
- context->scale (xscale, yscale);
- layout->update_from_cairo_context (context);
-
- /* 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 = subtitles.front().effect() == dcp::BORDER ? (target.width / 600.0) : 0;
- /* Move down a bit so that accents on capital letters can be seen */
- int const y_offset = target.height / 100.0;
-
- if (subtitles.front().effect() == dcp::SHADOW) {
- /* Drop-shadow effect */
- set_source_rgba (context, subtitles.front().effect_colour(), fade_factor);
- context->move_to (x_offset + 4, y_offset + 4);
- layout->add_to_cairo_context (context);
- context->fill ();
- }
-
- if (subtitles.front().effect() == dcp::BORDER) {
- /* Border effect; stroke the subtitle with a large (arbitrarily chosen) line width */
- set_source_rgba (context, subtitles.front().effect_colour(), fade_factor);
- context->set_line_width (subtitles.front().outline_width * target.width / 2048.0);
- context->set_line_join (Cairo::LINE_JOIN_ROUND);
- context->move_to (x_offset, y_offset);
- layout->add_to_cairo_context (context);
- context->stroke ();
- }
-
- /* The actual subtitle */
-
- context->set_line_width (0);
- 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
-
- int layout_width;
- int layout_height;
- layout->get_pixel_size (layout_width, layout_height);
- layout_width *= xscale;
- layout_height *= yscale;
-
- int x = 0;
- switch (subtitles.front().h_align ()) {
- case dcp::HALIGN_LEFT:
- /* h_position is distance between left of frame and left of subtitle */
- x = subtitles.front().h_position() * target.width;
- break;
- case dcp::HALIGN_CENTER:
- /* h_position is distance between centre of frame and centre of subtitle */
- x = (0.5 + subtitles.front().h_position()) * target.width - layout_width / 2;
- break;
- case dcp::HALIGN_RIGHT:
- /* h_position is distance between right of frame and right of subtitle */
- x = (1.0 - subtitles.front().h_position()) * target.width - layout_width;
- break;
- }
-
- int y = 0;
- switch (subtitles.front().v_align ()) {
- 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
- of frame and bottom of subtitle.
- */
- y = subtitles.front().v_position() * target.height - layout_height;
- break;
- case dcp::VALIGN_CENTER:
- /* v_position is distance between centre of frame and centre of subtitle */
- y = (0.5 + subtitles.front().v_position()) * target.height - layout_height / 2;
- break;
- case dcp::VALIGN_BOTTOM:
- /* v_position is distance between bottom of frame and bottom of subtitle */
- y = (1.0 - subtitles.front().v_position()) * target.height - layout_height;
- break;
- }
-
- return PositionImage (image, Position<int> (max (0, x), max (0, y)));
-}
-
-/** @param time Time of the frame that these subtitles are going on.
- * @param frame_rate DCP frame rate.
- */
-list<PositionImage>
-render_subtitles (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate)
-{
- list<SubtitleString> pending;
- list<PositionImage> images;
-
- BOOST_FOREACH (SubtitleString const & i, subtitles) {
- if (!pending.empty() && fabs (i.v_position() - pending.back().v_position()) > 1e-4) {
- images.push_back (render_line (pending, fonts, target, time, frame_rate));
- pending.clear ();
- }
- pending.push_back (i);
- }
-
- if (!pending.empty ()) {
- images.push_back (render_line (pending, fonts, target, time, frame_rate));
- }
-
- return images;
-}
+++ /dev/null
-/*
- Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
-
- This file is part of DCP-o-matic.
-
- DCP-o-matic is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- DCP-o-matic is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "position_image.h"
-#include "dcpomatic_time.h"
-#include "subtitle_string.h"
-#include <dcp/util.h>
-
-class Font;
-
-std::string marked_up (std::list<SubtitleString> subtitles, int target_height, float fade_factor);
-std::list<PositionImage> render_subtitles (
- std::list<SubtitleString>, std::list<boost::shared_ptr<Font> > fonts, dcp::Size, DCPTime, int
- );
--- /dev/null
+/*
+ Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "render_text.h"
+#include "types.h"
+#include "image.h"
+#include "cross.h"
+#include "font.h"
+#include "dcpomatic_assert.h"
+#include <dcp/raw_convert.h>
+#include <fontconfig/fontconfig.h>
+#include <cairomm/cairomm.h>
+#include <pangomm.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::list;
+using std::cout;
+using std::string;
+using std::min;
+using std::max;
+using std::pair;
+using std::cerr;
+using std::make_pair;
+using boost::shared_ptr;
+using boost::optional;
+using boost::algorithm::replace_all;
+
+static FcConfig* fc_config = 0;
+static list<pair<FontFiles, string> > fc_config_fonts;
+
+string
+marked_up (list<SubtitleString> subtitles, int target_height, float fade_factor)
+{
+ string out;
+
+ BOOST_FOREACH (SubtitleString const & i, subtitles) {
+ out += "<span ";
+ if (i.italic()) {
+ out += "style=\"italic\" ";
+ }
+ if (i.bold()) {
+ out += "weight=\"bold\" ";
+ }
+ if (i.underline()) {
+ out += "underline=\"single\" ";
+ }
+ out += "size=\"" + dcp::raw_convert<string>(i.size_in_pixels(target_height) * 72 * 1024 / 96) + "\" ";
+ /* Between 1-65535 inclusive, apparently... */
+ out += "alpha=\"" + dcp::raw_convert<string>(int(floor(fade_factor * 65534)) + 1) + "\" ";
+ out += "color=\"#" + i.colour().to_rgb_string() + "\">";
+
+ string t = i.text();
+ replace_all(t, "&", "&");
+ out += t;
+
+ out += "</span>";
+ }
+
+ return out;
+}
+
+static void
+set_source_rgba (Cairo::RefPtr<Cairo::Context> context, dcp::Colour colour, float fade_factor)
+{
+ context->set_source_rgba (float(colour.r) / 255, float(colour.g) / 255, float(colour.b) / 255, fade_factor);
+}
+
+/** @param subtitles A list of subtitles that are all on the same line,
+ * at the same time and with the same fade in/out.
+ */
+static PositionImage
+render_line (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate)
+{
+ /* XXX: this method can only handle italic / bold changes mid-line,
+ nothing else yet.
+ */
+
+ DCPOMATIC_ASSERT (!subtitles.empty ());
+
+ /* Calculate x and y scale factors. These are only used to stretch
+ the font away from its normal aspect ratio.
+ */
+ float xscale = 1;
+ float yscale = 1;
+ if (fabs (subtitles.front().aspect_adjust() - 1.0) > dcp::ASPECT_ADJUST_EPSILON) {
+ if (subtitles.front().aspect_adjust() < 1) {
+ xscale = max (0.25f, subtitles.front().aspect_adjust ());
+ yscale = 1;
+ } else {
+ xscale = 1;
+ yscale = 1 / min (4.0f, subtitles.front().aspect_adjust ());
+ }
+ }
+
+ /* Make an empty bitmap as wide as target and at
+ least tall enough for this subtitle.
+ */
+
+ int largest = 0;
+ BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
+ largest = max (largest, i.size());
+ }
+ /* Basic guess on height... */
+ int height = largest * target.height / (11 * 72);
+ /* ...scaled... */
+ height *= yscale;
+ /* ...and add a bit more for luck */
+ height += target.height / 11;
+
+ /* FFmpeg BGRA means first byte blue, second byte green, third byte red, fourth byte alpha */
+ shared_ptr<Image> image (new Image (AV_PIX_FMT_BGRA, dcp::Size (target.width, height), false));
+ image->make_black ();
+
+#ifdef DCPOMATIC_HAVE_FORMAT_STRIDE_FOR_WIDTH
+ Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
+ image->data()[0],
+ Cairo::FORMAT_ARGB32,
+ image->size().width,
+ image->size().height,
+ /* Cairo ARGB32 means first byte blue, second byte green, third byte red, fourth byte alpha */
+ Cairo::ImageSurface::format_stride_for_width (Cairo::FORMAT_ARGB32, image->size().width)
+ );
+#else
+ /* Centos 5 does not have Cairo::ImageSurface::format_stride_for_width, so just use width * 4
+ which I hope is safe (if slow)
+ */
+ Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
+ image->data()[0],
+ Cairo::FORMAT_ARGB32,
+ image->size().width,
+ image->size().height,
+ image->size().width * 4
+ );
+#endif
+
+ Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (surface);
+
+ if (!fc_config) {
+ fc_config = FcConfigCreate ();
+ }
+
+ FontFiles font_files;
+
+ try {
+ font_files.set (FontFiles::NORMAL, shared_path () / "LiberationSans-Regular.ttf");
+ font_files.set (FontFiles::ITALIC, shared_path () / "LiberationSans-Italic.ttf");
+ font_files.set (FontFiles::BOLD, shared_path () / "LiberationSans-Bold.ttf");
+ } catch (boost::filesystem::filesystem_error& e) {
+
+ }
+
+ /* Hack: try the debian/ubuntu locations if getting the shared path failed */
+
+ if (!font_files.get(FontFiles::NORMAL) || !boost::filesystem::exists(font_files.get(FontFiles::NORMAL).get())) {
+ font_files.set (FontFiles::NORMAL, "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf");
+ }
+ if (!font_files.get(FontFiles::ITALIC) || !boost::filesystem::exists(font_files.get(FontFiles::ITALIC).get())) {
+ font_files.set (FontFiles::ITALIC, "/usr/share/fonts/truetype/liberation/LiberationSans-Italic.ttf");
+ }
+ if (!font_files.get(FontFiles::BOLD) || !boost::filesystem::exists(font_files.get(FontFiles::BOLD).get())) {
+ font_files.set (FontFiles::BOLD, "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf");
+ }
+
+ BOOST_FOREACH (shared_ptr<Font> i, fonts) {
+ if (i->id() == subtitles.front().font() && i->file(FontFiles::NORMAL)) {
+ font_files = i->files ();
+ }
+ }
+
+ list<pair<FontFiles, string> >::const_iterator existing = fc_config_fonts.begin ();
+ while (existing != fc_config_fonts.end() && existing->first != font_files) {
+ ++existing;
+ }
+
+ string font_name;
+ if (existing != fc_config_fonts.end ()) {
+ font_name = existing->second;
+ } else {
+ /* Make this font available to DCP-o-matic */
+ for (int i = 0; i < FontFiles::VARIANTS; ++i) {
+ if (font_files.get(static_cast<FontFiles::Variant>(i))) {
+ FcConfigAppFontAddFile (
+ fc_config,
+ reinterpret_cast<FcChar8 const *> (font_files.get(static_cast<FontFiles::Variant>(i)).get().string().c_str())
+ );
+ }
+ }
+
+ FcPattern* pattern = FcPatternBuild (
+ 0, FC_FILE, FcTypeString, font_files.get(FontFiles::NORMAL).get().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_files, font_name));
+ }
+
+ FcConfigSetCurrent (fc_config);
+
+ Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
+
+ layout->set_alignment (Pango::ALIGN_LEFT);
+
+ context->set_line_width (1);
+ context->set_antialias (Cairo::ANTIALIAS_GRAY);
+ Cairo::FontOptions fo;
+ context->get_font_options (fo);
+ fo.set_antialias (Cairo::ANTIALIAS_GRAY);
+ context->set_font_options (fo);
+
+ /* Compute fade factor */
+ float fade_factor = 1;
+
+ /* Round the fade start/end to the nearest frame start. Otherwise if a subtitle starts just after
+ the start of a frame it will be faded out.
+ */
+ DCPTime const fade_in_start = DCPTime::from_seconds(subtitles.front().in().as_seconds()).round(frame_rate);
+ DCPTime const fade_in_end = fade_in_start + DCPTime::from_seconds (subtitles.front().fade_up_time().as_seconds ());
+ DCPTime const fade_out_end = DCPTime::from_seconds (subtitles.front().out().as_seconds()).round(frame_rate);
+ DCPTime const fade_out_start = fade_out_end - DCPTime::from_seconds (subtitles.front().fade_down_time().as_seconds ());
+
+ if (fade_in_start <= time && time <= fade_in_end && fade_in_start != fade_in_end) {
+ fade_factor *= DCPTime(time - fade_in_start).seconds() / DCPTime(fade_in_end - fade_in_start).seconds();
+ }
+ if (fade_out_start <= time && time <= fade_out_end && fade_out_start != fade_out_end) {
+ fade_factor *= 1 - DCPTime(time - fade_out_start).seconds() / DCPTime(fade_out_end - fade_out_start).seconds();
+ }
+ if (time < fade_in_start || time > fade_out_end) {
+ fade_factor = 0;
+ }
+
+ /* Render the subtitle at the top left-hand corner of image */
+
+ Pango::FontDescription font (font_name);
+ layout->set_font_description (font);
+ layout->set_markup (marked_up (subtitles, target.height, fade_factor));
+
+ context->scale (xscale, yscale);
+ layout->update_from_cairo_context (context);
+
+ /* 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 = subtitles.front().effect() == dcp::BORDER ? (target.width / 600.0) : 0;
+ /* Move down a bit so that accents on capital letters can be seen */
+ int const y_offset = target.height / 100.0;
+
+ if (subtitles.front().effect() == dcp::SHADOW) {
+ /* Drop-shadow effect */
+ set_source_rgba (context, subtitles.front().effect_colour(), fade_factor);
+ context->move_to (x_offset + 4, y_offset + 4);
+ layout->add_to_cairo_context (context);
+ context->fill ();
+ }
+
+ if (subtitles.front().effect() == dcp::BORDER) {
+ /* Border effect; stroke the subtitle with a large (arbitrarily chosen) line width */
+ set_source_rgba (context, subtitles.front().effect_colour(), fade_factor);
+ context->set_line_width (subtitles.front().outline_width * target.width / 2048.0);
+ context->set_line_join (Cairo::LINE_JOIN_ROUND);
+ context->move_to (x_offset, y_offset);
+ layout->add_to_cairo_context (context);
+ context->stroke ();
+ }
+
+ /* The actual subtitle */
+
+ context->set_line_width (0);
+ 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
+
+ int layout_width;
+ int layout_height;
+ layout->get_pixel_size (layout_width, layout_height);
+ layout_width *= xscale;
+ layout_height *= yscale;
+
+ int x = 0;
+ switch (subtitles.front().h_align ()) {
+ case dcp::HALIGN_LEFT:
+ /* h_position is distance between left of frame and left of subtitle */
+ x = subtitles.front().h_position() * target.width;
+ break;
+ case dcp::HALIGN_CENTER:
+ /* h_position is distance between centre of frame and centre of subtitle */
+ x = (0.5 + subtitles.front().h_position()) * target.width - layout_width / 2;
+ break;
+ case dcp::HALIGN_RIGHT:
+ /* h_position is distance between right of frame and right of subtitle */
+ x = (1.0 - subtitles.front().h_position()) * target.width - layout_width;
+ break;
+ }
+
+ int y = 0;
+ switch (subtitles.front().v_align ()) {
+ 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
+ of frame and bottom of subtitle.
+ */
+ y = subtitles.front().v_position() * target.height - layout_height;
+ break;
+ case dcp::VALIGN_CENTER:
+ /* v_position is distance between centre of frame and centre of subtitle */
+ y = (0.5 + subtitles.front().v_position()) * target.height - layout_height / 2;
+ break;
+ case dcp::VALIGN_BOTTOM:
+ /* v_position is distance between bottom of frame and bottom of subtitle */
+ y = (1.0 - subtitles.front().v_position()) * target.height - layout_height;
+ break;
+ }
+
+ return PositionImage (image, Position<int> (max (0, x), max (0, y)));
+}
+
+/** @param time Time of the frame that these subtitles are going on.
+ * @param frame_rate DCP frame rate.
+ */
+list<PositionImage>
+render_text (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time, int frame_rate)
+{
+ list<SubtitleString> pending;
+ list<PositionImage> images;
+
+ BOOST_FOREACH (SubtitleString const & i, subtitles) {
+ if (!pending.empty() && fabs (i.v_position() - pending.back().v_position()) > 1e-4) {
+ images.push_back (render_line (pending, fonts, target, time, frame_rate));
+ pending.clear ();
+ }
+ pending.push_back (i);
+ }
+
+ if (!pending.empty ()) {
+ images.push_back (render_line (pending, fonts, target, time, frame_rate));
+ }
+
+ return images;
+}
--- /dev/null
+/*
+ Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "position_image.h"
+#include "dcpomatic_time.h"
+#include "subtitle_string.h"
+#include <dcp/util.h>
+
+class Font;
+
+std::string marked_up (std::list<SubtitleString> subtitles, int target_height, float fade_factor);
+std::list<PositionImage> render_text (
+ std::list<SubtitleString>, std::list<boost::shared_ptr<Font> > fonts, dcp::Size, DCPTime, int
+ );
* of the video frame)
*/
void
-TextDecoder::emit_image_start (ContentTime from, shared_ptr<Image> image, dcpomatic::Rect<double> rect)
+TextDecoder::emit_bitmap_start (ContentTime from, shared_ptr<Image> image, dcpomatic::Rect<double> rect)
{
- ImageStart (ContentImageSubtitle (from, image, rect));
+ BitmapStart (ContentBitmapText (from, image, rect));
_position = from;
}
void
-TextDecoder::emit_text_start (ContentTime from, list<dcp::SubtitleString> s)
+TextDecoder::emit_plain_start (ContentTime from, list<dcp::SubtitleString> s)
{
BOOST_FOREACH (dcp::SubtitleString& i, s) {
/* We must escape < and > in strings, otherwise they might confuse our subtitle
}
}
- TextStart (ContentTextSubtitle (from, s));
+ PlainStart (ContentTextSubtitle (from, s));
_position = from;
}
void
-TextDecoder::emit_text_start (ContentTime from, sub::Subtitle const & subtitle)
+TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle)
{
/* See if our next subtitle needs to be vertically placed on screen by us */
bool needs_placement = false;
/* The idea here (rightly or wrongly) is that we set the appearance based on the
values in the libsub objects, and these are overridden with values from the
- content by the other emit_text_start() above.
+ content by the other emit_plain_start() above.
*/
out.push_back (
}
}
- emit_text_start (from, out);
+ emit_plain_start (from, out);
}
void
}
void
-TextDecoder::emit_text (ContentTimePeriod period, list<dcp::SubtitleString> s)
+TextDecoder::emit_plain (ContentTimePeriod period, list<dcp::SubtitleString> s)
{
- emit_text_start (period.from, s);
+ emit_plain_start (period.from, s);
emit_stop (period.to);
}
void
-TextDecoder::emit_text (ContentTimePeriod period, sub::Subtitle const & s)
+TextDecoder::emit_plain (ContentTimePeriod period, sub::Subtitle const & s)
{
- emit_text_start (period.from, s);
+ emit_plain_start (period.from, s);
emit_stop (period.to);
}
return _position;
}
- void emit_image_start (ContentTime from, boost::shared_ptr<Image> image, dcpomatic::Rect<double> rect);
- void emit_text_start (ContentTime from, std::list<dcp::SubtitleString> s);
- void emit_text_start (ContentTime from, sub::Subtitle const & subtitle);
- void emit_text (ContentTimePeriod period, std::list<dcp::SubtitleString> s);
- void emit_text (ContentTimePeriod period, sub::Subtitle const & subtitle);
+ void emit_bitmap_start (ContentTime from, boost::shared_ptr<Image> image, dcpomatic::Rect<double> rect);
+ void emit_plain_start (ContentTime from, std::list<dcp::SubtitleString> s);
+ void emit_plain_start (ContentTime from, sub::Subtitle const & subtitle);
+ void emit_plain (ContentTimePeriod period, std::list<dcp::SubtitleString> s);
+ void emit_plain (ContentTimePeriod period, sub::Subtitle const & subtitle);
void emit_stop (ContentTime to);
void seek ();
return _content;
}
- boost::signals2::signal<void (ContentImageSubtitle)> ImageStart;
- boost::signals2::signal<void (ContentTextSubtitle)> TextStart;
+ boost::signals2::signal<void (ContentBitmapText)> BitmapStart;
+ boost::signals2::signal<void (ContentTextSubtitle)> PlainStart;
boost::signals2::signal<void (ContentTime)> Stop;
private:
}
ContentTimePeriod const p = content_time_period (_subtitles[_next]);
- subtitle->emit_text (p, _subtitles[_next]);
+ subtitle->emit_plain (p, _subtitles[_next]);
++_next;
return false;
+++ /dev/null
-/*
- Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
-
- This file is part of DCP-o-matic.
-
- DCP-o-matic is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- DCP-o-matic is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "text_subtitle.h"
-#include "cross.h"
-#include "exceptions.h"
-#include "plain_text_content.h"
-#include <sub/subrip_reader.h>
-#include <sub/ssa_reader.h>
-#include <sub/collect.h>
-#include <unicode/ucsdet.h>
-#include <unicode/ucnv.h>
-#include <iostream>
-
-#include "i18n.h"
-
-using std::vector;
-using std::cout;
-using std::string;
-using boost::shared_ptr;
-using boost::scoped_array;
-using boost::optional;
-using dcp::Data;
-
-TextSubtitle::TextSubtitle (shared_ptr<const PlainText> content)
-{
- Data in (content->path (0));
-
- UErrorCode status = U_ZERO_ERROR;
- UCharsetDetector* detector = ucsdet_open (&status);
- ucsdet_setText (detector, reinterpret_cast<const char *> (in.data().get()), in.size(), &status);
-
- UCharsetMatch const * match = ucsdet_detect (detector, &status);
- char const * in_charset = ucsdet_getName (match, &status);
-
- UConverter* to_utf16 = ucnv_open (in_charset, &status);
- /* This is a guess; I think we should be able to encode any input in 4 times its input size */
- scoped_array<uint16_t> utf16 (new uint16_t[in.size() * 2]);
- int const utf16_len = ucnv_toUChars (
- to_utf16, reinterpret_cast<UChar*>(utf16.get()), in.size() * 2,
- reinterpret_cast<const char *> (in.data().get()), in.size(),
- &status
- );
-
- UConverter* to_utf8 = ucnv_open ("UTF-8", &status);
- /* Another guess */
- scoped_array<char> utf8 (new char[utf16_len * 2]);
- ucnv_fromUChars (to_utf8, utf8.get(), utf16_len * 2, reinterpret_cast<UChar*>(utf16.get()), utf16_len, &status);
-
- /* Fix OS X line endings */
- size_t utf8_len = strlen (utf8.get ());
- for (size_t i = 0; i < utf8_len; ++i) {
- if (utf8[i] == '\r' && ((i == utf8_len - 1) || utf8[i + 1] != '\n')) {
- utf8[i] = '\n';
- }
- }
-
- ucsdet_close (detector);
- ucnv_close (to_utf16);
- ucnv_close (to_utf8);
-
- sub::Reader* reader = 0;
-
- string ext = content->path(0).extension().string();
- transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
-
- if (ext == ".srt") {
- reader = new sub::SubripReader (utf8.get());
- } else if (ext == ".ssa" || ext == ".ass") {
- reader = new sub::SSAReader (utf8.get());
- }
-
- if (reader) {
- _subtitles = sub::collect<vector<sub::Subtitle> > (reader->subtitles ());
- }
-
- delete reader;
-}
-
-/** @return time of first subtitle, if there is one */
-optional<ContentTime>
-TextSubtitle::first () const
-{
- if (_subtitles.empty()) {
- return optional<ContentTime>();
- }
-
- return ContentTime::from_seconds(_subtitles[0].from.all_as_seconds());
-}
-
-ContentTime
-TextSubtitle::length () const
-{
- if (_subtitles.empty ()) {
- return ContentTime ();
- }
-
- return ContentTime::from_seconds (_subtitles.back().to.all_as_seconds ());
-}
+++ /dev/null
-/*
- Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
-
- This file is part of DCP-o-matic.
-
- DCP-o-matic is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- DCP-o-matic is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef DCPOMATIC_TEXT_SUBTITLE_H
-#define DCPOMATIC_TEXT_SUBTITLE_H
-
-#include "dcpomatic_time.h"
-#include <sub/subtitle.h>
-#include <boost/shared_ptr.hpp>
-#include <vector>
-
-class PlainText;
-class text_subtitle_time_test;
-class text_subtitle_coordinate_test;
-class plain_text_content_test;
-class text_subtitle_parse_test;
-
-class TextSubtitle
-{
-public:
- explicit TextSubtitle (boost::shared_ptr<const PlainText>);
-
- boost::optional<ContentTime> first () const;
- ContentTime length () const;
-
-protected:
- std::vector<sub::Subtitle> _subtitles;
-};
-
-#endif
ratio.cc
raw_image_proxy.cc
reel_writer.cc
- render_subtitles.cc
+ render_text.cc
resampler.cc
rgba.cc
scoped_temporary.cc
string_log_entry.cc
text_content.cc
text_decoder.cc
- text_subtitle.cc
+ plain_text.cc
plain_text_content.cc
plain_text_decoder.cc
timer.cc
#include "lib/log.h"
#include "lib/compose.hpp"
#include "lib/plain_text_content.h"
-#include "lib/text_subtitle.h"
+#include "lib/plain_text.h"
#include <wx/wx.h>
#include <wx/notebook.h>
#include <wx/listctrl.h>
_subs = 0;
_frc = film->active_frame_rate_change (content->position());
- decoder->subtitle->TextStart.connect (bind (&SubtitleView::data_start, this, _1));
+ decoder->subtitle->PlainStart.connect (bind (&SubtitleView::data_start, this, _1));
decoder->subtitle->Stop.connect (bind (&SubtitleView::data_stop, this, _1));
while (!decoder->pass ()) {}
SetSizerAndFit (sizer);
BOOST_REQUIRE (!wait_for_jobs ());
shared_ptr<DCPDecoder> decoder (new DCPDecoder (content, film->log(), false));
- decoder->subtitle->TextStart.connect (bind (store, _1));
+ decoder->subtitle->PlainStart.connect (bind (store, _1));
stored = optional<ContentTextSubtitle> ();
while (!decoder->pass() && !stored) {}
BOOST_REQUIRE (!wait_for_jobs ());
shared_ptr<DCPTextDecoder> decoder (new DCPTextDecoder (content, film->log()));
- decoder->subtitle->TextStart.connect (bind (store, _1));
+ decoder->subtitle->PlainStart.connect (bind (store, _1));
stored = optional<ContentTextSubtitle> ();
while (!decoder->pass ()) {
shared_ptr<DCPTextDecoder> decoder (new DCPTextDecoder (content, film->log()));
stored = optional<ContentTextSubtitle> ();
while (!decoder->pass ()) {
- decoder->subtitle->TextStart.connect (bind (store, _1));
+ decoder->subtitle->PlainStart.connect (bind (store, _1));
if (stored && stored->from() == ContentTime::from_seconds(0.08)) {
list<dcp::SubtitleString> s = stored->subs;
list<dcp::SubtitleString>::const_iterator i = s.begin ();
*/
-/** @file test/render_subtitles_test.cc
+/** @file test/render_text_test.cc
* @brief Check markup of subtitles for rendering.
* @ingroup specific
*/
-#include "lib/render_subtitles.h"
+#include "lib/render_text.h"
#include <dcp/subtitle_string.h>
#include <boost/test/unit_test.hpp>
);
}
-/** Test marked_up() in render_subtitles.cc */
+/** Test marked_up() in render_text.cc */
BOOST_AUTO_TEST_CASE (render_markup_test1)
{
std::list<SubtitleString> s;
BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
}
-/** Test marked_up() in render_subtitles.cc */
+/** Test marked_up() in render_text.cc */
BOOST_AUTO_TEST_CASE (render_markup_test2)
{
std::list<SubtitleString> s;
}
-/** Test marked_up() in render_subtitles.cc */
+/** Test marked_up() in render_text.cc */
BOOST_AUTO_TEST_CASE (render_markup_test3)
{
std::list<SubtitleString> s;
BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span style=\"italic\" weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
}
-/** Test marked_up() in render_subtitles.cc */
+/** Test marked_up() in render_text.cc */
BOOST_AUTO_TEST_CASE (render_markup_test4)
{
std::list<SubtitleString> s;
BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span style=\"italic\" weight=\"bold\" underline=\"single\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
}
-/** Test marked_up() in render_subtitles.cc */
+/** Test marked_up() in render_text.cc */
BOOST_AUTO_TEST_CASE (render_markup_test5)
{
std::list<SubtitleString> s;
BOOST_CHECK_EQUAL (marked_up (s, 1024, 1), "<span weight=\"bold\" size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span><span size=\"41472\" alpha=\"65535\" color=\"#FFFFFF\"> world.</span>");
}
-/** Test marked_up() in render_subtitles.cc */
+/** Test marked_up() in render_text.cc */
BOOST_AUTO_TEST_CASE (render_markup_test6)
{
std::list<SubtitleString> s;
BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471));
shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (content));
- list<ContentTextSubtitle> cts = decoder->get_text_subtitles (
+ list<ContentTextSubtitle> cts = decoder->get_plain_texts (
ContentTimePeriod (
ContentTime::from_seconds (109), ContentTime::from_seconds (110)
), false
);
BOOST_CHECK_EQUAL (cts.size(), 1);
- PositionImage image = render_subtitles (cts.front().subs, dcp::Size (1998, 1080));
+ PositionImage image = render_text (cts.front().subs, dcp::Size (1998, 1080));
write_image (image.image, "build/test/subrip_render_test.png");
check_file ("build/test/subrip_render_test.png", "test/data/subrip_render_test.png");
}
#include "lib/content.h"
#include "lib/film.h"
#include "lib/content_factory.h"
-#include "lib/text_subtitle.h"
+#include "lib/plain_text.h"
#include "lib/plain_text_content.h"
#include <boost/test/unit_test.hpp>