diff options
Diffstat (limited to 'src/lib/font_id_allocator.cc')
| -rw-r--r-- | src/lib/font_id_allocator.cc | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/src/lib/font_id_allocator.cc b/src/lib/font_id_allocator.cc index 5e4ae9c0f..b85fc90dc 100644 --- a/src/lib/font_id_allocator.cc +++ b/src/lib/font_id_allocator.cc @@ -24,9 +24,8 @@ #include "dcpomatic_assert.h" #include "font_id_allocator.h" #include <dcp/reel.h> -#include <dcp/reel_closed_caption_asset.h> -#include <dcp/reel_subtitle_asset.h> -#include <dcp/subtitle_asset.h> +#include <dcp/reel_text_asset.h> +#include <dcp/text_asset.h> #include <set> #include <string> #include <vector> @@ -61,7 +60,7 @@ FontIDAllocator::add_fonts_from_reels(vector<shared_ptr<dcp::Reel>> const& reels void -FontIDAllocator::add_fonts_from_asset(int reel_index, shared_ptr<const dcp::SubtitleAsset> asset) +FontIDAllocator::add_fonts_from_asset(int reel_index, shared_ptr<const dcp::TextAsset> asset) { for (auto const& font: asset->font_data()) { add_font(reel_index, asset->id(), font.first); @@ -76,37 +75,23 @@ FontIDAllocator::add_font(int reel_index, string asset_id, string font_id) if (!_default_font) { _default_font = font; } - _map[font] = 0; + _map[font] = {}; } void FontIDAllocator::allocate() { - /* We'll first try adding <reel>_ to the start of the font ID, but if a reel has multiple - * identical font IDs we will need to use some number that is not a reel ID. Find the - * first such number (1 higher than the highest reel index) - */ - auto next_unused = std::max_element( - _map.begin(), - _map.end(), - [] (std::pair<Font, int> const& a, std::pair<Font, int> const& b) { - return a.first.reel_index < b.first.reel_index; - })->first.reel_index + 1; - std::set<string> used_ids; for (auto& font: _map) { - auto const proposed = String::compose("%1_%2", font.first.reel_index, font.first.font_id); - if (used_ids.find(proposed) != used_ids.end()) { - /* This ID was already used; we need to disambiguate it. Do so by using - * one of our unused prefixes. - */ - font.second = next_unused++; - } else { - /* This ID was not yet used */ - font.second = font.first.reel_index; + auto proposed = font.first.font_id; + int prefix = 0; + while (used_ids.find(proposed) != used_ids.end()) { + proposed = String::compose("%1_%2", prefix++, font.first.font_id); + DCPOMATIC_ASSERT(prefix < 128); } + font.second = proposed; used_ids.insert(proposed); } } @@ -119,7 +104,7 @@ FontIDAllocator::font_id(int reel_index, string asset_id, string font_id) const if (iter == _map.end()) { return default_font_id(); } - return String::compose("%1_%2", iter->second, font_id); + return iter->second; } |
