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.
This commit is contained in:
Thomas Goyne 2012-11-26 16:37:53 -08:00
parent a5ac77368c
commit d7b01edc64

View file

@ -29,6 +29,8 @@
#include "ass_style.h" #include "ass_style.h"
#include "utils.h" #include "utils.h"
#include <libaegisub/of_type_adaptor.h>
#ifndef AGI_PRE #ifndef AGI_PRE
#include <algorithm> #include <algorithm>
@ -154,19 +156,18 @@ std::vector<wxString> FontCollector::GetFontPaths(const AssFile *file) {
status_callback(_("Parsing file\n"), 0); status_callback(_("Parsing file\n"), 0);
int index = 0; for (auto style : file->Line | agi::of_type<const AssStyle>()) {
for (auto const& line : file->Line) { StyleInfo &info = styles[style->name];
if (const AssStyle *style = dynamic_cast<const AssStyle*>(&line)) { info.facename = style->font;
StyleInfo &info = styles[style->name]; info.bold = style->bold;
info.facename = style->font; info.italic = style->italic;
info.bold = style->bold; used_styles[info].styles.insert(style->name);
info.italic = style->italic;
used_styles[info].styles.insert(style->name);
}
else if (const AssDialogue *diag = dynamic_cast<const AssDialogue*>(&line))
ProcessDialogueLine(diag, ++index);
} }
int index = 0;
for (auto diag : file->Line | agi::of_type<const AssDialogue>())
ProcessDialogueLine(diag, ++index);
status_callback(_("Searching for font files\n"), 0); status_callback(_("Searching for font files\n"), 0);
for_each(used_styles.begin(), used_styles.end(), bind(&FontCollector::ProcessChunk, this, _1)); for_each(used_styles.begin(), used_styles.end(), bind(&FontCollector::ProcessChunk, this, _1));
status_callback(_("Done\n\n"), 0); status_callback(_("Done\n\n"), 0);