2 Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef DCPOMATIC_FONT_ID_ALLOCATOR_H
23 #define DCPOMATIC_FONT_ID_ALLOCATOR_H
30 #include <boost/optional.hpp>
39 /** A class which, given some pairs of (asset-id, font-id) can return a font ID
40 * which is unique in a piece of content.
42 * When we examine a 2-reel DCP we may have a pair of subtitle assets that
43 * each have a font with ID "foo". We want to store these in
44 * TextContent::_fonts in such a way that they are distinguishable.
46 * If TextContent is to carry on storing a list of dcpomatic::Font, we can
47 * only do this by making each dcpomatic::Font have a different ID (i.e. not
50 * Hence when we add the fonts to the TextContent we re-write them to have
53 * When we do this, we must do it in a repeatable way so that when the
54 * DCPDecoder receives the "foo" font IDs it can obtain the same "new" ID given
55 * "foo" and the asset ID that it came from.
57 * FontIDAllocator can help with that: call add_fonts_from_reels() or add_font(),
58 * then allocate(), then it will return repeatable unique "new" font IDs from
59 * an asset map and "old" ID.
64 void add_fonts_from_reels(std::vector<std::shared_ptr<dcp::Reel>> const& reels);
65 void add_font(int reel_index, std::string asset_id, std::string font_id);
69 std::string font_id(int reel_index, std::string asset_id, std::string font_id) const;
70 std::string default_font_id() const;
72 bool has_default_font() const {
73 return static_cast<bool>(_default_font);
77 void add_fonts_from_asset(int reel_index, std::shared_ptr<const dcp::SubtitleAsset> asset);
81 Font(int reel_index_, std::string asset_id_, std::string font_id_)
82 : reel_index(reel_index_)
87 bool operator<(Font const& other) const {
88 if (reel_index != other.reel_index) {
89 return reel_index < other.reel_index;
92 if (asset_id != other.asset_id) {
93 return asset_id < other.asset_id;
96 return font_id < other.font_id;
100 std::string asset_id;
104 std::map<Font, int> _map;
105 boost::optional<Font> _default_font;