From f77ec143719c86ddbf098bff6d19fe2a159b8c3e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 27 Jan 2019 00:25:40 +0000 Subject: Remove specification of italic/bold fonts (#1451); synthesis will be used instead. --- src/lib/font.cc | 34 ++++++----------------------- src/lib/font.h | 20 +++++------------ src/lib/font_files.cc | 33 ----------------------------- src/lib/font_files.h | 51 -------------------------------------------- src/lib/hints.cc | 8 +++---- src/lib/reel_writer.cc | 4 ++-- src/lib/render_text.cc | 40 +++++++++++----------------------- src/lib/text_content.cc | 4 +--- src/lib/wscript | 1 - src/wx/font_files_dialog.h | 49 ------------------------------------------ src/wx/fonts_dialog.cc | 53 +++++++++++++++++++++++----------------------- src/wx/wscript | 3 +-- test/srt_subtitle_test.cc | 2 +- 13 files changed, 58 insertions(+), 244 deletions(-) delete mode 100644 src/lib/font_files.cc delete mode 100644 src/lib/font_files.h delete mode 100644 src/wx/font_files_dialog.h diff --git a/src/lib/font.cc b/src/lib/font.cc index 309f3d1eb..333539aa4 100644 --- a/src/lib/font.cc +++ b/src/lib/font.cc @@ -25,23 +25,13 @@ 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(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(i))) { - xmlpp::Element* e = node->add_child ("File"); - e->set_attribute ("Variant", names[i]); - e->add_child_text (_files.get(static_cast(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(i)) != b.file(static_cast(i))) { - return false; - } - } - - return true; + return a.file() == b.file(); } bool diff --git a/src/lib/font.h b/src/lib/font.h index cb18e4798..b2ae86daf 100644 --- a/src/lib/font.h +++ b/src/lib/font.h @@ -21,7 +21,6 @@ #ifndef DCPOMATIC_FONT_H #define DCPOMATIC_FONT_H -#include "font_files.h" #include #include #include @@ -42,21 +41,12 @@ public: return _id; } - boost::optional file (FontFiles::Variant variant) const { - return _files.get (variant); + boost::optional 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 _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 index 30466572b..000000000 --- a/src/lib/font_files.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright (C) 2015 Carl Hetherington - - 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 . - -*/ - -#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(i)) != b.get(static_cast(i))) { - return true; - } - } - - return false; -} diff --git a/src/lib/font_files.h b/src/lib/font_files.h deleted file mode 100644 index d32a0ce9e..000000000 --- a/src/lib/font_files.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright (C) 2015 Carl Hetherington - - 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 . - -*/ - -#ifndef DCPOMATIC_FONT_FILES_H -#define DCPOMATIC_FONT_FILES_H - -#include -#include - -class FontFiles -{ -public: - enum Variant { - NORMAL, - ITALIC, - BOLD, - VARIANTS - }; - - void set (Variant variant, boost::filesystem::path file) { - _file[variant] = file; - } - - boost::optional get (Variant variant) const { - return _file[variant]; - } - -private: - boost::optional _file[VARIANTS]; -}; - -bool operator!= (FontFiles const & a, FontFiles const & b); - -#endif diff --git a/src/lib/hints.cc b/src/lib/hints.cc index a517470d5..d3ad9dd23 100644 --- a/src/lib/hints.cc +++ b/src/lib/hints.cc @@ -102,11 +102,9 @@ Hints::thread () BOOST_FOREACH (shared_ptr i, content) { BOOST_FOREACH (shared_ptr j, i->text) { BOOST_FOREACH (shared_ptr k, j->fonts()) { - for (int l = 0; l < FontFiles::VARIANTS; ++l) { - optional const p = k->file (static_cast(l)); - if (p && boost::filesystem::file_size (p.get()) >= (640 * 1024)) { - big_font_files = true; - } + optional const p = k->file (); + if (p && boost::filesystem::file_size(p.get()) >= (640 * 1024)) { + big_font_files = true; } } } diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index d699adfba..8ed085dbd 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -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 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 (asset)) { diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index fafed3d82..d2631e340 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -48,7 +48,7 @@ using boost::optional; using boost::algorithm::replace_all; static FcConfig* fc_config = 0; -static list > fc_config_fonts; +static list > fc_config_fonts; string marked_up (list subtitles, int target_height, float fade_factor) @@ -161,36 +161,28 @@ render_line (list subtitles, list > fonts, dcp::Siz fc_config = FcInitLoadConfig (); } - FontFiles font_files; + optional 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 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 >::const_iterator existing = fc_config_fonts.begin (); - while (existing != fc_config_fonts.end() && existing->first != font_files) { + list >::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 subtitles, list > 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(i))) { - FcConfigAppFontAddFile ( - fc_config, - reinterpret_cast (font_files.get(static_cast(i)).get().string().c_str()) - ); - } - } - + FcConfigAppFontAddFile (fc_config, reinterpret_cast(font_file->string().c_str())); FcPattern* pattern = FcPatternBuild ( - 0, FC_FILE, FcTypeString, font_files.get(FontFiles::NORMAL).get().string().c_str(), static_cast (0) + 0, FC_FILE, FcTypeString, font_file->string().c_str(), static_cast (0) ); FcObjectSet* object_set = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_LANG, FC_FILE, static_cast (0)); FcFontSet* font_set = FcFontList (fc_config, pattern, object_set); @@ -234,7 +218,7 @@ render_line (list subtitles, list > 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); diff --git a/src/lib/text_content.cc b/src/lib/text_content.cc index ac49be474..e2f5264df 100644 --- a/src/lib/text_content.cc +++ b/src/lib/text_content.cc @@ -405,9 +405,7 @@ TextContent::identifier () const types of subtitle content involve fonts. */ BOOST_FOREACH (shared_ptr f, _fonts) { - for (int i = 0; i < FontFiles::VARIANTS; ++i) { - s += "_" + f->file(static_cast(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 diff --git a/src/lib/wscript b/src/lib/wscript index 9bd07c67d..cf38b3689 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -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 index c9db20e9a..000000000 --- a/src/wx/font_files_dialog.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright (C) 2015 Carl Hetherington - - 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 . - -*/ - -#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 -}; diff --git a/src/wx/fonts_dialog.cc b/src/wx/fonts_dialog.cc index 0660eea39..4ad118262 100644 --- a/src/wx/fonts_dialog.cc +++ b/src/wx/fonts_dialog.cc @@ -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, 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(j))) { - _fonts->SetItem (n, j + 1, i->file(static_cast(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 (); diff --git a/src/wx/wscript b/src/wx/wscript index 1b29b057b..183466106 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -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', diff --git a/test/srt_subtitle_test.cc b/test/srt_subtitle_test.cc index 3064abcc6..0c1f07161 100644 --- a/test/srt_subtitle_test.cc +++ b/test/srt_subtitle_test.cc @@ -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()); -- cgit v1.2.3