Start of Fonts dialog for setting up subtitle fonts.
authorCarl Hetherington <cth@carlh.net>
Mon, 15 Dec 2014 16:56:18 +0000 (16:56 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 15 Dec 2014 16:56:18 +0000 (16:56 +0000)
src/lib/dcp_subtitle_content.cc
src/lib/font.h [new file with mode: 0644]
src/lib/subrip_content.cc
src/lib/subtitle_content.cc
src/lib/subtitle_content.h
src/wx/fonts_dialog.cc [new file with mode: 0644]
src/wx/fonts_dialog.h [new file with mode: 0644]
src/wx/subtitle_panel.cc
src/wx/subtitle_panel.h
src/wx/subtitle_view.cc
src/wx/wscript

index 85c28d03832acbb8e2ec126175e370def41859ea..351d8c26ef8e07b958b2c2323f7a2893ede12b99 100644 (file)
 
 */
 
+#include "font.h"
 #include "dcp_subtitle_content.h"
 #include <dcp/interop_subtitle_content.h>
+#include <dcp/interop_load_font.h>
 #include <dcp/raw_convert.h>
 
 #include "i18n.h"
@@ -47,9 +49,18 @@ void
 DCPSubtitleContent::examine (shared_ptr<Job> job, bool calculate_digest)
 {
        Content::examine (job, calculate_digest);
+       
        dcp::InteropSubtitleContent sc (path (0));
+
+       boost::mutex::scoped_lock lm (_mutex);
+       
        _subtitle_language = sc.language ();
        _length = DCPTime::from_seconds (sc.latest_subtitle_out().to_seconds ());
+
+       list<shared_ptr<dcp::InteropLoadFont> > fonts = sc.load_font_nodes ();
+       for (list<shared_ptr<dcp::InteropLoadFont> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
+               _fonts.push_back (shared_ptr<Font> (new Font ((*i)->id)));
+       }
 }
 
 DCPTime
diff --git a/src/lib/font.h b/src/lib/font.h
new file mode 100644 (file)
index 0000000..59d9832
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+    Copyright (C) 2014 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.
+
+*/
+
+#include <boost/optional.hpp>
+#include <boost/filesystem.hpp>
+#include <string>
+
+class Font
+{
+public:
+       Font () {}
+       Font (std::string id_)
+               : id (id_) {}
+       
+       /** Font ID, or empty for the default font */
+       boost::optional<std::string> id;
+       boost::optional<boost::filesystem::path> file;
+};
index 7a336f88af632d3770eeed3beb3f9cd82b0915e7..969829b31e1a9075d2e7316fb1cfab2ecbaed58e 100644 (file)
@@ -21,6 +21,7 @@
 #include "util.h"
 #include "subrip.h"
 #include "film.h"
+#include "font.h"
 #include <dcp/raw_convert.h>
 
 #include "i18n.h"
@@ -59,6 +60,7 @@ SubRipContent::examine (boost::shared_ptr<Job> job, bool calculate_digest)
 
        boost::mutex::scoped_lock lm (_mutex);
        _length = len;
+       _fonts.push_back (shared_ptr<Font> (new Font ()));
 }
 
 string
index df90a4a1a2630056693bad3623de40935088c8ea..f6bceb753459032b8434973e7fe79247b73415ef 100644 (file)
@@ -39,6 +39,7 @@ int const SubtitleContentProperty::SUBTITLE_X_SCALE = 502;
 int const SubtitleContentProperty::SUBTITLE_Y_SCALE = 503;
 int const SubtitleContentProperty::USE_SUBTITLES = 504;
 int const SubtitleContentProperty::SUBTITLE_LANGUAGE = 505;
+int const SubtitleContentProperty::FONTS = 506;
 
 SubtitleContent::SubtitleContent (shared_ptr<const Film> f)
        : Content (f)
index 4cbef657ab5b18da060024ee4bd13f608e53552e..e8915fc960636ca9b0d9299613c513f3d556203d 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "content.h"
 
+class Font;
+
 class SubtitleContentProperty
 {
 public:
@@ -31,6 +33,7 @@ public:
        static int const SUBTITLE_Y_SCALE;
        static int const USE_SUBTITLES;
        static int const SUBTITLE_LANGUAGE;
+       static int const FONTS;
 };
 
 /** @class SubtitleContent
@@ -84,13 +87,20 @@ public:
                return _subtitle_y_scale;
        }
 
+       std::list<boost::shared_ptr<Font> > fonts () const {
+               boost::mutex::scoped_lock lm (_mutex);
+               return _fonts;
+       }
+
        std::string subtitle_language () const {
+               boost::mutex::scoped_lock lm (_mutex);
                return _subtitle_language;
        }
 
 protected:
        /** subtitle language (e.g. "German") or empty if it is not known */
        std::string _subtitle_language;
+       std::list<boost::shared_ptr<Font> > _fonts;
        
 private:
        friend struct ffmpeg_pts_offset_test;
diff --git a/src/wx/fonts_dialog.cc b/src/wx/fonts_dialog.cc
new file mode 100644 (file)
index 0000000..37df8f3
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+    Copyright (C) 2014 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.
+
+*/
+
+#include "lib/font.h"
+#include "lib/subtitle_content.h"
+#include "fonts_dialog.h"
+#include "wx_util.h"
+#include <wx/wx.h>
+
+using std::list;
+using boost::shared_ptr;
+
+FontsDialog::FontsDialog (wxWindow* parent, shared_ptr<SubtitleContent> content)
+       : wxDialog (parent, wxID_ANY, _("Fonts"))
+{
+       _fonts = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (400, 200), wxLC_REPORT | wxLC_SINGLE_SEL);
+
+       {
+               wxListItem ip;
+               ip.SetId (0);
+               ip.SetText (_("ID"));
+               ip.SetWidth (100);
+               _fonts->InsertColumn (0, ip);
+       }
+       
+       {
+               wxListItem ip;
+               ip.SetId (1);
+               ip.SetText (_("Font file"));
+               ip.SetWidth (300);
+               _fonts->InsertColumn (1, ip);
+       }
+
+       wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
+       sizer->Add (_fonts, 1, wxEXPAND);
+
+       {
+               wxSizer* s = new wxBoxSizer (wxVERTICAL);
+               _edit = new wxButton (this, wxID_ANY, _("Edit..."));
+               s->Add (_edit, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
+               sizer->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
+       }
+
+       wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
+       overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
+
+       wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
+       if (buttons) {
+               overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+       }
+
+       SetSizerAndFit (overall_sizer);
+
+       list<shared_ptr<Font> > fonts = content->fonts ();
+       size_t n = 0;
+       for (list<shared_ptr<Font> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
+               wxListItem item;
+               item.SetId (n);
+               _fonts->InsertItem (item);
+               _fonts->SetItem (n, 0, (*i)->id.get_value_or (wx_to_std (_("[Default]"))));
+               if ((*i)->file) {
+                       _fonts->SetItem (n, 1, (*i)->file.get().leaf().string ());
+               }
+               ++n;
+       }
+}
+
diff --git a/src/wx/fonts_dialog.h b/src/wx/fonts_dialog.h
new file mode 100644 (file)
index 0000000..32fc65f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+    Copyright (C) 2014 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.
+
+*/
+
+#include <wx/listctrl.h>
+#include <wx/wx.h>
+#include <boost/shared_ptr.hpp>
+
+class SubtitleContent;
+
+class FontsDialog : public wxDialog
+{
+public:
+       FontsDialog (wxWindow* parent, boost::shared_ptr<SubtitleContent>);
+
+private:
+       wxListCtrl* _fonts;
+       wxButton* _edit;
+};
index 3198723a5a7806cd5a2be8f6124bff6d9cce27f9..07b987a674e42fe4d0832feb34e2b3fd054ceb29 100644 (file)
@@ -30,6 +30,7 @@
 #include "wx_util.h"
 #include "subtitle_view.h"
 #include "content_panel.h"
+#include "fonts_dialog.h"
 
 using std::vector;
 using std::string;
@@ -39,7 +40,8 @@ using boost::dynamic_pointer_cast;
 
 SubtitlePanel::SubtitlePanel (ContentPanel* p)
        : ContentSubPanel (p, _("Subtitles"))
-       , _view (0)
+       , _subtitle_view (0)
+       , _fonts_dialog (0)
 {
        wxFlexGridSizer* grid = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
        _sizer->Add (grid, 0, wxALL, 8);
@@ -92,22 +94,28 @@ SubtitlePanel::SubtitlePanel (ContentPanel* p)
        _stream = new wxChoice (this, wxID_ANY);
        grid->Add (_stream, 1, wxEXPAND);
 
-       _view_button = new wxButton (this, wxID_ANY, _("View..."));
-       grid->Add (_view_button);
+       _subtitle_view_button = new wxButton (this, wxID_ANY, _("View..."));
+       grid->Add (_subtitle_view_button);
+       grid->AddSpacer (0);
+
+       _fonts_dialog_button = new wxButton (this, wxID_ANY, _("Fonts..."));
+       grid->Add (_fonts_dialog_button);
+       grid->AddSpacer (0);
        
        _x_offset->SetRange (-100, 100);
        _y_offset->SetRange (-100, 100);
        _x_scale->SetRange (10, 1000);
        _y_scale->SetRange (10, 1000);
 
-       _use->Bind         (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&SubtitlePanel::use_toggled, this));
-       _x_offset->Bind    (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::x_offset_changed, this));
-       _y_offset->Bind    (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::y_offset_changed, this));
-       _x_scale->Bind     (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::x_scale_changed, this));
-       _y_scale->Bind     (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::y_scale_changed, this));
-       _language->Bind    (wxEVT_COMMAND_TEXT_UPDATED,     boost::bind (&SubtitlePanel::language_changed, this));
-       _stream->Bind      (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&SubtitlePanel::stream_changed, this));
-       _view_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED,   boost::bind (&SubtitlePanel::view_clicked, this));
+       _use->Bind                  (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&SubtitlePanel::use_toggled, this));
+       _x_offset->Bind             (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::x_offset_changed, this));
+       _y_offset->Bind             (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::y_offset_changed, this));
+       _x_scale->Bind              (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::x_scale_changed, this));
+       _y_scale->Bind              (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::y_scale_changed, this));
+       _language->Bind             (wxEVT_COMMAND_TEXT_UPDATED,     boost::bind (&SubtitlePanel::language_changed, this));
+       _stream->Bind               (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&SubtitlePanel::stream_changed, this));
+       _subtitle_view_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED,   boost::bind (&SubtitlePanel::subtitle_view_clicked, this));
+       _fonts_dialog_button->Bind  (wxEVT_COMMAND_BUTTON_CLICKED,   boost::bind (&SubtitlePanel::fonts_dialog_clicked, this));
 }
 
 void
@@ -207,7 +215,8 @@ SubtitlePanel::setup_sensitivity ()
        _y_scale->Enable (any_subs > 0 && use);
        _language->Enable (any_subs > 0 && use);
        _stream->Enable (ffmpeg_subs == 1);
-       _view_button->Enable (subrip_or_dcp_subs == 1);
+       _subtitle_view_button->Enable (subrip_or_dcp_subs == 1);
+       _fonts_dialog_button->Enable (subrip_or_dcp_subs == 1);
 }
 
 void
@@ -287,14 +296,15 @@ SubtitlePanel::content_selection_changed ()
        film_content_changed (SubtitleContentProperty::SUBTITLE_X_SCALE);
        film_content_changed (SubtitleContentProperty::SUBTITLE_Y_SCALE);
        film_content_changed (SubtitleContentProperty::SUBTITLE_LANGUAGE);
+       film_content_changed (SubtitleContentProperty::FONTS);
 }
 
 void
-SubtitlePanel::view_clicked ()
+SubtitlePanel::subtitle_view_clicked ()
 {
-       if (_view) {
-               _view->Destroy ();
-               _view = 0;
+       if (_subtitle_view) {
+               _subtitle_view->Destroy ();
+               _subtitle_view = 0;
        }
 
        SubtitleContentList c = _parent->selected_subtitle ();
@@ -313,7 +323,22 @@ SubtitlePanel::view_clicked ()
        }
        
        if (decoder) {
-               _view = new SubtitleView (this, _parent->film(), decoder, c.front()->position ());
-               _view->Show ();
+               _subtitle_view = new SubtitleView (this, _parent->film(), decoder, c.front()->position ());
+               _subtitle_view->Show ();
+       }
+}
+
+void
+SubtitlePanel::fonts_dialog_clicked ()
+{
+       if (_fonts_dialog) {
+               _fonts_dialog->Destroy ();
+               _fonts_dialog = 0;
        }
+
+       SubtitleContentList c = _parent->selected_subtitle ();
+       assert (c.size() == 1);
+
+       _fonts_dialog = new FontsDialog (this, c.front ());
+       _fonts_dialog->Show ();
 }
index f82fb14e5bfe49ad2a224db55ef35fc59b633a3a..ef94adb5468ca959457aa5722e97e6c10ee43f09 100644 (file)
@@ -22,6 +22,7 @@
 class wxCheckBox;
 class wxSpinCtrl;
 class SubtitleView;
+class FontsDialog;
 
 class SubtitlePanel : public ContentSubPanel
 {
@@ -40,7 +41,8 @@ private:
        void y_scale_changed ();
        void language_changed ();
        void stream_changed ();
-       void view_clicked ();
+       void subtitle_view_clicked ();
+       void fonts_dialog_clicked ();
 
        void setup_sensitivity ();
        
@@ -51,6 +53,8 @@ private:
        wxSpinCtrl* _y_scale;
        wxTextCtrl* _language;
        wxChoice* _stream;
-       wxButton* _view_button;
-       SubtitleView* _view;
+       wxButton* _subtitle_view_button;
+       SubtitleView* _subtitle_view;
+       wxButton* _fonts_dialog_button;
+       FontsDialog* _fonts_dialog;
 };
index dc41db2fa51e82fd49ac5ba9c2165f7149174301..b58af3019db6357aebf9eb07901ba731ae1f9775 100644 (file)
@@ -58,7 +58,7 @@ SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<Film> film, shared_ptr<
        }
 
        wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
-       sizer->Add (_list, 1, wxEXPAND);
+       sizer->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
 
        wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
        if (buttons) {
index 38448cfb2225551ac0b354e6865e787efba813f4..10d6f4f1d20eda67b5bb99acd425c5b25b4b5622 100644 (file)
@@ -28,6 +28,7 @@ sources = """
           film_viewer.cc
           filter_dialog.cc
           filter_editor.cc
+          fonts_dialog.cc
           gain_calculator_dialog.cc
           hints_dialog.cc
           job_manager_view.cc