2006-01-16 22:02:54 +01:00
|
|
|
// Copyright (c) 2005, Rodrigo Braz Monteiro
|
2010-06-24 03:24:43 +02:00
|
|
|
// Copyright (c) 2010, Thomas Goyne <plorkyeran@aegisub.org>
|
2006-01-16 22:02:54 +01:00
|
|
|
// 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.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file ass_override.cpp
|
|
|
|
/// @brief Parse and modify ASSA style overrides
|
|
|
|
/// @ingroup subs_storage
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2007-09-12 01:22:26 +02:00
|
|
|
#include <wx/log.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
#endif
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-06-09 01:21:39 +02:00
|
|
|
#include <libaegisub/log.h>
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_override.h"
|
2010-06-24 03:24:43 +02:00
|
|
|
#include "utils.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
AssOverrideParameter::AssOverrideParameter()
|
|
|
|
: classification(PARCLASS_NORMAL)
|
|
|
|
, omitted(false)
|
|
|
|
{
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
AssOverrideParameter::AssOverrideParameter(const AssOverrideParameter ¶m)
|
|
|
|
: VariableData(param)
|
|
|
|
, classification(param.classification)
|
|
|
|
, omitted(param.omitted)
|
|
|
|
{
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
void AssOverrideParameter::operator=(const AssOverrideParameter ¶m) {
|
|
|
|
DeleteValue();
|
|
|
|
new(this) AssOverrideParameter(param);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
// From ass_dialogue.h
|
|
|
|
AssDialogueBlockOverride::~AssDialogueBlockOverride() {
|
|
|
|
delete_clear(Tags);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
void AssDialogueBlockOverride::ParseTags() {
|
|
|
|
delete_clear(Tags);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
wxStringTokenizer tkn(text, "\\", wxTOKEN_STRTOK);
|
2007-06-03 02:37:49 +02:00
|
|
|
wxString curTag;
|
2011-09-28 21:43:11 +02:00
|
|
|
if (text.StartsWith("\\")) curTag = "\\";
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
while (tkn.HasMoreTokens()) {
|
|
|
|
curTag += tkn.GetNextToken();
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
// Check for parenthesis matching for \t
|
2011-09-28 21:43:11 +02:00
|
|
|
while (curTag.Freq('(') > curTag.Freq(')') && tkn.HasMoreTokens()) {
|
|
|
|
curTag << "\\" << tkn.GetNextToken();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
Tags.push_back(new AssOverrideTag(curTag));
|
2007-06-03 02:37:49 +02:00
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
curTag = "\\";
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
2010-06-04 05:08:04 +02:00
|
|
|
void AssDialogueBlockOverride::AddTag(wxString const& tag) {
|
2010-06-24 03:24:43 +02:00
|
|
|
Tags.push_back(new AssOverrideTag(tag));
|
2010-06-04 05:08:04 +02:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
wxString AssDialogueBlockOverride::GetText() {
|
|
|
|
text.clear();
|
2012-10-05 04:10:20 +02:00
|
|
|
for (std::vector<AssOverrideTag*>::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) {
|
2010-06-24 03:24:43 +02:00
|
|
|
text += **cur;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2009-08-01 05:27:13 +02:00
|
|
|
void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::ProcessParametersCallback callback,void *userData) {
|
2012-10-05 04:10:20 +02:00
|
|
|
for (std::vector<AssOverrideTag*>::iterator cur = Tags.begin(); cur != Tags.end(); ++cur) {
|
2010-06-04 05:07:58 +02:00
|
|
|
AssOverrideTag *curTag = *cur;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Find parameters
|
2012-10-05 04:10:20 +02:00
|
|
|
for (size_t n = 0; n < curTag->Params.size(); ++n) {
|
2010-06-24 03:24:43 +02:00
|
|
|
AssOverrideParameter *curPar = curTag->Params[n];
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
if (curPar->GetType() != VARDATA_NONE && !curPar->omitted) {
|
2012-10-05 04:10:20 +02:00
|
|
|
(*callback)(curTag->Name, n, curPar, userData);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Go recursive if it's a block parameter
|
|
|
|
if (curPar->GetType() == VARDATA_BLOCK) {
|
2010-06-16 08:20:06 +02:00
|
|
|
curPar->Get<AssDialogueBlockOverride*>()->ProcessParameters(callback,userData);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 03:52:36 +02:00
|
|
|
AssOverrideParamProto::AssOverrideParamProto(VariableDataType type,int opt,AssParameterClass classi)
|
2010-08-02 22:25:29 +02:00
|
|
|
: optional(opt)
|
|
|
|
, type(type)
|
2010-06-24 03:24:43 +02:00
|
|
|
, classification(classi)
|
|
|
|
{
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-10-12 03:52:36 +02:00
|
|
|
void AssOverrideTagProto::AddParam(VariableDataType type, AssParameterClass classi, int opt) {
|
2010-06-24 03:24:43 +02:00
|
|
|
params.push_back(AssOverrideParamProto(type, opt, classi));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2012-10-12 03:52:36 +02:00
|
|
|
void AssOverrideTagProto::Set(wxString newName, VariableDataType type, AssParameterClass classi, int opt) {
|
2010-06-24 03:24:43 +02:00
|
|
|
name = newName;
|
|
|
|
params.push_back(AssOverrideParamProto(type, opt, classi));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
static std::vector<AssOverrideTagProto> proto;
|
|
|
|
static void load_protos() {
|
|
|
|
static bool loaded = false;
|
2006-01-16 22:02:54 +01:00
|
|
|
if (loaded) return;
|
|
|
|
loaded = true;
|
|
|
|
|
2010-06-04 05:07:58 +02:00
|
|
|
proto.resize(56);
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// Longer tag names must appear before shorter tag names
|
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[0].Set("\\alpha", VARDATA_TEXT); // \alpha
|
|
|
|
proto[++i].Set("\\bord", VARDATA_FLOAT,PARCLASS_ABSOLUTE_SIZE); // \bord<depth>
|
|
|
|
proto[++i].Set("\\xbord", VARDATA_FLOAT,PARCLASS_ABSOLUTE_SIZE); // \xbord<depth>
|
|
|
|
proto[++i].Set("\\ybord", VARDATA_FLOAT,PARCLASS_ABSOLUTE_SIZE); // \ybord<depth>
|
|
|
|
proto[++i].Set("\\shad", VARDATA_FLOAT,PARCLASS_ABSOLUTE_SIZE); // \shad<depth>
|
|
|
|
proto[++i].Set("\\xshad", VARDATA_FLOAT,PARCLASS_ABSOLUTE_SIZE); // \xshad<depth>
|
|
|
|
proto[++i].Set("\\yshad", VARDATA_FLOAT,PARCLASS_ABSOLUTE_SIZE); // \yshad<depth>
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// \fade(<a1>,<a2>,<a3>,<t1>,<t2>,<t3>,<t4>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\fade";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_INT);
|
|
|
|
proto[i].AddParam(VARDATA_INT);
|
|
|
|
proto[i].AddParam(VARDATA_INT);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// \move(<x1>,<y1>,<x2>,<y2>[,<t1>,<t2>])
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\move";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_FLOAT,PARCLASS_ABSOLUTE_POS_X);
|
|
|
|
proto[i].AddParam(VARDATA_FLOAT,PARCLASS_ABSOLUTE_POS_Y);
|
|
|
|
proto[i].AddParam(VARDATA_FLOAT,PARCLASS_ABSOLUTE_POS_X);
|
|
|
|
proto[i].AddParam(VARDATA_FLOAT,PARCLASS_ABSOLUTE_POS_Y);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START);
|
2010-06-04 05:07:58 +02:00
|
|
|
|
|
|
|
// If these are rearranged, keep rect clip and vector clip adjacent in this order
|
2006-01-16 22:02:54 +01:00
|
|
|
// \clip(<x1>,<y1>,<x2>,<y2>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\clip";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_X);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_Y);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_X);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_Y);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// \clip([<scale>,]<some drawings>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\clip";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_NORMAL,OPTIONAL_2);
|
|
|
|
proto[i].AddParam(VARDATA_TEXT,PARCLASS_DRAWING);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2008-09-10 18:13:54 +02:00
|
|
|
// \iclip(<x1>,<y1>,<x2>,<y2>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\iclip";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_X);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_Y);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_X);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_Y);
|
2008-09-10 18:13:54 +02:00
|
|
|
|
|
|
|
// \iclip([<scale>,]<some drawings>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\iclip";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_NORMAL,OPTIONAL_2);
|
|
|
|
proto[i].AddParam(VARDATA_TEXT,PARCLASS_DRAWING);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[++i].Set("\\fscx", VARDATA_FLOAT,PARCLASS_RELATIVE_SIZE_X); // \fscx<percent>
|
|
|
|
proto[++i].Set("\\fscy", VARDATA_FLOAT,PARCLASS_RELATIVE_SIZE_Y); // \fscy<percent>
|
2006-01-16 22:02:54 +01:00
|
|
|
// \pos(<x>,<y>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\pos";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_FLOAT,PARCLASS_ABSOLUTE_POS_X);
|
|
|
|
proto[i].AddParam(VARDATA_FLOAT,PARCLASS_ABSOLUTE_POS_Y);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// \org(<x>,<y>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\org";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_X);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_ABSOLUTE_POS_Y);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[++i].Set("\\pbo", VARDATA_INT,PARCLASS_ABSOLUTE_POS_Y); // \pbo<y>
|
2006-01-16 22:02:54 +01:00
|
|
|
// \fad(<t1>,<t2>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\fad";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_END);
|
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[++i].Set("\\fsp", VARDATA_FLOAT,PARCLASS_ABSOLUTE_SIZE); // \fsp<pixels>
|
|
|
|
proto[++i].Set("\\frx", VARDATA_FLOAT); // \frx<degrees>
|
|
|
|
proto[++i].Set("\\fry", VARDATA_FLOAT); // \fry<degrees>
|
|
|
|
proto[++i].Set("\\frz", VARDATA_FLOAT); // \frz<degrees>
|
|
|
|
proto[++i].Set("\\fr", VARDATA_FLOAT); // \fr<degrees>
|
|
|
|
proto[++i].Set("\\fax", VARDATA_FLOAT); // \fax<factor>
|
|
|
|
proto[++i].Set("\\fay", VARDATA_FLOAT); // \fay<factor>
|
|
|
|
proto[++i].Set("\\1c", VARDATA_TEXT); // \1c&H<bbggrr>&
|
|
|
|
proto[++i].Set("\\2c", VARDATA_TEXT); // \2c&H<bbggrr>&
|
|
|
|
proto[++i].Set("\\3c", VARDATA_TEXT); // \3c&H<bbggrr>&
|
|
|
|
proto[++i].Set("\\4c", VARDATA_TEXT); // \4c&H<bbggrr>&
|
|
|
|
proto[++i].Set("\\1a", VARDATA_TEXT); // \1a&H<aa>&
|
|
|
|
proto[++i].Set("\\2a", VARDATA_TEXT); // \2a&H<aa>&
|
|
|
|
proto[++i].Set("\\3a", VARDATA_TEXT); // \3a&H<aa>&
|
|
|
|
proto[++i].Set("\\4a", VARDATA_TEXT); // \4a&H<aa>&
|
|
|
|
proto[++i].Set("\\fe", VARDATA_TEXT); // \fe<charset>
|
|
|
|
proto[++i].Set("\\ko", VARDATA_INT,PARCLASS_KARAOKE); // \ko<duration>
|
|
|
|
proto[++i].Set("\\kf", VARDATA_INT,PARCLASS_KARAOKE); // \kf<duration>
|
|
|
|
proto[++i].Set("\\be", VARDATA_INT); // \be<strength>
|
|
|
|
proto[++i].Set("\\blur", VARDATA_FLOAT); // \blur<strength>
|
|
|
|
proto[++i].Set("\\fn", VARDATA_TEXT); // \fn<name>
|
|
|
|
proto[++i].Set("\\fs+", VARDATA_FLOAT); // \fs+<size>
|
|
|
|
proto[++i].Set("\\fs-", VARDATA_FLOAT); // \fs-<size>
|
|
|
|
proto[++i].Set("\\fs", VARDATA_FLOAT,PARCLASS_ABSOLUTE_SIZE); // \fs<size>
|
|
|
|
proto[++i].Set("\\an", VARDATA_INT); // \an<alignment>
|
|
|
|
proto[++i].Set("\\c", VARDATA_TEXT); // \c&H<bbggrr>&
|
|
|
|
proto[++i].Set("\\b", VARDATA_INT); // \b<0/1/weight>
|
|
|
|
proto[++i].Set("\\i", VARDATA_BOOL); // \i<0/1>
|
|
|
|
proto[++i].Set("\\u", VARDATA_BOOL); // \u<0/1>
|
|
|
|
proto[++i].Set("\\s", VARDATA_BOOL); // \s<0/1>
|
|
|
|
proto[++i].Set("\\a", VARDATA_INT); // \a<alignment>
|
|
|
|
proto[++i].Set("\\k", VARDATA_INT,PARCLASS_KARAOKE); // \k<duration>
|
|
|
|
proto[++i].Set("\\K", VARDATA_INT,PARCLASS_KARAOKE); // \K<duration>
|
|
|
|
proto[++i].Set("\\q", VARDATA_INT); // \q<0-3>
|
|
|
|
proto[++i].Set("\\p", VARDATA_INT); // \p<n>
|
|
|
|
proto[++i].Set("\\r", VARDATA_TEXT); // \r[<name>]
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// \t([<t1>,<t2>,][<accel>,]<style modifiers>)
|
2010-06-04 05:07:58 +02:00
|
|
|
i++;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto[i].name = "\\t";
|
2010-06-24 03:24:43 +02:00
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START,OPTIONAL_3 | OPTIONAL_4);
|
|
|
|
proto[i].AddParam(VARDATA_INT,PARCLASS_RELATIVE_TIME_START,OPTIONAL_3 | OPTIONAL_4);
|
|
|
|
proto[i].AddParam(VARDATA_FLOAT,PARCLASS_NORMAL,OPTIONAL_2 | OPTIONAL_4);
|
|
|
|
proto[i].AddParam(VARDATA_BLOCK);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
AssOverrideTag::AssOverrideTag() : valid(false) { }
|
|
|
|
AssOverrideTag::AssOverrideTag(wxString text) {
|
|
|
|
SetText(text);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AssOverrideTag::~AssOverrideTag () {
|
2010-06-24 03:24:43 +02:00
|
|
|
delete_clear(Params);
|
2007-01-15 07:56:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AssOverrideTag::Clear() {
|
2010-06-24 03:24:43 +02:00
|
|
|
delete_clear(Params);
|
2010-06-04 05:07:58 +02:00
|
|
|
Params.reserve(6);
|
2006-01-16 22:02:54 +01:00
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
void AssOverrideTag::SetText(const wxString &text) {
|
|
|
|
load_protos();
|
2012-10-05 04:10:20 +02:00
|
|
|
for (AssOverrideTagProto::iterator cur = proto.begin(); cur != proto.end(); ++cur) {
|
2010-06-04 05:07:58 +02:00
|
|
|
if (text.StartsWith(cur->name)) {
|
|
|
|
Name = cur->name;
|
|
|
|
ParseParameters(text.Mid(Name.length()), cur);
|
|
|
|
valid = true;
|
|
|
|
return;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Junk tag
|
2010-06-04 05:07:58 +02:00
|
|
|
Name = text;
|
|
|
|
valid = false;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
std::vector<wxString> tokenize(const wxString &text) {
|
|
|
|
std::vector<wxString> paramList;
|
2010-06-04 05:07:58 +02:00
|
|
|
paramList.reserve(6);
|
2006-01-29 23:46:18 +01:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
if (text.empty()) {
|
|
|
|
return paramList;
|
|
|
|
}
|
2011-09-28 21:43:11 +02:00
|
|
|
if (text[0] != '(') {
|
2010-06-24 03:24:43 +02:00
|
|
|
// There's just one parameter (because there's no parentheses)
|
|
|
|
// This means text is all our parameters
|
|
|
|
wxString param(text);
|
|
|
|
paramList.push_back(param.Trim(true).Trim(false));
|
|
|
|
return paramList;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ok, so there are parentheses used here, so there may be more than one parameter
|
|
|
|
// Enter fullscale parsing!
|
|
|
|
size_t i = 0, textlen = text.size();
|
|
|
|
size_t start = 0;
|
|
|
|
int parDepth = 1;
|
|
|
|
while (i < textlen && parDepth > 0) {
|
|
|
|
// Just skip until next ',' or ')', whichever comes first
|
|
|
|
// (Next ')' is achieved when parDepth == 0)
|
|
|
|
start = ++i;
|
2006-01-29 23:46:18 +01:00
|
|
|
while (i < textlen && parDepth > 0) {
|
2010-06-24 03:24:43 +02:00
|
|
|
wxChar c = text[i];
|
|
|
|
// parDepth 1 is where we start, and the tag-level we're interested in parsing on
|
2011-09-28 21:43:11 +02:00
|
|
|
if (c == ',' && parDepth == 1) break;
|
|
|
|
if (c == '(') parDepth++;
|
|
|
|
else if (c == ')') {
|
2010-06-24 03:24:43 +02:00
|
|
|
parDepth--;
|
|
|
|
if (parDepth < 0) {
|
2011-09-28 21:43:48 +02:00
|
|
|
wxLogWarning("Unmatched parenthesis near '%s'!\nTag-parsing incomplete.", text.SubString(i, 10));
|
2010-06-24 03:24:43 +02:00
|
|
|
return paramList;
|
|
|
|
}
|
|
|
|
else if (parDepth == 0) {
|
|
|
|
// We just ate the parenthesis ending this parameter block
|
|
|
|
// Make sure it doesn't get included in the parameter text
|
|
|
|
break;
|
2006-01-29 23:46:18 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2010-06-24 03:24:43 +02:00
|
|
|
i++;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2010-06-24 03:24:43 +02:00
|
|
|
// i now points to the first character not member of this parameter
|
|
|
|
paramList.push_back(text.SubString(start, i-1).Trim(true).Trim(false));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2010-06-24 03:24:43 +02:00
|
|
|
|
|
|
|
if (i+1 < textlen) {
|
|
|
|
// There's some additional garbage after the parentheses
|
|
|
|
// Just add it in for completeness
|
|
|
|
paramList.push_back(text.Mid(i+1));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2010-06-24 03:24:43 +02:00
|
|
|
return paramList;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-12-26 23:20:49 +01:00
|
|
|
void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto::iterator proto_it) {
|
2010-06-24 03:24:43 +02:00
|
|
|
Clear();
|
|
|
|
|
|
|
|
// Tokenize text, attempting to find all parameters
|
|
|
|
std::vector<wxString> paramList = tokenize(text);
|
|
|
|
size_t totalPars = paramList.size();
|
|
|
|
|
|
|
|
int parsFlag = 1 << (totalPars - 1); // Get optional parameters flag
|
2011-12-26 23:20:49 +01:00
|
|
|
// vector (i)clip is the second clip proto_ittype in the list
|
2011-09-28 21:43:11 +02:00
|
|
|
if ((Name == "\\clip" || Name == "\\iclip") && totalPars != 4) {
|
2011-12-26 23:20:49 +01:00
|
|
|
++proto_it;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2006-01-17 08:52:18 +01:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
unsigned curPar = 0;
|
2011-12-26 23:20:49 +01:00
|
|
|
for (size_t n = 0; n < proto_it->params.size(); n++) {
|
|
|
|
AssOverrideParamProto *curproto = &proto_it->params[n];
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Create parameter
|
|
|
|
AssOverrideParameter *newparam = new AssOverrideParameter;
|
2010-06-11 04:24:59 +02:00
|
|
|
newparam->classification = curproto->classification;
|
|
|
|
Params.push_back(newparam);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
// Check if it's optional and not present
|
|
|
|
if (!(curproto->optional & parsFlag) || curPar >= totalPars) {
|
|
|
|
newparam->omitted = true;
|
|
|
|
continue;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
wxString curtok = paramList[curPar++];
|
|
|
|
|
|
|
|
if (curtok.empty()) {
|
|
|
|
curPar++;
|
|
|
|
continue;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
wxChar firstChar = curtok[0];
|
2011-09-28 21:43:11 +02:00
|
|
|
bool auto4 = (firstChar == '!' || firstChar == '$' || firstChar == '%') && curproto->type != VARDATA_BLOCK;
|
2010-06-24 03:24:43 +02:00
|
|
|
if (auto4) {
|
|
|
|
newparam->Set(curtok);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (curproto->type) {
|
|
|
|
case VARDATA_INT: {
|
|
|
|
long temp;
|
|
|
|
curtok.ToLong(&temp);
|
|
|
|
newparam->Set<int>(temp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VARDATA_FLOAT: {
|
|
|
|
double temp;
|
|
|
|
curtok.ToDouble(&temp);
|
|
|
|
newparam->Set(temp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VARDATA_TEXT:
|
|
|
|
newparam->Set(curtok);
|
|
|
|
break;
|
|
|
|
case VARDATA_BOOL: {
|
|
|
|
long temp;
|
|
|
|
curtok.ToLong(&temp);
|
|
|
|
newparam->Set<bool>(temp != 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VARDATA_BLOCK: {
|
2011-12-26 23:21:08 +01:00
|
|
|
AssDialogueBlockOverride *temp = new AssDialogueBlockOverride(curtok);
|
2010-06-24 03:24:43 +02:00
|
|
|
temp->ParseTags();
|
|
|
|
newparam->Set(temp);
|
|
|
|
break;
|
2006-01-29 23:46:18 +01:00
|
|
|
}
|
2010-06-24 03:24:43 +02:00
|
|
|
default:
|
|
|
|
break;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 01:39:10 +01:00
|
|
|
AssOverrideTag::operator wxString() const {
|
2006-01-16 22:02:54 +01:00
|
|
|
wxString result = Name;
|
|
|
|
|
2006-01-29 23:46:18 +01:00
|
|
|
// Determine if it needs parentheses
|
2010-06-24 03:24:43 +02:00
|
|
|
bool parentheses =
|
2011-09-28 21:43:11 +02:00
|
|
|
Name == "\\t" ||
|
|
|
|
Name == "\\pos" ||
|
|
|
|
Name == "\\fad" ||
|
|
|
|
Name == "\\org" ||
|
|
|
|
Name == "\\clip" ||
|
|
|
|
Name == "\\iclip" ||
|
|
|
|
Name == "\\move" ||
|
|
|
|
Name == "\\fade";
|
|
|
|
if (parentheses) result += "(";
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Add parameters
|
2010-06-24 03:24:43 +02:00
|
|
|
bool any = false;
|
2012-10-05 04:10:20 +02:00
|
|
|
for (std::vector<AssOverrideParameter*>::const_iterator cur = Params.begin(); cur != Params.end(); ++cur) {
|
2010-06-24 03:24:43 +02:00
|
|
|
if ((*cur)->GetType() != VARDATA_NONE && !(*cur)->omitted) {
|
2010-06-16 08:20:06 +02:00
|
|
|
result += (*cur)->Get<wxString>();
|
2011-09-28 21:43:11 +02:00
|
|
|
result += ",";
|
2010-06-24 03:24:43 +02:00
|
|
|
any = true;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
2010-06-24 03:24:43 +02:00
|
|
|
if (any) result = result.Left(result.Length()-1);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
if (parentheses) result += ")";
|
2006-01-16 22:02:54 +01:00
|
|
|
return result;
|
|
|
|
}
|