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.
This commit is contained in:
Thomas Goyne 2012-10-10 07:04:44 -07:00
parent 983d0b19eb
commit a1fad1f947
11 changed files with 38 additions and 107 deletions

View file

@ -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<int>(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]);
}

View file

@ -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();
};

View file

@ -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;
}
}

View file

@ -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));

View file

@ -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();

View file

@ -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");
}

View file

@ -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();

View file

@ -102,7 +102,7 @@ class DialogStyleEditor : public wxDialog {
wxSpinCtrl *colorAlpha[4];
/// DOCME
wxSpinCtrl *margin[4];
wxSpinCtrl *margin[3];
/// DOCME
wxRadioBox *Alignment;

View file

@ -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));
}

View file

@ -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();
}

View file

@ -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];
}