diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/font.cc | 34 | ||||
| -rw-r--r-- | src/lib/font.h | 20 | ||||
| -rw-r--r-- | src/lib/font_files.cc | 33 | ||||
| -rw-r--r-- | src/lib/font_files.h | 51 | ||||
| -rw-r--r-- | src/lib/hints.cc | 8 | ||||
| -rw-r--r-- | src/lib/reel_writer.cc | 4 | ||||
| -rw-r--r-- | src/lib/render_text.cc | 40 | ||||
| -rw-r--r-- | src/lib/text_content.cc | 4 | ||||
| -rw-r--r-- | src/lib/wscript | 1 |
9 files changed, 29 insertions, 166 deletions
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<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 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 <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 index 30466572b..000000000 --- a/src/lib/font_files.cc +++ /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 index d32a0ce9e..000000000 --- a/src/lib/font_files.h +++ /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 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<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; } } } 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<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)) { 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<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); 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<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 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 |
