forked from mia/Aegisub
Store AssOverrideTags directly rather than a vector of pointers
This commit is contained in:
parent
a0d3b8595f
commit
8c2062f0c7
16 changed files with 83 additions and 75 deletions
|
@ -41,7 +41,6 @@
|
|||
#include <wx/tokenzr.h>
|
||||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_override.h"
|
||||
#include "compat.h"
|
||||
#include "subtitle_format.h"
|
||||
#include "utils.h"
|
||||
|
@ -226,9 +225,9 @@ std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> AssDialogue::ParseTags() cons
|
|||
Blocks.push_back(block);
|
||||
|
||||
// Look for \p in block
|
||||
for (auto tag : block->Tags) {
|
||||
if (tag->Name == "\\p")
|
||||
drawingLevel = tag->Params[0].Get<int>(0);
|
||||
for (auto const& tag : block->Tags) {
|
||||
if (tag.Name == "\\p")
|
||||
drawingLevel = tag.Params[0].Get<int>(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,9 +273,9 @@ void AssDialogue::StripTag(wxString const& tag_name) {
|
|||
|
||||
AssDialogueBlockOverride *over = static_cast<AssDialogueBlockOverride*>(&block);
|
||||
wxString temp;
|
||||
for (auto tag : over->Tags) {
|
||||
if (tag->Name != tag_name)
|
||||
temp += *tag;
|
||||
for (auto const& tag : over->Tags) {
|
||||
if (tag.Name != tag_name)
|
||||
temp += tag;
|
||||
}
|
||||
|
||||
if (!temp.empty())
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
///
|
||||
|
||||
#include "ass_entry.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_time.h"
|
||||
|
||||
#include <libaegisub/exception.h>
|
||||
|
@ -105,7 +106,7 @@ public:
|
|||
AssDialogueBlockOverride(wxString const& text = wxString()) : AssDialogueBlock(text) { }
|
||||
~AssDialogueBlockOverride();
|
||||
|
||||
std::vector<AssOverrideTag *> Tags;
|
||||
std::vector<AssOverrideTag> Tags;
|
||||
|
||||
AssBlockType GetType() const override { return BLOCK_OVERRIDE; }
|
||||
wxString GetText() override;
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include "ass_attachment.h"
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_info.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_style.h"
|
||||
#include "compat.h"
|
||||
#include "main.h"
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_override.h"
|
||||
#include "include/aegisub/context.h"
|
||||
#include "selection_controller.h"
|
||||
|
||||
|
@ -120,8 +119,8 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
|
|||
}
|
||||
else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(&block)) {
|
||||
bool in_tag = false;
|
||||
for (auto tag : ovr->Tags) {
|
||||
if (tag->IsValid() && tag->Name.Left(2).Lower() == "\\k") {
|
||||
for (auto& tag : ovr->Tags) {
|
||||
if (tag.IsValid() && tag.Name.Left(2).Lower() == "\\k") {
|
||||
if (in_tag) {
|
||||
syl.ovr_tags[syl.text.size()] += "}";
|
||||
in_tag = false;
|
||||
|
@ -129,7 +128,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
|
|||
|
||||
// Dealing with both \K and \kf is mildly annoying so just
|
||||
// convert them both to \kf
|
||||
if (tag->Name == "\\K") tag->Name = "\\kf";
|
||||
if (tag.Name == "\\K") tag.Name = "\\kf";
|
||||
|
||||
// Don't bother including zero duration zero length syls
|
||||
if (syl.duration > 0 || !syl.text.empty()) {
|
||||
|
@ -138,9 +137,9 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
|
|||
syl.ovr_tags.clear();
|
||||
}
|
||||
|
||||
syl.tag_type = tag->Name;
|
||||
syl.tag_type = tag.Name;
|
||||
syl.start_time += syl.duration;
|
||||
syl.duration = tag->Params[0].Get(0) * 10;
|
||||
syl.duration = tag.Params[0].Get(0) * 10;
|
||||
}
|
||||
else {
|
||||
wxString& otext = syl.ovr_tags[syl.text.size()];
|
||||
|
@ -151,7 +150,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
|
|||
otext += "{";
|
||||
|
||||
in_tag = true;
|
||||
otext += *tag;
|
||||
otext += tag;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,10 +35,10 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include "ass_dialogue.h"
|
||||
|
||||
#include <libaegisub/log.h>
|
||||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_override.h"
|
||||
#include "compat.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
@ -65,6 +65,14 @@ AssOverrideParameter::AssOverrideParameter(AssOverrideParameter&& o)
|
|||
{
|
||||
}
|
||||
|
||||
AssOverrideParameter& AssOverrideParameter::operator=(AssOverrideParameter&& rhs) {
|
||||
value = std::move(rhs.value);
|
||||
block = std::move(rhs.block);
|
||||
type = rhs.type;
|
||||
classification = rhs.classification;
|
||||
return *this;
|
||||
}
|
||||
|
||||
AssOverrideParameter::~AssOverrideParameter() {
|
||||
}
|
||||
|
||||
|
@ -179,7 +187,6 @@ struct AssOverrideTagProto {
|
|||
void Set(wxString name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL);
|
||||
};
|
||||
|
||||
|
||||
AssOverrideParamProto::AssOverrideParamProto(VariableDataType type, int opt, AssParameterClass classi)
|
||||
: optional(opt)
|
||||
, type(type)
|
||||
|
@ -404,7 +411,6 @@ void parse_parameters(AssOverrideTag *tag, const wxString &text, AssOverrideTagP
|
|||
for (auto& curproto : proto_it->params) {
|
||||
// Create parameter
|
||||
tag->Params.emplace_back(curproto.type, curproto.classification);
|
||||
AssOverrideParameter *newparam = &tag->Params.back();
|
||||
|
||||
// Check if it's optional and not present
|
||||
if (!(curproto.optional & parsFlag) || curPar >= totalPars)
|
||||
|
@ -418,11 +424,10 @@ void parse_parameters(AssOverrideTag *tag, const wxString &text, AssOverrideTagP
|
|||
|
||||
// From ass_dialogue.h
|
||||
AssDialogueBlockOverride::~AssDialogueBlockOverride() {
|
||||
delete_clear(Tags);
|
||||
}
|
||||
|
||||
void AssDialogueBlockOverride::ParseTags() {
|
||||
delete_clear(Tags);
|
||||
Tags.clear();
|
||||
|
||||
wxStringTokenizer tkn(text, "\\", wxTOKEN_STRTOK);
|
||||
wxString curTag;
|
||||
|
@ -435,27 +440,28 @@ void AssDialogueBlockOverride::ParseTags() {
|
|||
while (curTag.Freq('(') > curTag.Freq(')') && tkn.HasMoreTokens())
|
||||
curTag << "\\" << tkn.GetNextToken();
|
||||
|
||||
Tags.push_back(new AssOverrideTag(curTag));
|
||||
Tags.emplace_back(curTag);
|
||||
|
||||
curTag = "\\";
|
||||
}
|
||||
}
|
||||
|
||||
void AssDialogueBlockOverride::AddTag(wxString const& tag) {
|
||||
Tags.push_back(new AssOverrideTag(tag));
|
||||
Tags.emplace_back(tag);
|
||||
}
|
||||
|
||||
static wxString tag_str(AssOverrideTag *t) { return *t; }
|
||||
static wxString tag_str(AssOverrideTag const& t) { return t; }
|
||||
wxString AssDialogueBlockOverride::GetText() {
|
||||
text = "{" + join(Tags | transformed(tag_str), wxString()) + "}";
|
||||
return text;
|
||||
}
|
||||
|
||||
void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callback, void *userData) {
|
||||
for (auto tag : Tags) {
|
||||
for (auto& par : tag->Params) {
|
||||
for (auto& tag : Tags) {
|
||||
for (auto& par : tag.Params) {
|
||||
if (par.omitted) continue;
|
||||
|
||||
callback(tag->Name, &par, userData);
|
||||
callback(tag.Name, &par, userData);
|
||||
|
||||
// Go recursive if it's a block parameter
|
||||
if (par.GetType() == VARDATA_BLOCK)
|
||||
|
@ -465,9 +471,22 @@ void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callb
|
|||
}
|
||||
|
||||
AssOverrideTag::AssOverrideTag() : valid(false) { }
|
||||
AssOverrideTag::AssOverrideTag(wxString text) {
|
||||
AssOverrideTag::AssOverrideTag(wxString const& text) {
|
||||
SetText(text);
|
||||
}
|
||||
AssOverrideTag::AssOverrideTag(AssOverrideTag&& rhs)
|
||||
: valid(rhs.valid)
|
||||
, Name(std::move(rhs.Name))
|
||||
, Params(std::move(rhs.Params))
|
||||
{
|
||||
}
|
||||
|
||||
AssOverrideTag& AssOverrideTag::operator=(AssOverrideTag&& rhs) {
|
||||
valid = rhs.valid;
|
||||
Name = std::move(rhs.Name);
|
||||
Params = std::move(rhs.Params);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void AssOverrideTag::Clear() {
|
||||
Params.clear();
|
||||
|
|
|
@ -70,6 +70,7 @@ class AssOverrideParameter : boost::noncopyable {
|
|||
public:
|
||||
AssOverrideParameter(VariableDataType type, AssParameterClass classification);
|
||||
AssOverrideParameter(AssOverrideParameter&&);
|
||||
AssOverrideParameter& operator=(AssOverrideParameter&&);
|
||||
~AssOverrideParameter();
|
||||
|
||||
/// Type of parameter
|
||||
|
@ -90,12 +91,14 @@ class AssOverrideTag : boost::noncopyable {
|
|||
bool valid;
|
||||
|
||||
public:
|
||||
AssOverrideTag();
|
||||
AssOverrideTag(AssOverrideTag&&);
|
||||
AssOverrideTag(wxString const& text);
|
||||
AssOverrideTag& operator=(AssOverrideTag&&);
|
||||
|
||||
wxString Name;
|
||||
std::vector<AssOverrideParameter> Params;
|
||||
|
||||
AssOverrideTag();
|
||||
AssOverrideTag(wxString text);
|
||||
|
||||
bool IsValid() const { return valid; }
|
||||
void Clear();
|
||||
void SetText(const wxString &text);
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_karaoke.h"
|
||||
#include "ass_override.h"
|
||||
#include "audio_box.h"
|
||||
#include "audio_controller.h"
|
||||
#include "audio_timing.h"
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
#include "ass_info.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_karaoke.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_style.h"
|
||||
#include "auto4_lua.h"
|
||||
#include "utils.h"
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include "../ass_dialogue.h"
|
||||
#include "../ass_file.h"
|
||||
#include "../ass_karaoke.h"
|
||||
#include "../ass_override.h"
|
||||
#include "../ass_style.h"
|
||||
#include "../dialog_colorpicker.h"
|
||||
#include "../dialog_paste_over.h"
|
||||
|
@ -169,9 +168,9 @@ void paste_lines(agi::Context *c, bool paste_over) {
|
|||
template<class T>
|
||||
T get_value(boost::ptr_vector<AssDialogueBlock> const& blocks, int blockn, T initial, wxString const& tag_name, wxString alt = wxString()) {
|
||||
for (auto ovr : blocks | sliced(0, blockn + 1) | reversed | agi::of_type<AssDialogueBlockOverride>()) {
|
||||
for (auto tag : ovr->Tags | reversed) {
|
||||
if (tag->Name == tag_name || tag->Name == alt)
|
||||
return tag->Params[0].Get<T>(initial);
|
||||
for (auto const& tag : ovr->Tags | reversed) {
|
||||
if (tag.Name == tag_name || tag.Name == alt)
|
||||
return tag.Params[0].Get<T>(initial);
|
||||
}
|
||||
}
|
||||
return initial;
|
||||
|
@ -238,16 +237,15 @@ void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, wxS
|
|||
// Remove old of same
|
||||
bool found = false;
|
||||
for (size_t i = 0; i < ovr->Tags.size(); i++) {
|
||||
wxString name = ovr->Tags[i]->Name;
|
||||
wxString name = ovr->Tags[i].Name;
|
||||
if (tag == name || alt == name) {
|
||||
shift -= ((wxString)*ovr->Tags[i]).size();
|
||||
shift -= ((wxString)ovr->Tags[i]).size();
|
||||
if (found) {
|
||||
delete ovr->Tags[i];
|
||||
ovr->Tags.erase(ovr->Tags.begin() + i);
|
||||
i--;
|
||||
}
|
||||
else {
|
||||
ovr->Tags[i]->Params[0].Set(value);
|
||||
ovr->Tags[i].Params[0].Set(value);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_style.h"
|
||||
#include "include/aegisub/context.h"
|
||||
#include "help_button.h"
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_style.h"
|
||||
#include "ass_style_storage.h"
|
||||
#include "colour_button.h"
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_override.h"
|
||||
#include "export_framerate.h"
|
||||
#include "include/aegisub/context.h"
|
||||
#include "utils.h"
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_style.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
@ -56,23 +55,23 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
|
|||
|
||||
for (auto& block : blocks) {
|
||||
if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride *>(&block)) {
|
||||
for (auto tag : ovr->Tags) {
|
||||
wxString name = tag->Name;
|
||||
for (auto const& tag : ovr->Tags) {
|
||||
wxString name = tag.Name;
|
||||
|
||||
if (name == "\\r") {
|
||||
style = styles[tag->Params[0].Get<wxString>(line->Style)];
|
||||
style = styles[tag.Params[0].Get<wxString>(line->Style)];
|
||||
overriden = false;
|
||||
}
|
||||
else if (name == "\\b") {
|
||||
style.bold = tag->Params[0].Get(initial.bold);
|
||||
style.bold = tag.Params[0].Get(initial.bold);
|
||||
overriden = true;
|
||||
}
|
||||
else if (name == "\\i") {
|
||||
style.italic = tag->Params[0].Get(initial.italic);
|
||||
style.italic = tag.Params[0].Get(initial.italic);
|
||||
overriden = true;
|
||||
}
|
||||
else if (name == "\\fn") {
|
||||
style.facename = tag->Params[0].Get(initial.facename);
|
||||
style.facename = tag.Params[0].Get(initial.facename);
|
||||
overriden = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include "aegisub_endian.h"
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_style.h"
|
||||
#include "compat.h"
|
||||
#include "dialog_export_ebu3264.h"
|
||||
|
@ -122,16 +121,16 @@ namespace
|
|||
{
|
||||
void ProcessOverrides(AssDialogueBlockOverride *ob, bool &underline, bool &italic, int &align, bool style_underline, bool style_italic)
|
||||
{
|
||||
for (auto t : ob->Tags)
|
||||
for (auto const& t : ob->Tags)
|
||||
{
|
||||
if (t->Name == "\\u")
|
||||
underline = t->Params[0].Get<bool>(style_underline);
|
||||
else if (t->Name == "\\i")
|
||||
italic = t->Params[0].Get<bool>(style_italic);
|
||||
else if (t->Name == "\\an")
|
||||
align = t->Params[0].Get<int>(align);
|
||||
else if (t->Name == "\\a" && !t->Params[0].omitted)
|
||||
align = AssStyle::SsaToAss(t->Params[0].Get<int>());
|
||||
if (t.Name == "\\u")
|
||||
underline = t.Params[0].Get<bool>(style_underline);
|
||||
else if (t.Name == "\\i")
|
||||
italic = t.Params[0].Get<bool>(style_italic);
|
||||
else if (t.Name == "\\an")
|
||||
align = t.Params[0].Get<int>(align);
|
||||
else if (t.Name == "\\a" && !t.Params[0].omitted)
|
||||
align = AssStyle::SsaToAss(t.Params[0].Get<int>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "ass_attachment.h"
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_style.h"
|
||||
#include "colorspace.h"
|
||||
#include "compat.h"
|
||||
|
@ -535,8 +534,8 @@ bool SRTSubtitleFormat::CanSave(const AssFile *file) const {
|
|||
boost::ptr_vector<AssDialogueBlock> blocks(curdiag->ParseTags());
|
||||
for (auto ovr : blocks | agi::of_type<AssDialogueBlockOverride>()) {
|
||||
// Verify that all overrides used are supported
|
||||
for (auto tag : ovr->Tags) {
|
||||
if (!std::binary_search(supported_tags, std::end(supported_tags), tag->Name))
|
||||
for (auto const& tag : ovr->Tags) {
|
||||
if (!std::binary_search(supported_tags, std::end(supported_tags), tag.Name))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -559,11 +558,11 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const {
|
|||
for (auto& block : blocks) {
|
||||
if (AssDialogueBlockOverride* ovr = dynamic_cast<AssDialogueBlockOverride*>(&block)) {
|
||||
// Iterate through overrides
|
||||
for (auto tag : ovr->Tags) {
|
||||
if (tag->IsValid() && tag->Name.size() == 2) {
|
||||
auto it = tag_states.find(tag->Name[1]);
|
||||
for (auto const& tag : ovr->Tags) {
|
||||
if (tag.IsValid() && tag.Name.size() == 2) {
|
||||
auto it = tag_states.find(tag.Name[1]);
|
||||
if (it != tag_states.end()) {
|
||||
bool temp = tag->Params[0].Get(false);
|
||||
bool temp = tag.Params[0].Get(false);
|
||||
if (temp && !it->second)
|
||||
final += wxString::Format("<%c>", it->first);
|
||||
if (!temp && it->second)
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_override.h"
|
||||
#include "ass_style.h"
|
||||
#include "ass_time.h"
|
||||
#include "include/aegisub/context.h"
|
||||
|
@ -360,9 +359,9 @@ typedef const std::vector<AssOverrideParameter> * param_vec;
|
|||
// Find a tag's parameters in a line or return nullptr if it's not found
|
||||
static param_vec find_tag(boost::ptr_vector<AssDialogueBlock>& blocks, wxString tag_name) {
|
||||
for (auto ovr : blocks | agi::of_type<AssDialogueBlockOverride>()) {
|
||||
for (auto tag : ovr->Tags) {
|
||||
if (tag->Name == tag_name)
|
||||
return &tag->Params;
|
||||
for (auto const& tag : ovr->Tags) {
|
||||
if (tag.Name == tag_name)
|
||||
return &tag.Params;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -566,9 +565,8 @@ void VisualToolBase::SetOverride(AssDialogue* line, wxString const& tag, wxStrin
|
|||
else if (AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block)) {
|
||||
// Remove old of same
|
||||
for (size_t i = 0; i < ovr->Tags.size(); i++) {
|
||||
wxString const& name = ovr->Tags[i]->Name;
|
||||
wxString const& name = ovr->Tags[i].Name;
|
||||
if (tag == name || removeTag == name) {
|
||||
delete ovr->Tags[i];
|
||||
ovr->Tags.erase(ovr->Tags.begin() + i);
|
||||
i--;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue