De-wxify AssOverride

This commit is contained in:
Thomas Goyne 2012-12-29 15:53:56 -08:00
parent 134fe60517
commit d49758edbf
21 changed files with 233 additions and 242 deletions

View File

@ -33,13 +33,6 @@
#include "config.h"
#include <boost/algorithm/string/join.hpp>
#include <fstream>
#include <list>
#include <wx/regex.h>
#include <wx/tokenzr.h>
#include "ass_dialogue.h"
#include "compat.h"
#include "subtitle_format.h"
@ -47,6 +40,13 @@
#include <libaegisub/of_type_adaptor.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/tokenizer.hpp>
#include <wx/regex.h>
#include <wx/tokenzr.h>
using namespace boost::adaptors;
std::size_t hash_value(wxString const& s) {
@ -196,23 +196,24 @@ std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> AssDialogue::ParseTags() cons
}
int drawingLevel = 0;
std::string text(from_wx(Text.get()));
for (size_t len = Text.get().size(), cur = 0; cur < len; ) {
for (size_t len = text.size(), cur = 0; cur < len; ) {
// Overrides block
if (Text.get()[cur] == '{') {
size_t end = Text.get().find('}', cur);
if (text[cur] == '{') {
size_t end = text.find('}', cur);
// VSFilter requires that override blocks be closed, while libass
// does not. We match VSFilter here.
if (end == wxString::npos)
if (end == std::string::npos)
goto plain;
++cur;
// Get contents of block
wxString work = Text.get().substr(cur, end - cur);
std::string work = text.substr(cur, end - cur);
cur = end + 1;
if (work.size() && work.find('\\') == wxString::npos) {
if (work.size() && work.find('\\') == std::string::npos) {
//We've found an override block with no backslashes
//We're going to assume it's a comment and not consider it an override block
//Currently we'll treat this as a plain text block, but feel free to create a new class
@ -236,14 +237,14 @@ std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> AssDialogue::ParseTags() cons
// Plain-text/drawing block
plain:
wxString work;
size_t end = Text.get().find('{', cur + 1);
if (end == wxString::npos) {
work = Text.get().substr(cur);
std::string work;
size_t end = text.find('{', cur + 1);
if (end == std::string::npos) {
work = text.substr(cur);
cur = len;
}
else {
work = Text.get().substr(cur, end - cur);
work = text.substr(cur, end - cur);
cur = end;
}
@ -260,10 +261,10 @@ void AssDialogue::StripTags() {
Text = GetStrippedText();
}
static wxString get_text(AssDialogueBlock &d) { return d.GetText(); }
static std::string get_text(AssDialogueBlock &d) { return d.GetText(); }
void AssDialogue::UpdateText(boost::ptr_vector<AssDialogueBlock>& blocks) {
if (blocks.empty()) return;
Text = join(blocks | transformed(get_text), wxS(""));
Text = to_wx(join(blocks | transformed(get_text), ""));
}
void AssDialogue::SetMarginString(wxString const& origvalue, int which) {
@ -296,52 +297,45 @@ bool AssDialogue::CollidesWith(const AssDialogue *target) const {
return ((Start < target->Start) ? (target->Start < End) : (Start < target->End));
}
static wxString get_text_p(AssDialogueBlock *d) { return d->GetText(); }
static std::string get_text_p(AssDialogueBlock *d) { return d->GetText(); }
wxString AssDialogue::GetStrippedText() const {
wxString ret;
boost::ptr_vector<AssDialogueBlock> blocks(ParseTags());
return join(blocks | agi::of_type<AssDialogueBlockPlain>() | transformed(get_text_p), wxS(""));
return to_wx(join(blocks | agi::of_type<AssDialogueBlockPlain>() | transformed(get_text_p), ""));
}
AssEntry *AssDialogue::Clone() const {
return new AssDialogue(*this);
}
void AssDialogueBlockDrawing::TransformCoords(int mx,int my,double x,double y) {
void AssDialogueBlockDrawing::TransformCoords(int mx, int my, double x, double y) {
// HACK: Implement a proper parser ffs!!
// Could use Spline but it'd be slower and this seems to work fine
wxStringTokenizer tkn(GetText()," ",wxTOKEN_DEFAULT);
wxString cur;
wxString final;
bool isX = true;
long temp;
bool is_x = true;
std::string final;
// Process tokens
while (tkn.HasMoreTokens()) {
cur = tkn.GetNextToken().Lower();
// Number, process it
if (cur.IsNumber()) {
// Transform it
cur.ToLong(&temp);
if (isX) temp = (long int)((temp+mx)*x + 0.5);
else temp = (long int)((temp+my)*y + 0.5);
// Write back to list
final += wxString::Format("%i ",temp);
// Toggle X/Y
isX = !isX;
boost::char_separator<char> sep(" ");
for (auto const& cur : boost::tokenizer<boost::char_separator<char>>(text, sep)) {
if (std::all_of(begin(cur), end(cur), isdigit)) {
int val = boost::lexical_cast<int>(cur);
if (is_x)
val = (int)((val + mx) * x + .5);
else
val = (int)((val + my) * y + .5);
final += std::to_string(val);
final += ' ';
}
// Text
else {
if (cur == "m" || cur == "n" || cur == "l" || cur == "b" || cur == "s" || cur == "p" || cur == "c") isX = true;
final += cur + " ";
else if (cur.size() == 1) {
char c = tolower(cur[0]);
if (c == 'm' || c == 'n' || c == 'l' || c == 'b' || c == 's' || c == 'p' || c == 'c') {
is_x = true;
final += c;
final += ' ';
}
}
}
// Write back final
final = final.Left(final.Length()-1);
final.pop_back();
text = final;
}

View File

@ -74,19 +74,19 @@ std::size_t hash_value(wxString const& s);
class AssDialogueBlock {
protected:
/// Text of this block
wxString text;
std::string text;
public:
AssDialogueBlock(wxString const& text) : text(text) { }
AssDialogueBlock(std::string const& text) : text(text) { }
virtual ~AssDialogueBlock() { }
virtual AssBlockType GetType() const = 0;
virtual wxString GetText() { return text; }
virtual std::string GetText() { return text; }
};
class AssDialogueBlockPlain : public AssDialogueBlock {
public:
AssBlockType GetType() const override { return BLOCK_PLAIN; }
AssDialogueBlockPlain(wxString const& text = wxString()) : AssDialogueBlock(text) { }
AssDialogueBlockPlain(std::string const& text = std::string()) : AssDialogueBlock(text) { }
};
class AssDialogueBlockDrawing : public AssDialogueBlock {
@ -94,23 +94,23 @@ public:
int Scale;
AssBlockType GetType() const override { return BLOCK_DRAWING; }
AssDialogueBlockDrawing(wxString const& text, int scale) : AssDialogueBlock(text), Scale(scale) { }
AssDialogueBlockDrawing(std::string const& text, int scale) : AssDialogueBlock(text), Scale(scale) { }
void TransformCoords(int trans_x,int trans_y,double mult_x,double mult_y);
};
class AssDialogueBlockOverride : public AssDialogueBlock {
public:
AssDialogueBlockOverride(wxString const& text = wxString()) : AssDialogueBlock(text) { }
AssDialogueBlockOverride(std::string const& text = std::string()) : AssDialogueBlock(text) { }
std::vector<AssOverrideTag> Tags;
AssBlockType GetType() const override { return BLOCK_OVERRIDE; }
wxString GetText() override;
std::string GetText() override;
void ParseTags();
void AddTag(wxString const& tag);
void AddTag(std::string const& tag);
/// Type of callback function passed to ProcessParameters
typedef void (*ProcessParametersCallback)(wxString const&, AssOverrideParameter *, void *);
typedef void (*ProcessParametersCallback)(std::string const&, AssOverrideParameter *, void *);
/// @brief Process parameters via callback
/// @param callback The callback function to call per tag parameter
/// @param userData User data to pass to callback function

View File

@ -25,24 +25,28 @@
#include "ass_dialogue.h"
#include "ass_file.h"
#include "compat.h"
#include "include/aegisub/context.h"
#include "selection_controller.h"
#include <boost/format.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <wx/intl.h>
wxString AssKaraoke::Syllable::GetText(bool k_tag) const {
wxString ret;
std::string AssKaraoke::Syllable::GetText(bool k_tag) const {
std::string ret;
if (k_tag)
ret = wxString::Format("{%s%d}", tag_type, (duration + 5) / 10);
ret = str(boost::format("{%s%d}") % tag_type % ((duration + 5) / 10));
size_t idx = 0;
for (auto const& ovr : ovr_tags) {
ret += text.Mid(idx, ovr.first - idx);
ret += text.substr(idx, ovr.first - idx);
ret += ovr.second;
idx = ovr.first;
}
ret += text.Mid(idx);
ret += text.substr(idx);
return ret;
}
@ -91,7 +95,7 @@ void AssKaraoke::SetLine(AssDialogue *line, bool auto_split, bool normalize) {
if (auto_split && syls.size() == 1) {
size_t pos;
no_announce = true;
while ((pos = syls.back().text.find(' ')) != wxString::npos)
while ((pos = syls.back().text.find(' ')) != std::string::npos)
AddSplit(syls.size() - 1, pos + 1);
no_announce = false;
}
@ -103,11 +107,11 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
for (auto& block : blocks) {
wxString text = block.GetText();
std::string text = block.GetText();
if (dynamic_cast<AssDialogueBlockPlain*>(&block)) {
// treat comments as overrides rather than dialogue
if (text.size() && text[0] == '{')
if (boost::starts_with(text, "{"))
syl.ovr_tags[syl.text.size()] += text;
else
syl.text += text;
@ -120,7 +124,7 @@ 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") {
if (tag.IsValid() && boost::istarts_with(tag.Name, "\\k")) {
if (in_tag) {
syl.ovr_tags[syl.text.size()] += "}";
in_tag = false;
@ -142,11 +146,10 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
syl.duration = tag.Params[0].Get(0) * 10;
}
else {
wxString& otext = syl.ovr_tags[syl.text.size()];
std::string& otext = syl.ovr_tags[syl.text.size()];
// Merge adjacent override tags
if (otext.size() && otext.Last() == '}')
otext.RemoveLast();
else if (!in_tag)
boost::trim_right_if(text, boost::is_any_of("}"));
if (!in_tag)
otext += "{";
in_tag = true;
@ -167,16 +170,16 @@ wxString AssKaraoke::GetText() const {
text.reserve(size() * 10);
for (auto const& syl : syls)
text += syl.GetText(true);
text += to_wx(syl.GetText(true));
return text;
}
wxString AssKaraoke::GetTagType() const {
std::string AssKaraoke::GetTagType() const {
return begin()->tag_type;
}
void AssKaraoke::SetTagType(wxString const& new_type) {
void AssKaraoke::SetTagType(std::string const& new_type) {
for (auto& syl : syls)
syl.tag_type = new_type;
}
@ -190,8 +193,8 @@ void AssKaraoke::AddSplit(size_t syl_idx, size_t pos) {
// character then pos will be out of bounds. Doing this is a bit goofy,
// but it's sometimes required for complex karaoke scripts
if (pos < syl.text.size()) {
new_syl.text = syl.text.Mid(pos);
syl.text = syl.text.Left(pos);
new_syl.text = syl.text.substr(pos);
syl.text = syl.text.substr(0, pos);
}
if (new_syl.text.empty())
@ -302,7 +305,7 @@ void AssKaraoke::SplitLines(std::set<AssDialogue*> const& lines, agi::Context *c
new_line->Start = syl.start_time;
new_line->End = syl.start_time + syl.duration;
new_line->Text = syl.GetText(false);
new_line->Text = to_wx(syl.GetText(false));
c->ass->Line.insert(it, *new_line);

View File

@ -22,6 +22,7 @@
#include <map>
#include <set>
#include <string>
#include <vector>
#include <wx/string.h>
@ -39,14 +40,14 @@ public:
struct Syllable {
int start_time; ///< Start time relative to time zero (not line start) in milliseconds
int duration; ///< Duration in milliseconds
wxString text; ///< Stripped syllable text
wxString tag_type; ///< \k, \kf or \ko
std::string text; ///< Stripped syllable text
std::string tag_type; ///< \k, \kf or \ko
/// Non-karaoke override tags in this syllable. Key is an index in text
/// before which the value should be inserted
std::map<size_t, wxString> ovr_tags;
std::map<size_t, std::string> ovr_tags;
/// Get the text of this line with override tags and optionally the karaoke tag
wxString GetText(bool k_tag) const;
std::string GetText(bool k_tag) const;
};
private:
std::vector<Syllable> syls;
@ -87,9 +88,9 @@ public:
/// Get the karaoke tag type used, with leading slash
/// @returns "\k", "\kf", or "\ko"
wxString GetTagType() const;
std::string GetTagType() const;
/// Set the tag type for all karaoke tags in this line
void SetTagType(wxString const& new_type);
void SetTagType(std::string const& new_type);
/// Split lines so that each syllable is its own line
/// @param lines Lines to split

View File

@ -37,17 +37,15 @@
#include "ass_dialogue.h"
#include <libaegisub/log.h>
#include "compat.h"
#include "utils.h"
#include <libaegisub/color.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <functional>
#include <wx/log.h>
#include <wx/tokenzr.h>
using namespace boost::adaptors;
@ -78,31 +76,27 @@ AssOverrideParameter& AssOverrideParameter::operator=(AssOverrideParameter&& rhs
AssOverrideParameter::~AssOverrideParameter() {
}
template<> wxString AssOverrideParameter::Get<wxString>() const {
template<> std::string AssOverrideParameter::Get<std::string>() const {
if (omitted) throw agi::InternalError("AssOverrideParameter::Get() called on omitted parameter", 0);
if (block.get()) {
wxString str(block->GetText());
str.Replace("{", "");
str.Replace("}", "");
std::string str(block->GetText());
if (boost::starts_with(str, "{")) str.erase(0);
if (boost::ends_with(str, "}")) str.erase(str.size() - 1);
return str;
}
return value;
}
template<> int AssOverrideParameter::Get<int>() const {
long v = 0;
Get<wxString>().ToLong(&v);
return v;
return boost::lexical_cast<int>(Get<std::string>());
}
template<> double AssOverrideParameter::Get<double>() const {
double v = 0;
Get<wxString>().ToDouble(&v);
return v;
return boost::lexical_cast<double>(Get<std::string>());
}
template<> float AssOverrideParameter::Get<float>() const {
return Get<double>();
return boost::lexical_cast<float>(Get<std::string>());
}
template<> bool AssOverrideParameter::Get<bool>() const {
@ -110,29 +104,29 @@ template<> bool AssOverrideParameter::Get<bool>() const {
}
template<> agi::Color AssOverrideParameter::Get<agi::Color>() const {
return from_wx(Get<wxString>());
return Get<std::string>();
}
template<> AssDialogueBlockOverride *AssOverrideParameter::Get<AssDialogueBlockOverride*>() const {
if (!block.get()) {
block.reset(new AssDialogueBlockOverride(Get<wxString>()));
block.reset(new AssDialogueBlockOverride(Get<std::string>()));
block->ParseTags();
}
return block.get();
}
template<> void AssOverrideParameter::Set<wxString>(wxString new_value) {
template<> void AssOverrideParameter::Set<std::string>(std::string new_value) {
omitted = false;
value = new_value;
block.reset();
}
template<> void AssOverrideParameter::Set<int>(int new_value) {
Set(wxString::Format("%d", new_value));
Set(std::to_string(new_value));
}
template<> void AssOverrideParameter::Set<double>(double new_value) {
Set(wxString::Format("%g", new_value));
Set(std::to_string(new_value));
}
template<> void AssOverrideParameter::Set<bool>(bool new_value) {
@ -166,45 +160,42 @@ struct AssOverrideParamProto {
/// Semantic type of this parameter
AssParameterClass classification;
AssOverrideParamProto (VariableDataType type, int opt=NOT_OPTIONAL, AssParameterClass classi=PARCLASS_NORMAL);
AssOverrideParamProto(VariableDataType type, int opt, AssParameterClass classi)
: optional(opt)
, type(type)
, classification(classi)
{
}
};
struct AssOverrideTagProto {
/// Name of the tag, with slash
wxString name;
std::string name;
/// Parameters to this tag
std::vector<AssOverrideParamProto> params;
typedef std::vector<AssOverrideTagProto>::iterator iterator;
/// @brief Add a parameter to this tag prototype
/// @param type Data type of the parameter
/// @param classi Semantic type of the parameter
/// @param opt Situations in which this parameter is present
void AddParam(VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL);
void AddParam(VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL) {
params.emplace_back(type, opt, classi);
}
/// @brief Convenience function for single-argument tags
/// @param name Name of the tag, with slash
/// @param type Data type of the parameter
/// @param classi Semantic type of the parameter
/// @param opt Situations in which this parameter is present
void Set(wxString name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL);
void Set(const char *name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL) {
this->name = name;
params.emplace_back(type, opt, classi);
}
};
AssOverrideParamProto::AssOverrideParamProto(VariableDataType type, int opt, AssParameterClass classi)
: optional(opt)
, type(type)
, classification(classi)
{
}
void AssOverrideTagProto::AddParam(VariableDataType type, AssParameterClass classi, int opt) {
params.emplace_back(type, opt, classi);
}
void AssOverrideTagProto::Set(wxString newName, VariableDataType type, AssParameterClass classi, int opt) {
name = newName;
params.emplace_back(type, opt, classi);
}
static std::vector<AssOverrideTagProto> proto;
static void load_protos() {
static bool loaded = false;
@ -341,8 +332,8 @@ static void load_protos() {
proto[i].AddParam(VARDATA_BLOCK);
}
std::vector<wxString> tokenize(const wxString &text) {
std::vector<wxString> paramList;
std::vector<std::string> tokenize(const std::string &text) {
std::vector<std::string> paramList;
paramList.reserve(6);
if (text.empty())
@ -351,32 +342,25 @@ std::vector<wxString> tokenize(const wxString &text) {
if (text[0] != '(') {
// 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));
paramList.emplace_back(boost::trim_copy(text));
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;
size_t start = ++i;
while (i < textlen && parDepth > 0) {
wxChar c = text[i];
char c = text[i];
// parDepth 1 is where we start, and the tag-level we're interested in parsing on
if (c == ',' && parDepth == 1) break;
if (c == '(') parDepth++;
else if (c == ')') {
parDepth--;
if (parDepth < 0) {
wxLogWarning("Unmatched parenthesis near '%s'!\nTag-parsing incomplete.", text.SubString(i, 10));
return paramList;
}
else if (parDepth == 0) {
if (--parDepth == 0) {
// We just ate the parenthesis ending this parameter block
// Make sure it doesn't get included in the parameter text
break;
@ -385,22 +369,22 @@ std::vector<wxString> tokenize(const wxString &text) {
i++;
}
// i now points to the first character not member of this parameter
paramList.push_back(text.SubString(start, i-1).Trim(true).Trim(false));
paramList.emplace_back(boost::trim_copy(text.substr(start, i - start)));
}
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));
paramList.emplace_back(text.begin() + i + 1, text.end());
}
return paramList;
}
void parse_parameters(AssOverrideTag *tag, const wxString &text, AssOverrideTagProto::iterator proto_it) {
void parse_parameters(AssOverrideTag *tag, const std::string &text, AssOverrideTagProto::iterator proto_it) {
tag->Clear();
// Tokenize text, attempting to find all parameters
std::vector<wxString> paramList = tokenize(text);
std::vector<std::string> paramList = tokenize(text);
size_t totalPars = paramList.size();
int parsFlag = 1 << (totalPars - 1); // Get optional parameters flag
@ -428,30 +412,32 @@ void parse_parameters(AssOverrideTag *tag, const wxString &text, AssOverrideTagP
void AssDialogueBlockOverride::ParseTags() {
Tags.clear();
wxStringTokenizer tkn(text, "\\", wxTOKEN_STRTOK);
wxString curTag;
if (text.StartsWith("\\")) curTag = "\\";
while (tkn.HasMoreTokens()) {
curTag += tkn.GetNextToken();
// Check for parenthesis matching for \t
while (curTag.Freq('(') > curTag.Freq(')') && tkn.HasMoreTokens())
curTag << "\\" << tkn.GetNextToken();
Tags.emplace_back(curTag);
curTag = "\\";
int depth = 0;
size_t start = 0;
for (size_t i = 1; i < text.size(); ++i) {
if (depth > 0) {
if (text[i] == ')')
--depth;
}
else if (text[i] == '\\') {
Tags.emplace_back(text.substr(start, i - start));
start = i;
}
else if (text[i] == '(')
++depth;
}
if (!text.empty())
Tags.emplace_back(text.substr(start));
}
void AssDialogueBlockOverride::AddTag(wxString const& tag) {
void AssDialogueBlockOverride::AddTag(std::string const& tag) {
Tags.emplace_back(tag);
}
static wxString tag_str(AssOverrideTag const& t) { return t; }
wxString AssDialogueBlockOverride::GetText() {
text = "{" + join(Tags | transformed(tag_str), wxString()) + "}";
static std::string tag_str(AssOverrideTag const& t) { return t; }
std::string AssDialogueBlockOverride::GetText() {
text = "{" + join(Tags | transformed(tag_str), std::string()) + "}";
return text;
}
@ -470,7 +456,7 @@ void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callb
}
AssOverrideTag::AssOverrideTag() : valid(false) { }
AssOverrideTag::AssOverrideTag(wxString const& text) {
AssOverrideTag::AssOverrideTag(std::string const& text) {
SetText(text);
}
AssOverrideTag::AssOverrideTag(AssOverrideTag&& rhs)
@ -493,24 +479,25 @@ void AssOverrideTag::Clear() {
valid = false;
}
void AssOverrideTag::SetText(const wxString &text) {
void AssOverrideTag::SetText(const std::string &text) {
load_protos();
for (auto cur = proto.begin(); cur != proto.end(); ++cur) {
if (text.StartsWith(cur->name)) {
if (boost::starts_with(text, cur->name)) {
Name = cur->name;
parse_parameters(this, text.Mid(Name.length()), cur);
parse_parameters(this, text.substr(Name.size()), cur);
valid = true;
return;
}
}
// Junk tag
Name = text;
valid = false;
}
static wxString param_str(AssOverrideParameter const& p) { return p.Get<wxString>(); }
AssOverrideTag::operator wxString() const {
wxString result = Name;
static std::string param_str(AssOverrideParameter const& p) { return p.Get<std::string>(); }
AssOverrideTag::operator std::string() const {
std::string result = Name;
// Determine if it needs parentheses
bool parentheses = Params.size() > 1;
@ -520,7 +507,7 @@ AssOverrideTag::operator wxString() const {
result += join(Params
| filtered([](AssOverrideParameter const& p) { return !p.omitted; } )
| transformed(param_str),
wxS(","));
",");
if (parentheses) result += ")";
return result;

View File

@ -37,7 +37,6 @@
#include <vector>
class AssDialogueBlockOverride;
class wxString;
/// Type of parameter; probably only used by the resample tool
enum AssParameterClass {
@ -63,7 +62,7 @@ enum VariableDataType {
/// A single parameter to an override tag
class AssOverrideParameter : boost::noncopyable {
wxString value;
std::string value;
mutable std::unique_ptr<AssDialogueBlockOverride> block;
VariableDataType type;
@ -93,14 +92,14 @@ class AssOverrideTag : boost::noncopyable {
public:
AssOverrideTag();
AssOverrideTag(AssOverrideTag&&);
AssOverrideTag(wxString const& text);
AssOverrideTag(std::string const& text);
AssOverrideTag& operator=(AssOverrideTag&&);
wxString Name;
std::string Name;
std::vector<AssOverrideParameter> Params;
bool IsValid() const { return valid; }
void Clear();
void SetText(const wxString &text);
operator wxString() const;
void SetText(const std::string &text);
operator std::string() const;
};

View File

@ -26,16 +26,6 @@
#include <algorithm>
#include <numeric>
#include <wx/bmpbuttn.h>
#include <wx/button.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <wx/menu.h>
#include <wx/panel.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/tokenzr.h>
#include "include/aegisub/context.h"
#include "ass_dialogue.h"
@ -44,11 +34,21 @@
#include "audio_box.h"
#include "audio_controller.h"
#include "audio_timing.h"
#include "compat.h"
#include "libresrc/libresrc.h"
#include "main.h"
#include "selection_controller.h"
#include "utils.h"
#include <wx/bmpbuttn.h>
#include <wx/button.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <wx/menu.h>
#include <wx/panel.h>
#include <wx/settings.h>
#include <wx/sizer.h>
template<class Container, class Value>
static inline size_t last_lt_or_eq(Container const& c, Value const& v) {
typename Container::const_iterator it = lower_bound(c.begin(), c.end(), v);
@ -236,8 +236,8 @@ void AudioKaraoke::RenderText() {
}
}
void AudioKaraoke::AddMenuItem(wxMenu &menu, wxString const& tag, wxString const& help, wxString const& selected) {
wxMenuItem *item = menu.AppendCheckItem(-1, tag, help);
void AudioKaraoke::AddMenuItem(wxMenu &menu, std::string const& tag, wxString const& help, std::string const& selected) {
wxMenuItem *item = menu.AppendCheckItem(-1, to_wx(tag), help);
menu.Bind(wxEVT_COMMAND_MENU_SELECTED, std::bind(&AudioKaraoke::SetTagType, this, tag), item->GetId());
item->Check(tag == selected);
}
@ -246,7 +246,7 @@ void AudioKaraoke::OnContextMenu(wxContextMenuEvent&) {
if (!enabled) return;
wxMenu context_menu(_("Karaoke tag"));
wxString type = kara->GetTagType();
std::string type = kara->GetTagType();
AddMenuItem(context_menu, "\\k", _("Change karaoke tag to \\k"), type);
AddMenuItem(context_menu, "\\kf", _("Change karaoke tag to \\kf"), type);
@ -359,7 +359,7 @@ void AudioKaraoke::SetDisplayText() {
syl_start_points.reserve(kara->size());
for (auto const& syl : *kara) {
syl_start_points.push_back(spaced_text.size());
spaced_text += " " + syl.text;
spaced_text += to_wx(" " + syl.text);
}
// Get the x-coordinates of the right edge of each character
@ -408,7 +408,7 @@ void AudioKaraoke::AcceptSplit() {
cancel_button->Enable(false);
}
void AudioKaraoke::SetTagType(wxString new_tag) {
void AudioKaraoke::SetTagType(std::string const& new_tag) {
kara->SetTagType(new_tag);
AcceptSplit();
}

View File

@ -118,9 +118,9 @@ class AudioKaraoke : public wxWindow {
void SetDisplayText();
/// Helper function for context menu creation
void AddMenuItem(wxMenu &menu, wxString const& tag, wxString const& help, wxString const& selected);
void AddMenuItem(wxMenu &menu, std::string const& tag, wxString const& help, std::string const& selected);
/// Set the karaoke tags for the selected syllables to the indicated one
void SetTagType(wxString new_type);
void SetTagType(std::string const& new_type);
/// Prerender the current line along with syllable split lines
void RenderText();

View File

@ -29,6 +29,7 @@
#include "audio_controller.h"
#include "audio_renderer.h"
#include "audio_timing.h"
#include "compat.h"
#include "include/aegisub/context.h"
#include "main.h"
#include "pen.h"

View File

@ -48,6 +48,7 @@
#include "../ass_file.h"
#include "../ass_karaoke.h"
#include "../ass_style.h"
#include "../compat.h"
#include "../dialog_colorpicker.h"
#include "../dialog_paste_over.h"
#include "../dialog_search_replace.h"
@ -59,6 +60,7 @@
#include "../utils.h"
#include "../video_context.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/adaptor/sliced.hpp>
@ -166,7 +168,7 @@ 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()) {
T get_value(boost::ptr_vector<AssDialogueBlock> const& blocks, int blockn, T initial, std::string const& tag_name, std::string alt = "") {
for (auto ovr : blocks | sliced(0, blockn + 1) | reversed | agi::of_type<AssDialogueBlockOverride>()) {
for (auto const& tag : ovr->Tags | reversed) {
if (tag.Name == tag_name || tag.Name == alt)
@ -190,7 +192,7 @@ int block_at_pos(wxString const& text, int pos) {
return n;
}
void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, wxString const& tag, wxString const& value, int &sel_start, int &sel_end, bool at_end = false) {
void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, std::string const& tag, std::string const& value, int &sel_start, int &sel_end, bool at_end = false) {
if (blocks.empty())
blocks = line->ParseTags();
@ -205,7 +207,7 @@ void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, wxS
--blockn;
else if ((plain = dynamic_cast<AssDialogueBlockPlain*>(block))) {
// Cursor is in a comment block, so try the previous block instead
if (plain->GetText().StartsWith("{")) {
if (boost::starts_with(plain->GetText(), "{")) {
--blockn;
start = line->Text.get().rfind('{', start);
}
@ -224,22 +226,22 @@ void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, wxS
if (blockn < 0)
start = 0;
wxString insert = tag + value;
std::string insert(tag + value);
int shift = insert.size();
if (plain || blockn < 0) {
line->Text = line->Text.get().Left(start) + "{" + insert + "}" + line->Text.get().Mid(start);
line->Text = line->Text.get().Left(start) + "{" + to_wx(insert) + "}" + line->Text.get().Mid(start);
shift += 2;
blocks = line->ParseTags();
}
else if (ovr) {
wxString alt;
std::string alt;
if (tag == "\\c") alt = "\\1c";
// Remove old of same
bool found = false;
for (size_t i = 0; i < ovr->Tags.size(); i++) {
wxString name = ovr->Tags[i].Name;
std::string const& name = ovr->Tags[i].Name;
if (tag == name || alt == name) {
shift -= ((wxString)ovr->Tags[i]).size();
shift -= ((std::string)ovr->Tags[i]).size();
if (found) {
ovr->Tags.erase(ovr->Tags.begin() + i);
i--;
@ -433,21 +435,21 @@ struct edit_font : public Command {
get_value(blocks, blockn, style->italic, "\\i") ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL,
get_value(blocks, blockn, style->bold, "\\b") ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL,
get_value(blocks, blockn, style->underline, "\\u"),
get_value(blocks, blockn, style->font, "\\fn"));
to_wx(get_value(blocks, blockn, from_wx(style->font), "\\fn")));
const wxFont font = wxGetFontFromUser(c->parent, startfont);
if (!font.Ok() || font == startfont) return;
if (font.GetFaceName() != startfont.GetFaceName())
set_tag(line, blocks, "\\fn", font.GetFaceName(), sel_start, sel_end);
set_tag(line, blocks, "\\fn", from_wx(font.GetFaceName()), sel_start, sel_end);
if (font.GetPointSize() != startfont.GetPointSize())
set_tag(line, blocks, "\\fs", wxString::Format("%d", font.GetPointSize()), sel_start, sel_end);
set_tag(line, blocks, "\\fs", std::to_string(font.GetPointSize()), sel_start, sel_end);
if (font.GetWeight() != startfont.GetWeight())
set_tag(line, blocks, "\\b", wxString::Format("%d", font.GetWeight() == wxFONTWEIGHT_BOLD), sel_start, sel_end);
set_tag(line, blocks, "\\b", std::to_string(font.GetWeight() == wxFONTWEIGHT_BOLD), sel_start, sel_end);
if (font.GetStyle() != startfont.GetStyle())
set_tag(line, blocks, "\\i", wxString::Format("%d", font.GetStyle() == wxFONTSTYLE_ITALIC), sel_start, sel_end);
set_tag(line, blocks, "\\i", std::to_string(font.GetStyle() == wxFONTSTYLE_ITALIC), sel_start, sel_end);
if (font.GetUnderlined() != startfont.GetUnderlined())
set_tag(line, blocks, "\\i", wxString::Format("%d", font.GetUnderlined()), sel_start, sel_end);
set_tag(line, blocks, "\\i", std::to_string(font.GetUnderlined()), sel_start, sel_end);
commit_text(c, _("set font"), sel_start, sel_end);
}

View File

@ -53,6 +53,7 @@
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_karaoke.h"
#include "compat.h"
#include "help_button.h"
#include "include/aegisub/context.h"
#include "kana_table.h"
@ -266,7 +267,7 @@ void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &)
// Matched source syllables
int syl_x = next_x;
for (auto const& syl : grp.src)
syl_x += DrawBoxedText(dc, syl.text, syl_x, y_line1);
syl_x += DrawBoxedText(dc, to_wx(syl.text), syl_x, y_line1);
// Matched destination text
{
@ -305,7 +306,7 @@ void KaraokeLineMatchDisplay::OnPaint(wxPaintEvent &)
dc.SetBrush(wxBrush(inner_back));
}
syl_x += DrawBoxedText(dc, unmatched_source[j].text, syl_x, y_line1);
syl_x += DrawBoxedText(dc, to_wx(unmatched_source[j].text), syl_x, y_line1);
}
// Remaining destination
@ -413,7 +414,7 @@ void KaraokeLineMatchDisplay::AutoMatchJapanese()
}
// We'll first see if we can do something with the first unmatched source syllable
wxString src(unmatched_source[0].text.Lower());
wxString src(to_wx(unmatched_source[0].text).Lower());
wxString dst(unmatched_destination);
source_sel_length = 1; // we're working on the first, assume it was matched
destination_sel_length = 0;
@ -531,12 +532,12 @@ void KaraokeLineMatchDisplay::AutoMatchJapanese()
// Check if we've gone too far ahead in the source
if (src_lookahead_pos++ >= src_lookahead_max) break;
// Otherwise look for a match
if (syl.text.StartsWith(matched_roma))
if (to_wx(syl.text).StartsWith(matched_roma))
{
// Yay! Time to interpolate.
// Special case: If the last source syllable before the matching one is
// empty or contains just whitespace, don't include that one.
if (src_lookahead_pos > 1 && StringEmptyOrWhitespace(unmatched_source[src_lookahead_pos-2].text))
if (src_lookahead_pos > 1 && StringEmptyOrWhitespace(to_wx(unmatched_source[src_lookahead_pos-2].text)))
src_lookahead_pos -= 1;
// Special case: Just one source syllable matching, pick all destination found
if (src_lookahead_pos == 2)

View File

@ -152,7 +152,7 @@ namespace {
double ar;
};
void resample_tags(wxString const& name, AssOverrideParameter *cur, void *ud) {
void resample_tags(std::string const& name, AssOverrideParameter *cur, void *ud) {
resample_state *state = static_cast<resample_state *>(ud);
double resizer = 1.0;
@ -182,7 +182,7 @@ namespace {
break;
case PARCLASS_DRAWING: {
AssDialogueBlockDrawing block(cur->Get<wxString>(), 1);
AssDialogueBlockDrawing block(cur->Get<std::string>(), 1);
block.TransformCoords(state->margin[LEFT], state->margin[TOP], state->rx, state->ry);
cur->Set(block.GetText());
return;

View File

@ -73,11 +73,11 @@ class StyleRenamer {
wxString new_name;
/// Process a single override parameter to check if it's \r with this style name
static void ProcessTag(wxString const& tag, AssOverrideParameter* param, void *userData) {
static void ProcessTag(std::string const& tag, AssOverrideParameter* param, void *userData) {
StyleRenamer *self = static_cast<StyleRenamer*>(userData);
if (tag == "\\r" && param->GetType() == VARDATA_TEXT && param->Get<wxString>() == self->source_name) {
if (tag == "\\r" && param->GetType() == VARDATA_TEXT && to_wx(param->Get<std::string>()) == self->source_name) {
if (self->do_replace)
param->Set(self->new_name);
param->Set(from_wx(self->new_name));
else
self->found_any = true;
}

View File

@ -39,6 +39,9 @@
#include "utils.h"
#include "video_context.h"
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <wx/checkbox.h>
#include <wx/msgdlg.h>
#include <wx/sizer.h>
@ -53,9 +56,9 @@ static void add_hotkey(wxSizer *sizer, wxWindow *parent, const char *command, wx
// Skip over override blocks, comments, and whitespace between blocks
static bool bad_block(AssDialogueBlock &block) {
if (block.GetType() != BLOCK_PLAIN) return true;
wxString text = block.GetText();
if (text.Trim().Trim(false).empty()) return true;
if (text[0] == '{' && text.Last() == '}') return true;
std::string text = block.GetText();
if (boost::all(text, boost::is_space())) return true;
if (boost::starts_with(text, "{") && boost::ends_with(text, "}")) return true;
return false;
}
@ -247,14 +250,14 @@ void DialogTranslation::UpdateDisplay() {
for (auto& block : blocks) {
if (block.GetType() == BLOCK_PLAIN) {
int cur_size = original_text->GetReverseUnicodePosition(original_text->GetLength());
original_text->AppendText(block.GetText());
original_text->AppendTextRaw(block.GetText().c_str());
if (i == cur_block) {
original_text->StartUnicodeStyling(cur_size);
original_text->SetUnicodeStyling(cur_size, block.GetText().size(), 1);
}
}
else if (block.GetType() == BLOCK_OVERRIDE)
original_text->AppendText(block.GetText());
original_text->AppendTextRaw(block.GetText().c_str());
++i;
}
@ -271,7 +274,7 @@ void DialogTranslation::Commit(bool next) {
new_value.Replace("\r\n", "\\N");
new_value.Replace("\r", "\\N");
new_value.Replace("\n", "\\N");
blocks[cur_block] = AssDialogueBlockPlain(new_value);
blocks[cur_block] = AssDialogueBlockPlain(from_wx(new_value));
active_line->UpdateText(blocks);
file_change_connection.Block();
@ -290,7 +293,7 @@ void DialogTranslation::Commit(bool next) {
}
void DialogTranslation::InsertOriginal() {
translated_text->AddText(blocks[cur_block].GetText());
translated_text->AddText(to_wx(blocks[cur_block].GetText()));
}

View File

@ -167,7 +167,7 @@ int FORCEINLINE trunc_cs(int time) {
return (time / 10) * 10;
}
void AssTransformFramerateFilter::TransformTimeTags(wxString const& name, AssOverrideParameter *curParam, void *curData) {
void AssTransformFramerateFilter::TransformTimeTags(std::string const& name, AssOverrideParameter *curParam, void *curData) {
VariableDataType type = curParam->GetType();
if (type != VARDATA_INT && type != VARDATA_FLOAT) return;

View File

@ -72,7 +72,7 @@ class AssTransformFramerateFilter : public AssExportFilter {
/// @param name Name of the tag
/// @param curParam Current parameter being processed
/// @param userdata Filter instance
static void TransformTimeTags(wxString const& name, AssOverrideParameter *curParam, void *userdata);
static void TransformTimeTags(std::string const& name, AssOverrideParameter *curParam, void *userdata);
/// @brief Convert a time from the input frame rate to the output frame rate
/// @param time Time in ms to convert

View File

@ -26,6 +26,7 @@
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_style.h"
#include "compat.h"
#include "utils.h"
#include <libaegisub/of_type_adaptor.h>
@ -59,7 +60,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
std::string const& name = tag.Name;
if (name == "\\r") {
style = styles[tag.Params[0].Get<wxString>(line->Style)];
style = styles[to_wx(tag.Params[0].Get(from_wx(line->Style)))];
overriden = false;
}
else if (name == "\\b") {
@ -71,7 +72,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
overriden = true;
}
else if (name == "\\fn") {
style.facename = tag.Params[0].Get(initial.facename);
style.facename = to_wx(tag.Params[0].Get(from_wx(initial.facename)));
overriden = true;
}
}

View File

@ -285,7 +285,7 @@ namespace
case BLOCK_PLAIN:
// find special characters and convert them
{
wxString text = b.GetText();
wxString text = to_wx(b.GetText());
// Skip comments
if (text.size() > 1 && text[0] =='{' && text.Last() == '}')

View File

@ -516,7 +516,7 @@ void SRTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename,
}
bool SRTSubtitleFormat::CanSave(const AssFile *file) const {
wxString supported_tags[] = { "\\b", "\\i", "\\s", "\\u" };
std::string supported_tags[] = { "\\b", "\\i", "\\s", "\\u" };
AssStyle defstyle;
for (auto const& line : file->Line) {
@ -574,7 +574,7 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const {
}
// Plain text
else if (AssDialogueBlockPlain *plain = dynamic_cast<AssDialogueBlockPlain*>(&block)) {
final += plain->GetText();
final += to_wx(plain->GetText());
}
}

View File

@ -28,6 +28,7 @@
#include "ass_file.h"
#include "ass_style.h"
#include "ass_time.h"
#include "compat.h"
#include "include/aegisub/context.h"
#include "main.h"
#include "utils.h"
@ -354,7 +355,7 @@ void VisualTool<FeatureType>::RemoveSelection(feature_iterator feat) {
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) {
static param_vec find_tag(boost::ptr_vector<AssDialogueBlock>& blocks, std::string const& tag_name) {
for (auto ovr : blocks | agi::of_type<AssDialogueBlockOverride>()) {
for (auto const& tag : ovr->Tags) {
if (tag.Name == tag_name)
@ -526,21 +527,21 @@ wxString VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, bool &
}
if (tag) {
scale = std::max((*tag)[0].Get(scale), 1);
return (*tag)[1].Get<wxString>("");
return to_wx((*tag)[1].Get<std::string>(""));
}
return "";
}
void VisualToolBase::SetSelectedOverride(wxString const& tag, wxString const& value) {
void VisualToolBase::SetSelectedOverride(std::string const& tag, wxString const& value) {
for (auto line : c->selectionController->GetSelectedSet())
SetOverride(line, tag, value);
}
void VisualToolBase::SetOverride(AssDialogue* line, wxString const& tag, wxString const& value) {
void VisualToolBase::SetOverride(AssDialogue* line, std::string const& tag, wxString const& value) {
if (!line) return;
wxString removeTag;
std::string removeTag;
if (tag == "\\1c") removeTag = "\\c";
else if (tag == "\\frz") removeTag = "\\fr";
else if (tag == "\\pos") removeTag = "\\move";
@ -548,8 +549,6 @@ void VisualToolBase::SetOverride(AssDialogue* line, wxString const& tag, wxStrin
else if (tag == "\\clip") removeTag = "\\iclip";
else if (tag == "\\iclip") removeTag = "\\clip";
wxString insert = tag + value;
// Get block at start
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
AssDialogueBlock *block = &blocks.front();
@ -558,17 +557,17 @@ void VisualToolBase::SetOverride(AssDialogue* line, wxString const& tag, wxStrin
assert(dynamic_cast<AssDialogueBlockDrawing*>(block) == nullptr);
if (dynamic_cast<AssDialogueBlockPlain*>(block))
line->Text = "{" + insert + "}" + line->Text;
line->Text = "{" + to_wx(tag) + value + "}" + line->Text;
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;
std::string const& name = ovr->Tags[i].Name;
if (tag == name || removeTag == name) {
ovr->Tags.erase(ovr->Tags.begin() + i);
i--;
}
}
ovr->AddTag(insert);
ovr->AddTag(tag + from_wx(value));
line->UpdateText(blocks);
}

View File

@ -135,8 +135,8 @@ protected:
void GetLineClip(AssDialogue *diag, Vector2D &p1, Vector2D &p2, bool &inverse);
wxString GetLineVectorClip(AssDialogue *diag, int &scale, bool &inverse);
void SetOverride(AssDialogue* line, wxString const& tag, wxString const& value);
void SetSelectedOverride(wxString const& tag, wxString const& value);
void SetOverride(AssDialogue* line, std::string const& tag, wxString const& value);
void SetSelectedOverride(std::string const& tag, wxString const& value);
VisualToolBase(VideoDisplay *parent, agi::Context *context);