Remove specification of italic/bold fonts (#1451); synthesis will be used instead. v2.13.110
authorCarl Hetherington <cth@carlh.net>
Sun, 27 Jan 2019 00:25:40 +0000 (00:25 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 27 Jan 2019 00:25:40 +0000 (00:25 +0000)
13 files changed:
src/lib/font.cc
src/lib/font.h
src/lib/font_files.cc [deleted file]
src/lib/font_files.h [deleted file]
src/lib/hints.cc
src/lib/reel_writer.cc
src/lib/render_text.cc
src/lib/text_content.cc
src/lib/wscript
src/wx/font_files_dialog.h [deleted file]
src/wx/fonts_dialog.cc
src/wx/wscript
test/srt_subtitle_test.cc

index 309f3d1eb3a6eab77673d75b5d58802b9c376a6e..333539aa4b7cbc6441dbc2e5c75dae4d0f7752a3 100644 (file)
 
 using std::string;
 
-static char const * names[] = {
-       "Normal",
-       "Italic",
-       "Bold"
-};
-
 Font::Font (cxml::NodePtr node)
        : _id (node->string_child ("Id"))
 {
-       DCPOMATIC_ASSERT (FontFiles::VARIANTS == 3);
-
-       BOOST_FOREACH (cxml::NodePtr i, node->node_children ("File")) {
+       BOOST_FOREACH (cxml::NodePtr i, node->node_children("File")) {
                string variant = i->optional_string_attribute("Variant").get_value_or ("Normal");
-               for (int j = 0; j < FontFiles::VARIANTS; ++j) {
-                       if (variant == names[j]) {
-                               _files.set (static_cast<FontFiles::Variant>(j), i->content());
-                       }
+               if (variant == "Normal") {
+                       _file = i->content();
                }
        }
 }
@@ -49,15 +39,9 @@ Font::Font (cxml::NodePtr node)
 void
 Font::as_xml (xmlpp::Node* node)
 {
-       DCPOMATIC_ASSERT (FontFiles::VARIANTS == 3);
-
        node->add_child("Id")->add_child_text (_id);
-       for (int i = 0; i < FontFiles::VARIANTS; ++i) {
-               if (_files.get(static_cast<FontFiles::Variant>(i))) {
-                       xmlpp::Element* e = node->add_child ("File");
-                       e->set_attribute ("Variant", names[i]);
-                       e->add_child_text (_files.get(static_cast<FontFiles::Variant>(i)).get().string ());
-               }
+       if (_file) {
+               node->add_child("File")->add_child_text(_file->string());
        }
 }
 
@@ -69,13 +53,7 @@ operator== (Font const & a, Font const & b)
                return false;
        }
 
-       for (int i = 0; i < FontFiles::VARIANTS; ++i) {
-               if (a.file(static_cast<FontFiles::Variant>(i)) != b.file(static_cast<FontFiles::Variant>(i))) {
-                       return false;
-               }
-       }
-
-       return true;
+       return a.file() == b.file();
 }
 
 bool
index cb18e4798b6e7b29ef1863ddc8216a6c759431e1..b2ae86daff328d208a1e5c59d4f6b2ae83fe4b2f 100644 (file)
@@ -21,7 +21,6 @@
 #ifndef DCPOMATIC_FONT_H
 #define DCPOMATIC_FONT_H
 
-#include "font_files.h"
 #include <libcxml/cxml.h>
 #include <boost/optional.hpp>
 #include <boost/signals2.hpp>
@@ -42,21 +41,12 @@ public:
                return _id;
        }
 
-       boost::optional<boost::filesystem::path> file (FontFiles::Variant variant) const {
-               return _files.get (variant);
+       boost::optional<boost::filesystem::path> file () const {
+               return _file;
        }
 
-       void set_file (FontFiles::Variant variant, boost::filesystem::path file) {
-               _files.set (variant, file);
-               Changed ();
-       }
-
-       FontFiles files () const {
-               return _files;
-       }
-
-       void set_files (FontFiles files) {
-               _files = files;
+       void set_file (boost::filesystem::path file) {
+               _file = file;
                Changed ();
        }
 
@@ -65,7 +55,7 @@ public:
 private:
        /** Font ID, used to describe it in the subtitle content */
        std::string _id;
-       FontFiles _files;
+       boost::optional<boost::filesystem::path> _file;
 };
 
 bool operator!= (Font const & a, Font const & b);
diff --git a/src/lib/font_files.cc b/src/lib/font_files.cc
deleted file mode 100644 (file)
index 3046657..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-    Copyright (C) 2015 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 "font_files.h"
-
-bool
-operator!= (FontFiles const & a, FontFiles const & b)
-{
-       for (int i = 0; i < FontFiles::VARIANTS; ++i) {
-               if (a.get(static_cast<FontFiles::Variant>(i)) != b.get(static_cast<FontFiles::Variant>(i))) {
-                       return true;
-               }
-       }
-
-       return false;
-}
diff --git a/src/lib/font_files.h b/src/lib/font_files.h
deleted file mode 100644 (file)
index d32a0ce..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-    Copyright (C) 2015 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_FONT_FILES_H
-#define DCPOMATIC_FONT_FILES_H
-
-#include <boost/filesystem.hpp>
-#include <boost/optional.hpp>
-
-class FontFiles
-{
-public:
-       enum Variant {
-               NORMAL,
-               ITALIC,
-               BOLD,
-               VARIANTS
-       };
-
-       void set (Variant variant, boost::filesystem::path file) {
-               _file[variant] = file;
-       }
-
-       boost::optional<boost::filesystem::path> get (Variant variant) const {
-               return _file[variant];
-       }
-
-private:
-       boost::optional<boost::filesystem::path> _file[VARIANTS];
-};
-
-bool operator!= (FontFiles const & a, FontFiles const & b);
-
-#endif
index a517470d50933259e9ad8d8d44f1f2e2a838c067..d3ad9dd235f92453e76d358cc66e1d144505377a 100644 (file)
@@ -102,11 +102,9 @@ Hints::thread ()
                BOOST_FOREACH (shared_ptr<Content> i, content) {
                        BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
                                BOOST_FOREACH (shared_ptr<Font> k, j->fonts()) {
-                                       for (int l = 0; l < FontFiles::VARIANTS; ++l) {
-                                               optional<boost::filesystem::path> const p = k->file (static_cast<FontFiles::Variant>(l));
-                                               if (p && boost::filesystem::file_size (p.get()) >= (640 * 1024)) {
-                                                       big_font_files = true;
-                                               }
+                                       optional<boost::filesystem::path> const p = k->file ();
+                                       if (p && boost::filesystem::file_size(p.get()) >= (640 * 1024)) {
+                                               big_font_files = true;
                                        }
                                }
                        }
index d699adfba0e7ae52e05082712382f188b3530101..8ed085dbd18480bf528904406087a73a54466eab 100644 (file)
@@ -362,9 +362,9 @@ maybe_add_text (
                        liberation_normal = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf";
                }
 
-               /* Add all the fonts to the subtitle content */
+               /* Add the font to the subtitle content */
                BOOST_FOREACH (shared_ptr<Font> j, fonts) {
-                       asset->add_font (j->id(), j->file(FontFiles::NORMAL).get_value_or(liberation_normal));
+                       asset->add_font (j->id(), j->file().get_value_or(liberation_normal));
                }
 
                if (dynamic_pointer_cast<dcp::InteropSubtitleAsset> (asset)) {
index fafed3d821879c8cfe7a4b9369ea5a4eddd5d425..d2631e3407808ed7f1c186f0011823fc5b92b317 100644 (file)
@@ -48,7 +48,7 @@ using boost::optional;
 using boost::algorithm::replace_all;
 
 static FcConfig* fc_config = 0;
-static list<pair<FontFiles, string> > fc_config_fonts;
+static list<pair<boost::filesystem::path, string> > fc_config_fonts;
 
 string
 marked_up (list<StringText> subtitles, int target_height, float fade_factor)
@@ -161,36 +161,28 @@ render_line (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Siz
                fc_config = FcInitLoadConfig ();
        }
 
-       FontFiles font_files;
+       optional<boost::filesystem::path> font_file;
 
        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");
+               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_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");
+       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) {
-               if (i->id() == subtitles.front().font() && i->file(FontFiles::NORMAL)) {
-                       font_files = i->files ();
+               if (i->id() == subtitles.front().font() && i->file()) {
+                       font_file = i->file ();
                }
        }
 
-       list<pair<FontFiles, string> >::const_iterator existing = fc_config_fonts.begin ();
-       while (existing != fc_config_fonts.end() && existing->first != font_files) {
+       list<pair<boost::filesystem::path, string> >::const_iterator existing = fc_config_fonts.begin ();
+       while (existing != fc_config_fonts.end() && existing->first != *font_file) {
                ++existing;
        }
 
@@ -199,17 +191,9 @@ render_line (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Siz
                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())
-                                       );
-                       }
-               }
-
+               FcConfigAppFontAddFile (fc_config, reinterpret_cast<FcChar8 const *>(font_file->string().c_str()));
                FcPattern* pattern = FcPatternBuild (
-                       0, FC_FILE, FcTypeString, font_files.get(FontFiles::NORMAL).get().string().c_str(), static_cast<char *> (0)
+                       0, FC_FILE, FcTypeString, font_file->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);
@@ -234,7 +218,7 @@ render_line (list<StringText> subtitles, list<shared_ptr<Font> > fonts, dcp::Siz
                FcObjectSetDestroy (object_set);
                FcPatternDestroy (pattern);
 
-               fc_config_fonts.push_back (make_pair (font_files, font_name));
+               fc_config_fonts.push_back (make_pair(*font_file, font_name));
        }
 
        FcConfigSetCurrent (fc_config);
index ac49be474e1ae70c4685bfaa5b5d93df966a8bd0..e2f5264dfdad889912be6806371389c8aff52777 100644 (file)
@@ -405,9 +405,7 @@ TextContent::identifier () const
           types of subtitle content involve fonts.
        */
        BOOST_FOREACH (shared_ptr<Font> f, _fonts) {
-               for (int i = 0; i < FontFiles::VARIANTS; ++i) {
-                       s += "_" + f->file(static_cast<FontFiles::Variant>(i)).get_value_or("Default").string();
-               }
+               s += "_" + f->file().get_value_or("Default").string();
        }
 
        /* The DCP track and language are for metadata only, and don't affect
index 9bd07c67d00268dcb4acdda5f9de42ad87932a6d..cf38b368994876595814dbe21758a46c06a37fa8 100644 (file)
@@ -103,7 +103,6 @@ sources = """
           filter.cc
           ffmpeg_image_proxy.cc
           font.cc
-          font_files.cc
           frame_rate_change.cc
           hints.cc
           internet.cc
diff --git a/src/wx/font_files_dialog.h b/src/wx/font_files_dialog.h
deleted file mode 100644 (file)
index c9db20e..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-    Copyright (C) 2015 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 "table_dialog.h"
-#include "wx_util.h"
-#include "lib/font_files.h"
-
-class FontFilesDialog : public TableDialog
-{
-public:
-       FontFilesDialog (wxWindow* parent, FontFiles files);
-
-       FontFiles get () const {
-               return _files;
-       }
-
-private:
-       void set_from_file_clicked (FontFiles::Variant variant);
-#ifdef DCPOMATIC_WINDOWS
-       void set_from_system_clicked (FontFiles::Variant variant);
-#endif
-       void set (FontFiles::Variant variant, boost::filesystem::path path);
-
-       FontFiles _files;
-
-       wxStaticText* _name[FontFiles::VARIANTS];
-       wxButton* _set_file[FontFiles::VARIANTS];
-
-#ifdef DCPOMATIC_WINDOWS
-       wxButton* _set_system[FontFiles::VARIANTS];
-#endif
-};
index 0660eea39ec2fbdec05f327f6270b46a4e02b3b0..4ad118262367bd7f5e25d8ad52dccf2befce6e7c 100644 (file)
@@ -21,7 +21,6 @@
 #include "fonts_dialog.h"
 #include "wx_util.h"
 #include "system_font_dialog.h"
-#include "font_files_dialog.h"
 #include "dcpomatic_button.h"
 #include "lib/font.h"
 #include "lib/content.h"
@@ -53,27 +52,11 @@ FontsDialog::FontsDialog (wxWindow* parent, shared_ptr<Content> content, shared_
        {
                wxListItem ip;
                ip.SetId (1);
-               ip.SetText (_("Normal file"));
-               ip.SetWidth (150);
+               ip.SetText (_("File"));
+               ip.SetWidth (450);
                _fonts->InsertColumn (1, ip);
        }
 
-       {
-               wxListItem ip;
-               ip.SetId (2);
-               ip.SetText (_("Italic file"));
-               ip.SetWidth (150);
-               _fonts->InsertColumn (2, ip);
-       }
-
-       {
-               wxListItem ip;
-               ip.SetId (3);
-               ip.SetText (_("Bold file"));
-               ip.SetWidth (150);
-               _fonts->InsertColumn (3, ip);
-       }
-
        wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
        sizer->Add (_fonts, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
 
@@ -113,10 +96,8 @@ FontsDialog::setup ()
                item.SetId (n);
                _fonts->InsertItem (item);
                _fonts->SetItem (n, 0, std_to_wx (i->id ()));
-               for (int j = 0; j < FontFiles::VARIANTS; ++j) {
-                       if (i->file(static_cast<FontFiles::Variant>(j))) {
-                               _fonts->SetItem (n, j + 1, i->file(static_cast<FontFiles::Variant>(j)).get().leaf().string ());
-                       }
+               if (i->file()) {
+                       _fonts->SetItem (n, 1, i->file()->leaf().string ());
                }
                ++n;
        }
@@ -159,10 +140,30 @@ FontsDialog::edit_clicked ()
                return;
        }
 
-       FontFilesDialog* d = new FontFilesDialog (this, font->files ());
-       if (d->ShowModal () == wxID_OK) {
-               font->set_files (d->get ());
+        /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
+           non-Latin filenames or paths.
+        */
+        wxString default_dir = "";
+#ifdef DCPOMATIC_LINUX
+        if (boost::filesystem::exists ("/usr/share/fonts/truetype")) {
+                default_dir = "/usr/share/fonts/truetype";
+        } else {
+                default_dir = "/usr/share/fonts";
+        }
+#endif
+#ifdef DCPOMATIC_OSX
+        default_dir = "/System/Library/Fonts";
+#endif
+
+       wxFileDialog* d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT (""), wxT ("*.ttf"), wxFD_CHANGE_DIR);
+       int const r = d->ShowModal ();
+
+       if (r != wxID_OK) {
+               d->Destroy ();
+               return;
        }
+
+       font->set_file (wx_to_std(d->GetPath()));
        d->Destroy ();
 
        setup ();
index 1b29b057b898e9bbe233fe3fc2e407be1acdc7e5..183466106db5647e805752491f4a585d8a3157b8 100644 (file)
@@ -67,7 +67,6 @@ sources = """
           filter_editor.cc
           focus_manager.cc
           fonts_dialog.cc
-          font_files_dialog.cc
           full_config_dialog.cc
           gain_calculator_dialog.cc
           gdc_certificate_panel.cc
@@ -144,7 +143,7 @@ sources = """
 def configure(conf):
 
     wx_libs = 'core,richtext,adv,html,xml'
-    
+
     try:
         wx_config = '/usr/lib64/wx/config/gtk2-unicode-3.0'
         conf.check_cfg(msg='Checking for wxWidgets using gtk2-unicode-3.0',
index 3064abcc6e5cffd474200d7d27eb24f58130fee8..0c1f0716166eff0c0a1a9265ab1e736bb3195563 100644 (file)
@@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE (srt_subtitle_test2)
        content->only_text()->set_use (true);
        content->only_text()->set_burn (false);
        /* Use test/data/subrip2.srt as if it were a font file  */
-       content->only_text()->fonts().front()->set_file (FontFiles::NORMAL, "test/data/subrip2.srt");
+       content->only_text()->fonts().front()->set_file("test/data/subrip2.srt");
 
        film->make_dcp ();
        BOOST_REQUIRE (!wait_for_jobs());