X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=1f6fba96302b4f9b3dc8943374860221fcc7b1cf;hb=c4403784febdbdd42e9c32e67fadb147f11fe566;hp=0b6f4be72b63c7ce1edbbc30fc06f5f33b19b5c0;hpb=6f856af55898f94b45e3be28aa4f7c962de8a398;p=dcpomatic.git diff --git a/src/lib/util.cc b/src/lib/util.cc index 0b6f4be72..1f6fba963 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington This file is part of DCP-o-matic. @@ -41,6 +41,9 @@ #include "string_text.h" #include "font.h" #include "render_text.h" +#include "ffmpeg_image_proxy.h" +#include "image.h" +#include "text_decoder.h" #include #include #include @@ -59,6 +62,7 @@ extern "C" { #include #include #include +#include #ifdef DCPOMATIC_WINDOWS #include #include @@ -77,6 +81,7 @@ extern "C" { #include "i18n.h" using std::string; +using std::wstring; using std::setfill; using std::ostream; using std::endl; @@ -101,6 +106,7 @@ using boost::scoped_array; using dcp::Size; using dcp::raw_convert; using dcp::locale_convert; +using namespace dcpomatic; /** Path to our executable, required by the stacktrace stuff and filled * in during App::onInit(). @@ -374,7 +380,7 @@ dcpomatic_setup () Pango::init (); dcp::init (); -#ifdef DCPOMATIC_WINDOWS +#if defined(DCPOMATIC_WINDOWS) || defined(DCPOMATIC_OSX) /* Render something to fontconfig to create its cache */ list subs; dcp::SubtitleString ss( @@ -740,15 +746,34 @@ careful_string_filter (string s) Safety first and all that. */ + wstring ws = boost::locale::conv::utf_to_utf(s); + string out; string const allowed = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_%.+"; - for (size_t i = 0; i < s.size(); ++i) { - if (allowed.find (s[i]) != string::npos) { - out += s[i]; + for (size_t i = 0; i < ws.size(); ++i) { + + wchar_t c = ws[i]; + + /* Remove some accents */ + if (wstring(L"áàâ").find(c) != string::npos) { + c = 'a'; + } + if (wstring(L"éèêë").find(c) != string::npos) { + c = 'e'; + } + if (wstring(L"ö").find(c) != string::npos) { + c = 'o'; + } + if (wstring(L"ü").find(c) != string::npos) { + c = 'u'; + } + + if (allowed.find(c) != string::npos) { + out += c; } } - return out; + return boost::locale::conv::utf_to_utf(out); } /** @param mapped List of mapped audio channels from a Film. @@ -881,6 +906,45 @@ day_of_week_to_string (boost::gregorian::greg_weekday d) return d.as_long_string (); } +/** @param size Size of picture that the subtitle will be overlaid onto */ +void +emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size size, shared_ptr decoder) +{ + /* XXX: this is rather inefficient; decoding the image just to get its size */ + FFmpegImageProxy proxy (sub.png_image()); + shared_ptr image = proxy.image().first; + /* set up rect with height and width */ + dcpomatic::Rect rect(0, 0, image->size().width / double(size.width), image->size().height / double(size.height)); + + /* add in position */ + + switch (sub.h_align()) { + case dcp::HALIGN_LEFT: + rect.x += sub.h_position(); + break; + case dcp::HALIGN_CENTER: + rect.x += 0.5 + sub.h_position() - rect.width / 2; + break; + case dcp::HALIGN_RIGHT: + rect.x += 1 - sub.h_position() - rect.width; + break; + } + + switch (sub.v_align()) { + case dcp::VALIGN_TOP: + rect.y += sub.v_position(); + break; + case dcp::VALIGN_CENTER: + rect.y += 0.5 + sub.v_position() - rect.height / 2; + break; + case dcp::VALIGN_BOTTOM: + rect.y += 1 - sub.v_position() - rect.height; + break; + } + + decoder->emit_bitmap (period, image, rect); +} + #ifdef DCPOMATIC_VARIANT_SWAROOP /* Make up a key from the machine UUID */