summaryrefslogtreecommitdiff
path: root/src/lib/dcp_examiner.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-10-14 21:48:25 +0200
committerCarl Hetherington <cth@carlh.net>2023-10-15 09:10:18 +0200
commit3c802dd6d1451c2c8a7e188f8379738d72e907eb (patch)
tree454396cf5451535b8708a0c4961c7d5c2b30ea1f /src/lib/dcp_examiner.cc
parent1bfe44b1503fb0f5cffda135076709014337de52 (diff)
Fix DCP content font ID allocation to cope with DCPs that have multiple fonts
with the same name in the same reel (#2600). Previously we had this id_for_font_in_reel() which would give an ID of N_font-ID. This means we got duplicate font IDs. Here we replace that method with FontAllocator, which gives an ID of N_font-ID for the first font and M_font-ID, where M is a number higher than the highest reel index. The idea is to support the required new IDs without breaking exisiting projects. There is some documentation of how it works in doc/design/fonts
Diffstat (limited to 'src/lib/dcp_examiner.cc')
-rw-r--r--src/lib/dcp_examiner.cc44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/lib/dcp_examiner.cc b/src/lib/dcp_examiner.cc
index 3163f59c4..a9a6dee5e 100644
--- a/src/lib/dcp_examiner.cc
+++ b/src/lib/dcp_examiner.cc
@@ -20,11 +20,13 @@
#include "config.h"
+#include "constants.h"
#include "dcp_content.h"
#include "dcp_examiner.h"
#include "dcpomatic_log.h"
#include "exceptions.h"
#include "image.h"
+#include "text_content.h"
#include "util.h"
#include <dcp/cpl.h>
#include <dcp/dcp.h>
@@ -128,9 +130,9 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
LOG_GENERAL("Looking at %1 reels", selected_cpl->reels().size());
+ int reel_index = 0;
for (auto reel: selected_cpl->reels()) {
LOG_GENERAL("Reel %1", reel->id());
- vector<shared_ptr<dcpomatic::Font>> reel_fonts;
if (reel->main_picture()) {
if (!reel->main_picture()->asset_ref().resolved()) {
@@ -205,8 +207,12 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
_text_count[TextType::OPEN_SUBTITLE] = 1;
_open_subtitle_language = try_to_parse_language(reel->main_subtitle()->language());
- for (auto const& font: reel->main_subtitle()->asset()->font_data()) {
- reel_fonts.push_back(make_shared<dcpomatic::Font>(font.first, font.second));
+ auto asset = reel->main_subtitle()->asset();
+ for (auto const& font: asset->font_data()) {
+ _fonts.push_back({reel_index, asset->id(), make_shared<dcpomatic::Font>(font.first, font.second)});
+ }
+ if (asset->font_data().empty()) {
+ _fonts.push_back({reel_index, asset->id(), make_shared<dcpomatic::Font>("")});
}
}
@@ -232,8 +238,12 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
LOG_GENERAL("Closed caption %1 of reel %2 found", ccap->id(), reel->id());
- for (auto const& font: ccap->asset()->font_data()) {
- reel_fonts.push_back(make_shared<dcpomatic::Font>(font.first, font.second));
+ auto asset = ccap->asset();
+ for (auto const& font: asset->font_data()) {
+ _fonts.push_back({reel_index, asset->id(), make_shared<dcpomatic::Font>(font.first, font.second)});
+ }
+ if (asset->font_data().empty()) {
+ _fonts.push_back({reel_index, asset->id(), make_shared<dcpomatic::Font>("")});
}
}
@@ -263,11 +273,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
_reel_lengths.push_back(reel->atmos()->actual_duration());
}
- if (reel_fonts.empty()) {
- reel_fonts.push_back(make_shared<dcpomatic::Font>(""));
- }
-
- _fonts.push_back(reel_fonts);
+ ++reel_index;
}
_encrypted = selected_cpl->any_encrypted();
@@ -355,3 +361,21 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
_cpl = selected_cpl->id();
}
+
+
+void
+DCPExaminer::add_fonts(shared_ptr<TextContent> content)
+{
+ for (auto const& font: _fonts) {
+ _font_id_allocator.add_font(font.reel_index, font.asset_id, font.font->id());
+ }
+
+ _font_id_allocator.allocate();
+
+ for (auto const& font: _fonts) {
+ auto font_copy = make_shared<dcpomatic::Font>(*font.font);
+ font_copy->set_id(_font_id_allocator.font_id(font.reel_index, font.asset_id, font.font->id()));
+ content->add_font(font_copy);
+ }
+}
+