Some re-structuring of the ass parser in gorgonsub.

Originally committed to SVN as r2068.
This commit is contained in:
Rodrigo Braz Monteiro 2008-03-16 03:31:51 +00:00
parent fb1de2da07
commit 072d747921
11 changed files with 318 additions and 131 deletions

View file

@ -261,6 +261,10 @@
RelativePath=".\src\prec.h"
>
</File>
<File
RelativePath=".\include\aegilib\serialize.h"
>
</File>
<File
RelativePath=".\src\text_file_reader.cpp"
>
@ -325,10 +329,22 @@
RelativePath=".\src\formats\format_ass_dialogue.cpp"
>
</File>
<File
RelativePath=".\src\formats\format_ass_dialogue.h"
>
</File>
<File
RelativePath=".\src\formats\format_ass_plain.h"
>
</File>
<File
RelativePath=".\src\formats\format_ass_style.cpp"
>
</File>
<File
RelativePath=".\src\formats\format_ass_style.h"
>
</File>
<File
RelativePath=".\include\aegilib\format_handler.h"
>

View file

@ -59,13 +59,14 @@ namespace Gorgonsub {
ActionList(Model &model,const String actionName,const String owner,bool undoAble);
void Start(const String actionName);
void AddAction(const ActionPtr action);
void AddActionStart(const ActionPtr action);
public:
~ActionList();
void AddAction(const ActionPtr action);
void Finish();
void InsertLine(SectionEntryPtr line,int position=-1,const String section=L"");
void RemoveLine(int position,const String section);
SectionEntryPtr ModifyLine(int position,const String section);

View file

@ -0,0 +1,46 @@
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/GORGONSUB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#pragma once
#include "gorgonstring.h"
namespace Gorgonsub {
// Interface to serialize classes
class SerializeText {
public:
virtual ~SerializeText(){}
virtual String ToText(int param) const=0;
};
};

View file

@ -139,6 +139,6 @@ void ActionModify::Execute(Model &model)
if (sectionName.IsEmpty()) sectionName = entry->GetDefaultGroup();
SectionPtr sect = GetSection(model,sectionName);
// Insert the line
// Modify the line
sect->GetEntryRef(lineNumber) = entry;
}

View file

@ -36,6 +36,7 @@
#include "section.h"
#include "model.h"
#include "format_ass.h"
#include "format_ass_plain.h"
#include "version.h"
#include "../text_file_reader.h"
#include "../text_file_writer.h"

View file

@ -36,6 +36,8 @@
#pragma once
#include "format.h"
#include "format_handler.h"
#include "format_ass_dialogue.h"
#include "format_ass_style.h"
#include "section.h"
#include "section_entry_dialogue.h"
#include "section_entry_style.h"
@ -47,13 +49,6 @@ namespace Gorgonsub {
class Model;
class TextFileWriter;
// Interface to serialize classes
class SerializeText {
public:
virtual ~SerializeText(){}
virtual String ToText(int param) const=0;
};
// Advanced Substation Alpha format handler
class FormatHandlerASS : public FormatHandler {
private:
@ -71,126 +66,6 @@ namespace Gorgonsub {
void Save(wxOutputStream &file,const String encoding);
};
// Dialogue
class DialogueASS : public SectionEntryDialogue, public SerializeText {
private:
String text;
String style;
String effect;
String actor;
Time start,end;
array<short,4> margin;
int layer;
bool isComment;
bool Parse(String data,int version);
String ToText(int param) const;
public:
// Constructors
DialogueASS();
DialogueASS(const String &data,int version);
// Basic features
String GetDefaultGroup() const { return L"Events"; }
SectionEntryPtr Clone() const { return SectionEntryPtr(new DialogueASS(*this)); }
// Capabilities
bool HasText() const { return true; }
bool HasTime() const { return true; }
bool HasStyle() const { return true; }
bool HasMargins() const { return true; }
// Read accessors
const String& GetText() const { return text; }
Time GetStartTime() const { return start; }
Time GetEndTime() const { return end; }
bool IsComment() const { return isComment; }
int GetLayer() const { return layer; }
int GetMargin(int n) const { return margin.at(n); }
const String& GetStyle() const { return style; }
const String& GetActor() const { return actor; }
const String& GetUserField() const { return effect; }
// Write acessors
void SetText(const String &setText) { text = setText; }
void SetStartTime(Time setStart) { start = setStart; }
void SetEndTime(Time setEnd) { end = setEnd; }
void SetComment(bool _isComment) { isComment = _isComment; }
void SetLayer(int _layer) { layer = _layer; }
void SetMargin(int _margin,int value) { margin.at(_margin) = value; }
void SetStyle(const String &_style) { style = _style; }
void SetUserField(const String &userField) { effect = userField; }
};
// Style
class StyleASS : public SectionEntryStyle, public SerializeText {
private:
String name;
String font;
float fontSize;
int formatVersion;
array<Colour,5> colour; // 0 = Primary, 1 = Secondary, 2 = Tertiary, 3 = Outline, 4 = Shadow
array<int,4> margin;
bool bold;
bool italic;
bool underline;
bool strikeout;
int borderStyle;
int alignment;
int encoding;
int relativeTo;
float scalex;
float scaley;
float spacing;
float angle;
float outline_w;
float shadow_w;
bool Parse(String data,int version);
int AlignSSAtoASS(int ssaAlignment) const;
int AlignASStoSSA(int assAlignment) const;
String ToText(int param) const;
public:
// Constructors
StyleASS();
StyleASS(String data,int version);
// Basic features
String GetDefaultGroup() const;
SectionEntryPtr Clone() const { return SectionEntryPtr(new StyleASS(*this)); }
// Read accessors
String GetName() const { return name; }
String GetFontName() const { return font; }
float GetFontSize() const { return fontSize; }
Colour GetColour(int n) const { return colour.at(n); }
int GetMargin(int n) const { return margin.at(n); }
};
// Raw line
class PlainASS : public SectionEntryPlain, public SerializeText {
private:
String data;
String ToText(int param) const { (void)param; return data; }
public:
PlainASS();
PlainASS(String _data) : data(_data) {}
// Basic features
String GetDefaultGroup() const { return L"Events"; }
SectionEntryPtr Clone() const { return SectionEntryPtr(new PlainASS(*this)); }
String GetText() const { return data; }
void SetText(const String &_data) { data = _data; }
};
// Advanced Substation Alpha format base class
class FormatASSFamily : public Format {
public:

View file

@ -33,7 +33,7 @@
// Contact: mailto:amz@aegisub.net
//
#include "format_ass.h"
#include "format_ass_dialogue.h"
#include "tokenizer.h"
#include "utils.h"
using namespace Gorgonsub;

View file

@ -0,0 +1,95 @@
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/GORGONSUB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#pragma once
#include "gorgonstring.h"
#include "section_entry_dialogue.h"
#include "serialize.h"
namespace Gorgonsub {
// Dialogue
class DialogueASS : public SectionEntryDialogue, public SerializeText {
private:
String text;
String style;
String effect;
String actor;
Time start,end;
array<short,4> margin;
int layer;
bool isComment;
bool Parse(String data,int version);
String ToText(int param) const;
public:
// Constructors
DialogueASS();
DialogueASS(const String &data,int version);
// Basic features
String GetDefaultGroup() const { return L"Events"; }
SectionEntryPtr Clone() const { return SectionEntryPtr(new DialogueASS(*this)); }
// Capabilities
bool HasText() const { return true; }
bool HasTime() const { return true; }
bool HasStyle() const { return true; }
bool HasMargins() const { return true; }
// Read accessors
const String& GetText() const { return text; }
Time GetStartTime() const { return start; }
Time GetEndTime() const { return end; }
bool IsComment() const { return isComment; }
int GetLayer() const { return layer; }
int GetMargin(int n) const { return margin.at(n); }
const String& GetStyle() const { return style; }
const String& GetActor() const { return actor; }
const String& GetUserField() const { return effect; }
// Write acessors
void SetText(const String &setText) { text = setText; }
void SetStartTime(Time setStart) { start = setStart; }
void SetEndTime(Time setEnd) { end = setEnd; }
void SetComment(bool _isComment) { isComment = _isComment; }
void SetLayer(int _layer) { layer = _layer; }
void SetMargin(int _margin,int value) { margin.at(_margin) = value; }
void SetStyle(const String &_style) { style = _style; }
void SetUserField(const String &userField) { effect = userField; }
};
};

View file

@ -0,0 +1,60 @@
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/GORGONSUB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#pragma once
#include "section_entry.h"
#include "serialize.h"
namespace Gorgonsub {
// Raw line
class PlainASS : public SectionEntryPlain, public SerializeText {
private:
String data;
String ToText(int param) const { (void)param; return data; }
public:
PlainASS();
PlainASS(String _data) : data(_data) {}
// Basic features
String GetDefaultGroup() const { return L"Events"; }
SectionEntryPtr Clone() const { return SectionEntryPtr(new PlainASS(*this)); }
String GetText() const { return data; }
void SetText(const String &_data) { data = _data; }
};
};

View file

@ -33,7 +33,7 @@
// Contact: mailto:amz@aegisub.net
//
#include "format_ass.h"
#include "format_ass_style.h"
#include "tokenizer.h"
#include "utils.h"
using namespace Gorgonsub;

View file

@ -0,0 +1,93 @@
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/GORGONSUB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#pragma once
#include "section_entry_style.h"
#include "serialize.h"
#include "tr1.h"
namespace Gorgonsub {
// Style
class StyleASS : public SectionEntryStyle, public SerializeText {
private:
String name;
String font;
float fontSize;
int formatVersion;
array<Colour,5> colour; // 0 = Primary, 1 = Secondary, 2 = Tertiary, 3 = Outline, 4 = Shadow
array<int,4> margin;
bool bold;
bool italic;
bool underline;
bool strikeout;
int borderStyle;
int alignment;
int encoding;
int relativeTo;
float scalex;
float scaley;
float spacing;
float angle;
float outline_w;
float shadow_w;
bool Parse(String data,int version);
int AlignSSAtoASS(int ssaAlignment) const;
int AlignASStoSSA(int assAlignment) const;
String ToText(int param) const;
public:
// Constructors
StyleASS();
StyleASS(String data,int version);
// Basic features
String GetDefaultGroup() const;
SectionEntryPtr Clone() const { return SectionEntryPtr(new StyleASS(*this)); }
// Read accessors
String GetName() const { return name; }
String GetFontName() const { return font; }
float GetFontSize() const { return fontSize; }
Colour GetColour(int n) const { return colour.at(n); }
int GetMargin(int n) const { return margin.at(n); }
};
};