Don't unconditionally clear _fonts when inspecting assets (DoM #2536). v1.8.70
authorCarl Hetherington <cth@carlh.net>
Sun, 28 May 2023 00:12:39 +0000 (02:12 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 28 May 2023 18:55:30 +0000 (20:55 +0200)
resolve_fonts() is sometimes called for the same asset with different
lists of things to check.  If it is called first with a font, and
then without one, we want to keep the font from the first call.

src/interop_subtitle_asset.cc

index 0116c11c539a1a2d0390a6ac1003a6af9f8427b5..d0c80f5e8300d8201e0047d3d9233371d853dede 100644 (file)
@@ -230,8 +230,6 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const
 void
 InteropSubtitleAsset::resolve_fonts (vector<shared_ptr<Asset>> assets)
 {
-       _fonts.clear();
-
        for (auto asset: assets) {
                auto font = dynamic_pointer_cast<FontAsset>(asset);
                if (!font) {
@@ -243,7 +241,12 @@ InteropSubtitleAsset::resolve_fonts (vector<shared_ptr<Asset>> assets)
                for (auto load_font_node: _load_font_nodes) {
                        auto const path_in_load_font_node = _file->parent_path() / load_font_node->uri;
                        if (font->file() && path_in_load_font_node == *font->file()) {
-                               _fonts.push_back(Font(load_font_node->id, asset->id(), font->file().get()));
+                               auto existing = std::find_if(_fonts.begin(), _fonts.end(), [load_font_node](Font const& font) { return font.load_id == load_font_node->id; });
+                               if (existing != _fonts.end()) {
+                                       *existing = Font(load_font_node->id, asset->id(), font->file().get());
+                               } else {
+                                       _fonts.push_back(Font(load_font_node->id, asset->id(), font->file().get()));
+                               }
                        }
                }
        }