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();
}
}
}
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());
}
}
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
#ifndef DCPOMATIC_FONT_H
#define DCPOMATIC_FONT_H
-#include "font_files.h"
#include <libcxml/cxml.h>
#include <boost/optional.hpp>
#include <boost/signals2.hpp>
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 ();
}
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);
+++ /dev/null
-/*
- 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;
-}
+++ /dev/null
-/*
- 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
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;
}
}
}
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)) {
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)
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;
}
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);
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);
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
filter.cc
ffmpeg_image_proxy.cc
font.cc
- font_files.cc
frame_rate_change.cc
hints.cc
internet.cc
+++ /dev/null
-/*
- 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
-};
#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"
{
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);
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;
}
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 ();
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
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',
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());