From b651392d70d7e37ce5a8a20da81d86e5d19aadd8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 15 Dec 2019 22:58:21 +0100 Subject: Add fix_empty_font_ids() to replace empty Font ids with a dummy string. Back-ported from abf4f7577877254ecd7a1dc7955e0d7ca49ad07c in master. --- src/subtitle_asset.cc | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/subtitle_asset.cc') diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index bb7b0b1c..083a8040 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington + Copyright (C) 2012-2019 Carl Hetherington This file is part of libdcp. @@ -40,6 +40,7 @@ #include "subtitle_string.h" #include "subtitle_image.h" #include "dcp_assert.h" +#include "load_font_node.h" #include #include #include @@ -655,3 +656,40 @@ SubtitleAsset::fonts_with_load_ids () const } return out; } + +/** Replace empty IDs in any and tags with + * a dummy string. Some systems give errors with empty font IDs + * (see DCP-o-matic bug #1689). + */ +void +SubtitleAsset::fix_empty_font_ids () +{ + bool have_empty = false; + list ids; + BOOST_FOREACH (shared_ptr i, load_font_nodes()) { + if (i->id == "") { + have_empty = true; + } else { + ids.push_back (i->id); + } + } + + if (!have_empty) { + return; + } + + string const empty_id = unique_string (ids, "font"); + + BOOST_FOREACH (shared_ptr i, load_font_nodes()) { + if (i->id == "") { + i->id = empty_id; + } + } + + BOOST_FOREACH (shared_ptr i, _subtitles) { + shared_ptr j = dynamic_pointer_cast (i); + if (j && j->font() && j->font().get() == "") { + j->set_font (empty_id); + } + } +} -- cgit v1.2.3