From 8771c1f7b00ab0fb5c252adaa437d753155b7c18 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 10 Jun 2015 10:55:22 +0100 Subject: Rename Font -> FontAsset; add dcpdumpsub tool. --- src/data.h | 38 ++++++++++++++++++++++++++++++++++++++ src/dcp.cc | 4 ++-- src/font.cc | 40 ---------------------------------------- src/font.h | 40 ---------------------------------------- src/font_asset.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/font_asset.h | 40 ++++++++++++++++++++++++++++++++++++++++ src/interop_subtitle_asset.cc | 10 +++++----- src/smpte_subtitle_asset.cc | 6 +++--- src/subtitle_asset.cc | 13 ++++++++++++- src/subtitle_asset.h | 15 +++++++-------- src/wscript | 5 +++-- 11 files changed, 150 insertions(+), 101 deletions(-) create mode 100644 src/data.h delete mode 100644 src/font.cc delete mode 100644 src/font.h create mode 100644 src/font_asset.cc create mode 100644 src/font_asset.h (limited to 'src') diff --git a/src/data.h b/src/data.h new file mode 100644 index 00000000..d1f52b3b --- /dev/null +++ b/src/data.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2015 Carl Hetherington + + 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 + +namespace dcp { + +class Data +{ +public: + Data () {} + + Data (boost::shared_array data_, boost::uintmax_t size_) + : data (data_) + , size (size_) + {} + + boost::shared_array data; + boost::uintmax_t size; +}; + +} diff --git a/src/dcp.cc b/src/dcp.cc index 12aaee47..c1675401 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -41,7 +41,7 @@ #include "decrypted_kdm_key.h" #include "dcp_assert.h" #include "reel_asset.h" -#include "font.h" +#include "font_asset.h" #include #include #include @@ -176,7 +176,7 @@ DCP::read (bool keep_going, ReadErrors* errors) throw DCPReadError ("Unknown MXF essence type"); } } else if (boost::filesystem::extension (path) == ".ttf") { - other_assets.push_back (shared_ptr (new Font (path))); + other_assets.push_back (shared_ptr (new FontAsset (path))); } } diff --git a/src/font.cc b/src/font.cc deleted file mode 100644 index cbfb999a..00000000 --- a/src/font.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2015 Carl Hetherington - - 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. - -*/ - -/** @file src/font.cc - * @brief Font class. - */ - -#include "font.h" - -using std::string; - -using namespace dcp; - -Font::Font (boost::filesystem::path file) - : Asset (file) -{ - -} - -string -Font::pkl_type (Standard) const -{ - return "application/ttf"; -} diff --git a/src/font.h b/src/font.h deleted file mode 100644 index e87419c0..00000000 --- a/src/font.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2015 Carl Hetherington - - 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. - -*/ - -/** @file src/font.h - * @brief Font class. - */ - -#include "asset.h" - -namespace dcp { - -/** @class Font - * @brief A (truetype) font asset for subtitles in an Interop DCP. - */ -class Font : public Asset -{ -public: - Font (boost::filesystem::path file); - -private: - std::string pkl_type (Standard standard) const; -}; - -} diff --git a/src/font_asset.cc b/src/font_asset.cc new file mode 100644 index 00000000..8f8e4ff3 --- /dev/null +++ b/src/font_asset.cc @@ -0,0 +1,40 @@ +/* + Copyright (C) 2015 Carl Hetherington + + 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. + +*/ + +/** @file src/font_asset.cc + * @brief FontAsset class. + */ + +#include "font_asset.h" + +using std::string; + +using namespace dcp; + +FontAsset::FontAsset (boost::filesystem::path file) + : Asset (file) +{ + +} + +string +FontAsset::pkl_type (Standard) const +{ + return "application/ttf"; +} diff --git a/src/font_asset.h b/src/font_asset.h new file mode 100644 index 00000000..13333777 --- /dev/null +++ b/src/font_asset.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2015 Carl Hetherington + + 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. + +*/ + +/** @file src/font_asset.h + * @brief FontAsset class. + */ + +#include "asset.h" + +namespace dcp { + +/** @class FontAsset + * @brief A (truetype) font asset for subtitles in an Interop DCP. + */ +class FontAsset : public Asset +{ +public: + FontAsset (boost::filesystem::path file); + +private: + std::string pkl_type (Standard standard) const; +}; + +} diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 5be4c53c..e329158e 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -23,7 +23,7 @@ #include "raw_convert.h" #include "font_node.h" #include "util.h" -#include "font.h" +#include "font_asset.h" #include "dcp_assert.h" #include #include @@ -163,7 +163,7 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const if (!f) { throw FileError ("could not open font file for writing", file, errno); } - map::const_iterator j = _fonts.find (i->id); + map::const_iterator j = _fonts.find (i->id); if (j != _fonts.end ()) { fwrite (j->second.data.get(), 1, j->second.size, f); j->second.file = file; @@ -176,7 +176,7 @@ void InteropSubtitleAsset::resolve_fonts (list > objects) { BOOST_FOREACH (shared_ptr i, objects) { - shared_ptr font = dynamic_pointer_cast (i); + shared_ptr font = dynamic_pointer_cast (i); if (!font) { continue; } @@ -192,8 +192,8 @@ InteropSubtitleAsset::resolve_fonts (list > objects) void InteropSubtitleAsset::add_font_assets (list >& assets) { - for (map::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { + for (map::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { DCP_ASSERT (i->second.file); - assets.push_back (shared_ptr (new Font (i->second.file.get ()))); + assets.push_back (shared_ptr (new FontAsset (i->second.file.get ()))); } } diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 362211cf..e426ae22 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -144,7 +144,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file) } if (j != _load_font_nodes.end ()) { - _fonts[(*j)->id] = FontData (data, buffer.Size ()); + _fonts[(*j)->id] = FileData (data, buffer.Size ()); } } } @@ -217,7 +217,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const descriptor.EncodingName = "UTF-8"; BOOST_FOREACH (shared_ptr i, _load_font_nodes) { - map::const_iterator j = _fonts.find (i->id); + map::const_iterator j = _fonts.find (i->id); if (j != _fonts.end ()) { ASDCP::TimedText::TimedTextResourceDescriptor res; unsigned int c; @@ -245,7 +245,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const } BOOST_FOREACH (shared_ptr i, _load_font_nodes) { - map::const_iterator j = _fonts.find (i->id); + map::const_iterator j = _fonts.find (i->id); if (j != _fonts.end ()) { ASDCP::TimedText::FrameBuffer buffer; buffer.SetData (j->second.data.get(), j->second.size); diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 085e5959..d9a87263 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -39,6 +39,7 @@ using std::ofstream; using std::stringstream; using std::cout; using std::cerr; +using std::map; using boost::shared_ptr; using boost::shared_array; using boost::optional; @@ -324,5 +325,15 @@ SubtitleAsset::add_font_data (string id, boost::filesystem::path file) throw FileError ("could not read font file", file, -1); } - _fonts[id] = FontData (data, size); + _fonts[id] = FileData (data, size); +} + +map +SubtitleAsset::fonts () const +{ + map out; + for (map::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { + out[i->first] = i->second; + } + return out; } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 4cbbff0d..c28f6446 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -23,6 +23,7 @@ #include "asset.h" #include "dcp_time.h" #include "subtitle_string.h" +#include "data.h" #include #include @@ -69,6 +70,7 @@ public: void add (SubtitleString); virtual void add_font (std::string id, boost::filesystem::path file) = 0; + std::map fonts () const; virtual void write (boost::filesystem::path) const = 0; virtual Glib::ustring xml_as_string () const = 0; @@ -88,17 +90,14 @@ protected: /** All our subtitles, in no particular order */ std::list _subtitles; - class FontData { + class FileData : public Data { public: - FontData () {} + FileData () {} - FontData (boost::shared_array data_, boost::uintmax_t size_) - : data (data_) - , size (size_) + FileData (boost::shared_array data_, boost::uintmax_t size_) + : Data (data_, size_) {} - boost::shared_array data; - boost::uintmax_t size; /** .ttf file that this data was last written to */ mutable boost::optional file; }; @@ -107,7 +106,7 @@ protected: * For Interop, the string is the font ID from the subtitle file. * For SMPTE, the string is the font's URN from the subtitle file. */ - std::map _fonts; + std::map _fonts; private: /** @struct ParseState diff --git a/src/wscript b/src/wscript index f54aaa8f..ede704bb 100644 --- a/src/wscript +++ b/src/wscript @@ -15,7 +15,7 @@ def build(bld): encrypted_kdm.cc exceptions.cc file.cc - font.cc + font_asset.cc font_node.cc gamma_transfer_function.cc interop_load_font_node.cc @@ -71,11 +71,12 @@ def build(bld): cpl.h dcp.h dcp_time.h + data.h decrypted_kdm.h decrypted_kdm_key.h encrypted_kdm.h exceptions.h - font.h + font_asset.h gamma_transfer_function.h interop_load_font_node.h interop_subtitle_asset.h -- cgit v1.2.3