From a1fad1f947397c1a7103e918daeb59b45e017055 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 10 Oct 2012 07:04:44 -0700 Subject: [PATCH] Drop support for ASS2 It is very unlikely that anyone has ever actually used ASS2 for anything, and in practice it was not usable anyway as the bottom margin was always either ignored or blindly overwritten. --- aegisub/src/ass_dialogue.cpp | 70 +++++++---------------------- aegisub/src/ass_dialogue.h | 15 +++---- aegisub/src/ass_file.cpp | 16 ++----- aegisub/src/ass_style.cpp | 14 +----- aegisub/src/ass_style.h | 3 +- aegisub/src/auto4_lua_assfile.cpp | 6 +-- aegisub/src/dialog_style_editor.cpp | 4 +- aegisub/src/dialog_style_editor.h | 2 +- aegisub/src/subs_edit_box.cpp | 7 +-- aegisub/src/subs_preview.cpp | 2 +- aegisub/src/visual_tool.cpp | 6 +-- 11 files changed, 38 insertions(+), 107 deletions(-) diff --git a/aegisub/src/ass_dialogue.cpp b/aegisub/src/ass_dialogue.cpp index 924fe428d..76ed31eed 100644 --- a/aegisub/src/ass_dialogue.cpp +++ b/aegisub/src/ass_dialogue.cpp @@ -70,13 +70,10 @@ AssDialogue::AssDialogue(AssDialogue const& that) , Effect(that.Effect) , Text(that.Text) { - for (int i=0;i<4;i++) Margin[i] = that.Margin[i]; + memmove(Margin, that.Margin, sizeof Margin); } -/// @brief DOCME -/// @param _data -/// @param version -AssDialogue::AssDialogue(wxString _data,int version) +AssDialogue::AssDialogue(wxString const& data) : AssEntry(wxString(), "[Events]") , Comment(false) , Layer(0) @@ -84,18 +81,7 @@ AssDialogue::AssDialogue(wxString _data,int version) , End(5000) , Style("Default") { - bool valid = false; - // Try parsing in different ways - int count = 0; - while (!valid && count < 3) { - valid = Parse(_data,version); - count++; - version++; - if (version > 2) version = 0; - } - - // Not valid - if (!valid) + if (!Parse(data)) throw "Failed parsing line."; } @@ -107,7 +93,7 @@ void AssDialogue::ClearBlocks() { delete_clear(Blocks); } -bool AssDialogue::Parse(wxString rawData, int version) { +bool AssDialogue::Parse(wxString const& rawData) { size_t pos = 0; wxString temp; @@ -127,11 +113,11 @@ bool AssDialogue::Parse(wxString rawData, int version) { // Get first token and see if it has "Marked=" in it temp = tkn.GetNextToken().Trim(false).Trim(true); - if (temp.Lower().StartsWith("marked=")) version = 0; - else if (version == 0) version = 1; + bool ssa = temp.Lower().StartsWith("marked="); // Get layer number - if (version == 0) Layer = 0; + if (ssa) + Layer = 0; else { long templ; temp.ToLong(&templ); @@ -158,43 +144,19 @@ bool AssDialogue::Parse(wxString rawData, int version) { Actor.Trim(true); Actor.Trim(false); - // Get left margin - if (!tkn.HasMoreTokens()) return false; - SetMarginString(tkn.GetNextToken().Trim(false).Trim(true),0); - - // Get right margin - if (!tkn.HasMoreTokens()) return false; - SetMarginString(tkn.GetNextToken().Trim(false).Trim(true),1); - - // Get top margin - if (!tkn.HasMoreTokens()) return false; - temp = tkn.GetNextToken().Trim(false).Trim(true); - SetMarginString(temp,2); - if (version == 1) SetMarginString(temp,3); - - // Get bottom margin - bool rollBack = false; - if (version == 2) { + // Get margins + for (int i = 0; i < 3; ++i) { if (!tkn.HasMoreTokens()) return false; - wxString oldTemp = temp; - temp = tkn.GetNextToken().Trim(false).Trim(true); - if (!temp.IsNumber()) { - version = 1; - rollBack = true; - } + SetMarginString(tkn.GetNextToken().Trim(false).Trim(true), i); } - // Get effect - if (!rollBack) { - if (!tkn.HasMoreTokens()) return false; - temp = tkn.GetNextToken(); - } - Effect = temp; + if (!tkn.HasMoreTokens()) return false; + Effect = tkn.GetNextToken(); Effect.Trim(true); Effect.Trim(false); // Get text - Text = rawData.Mid(pos+tkn.GetPosition()); + Text = rawData.Mid(pos + tkn.GetPosition()); return true; } @@ -357,7 +319,7 @@ void AssDialogue::UpdateText () { } void AssDialogue::SetMarginString(wxString const& origvalue, int which) { - if (which < 0 || which >= 4) throw Aegisub::InvalidMarginIdError(); + if (which < 0 || which > 2) throw Aegisub::InvalidMarginIdError(); // Make it numeric wxString strvalue = origvalue; @@ -376,8 +338,8 @@ void AssDialogue::SetMarginString(wxString const& origvalue, int which) { Margin[which] = mid(0, value, 9999); } -wxString AssDialogue::GetMarginString(int which,bool pad) const { - if (which < 0 || which >= 4) throw Aegisub::InvalidMarginIdError(); +wxString AssDialogue::GetMarginString(int which, bool pad) const { + if (which < 0 || which > 2) throw Aegisub::InvalidMarginIdError(); return wxString::Format(pad ? "%04d" : "%d", Margin[which]); } diff --git a/aegisub/src/ass_dialogue.h b/aegisub/src/ass_dialogue.h index 64a4ed191..0a1511304 100644 --- a/aegisub/src/ass_dialogue.h +++ b/aegisub/src/ass_dialogue.h @@ -128,8 +128,8 @@ public: bool Comment; /// Layer number int Layer; - /// Margins: 0 = Left, 1 = Right, 2 = Top (Vertical), 3 = Bottom - int Margin[4]; + /// Margins: 0 = Left, 1 = Right, 2 = Top (Vertical) + int Margin[3]; /// Starting time AssTime Start; /// Ending time @@ -147,9 +147,8 @@ public: /// @brief Parse raw ASS data into everything else /// @param data ASS line - /// @param version ASS version to try first (4, 4+, ASS2) /// @return Did it successfully parse? - bool Parse(wxString data,int version=1); + bool Parse(wxString const& data); /// Parse text as ASS to generate block information void ParseASSTags(); @@ -181,12 +180,12 @@ public: void SetMarginString(wxString const& value) { SetMarginString(value, which);} /// @brief Set a margin /// @param value New value of the margin - /// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom + /// @param which 0 = left, 1 = right, 2 = vertical void SetMarginString(wxString const& value, int which); /// @brief Get a margin - /// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom + /// @param which 0 = left, 1 = right, 2 = vertical /// @param pad Pad the number to four digits - wxString GetMarginString(int which,bool pad=true) const; + wxString GetMarginString(int which, bool pad=true) const; /// Get the line as SSA rather than ASS wxString GetSSAText() const; /// Does this line collide with the passed line? @@ -196,6 +195,6 @@ public: AssDialogue(); AssDialogue(AssDialogue const&); - AssDialogue(wxString data,int version=1); + AssDialogue(wxString const& data); ~AssDialogue(); }; diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index d67202f18..64ccc5860 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -280,10 +280,6 @@ void AssFile::AddLine(wxString data, int *version, AssAttachment **attach) { data = "[V4+ Styles]"; *version = 1; } - else if (low == "[v4++ styles]") { - data = "[V4+ Styles]"; - *version = 2; - } Line.push_back(new AssEntry(data, data)); return; @@ -305,7 +301,7 @@ void AssFile::AddLine(wxString data, int *version, AssAttachment **attach) { // Dialogue else if (lowGroup == "[events]") { if (data.StartsWith("Dialogue:") || data.StartsWith("Comment:")) - Line.push_back(new AssDialogue(data, *version)); + Line.push_back(new AssDialogue(data)); else if (data.StartsWith("Format:")) Line.push_back(new AssEntry("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text", group)); } @@ -332,14 +328,10 @@ void AssFile::AddLine(wxString data, int *version, AssAttachment **attach) { trueVersion = 0; else if (versionString == "v4.00+") trueVersion = 1; - else if (versionString == "v4.00++") - trueVersion = 2; - else throw - "Unknown SSA file format version"; + else + throw "Unknown SSA file format version"; if (trueVersion != *version) { - if (!(trueVersion == 2 && *version == 1)) { - wxLogMessage("Warning: File has the wrong extension."); - } + wxLogMessage("Warning: File has the wrong extension."); *version = trueVersion; } } diff --git a/aegisub/src/ass_style.cpp b/aegisub/src/ass_style.cpp index 1f407a7dc..279855dc7 100644 --- a/aegisub/src/ass_style.cpp +++ b/aegisub/src/ass_style.cpp @@ -164,7 +164,6 @@ AssStyle::AssStyle() , shadow_w(2.) , alignment(2) , encoding(1) -, relativeTo(1) { for (int i = 0; i < 4; i++) Margin[i] = 10; @@ -255,15 +254,9 @@ AssStyle::AssStyle(wxString rawData, int version) // Read right margin Margin[1] = mid(0, get_next_int(tkn), 9999); - // Read top margin + // Read vertical margin Margin[2] = mid(0, get_next_int(tkn), 9999); - // Read bottom margin - if (version == 2) - Margin[3] = mid(0, get_next_int(tkn), 9999); - else - Margin[3] = Margin[2]; - // Skip alpha level if (version == 0) get_next_string(tkn); @@ -271,10 +264,6 @@ AssStyle::AssStyle(wxString rawData, int version) // Read encoding encoding = get_next_int(tkn); - // Read relative to - if (version == 2) - relativeTo = get_next_int(tkn); - if (tkn.HasMoreTokens()) throw "Malformed style: too many fields"; @@ -305,7 +294,6 @@ AssStyle& AssStyle::operator=(AssStyle const& rgt) { shadow_w = rgt.shadow_w; alignment = rgt.alignment; encoding = rgt.encoding; - relativeTo = rgt.relativeTo; memcpy(Margin, rgt.Margin, sizeof(Margin)); diff --git a/aegisub/src/ass_style.h b/aegisub/src/ass_style.h index d383001ec..64360589f 100644 --- a/aegisub/src/ass_style.h +++ b/aegisub/src/ass_style.h @@ -94,9 +94,8 @@ public: double outline_w; ///< Outline width in pixels double shadow_w; ///< Shadow distance in pixels int alignment; ///< \an-style line alignment - int Margin[4]; ///< Left/Right/Vertical/Unused margins in pixels + int Margin[3]; ///< Left/Right/Vertical int encoding; ///< ASS font encoding needed for some non-unicode fonts - int relativeTo; ///< ASS2 extension; do not use /// Update the raw line data after one or more of the public members have been changed void UpdateData(); diff --git a/aegisub/src/auto4_lua_assfile.cpp b/aegisub/src/auto4_lua_assfile.cpp index 747b1c929..c6c812acb 100644 --- a/aegisub/src/auto4_lua_assfile.cpp +++ b/aegisub/src/auto4_lua_assfile.cpp @@ -229,7 +229,7 @@ namespace Automation4 { set_field(L, "margin_l", dia->Margin[0]); set_field(L, "margin_r", dia->Margin[1]); set_field(L, "margin_t", dia->Margin[2]); - set_field(L, "margin_b", dia->Margin[3]); + set_field(L, "margin_b", dia->Margin[2]); set_field(L, "text", dia->Text); @@ -267,7 +267,7 @@ namespace Automation4 { set_field(L, "margin_l", sty->Margin[0]); set_field(L, "margin_r", sty->Margin[1]); set_field(L, "margin_t", sty->Margin[2]); - set_field(L, "margin_b", sty->Margin[3]); + set_field(L, "margin_b", sty->Margin[2]); set_field(L, "encoding", sty->encoding); @@ -340,7 +340,6 @@ namespace Automation4 { sty->Margin[0] = get_int_field(L, "margin_l", "style"); sty->Margin[1] = get_int_field(L, "margin_r", "style"); sty->Margin[2] = get_int_field(L, "margin_t", "style"); - sty->Margin[3] = get_int_field(L, "margin_b", "style"); sty->encoding = get_int_field(L, "encoding", "style"); sty->UpdateData(); } @@ -357,7 +356,6 @@ namespace Automation4 { dia->Margin[0] = get_int_field(L, "margin_l", "dialogue"); dia->Margin[1] = get_int_field(L, "margin_r", "dialogue"); dia->Margin[2] = get_int_field(L, "margin_t", "dialogue"); - dia->Margin[3] = get_int_field(L, "margin_b", "dialogue"); dia->Effect = get_string_field(L, "effect", "dialogue"); dia->Text = get_string_field(L, "text", "dialogue"); } diff --git a/aegisub/src/dialog_style_editor.cpp b/aegisub/src/dialog_style_editor.cpp index 2b3a3912f..d6da9ace6 100644 --- a/aegisub/src/dialog_style_editor.cpp +++ b/aegisub/src/dialog_style_editor.cpp @@ -203,7 +203,6 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con colorAlpha[3] = spin_ctrl(this, style->shadow.a, 255); for (int i = 0; i < 3; i++) margin[i] = spin_ctrl(this, style->Margin[i], 9999); - margin[3] = 0; Alignment = new wxRadioBox(this, -1, _("Alignment"), wxDefaultPosition, wxDefaultSize, 9, alignValues, 3, wxRA_SPECIFY_COLS); Outline = num_text_ctrl(this, style->outline_w, wxSize(50, -1)); Shadow = num_text_ctrl(this, style->shadow_w, wxSize(50, -1)); @@ -508,9 +507,8 @@ void DialogStyleEditor::UpdateWorkStyle() { work->alignment = ControlToAlign(Alignment->GetSelection()); - for (int i=0;i<3;i++) + for (size_t i = 0; i < 3; ++i) work->Margin[i] = margin[i]->GetValue(); - work->Margin[3] = margin[2]->GetValue(); work->primary.a = colorAlpha[0]->GetValue(); work->secondary.a = colorAlpha[1]->GetValue(); diff --git a/aegisub/src/dialog_style_editor.h b/aegisub/src/dialog_style_editor.h index 9ba357b3f..29fa8ad72 100644 --- a/aegisub/src/dialog_style_editor.h +++ b/aegisub/src/dialog_style_editor.h @@ -102,7 +102,7 @@ class DialogStyleEditor : public wxDialog { wxSpinCtrl *colorAlpha[4]; /// DOCME - wxSpinCtrl *margin[4]; + wxSpinCtrl *margin[3]; /// DOCME wxRadioBox *Alignment; diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index c3ca7a008..eeec0a584 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -536,13 +536,8 @@ void SubsEditBox::OnMarginRChange(wxCommandEvent &) { if (line) change_value(MarginR, line->GetMarginString(1, false)); } -static void set_margin_v(AssDialogue* diag, wxString value) { - diag->SetMarginString(value, 2); - diag->SetMarginString(value, 3); -} - void SubsEditBox::OnMarginVChange(wxCommandEvent &) { - SetSelectedRows(set_margin_v, MarginV->GetValue(), _("MarginV change"), AssFile::COMMIT_DIAG_META); + SetSelectedRows(std::mem_fun(&AssDialogue::SetMarginString<2>), MarginV->GetValue(), _("MarginV change"), AssFile::COMMIT_DIAG_META); if (line) change_value(MarginV, line->GetMarginString(2, false)); } diff --git a/aegisub/src/subs_preview.cpp b/aegisub/src/subs_preview.cpp index 53e8ca32c..bada83ba2 100644 --- a/aegisub/src/subs_preview.cpp +++ b/aegisub/src/subs_preview.cpp @@ -81,7 +81,7 @@ void SubtitlesPreview::SetStyle(AssStyle const& newStyle) { *style = newStyle; style->name = "Default"; style->alignment = 5; - memset(style->Margin, 0, 4 * sizeof(int)); + memset(style->Margin, 0, sizeof style->Margin); style->UpdateData(); UpdateBitmap(); } diff --git a/aegisub/src/visual_tool.cpp b/aegisub/src/visual_tool.cpp index e3dc19d22..acac21d7c 100644 --- a/aegisub/src/visual_tool.cpp +++ b/aegisub/src/visual_tool.cpp @@ -404,13 +404,13 @@ Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) { if (Vector2D ret = vec_or_bad(find_tag(diag, "\\move"), 0, 1)) return ret; // Get default position - int margin[4]; - std::copy(diag->Margin, diag->Margin + 4, margin); + int margin[3]; + memcpy(margin, diag->Margin, sizeof margin); int align = 2; if (AssStyle *style = c->ass->GetStyle(diag->Style)) { align = style->alignment; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 3; i++) { if (margin[i] == 0) margin[i] = style->Margin[i]; }