From d7b01edc64909bfa322843a2e5e6ceb031a2059b Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 26 Nov 2012 16:37:53 -0800 Subject: [PATCH] Support styles after the dialogue in the fonts collector Make two passes over the file to collect all of the styles before processing the dialogue lines, as the styles section can legally come after the dialogue lines which use those styles. --- aegisub/src/font_file_lister.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/aegisub/src/font_file_lister.cpp b/aegisub/src/font_file_lister.cpp index e7d16a0f3..e474b98f5 100644 --- a/aegisub/src/font_file_lister.cpp +++ b/aegisub/src/font_file_lister.cpp @@ -29,6 +29,8 @@ #include "ass_style.h" #include "utils.h" +#include + #ifndef AGI_PRE #include @@ -154,19 +156,18 @@ std::vector FontCollector::GetFontPaths(const AssFile *file) { status_callback(_("Parsing file\n"), 0); - int index = 0; - for (auto const& line : file->Line) { - if (const AssStyle *style = dynamic_cast(&line)) { - StyleInfo &info = styles[style->name]; - info.facename = style->font; - info.bold = style->bold; - info.italic = style->italic; - used_styles[info].styles.insert(style->name); - } - else if (const AssDialogue *diag = dynamic_cast(&line)) - ProcessDialogueLine(diag, ++index); + for (auto style : file->Line | agi::of_type()) { + StyleInfo &info = styles[style->name]; + info.facename = style->font; + info.bold = style->bold; + info.italic = style->italic; + used_styles[info].styles.insert(style->name); } + int index = 0; + for (auto diag : file->Line | agi::of_type()) + ProcessDialogueLine(diag, ++index); + status_callback(_("Searching for font files\n"), 0); for_each(used_styles.begin(), used_styles.end(), bind(&FontCollector::ProcessChunk, this, _1)); status_callback(_("Done\n\n"), 0);