Various bits related to subtitle font handling, particularly copying fonts to the...
authorCarl Hetherington <cth@carlh.net>
Thu, 30 Apr 2015 21:20:57 +0000 (22:20 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 30 Apr 2015 21:20:57 +0000 (22:20 +0100)
16 files changed:
ChangeLog
LiberationSans-Regular.ttf [new file with mode: 0644]
platform/osx/make_dmg.sh
platform/windows/wscript
src/lib/cross.cc
src/lib/cross.h
src/lib/dcp_subtitle_content.cc
src/lib/font.h
src/lib/util.cc
src/lib/writer.cc
src/lib/writer.h
src/tools/dcpomatic_server.cc
src/wx/wx_util.cc
test/srt_subtitle_test.cc [new file with mode: 0644]
test/wscript
wscript

index 88dde9c02bee9213c05ddbd741c1691c70bff963..9b736b1f9f2f36038aa6331d0a8fb8f734e6943a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-04-30  Carl Hetherington  <cth@carlh.net>
+
+       * Copy subtitle fonts to the DCP, and provide
+       LiberationSans-Regular as a default Arial equivalent.
+
 2015-04-29  Carl Hetherington  <cth@carlh.net>
 
        * Make disk space check take account of whether hard links
diff --git a/LiberationSans-Regular.ttf b/LiberationSans-Regular.ttf
new file mode 100644 (file)
index 0000000..626dd93
Binary files /dev/null and b/LiberationSans-Regular.ttf differ
index 4e46606bdb94e3e6dd937d17ed57d95e259a8556..e9727476639e10bc6243777ec3fbd03ca98d66f0 100644 (file)
@@ -137,6 +137,7 @@ cp $ROOT/32/src/dcpomatic/icons/kdm_email.png "$WORK/$resources"
 cp $ROOT/32/src/dcpomatic/icons/servers.png "$WORK/$resources"
 cp $ROOT/32/src/dcpomatic/icons/tms.png "$WORK/$resources"
 cp $ROOT/32/src/dcpomatic/icons/keys.png "$WORK/$resources"
+cp $ROOT/32/src/dcpomatic/LiberationSans-Regular.ttf "$WORK/$resources"
 
 # i18n: DCP-o-matic .mo files
 for lang in de_DE es_ES fr_FR it_IT sv_SE nl_NL; do
index 8d48bd707e388d52ddc8b46609878244e46ec53f..efe250e10ab480aec4bccc04392f820ebe438f2c 100644 (file)
@@ -191,6 +191,9 @@ File "%binaries%/src/lib/mo/nl_NL/libdcpomatic2.mo"
 File "%binaries%/src/wx/mo/nl_NL/libdcpomatic2-wx.mo"
 File "%binaries%/src/tools/mo/nl_NL/dcpomatic2.mo"
 File "%static_deps%/share/locale/nl/LC_MESSAGES/wxstd.mo"
+
+SetOutPath "$INSTDIR"
+File "%resources%/../../LiberationSans-Regular.ttf"
     """, file=f)
 
     if debug:
index e189222faeb94c031bb0a6a9d55744766de0aafe..7f95d1f71885fd07f172d53ddc3c1e928335005e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -151,6 +151,23 @@ app_contents ()
 }
 #endif
 
+boost::filesystem::path
+shared_path ()
+{
+#ifdef DCPOMATIC_LINUX
+       return boost::filesystem::canonical (LINUX_SHARE_PREFIX);
+#endif
+#ifdef DCPOMATIC_WINDOWS
+       wchar_t dir[512];
+       GetModuleFileName (GetModuleHandle (0), dir, sizeof (dir));
+       PathRemoveFileSpec (dir);
+       return dir.parent_path();
+#endif
+#ifdef DCPOMATIC_OSX
+       return app_contents();
+#endif 
+}
+
 void
 run_ffprobe (boost::filesystem::path content, boost::filesystem::path out, shared_ptr<Log> log)
 {
index 6a77aaa18d8127e972c261d7c7ce200baa3e5008..fee68cedc6f05bf220d11b7b1307f43ed16e9b48 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -43,6 +43,7 @@ extern boost::filesystem::path openssl_path ();
 #ifdef DCPOMATIC_OSX
 extern boost::filesystem::path app_contents ();
 #endif
+extern boost::filesystem::path shared_path ();
 extern FILE * fopen_boost (boost::filesystem::path, std::string);
 extern int dcpomatic_fseek (FILE *, int64_t, int);
 
index f3198c58d2b918adfd1c5f8d0282395579a6d5d7..3f9772d597de3b6464fe6b888a3f0be821d503d6 100644 (file)
@@ -22,7 +22,8 @@
 #include "raw_convert.h"
 #include <dcp/interop_subtitle_content.h>
 #include <dcp/smpte_subtitle_content.h>
-#include <dcp/interop_load_font.h>
+#include <dcp/interop_load_font_node.h>
+#include <boost/foreach.hpp>
 
 #include "i18n.h"
 
@@ -57,9 +58,8 @@ DCPSubtitleContent::examine (shared_ptr<Job> job)
        _subtitle_language = sc->language ();
        _length = DCPTime::from_seconds (sc->latest_subtitle_out().to_seconds ());
 
-       list<shared_ptr<dcp::LoadFont> > fonts = sc->load_font_nodes ();
-       for (list<shared_ptr<dcp::LoadFont> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
-               _fonts.push_back (shared_ptr<Font> (new Font ((*i)->id)));
+       BOOST_FOREACH (shared_ptr<dcp::LoadFontNode> i, sc->load_font_nodes ()) {
+               _fonts.push_back (shared_ptr<Font> (new Font (i->id)));
        }
 }
 
index 7009555c44a1b297fdee256fa00159ea570588fb..8021ab5bc662e59bc918a48fdf3bea18631637cd 100644 (file)
@@ -35,7 +35,7 @@ public:
 
        void as_xml (xmlpp::Node* node);
        
-       /** Font ID */
+       /** Font ID, used to describe it in the subtitle content */
        std::string id;
        boost::optional<boost::filesystem::path> file;
 };
index 1c99682063ff76d19279d0f8c73e0a6c5d7aa7cc..f98e5960bb20e807f8bf2c9df0c0594a38f54926 100644 (file)
@@ -381,7 +381,7 @@ dcpomatic_setup_gettext_i18n (string lang)
 #endif 
 
 #ifdef DCPOMATIC_LINUX
-       bindtextdomain ("libdcpomatic", POSIX_LOCALE_PREFIX);
+       bindtextdomain ("libdcpomatic", LINUX_LOCALE_PREFIX);
 #endif
 }
 
index 8d73b31267a368f768598a9e3e5ab1343f024bef..9f6886a2103e4709a0883f315bdb81266c606d92 100644 (file)
@@ -46,6 +46,8 @@
 #include <dcp/cpl.h>
 #include <dcp/signer.h>
 #include <dcp/interop_subtitle_content.h>
+#include <dcp/font.h>
+#include <boost/foreach.hpp>
 #include <fstream>
 #include <cerrno>
 
@@ -514,6 +516,24 @@ Writer::finish ()
                                   ));
                
                dcp.add (_subtitle_content);
+
+               boost::filesystem::path const liberation = shared_path () / "LiberationSans-Regular.ttf";
+
+               /* Add all the fonts to the subtitle content and as assets to the DCP */
+               BOOST_FOREACH (shared_ptr<Font> i, _fonts) {
+                       boost::filesystem::path const from = i->file.get_value_or (liberation);
+                       _subtitle_content->add_font (i->id, from.leaf().string ());
+
+                       boost::filesystem::path to = _film->dir (_film->dcp_name ()) / from.leaf();
+
+                       boost::system::error_code ec;
+                       boost::filesystem::copy_file (from, to, ec);
+                       if (!ec) {
+                               dcp.add (shared_ptr<dcp::Font> (new dcp::Font (to)));
+                       } else {
+                               LOG_WARNING_NC (String::compose ("Could not copy font %1 to DCP", from.string ()));
+                       }
+               }
        }
        
        cpl->add (reel);
@@ -654,18 +674,8 @@ Writer::write (PlayerSubtitles subs)
 void
 Writer::write (list<shared_ptr<Font> > fonts)
 {
-       if (fonts.empty ()) {
-               return;
-       }
-       
-       if (!_subtitle_content) {
-               _subtitle_content.reset (new dcp::InteropSubtitleContent (_film->name(), _film->subtitle_language ()));
-       }
-       
-       for (list<shared_ptr<Font> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
-               /* XXX: this LiberationSans-Regular needs to be a path to a DCP-o-matic-distributed copy */
-               _subtitle_content->add_font ((*i)->id, (*i)->file.get_value_or ("LiberationSans-Regular.ttf").leaf().string ());
-       }
+       /* Just keep a list of fonts and we'll deal with them in ::finish */
+       copy (fonts.begin (), fonts.end (), back_inserter (_fonts));
 }
 
 bool
index 68ac972eec866923221185422d6f220c81afc0c0..41d4d4474bae3dde1e97e35f9d6392aeb165315b 100644 (file)
@@ -152,4 +152,6 @@ private:
        boost::shared_ptr<dcp::SoundMXF> _sound_mxf;
        boost::shared_ptr<dcp::SoundMXFWriter> _sound_mxf_writer;
        boost::shared_ptr<dcp::InteropSubtitleContent> _subtitle_content;
+
+       std::list<boost::shared_ptr<Font> > _fonts;
 };
index 9158a897ee4aa8a1fd5bd0d10f887c263a6abaa5..8107949f5a9a4950e5661c728bc57eec15c74970 100644 (file)
@@ -108,7 +108,7 @@ public:
 #endif
 #ifdef __WXGTK__
                wxInitAllImageHandlers();
-               wxBitmap bitmap (wxString::Format (wxT ("%s/taskbar_icon.png"), POSIX_ICON_PREFIX), wxBITMAP_TYPE_PNG);
+               wxBitmap bitmap (wxString::Format (wxT ("%s/taskbar_icon.png"), LINUX_SHARE_PREFIX), wxBITMAP_TYPE_PNG);
                wxIcon icon;
                icon.CopyFromBitmap (bitmap);
 #endif
index a46ba98e27a55ebbc998db346f53de2c3d8af52b..ea8255f8169a9ae7fbddf01c5e771ed1dbc7bac1 100644 (file)
@@ -272,7 +272,7 @@ dcpomatic_setup_i18n ()
 #endif         
 
 #ifdef DCPOMATIC_POSIX
-               locale->AddCatalogLookupPathPrefix (POSIX_LOCALE_PREFIX);
+               locale->AddCatalogLookupPathPrefix (LINUX_LOCALE_PREFIX);
 #endif
 
 #ifdef DCPOMATIC_LINUX
diff --git a/test/srt_subtitle_test.cc b/test/srt_subtitle_test.cc
new file mode 100644 (file)
index 0000000..4497e40
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file  test/subtitle_write_test.cc
+ *  @brief Test writing DCPs with XML subtitles.
+ */
+
+#include "lib/film.h"
+#include "lib/subrip_content.h"
+#include "lib/dcp_content_type.h"
+#include "lib/font.h"
+#include "test.h"
+#include <boost/test/unit_test.hpp>
+
+using boost::shared_ptr;
+
+/** Make a very short DCP with a single subtitle from .srt with no specified fonts */
+BOOST_AUTO_TEST_CASE (srt_subtitle_test)
+{
+       shared_ptr<Film> film = new_test_film ("srt_subtitle_test");
+       film->set_container (Ratio::from_id ("185"));
+       film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
+       film->set_name ("frobozz");
+       film->set_burn_subtitles (false);
+       shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip2.srt"));
+       film->examine_and_add_content (content);
+       wait_for_jobs ();
+
+       content->set_use_subtitles (true);
+       film->make_dcp ();
+       wait_for_jobs ();
+
+       check_dcp ("test/data/srt_subtitle_test", film->dir (film->dcp_name ()));
+}
+
+/** Same again but with a `font' specified */
+BOOST_AUTO_TEST_CASE (srt_subtitle_test2)
+{
+       shared_ptr<Film> film = new_test_film ("srt_subtitle_test2");
+       film->set_container (Ratio::from_id ("185"));
+       film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
+       film->set_name ("frobozz");
+       film->set_burn_subtitles (false);
+       shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip2.srt"));
+       film->examine_and_add_content (content);
+       wait_for_jobs ();
+
+       content->set_use_subtitles (true);
+       /* Use test/data/subrip2.srt as if it were a font file  */
+       content->fonts().front()->file = "test/data/subrip2.srt";
+       
+       film->make_dcp ();
+       wait_for_jobs ();
+
+       check_dcp ("test/data/srt_subtitle_test2", film->dir (film->dcp_name ()));
+}
+
index 16e84f2314c1765802ae036833cb5f9f788939a8..ffc93ea5edce5fee784dea3a01958061d949b34f 100644 (file)
@@ -55,6 +55,7 @@ def build(bld):
                  seek_zero_test.cc
                  silence_padding_test.cc
                  skip_frame_test.cc
+                 srt_subtitle_test.cc
                  stream_test.cc
                  test.cc
                  threed_test.cc
diff --git a/wscript b/wscript
index be7b0f985df4f141cc84042ac47e4c12b5e191dd..4da8c8877d2dc960119ef4a3cad8cf019babc942 100644 (file)
--- a/wscript
+++ b/wscript
@@ -224,8 +224,6 @@ def configure(conf):
     # POSIX
     if conf.env.TARGET_LINUX or conf.env.TARGET_OSX:
         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_POSIX')
-        conf.env.append_value('CXXFLAGS', '-DPOSIX_LOCALE_PREFIX="%s/share/locale"' % conf.env['INSTALL_PREFIX'])
-        conf.env.append_value('CXXFLAGS', '-DPOSIX_ICON_PREFIX="%s/share/dcpomatic2"' % conf.env['INSTALL_PREFIX'])
         boost_lib_suffix = ''
         boost_thread = 'boost_thread'
         conf.env.append_value('LINKFLAGS', '-pthread')
@@ -233,6 +231,8 @@ def configure(conf):
     # Linux
     if conf.env.TARGET_LINUX:
         conf.env.append_value('CXXFLAGS', '-mfpmath=sse')
+        conf.env.append_value('CXXFLAGS', '-DLINUX_LOCALE_PREFIX="%s/share/locale"' % conf.env['INSTALL_PREFIX'])
+        conf.env.append_value('CXXFLAGS', '-DLINUX_SHARE_PREFIX="%s/share/dcpomatic2"' % conf.env['INSTALL_PREFIX'])
         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_LINUX')
 
     if conf.env.TARGET_DEBIAN:
@@ -374,8 +374,9 @@ def build(bld):
     for r in ['22x22', '32x32', '48x48', '64x64', '128x128']:
         bld.install_files('${PREFIX}/share/icons/hicolor/%s/apps' % r, 'icons/%s/dcpomatic2.png' % r)
 
-    if not bld.env.TARGET_WINDOWS:
+    if bld.env.TARGET_LINUX:
         bld.install_files('${PREFIX}/share/dcpomatic2', 'icons/taskbar_icon.png')
+        bld.install_files('${PREFIX}/share/dcpomatic2', 'LiberationSans-Regular.ttf')
 
     bld.add_post_fun(post)