diff --git a/aegisub/src/ass_dialogue.cpp b/aegisub/src/ass_dialogue.cpp index 0152aa822..73be4c5f7 100644 --- a/aegisub/src/ass_dialogue.cpp +++ b/aegisub/src/ass_dialogue.cpp @@ -216,8 +216,7 @@ std::auto_ptr> AssDialogue::ParseTags() cons if (work.size() && work.find('\\') == std::string::npos) { //We've found an override block with no backslashes //We're going to assume it's a comment and not consider it an override block - //Currently we'll treat this as a plain text block, but feel free to create a new class - Blocks.push_back(new AssDialogueBlockPlain("{" + work + "}")); + Blocks.push_back(new AssDialogueBlockComment(work)); } else { // Create block diff --git a/aegisub/src/ass_dialogue.h b/aegisub/src/ass_dialogue.h index d147d1bd3..33a8f97ca 100644 --- a/aegisub/src/ass_dialogue.h +++ b/aegisub/src/ass_dialogue.h @@ -45,6 +45,7 @@ enum AssBlockType { BLOCK_BASE, BLOCK_PLAIN, + BLOCK_COMMENT, BLOCK_OVERRIDE, BLOCK_DRAWING }; @@ -89,6 +90,12 @@ public: AssDialogueBlockPlain(std::string const& text = std::string()) : AssDialogueBlock(text) { } }; +class AssDialogueBlockComment : public AssDialogueBlock { +public: + AssBlockType GetType() const override { return BLOCK_COMMENT; } + AssDialogueBlockComment(std::string const& text = std::string()) : AssDialogueBlock("{" + text + "}") { } +}; + class AssDialogueBlockDrawing : public AssDialogueBlock { public: int Scale; diff --git a/aegisub/src/ass_karaoke.cpp b/aegisub/src/ass_karaoke.cpp index 7a22d7102..0f34fed15 100644 --- a/aegisub/src/ass_karaoke.cpp +++ b/aegisub/src/ass_karaoke.cpp @@ -109,18 +109,14 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) { for (auto& block : blocks) { std::string text = block.GetText(); - if (dynamic_cast(&block)) { - // treat comments as overrides rather than dialogue - if (boost::starts_with(text, "{")) - syl.ovr_tags[syl.text.size()] += text; - else - syl.text += text; - } - else if (dynamic_cast(&block)) { + if (dynamic_cast(&block)) + syl.text += text; + else if (dynamic_cast(&block)) + syl.ovr_tags[syl.text.size()] += text; + else if (dynamic_cast(&block)) // drawings aren't override tags but they shouldn't show up in the // stripped text so pretend they are syl.ovr_tags[syl.text.size()] += text; - } else if (AssDialogueBlockOverride *ovr = dynamic_cast(&block)) { bool in_tag = false; for (auto& tag : ovr->Tags) { diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index c0396590a..9b5a5979c 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -205,15 +205,13 @@ void set_tag(AssDialogue *line, boost::ptr_vector &blocks, std AssDialogueBlock *block = &blocks[blockn]; if (dynamic_cast(block)) --blockn; - else if ((plain = dynamic_cast(block))) { + else if (dynamic_cast(block)) { // Cursor is in a comment block, so try the previous block instead - if (boost::starts_with(plain->GetText(), "{")) { - --blockn; - start = line->Text.get().rfind('{', start); - } - else - break; + --blockn; + start = line->Text.get().rfind('{', start); } + else if ((plain = dynamic_cast(block))) + break; else { ovr = dynamic_cast(block); assert(ovr); diff --git a/aegisub/src/dialog_translation.cpp b/aegisub/src/dialog_translation.cpp index 5765670df..10ae3e80f 100644 --- a/aegisub/src/dialog_translation.cpp +++ b/aegisub/src/dialog_translation.cpp @@ -55,11 +55,7 @@ static void add_hotkey(wxSizer *sizer, wxWindow *parent, const char *command, wx // Skip over override blocks, comments, and whitespace between blocks static bool bad_block(AssDialogueBlock &block) { - if (block.GetType() != BLOCK_PLAIN) return true; - std::string text = block.GetText(); - if (boost::all(text, boost::is_space())) return true; - if (boost::starts_with(text, "{") && boost::ends_with(text, "}")) return true; - return false; + return block.GetType() != BLOCK_PLAIN || boost::all(block.GetText(), boost::is_space()); } DialogTranslation::DialogTranslation(agi::Context *c) @@ -256,7 +252,7 @@ void DialogTranslation::UpdateDisplay() { original_text->SetUnicodeStyling(cur_size, block.GetText().size(), 1); } } - else if (block.GetType() == BLOCK_OVERRIDE) + else original_text->AppendTextRaw(block.GetText().c_str()); ++i; } diff --git a/aegisub/src/font_file_lister.cpp b/aegisub/src/font_file_lister.cpp index d206867b8..4e5e22377 100644 --- a/aegisub/src/font_file_lister.cpp +++ b/aegisub/src/font_file_lister.cpp @@ -80,7 +80,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { else if (AssDialogueBlockPlain *txt = dynamic_cast(&block)) { wxString text(to_wx(txt->GetText())); - if (text.empty() || (text.size() >= 2 && text.StartsWith("{") && text.EndsWith("}"))) + if (text.empty()) continue; if (overriden) @@ -100,7 +100,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { chars.insert(cur); } } - // Do nothing with drawing blocks + // Do nothing with drawing and comment blocks } } diff --git a/aegisub/src/subtitle_format_ebu3264.cpp b/aegisub/src/subtitle_format_ebu3264.cpp index f54de07c1..183343083 100644 --- a/aegisub/src/subtitle_format_ebu3264.cpp +++ b/aegisub/src/subtitle_format_ebu3264.cpp @@ -287,10 +287,6 @@ namespace { wxString text = to_wx(b.GetText()); - // Skip comments - if (text.size() > 1 && text[0] =='{' && text.Last() == '}') - continue; - text.Replace("\\t", " "); while (special_char_search.Matches(text)) @@ -354,7 +350,7 @@ namespace break; default: - // ignore block, we don't want to output it (drawing or unknown) + // ignore block, we don't want to output it (drawing or comment) break; } } diff --git a/aegisub/src/visual_tool.cpp b/aegisub/src/visual_tool.cpp index 45483e833..82a2b8d04 100644 --- a/aegisub/src/visual_tool.cpp +++ b/aegisub/src/visual_tool.cpp @@ -553,12 +553,7 @@ void VisualToolBase::SetOverride(AssDialogue* line, std::string const& tag, wxSt boost::ptr_vector blocks(line->ParseTags()); AssDialogueBlock *block = &blocks.front(); - // Get current block as plain or override - assert(dynamic_cast(block) == nullptr); - - if (dynamic_cast(block)) - line->Text = "{" + to_wx(tag) + value + "}" + line->Text; - else if (AssDialogueBlockOverride *ovr = dynamic_cast(block)) { + if (AssDialogueBlockOverride *ovr = dynamic_cast(block)) { // Remove old of same for (size_t i = 0; i < ovr->Tags.size(); i++) { std::string const& name = ovr->Tags[i].Name; @@ -571,6 +566,8 @@ void VisualToolBase::SetOverride(AssDialogue* line, std::string const& tag, wxSt line->UpdateText(blocks); } + else + line->Text = "{" + to_wx(tag) + value + "}" + line->Text; } // If only export worked