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
38 /** A class which, given some pairs of (asset-id, font-id) can return a font ID
39 * which is unique in a piece of content.
41 * When we examine a 2-reel DCP we may have a pair of subtitle assets that
42 * each have a font with ID "foo". We want to store these in
43 * TextContent::_fonts in such a way that they are distinguishable.
45 * If TextContent is to carry on storing a list of dcpomatic::Font, we can
46 * only do this by making each dcpomatic::Font have a different ID (i.e. not
49 * Hence when we add the fonts to the TextContent we re-write them to have
52 * When we do this, we must do it in a repeatable way so that when the
53 * DCPDecoder receives the "foo" font IDs it can obtain the same "new" ID given
54 * "foo" and the asset ID that it came from.
56 * FontIDAllocator can help with that: call add_fonts_from_reels() or add_font(),
57 * then allocate(), then it will return repeatable unique "new" font IDs from
58 * an asset map and "old" ID.
63 void add_fonts_from_reels(std::vector<std::shared_ptr<dcp::Reel>> const& reels);
64 void add_font(int reel_index, std::string asset_id, std::string font_id);
68 std::string font_id(int reel_index, std::string asset_id, std::string font_id) const;
71 void add_fonts_from_asset(int reel_index, std::shared_ptr<const dcp::SubtitleAsset> asset);
75 Font(int reel_index_, std::string asset_id_, std::string font_id_)
76 : reel_index(reel_index_)
81 bool operator<(Font const& other) const {
82 if (reel_index != other.reel_index) {
83 return reel_index < other.reel_index;
86 if (asset_id != other.asset_id) {
87 return asset_id < other.asset_id;
90 return font_id < other.font_id;
98 std::map<Font, int> _map;