Partially de-wxify AssStyle

This commit is contained in:
Thomas Goyne 2012-12-29 16:32:36 -08:00
parent d49758edbf
commit 3ec82952f8
26 changed files with 226 additions and 189 deletions

View File

@ -36,6 +36,7 @@
#include "ass_file.h"
#include <algorithm>
#include <boost/algorithm/string/predicate.hpp>
#include <fstream>
#include <inttypes.h>
#include <list>
@ -350,16 +351,16 @@ void AssFile::GetResolution(int &sw,int &sh) const {
}
}
wxArrayString AssFile::GetStyles() const {
wxArrayString styles;
std::vector<std::string> AssFile::GetStyles() const {
std::vector<std::string> styles;
for (auto style : Line | agi::of_type<AssStyle>())
styles.push_back(style->name);
return styles;
}
AssStyle *AssFile::GetStyle(wxString const& name) {
AssStyle *AssFile::GetStyle(std::string const& name) {
for (auto style : Line | agi::of_type<AssStyle>()) {
if (style->name == name)
if (boost::iequals(style->name, name))
return style;
}
return nullptr;

View File

@ -37,8 +37,6 @@
#include <set>
#include <vector>
#include <wx/arrstr.h>
#include <libaegisub/signal.h>
#include "ass_entry.h"
@ -98,11 +96,11 @@ public:
/// Attach a file to the ass file
void InsertAttachment(wxString filename);
/// Get the names of all of the styles available
wxArrayString GetStyles() const;
std::vector<std::string> GetStyles() const;
/// @brief Get a style by name
/// @param name Style name
/// @return Pointer to style or nullptr
AssStyle *GetStyle(wxString const& name);
AssStyle *GetStyle(std::string const& name);
void swap(AssFile &) throw();

View File

@ -34,16 +34,19 @@
#include "config.h"
#include <cctype>
#include <wx/intl.h>
#include <wx/tokenzr.h>
#include "ass_style.h"
#include "compat.h"
#include "subtitle_format.h"
#include "utils.h"
#include <algorithm>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
#include <cctype>
#include <wx/intl.h>
AssStyle::AssStyle()
: name("Default")
, font("Arial")
@ -69,61 +72,105 @@ AssStyle::AssStyle()
UpdateData();
}
static wxString get_next_string(wxStringTokenizer &tok) {
if (!tok.HasMoreTokens()) throw SubtitleFormatParseError("Malformed style: not enough fields", 0);
return tok.GetNextToken();
namespace {
class parser {
typedef boost::iterator_range<std::string::const_iterator> string_range;
string_range str;
std::vector<string_range> tkns;
size_t tkn_idx;
string_range& next_tok() {
if (tkn_idx >= tkns.size())
throw SubtitleFormatParseError("Malformed style: not enough fields", 0);
return tkns[tkn_idx++];
}
public:
parser(std::string const& str)
: tkn_idx(0)
{
auto pos = find(str.begin(), str.end(), ':');
if (pos != str.end()) {
this->str = string_range(pos + 1, str.end());
split(tkns, this->str, [](char c) { return c == ','; });
}
}
~parser() {
if (tkn_idx != tkns.size())
throw SubtitleFormatParseError("Malformed style: too many fields", 0);
}
std::string next_str() {
auto tkn = trim_copy(next_tok());
return std::string(begin(tkn), end(tkn));
}
agi::Color next_color() {
auto &tkn = next_tok();
return std::string(begin(tkn), end(tkn));
}
int next_int() {
try {
return boost::lexical_cast<int>(next_tok());
}
catch (boost::bad_lexical_cast const&) {
throw SubtitleFormatParseError("Malformed style: bad int field", 0);
}
}
double next_double() {
try {
return boost::lexical_cast<double>(next_tok());
}
catch (boost::bad_lexical_cast const&) {
throw SubtitleFormatParseError("Malformed style: bad double field", 0);
}
}
void skip_token() {
++tkn_idx;
}
};
}
static int get_next_int(wxStringTokenizer &tok) {
long temp;
if (!get_next_string(tok).ToLong(&temp))
throw SubtitleFormatParseError("Malformed style: could not parse int field", 0);
return temp;
}
AssStyle::AssStyle(wxString const& rawData, int version) {
parser p(from_wx(rawData));
static double get_next_double(wxStringTokenizer &tok) {
double temp;
if (!get_next_string(tok).ToDouble(&temp))
throw SubtitleFormatParseError("Malformed style: could not parse double field", 0);
return temp;
}
AssStyle::AssStyle(wxString rawData, int version) {
wxStringTokenizer tkn(rawData.Trim(false).Mid(6), ",", wxTOKEN_RET_EMPTY_ALL);
name = get_next_string(tkn).Trim(true).Trim(false);
font = get_next_string(tkn).Trim(true).Trim(false);
fontsize = get_next_double(tkn);
name = p.next_str();
font = p.next_str();
fontsize = p.next_double();
if (version != 0) {
primary = from_wx(get_next_string(tkn));
secondary = from_wx(get_next_string(tkn));
outline = from_wx(get_next_string(tkn));
shadow = from_wx(get_next_string(tkn));
primary = p.next_color();
secondary = p.next_color();
outline = p.next_color();
shadow = p.next_color();
}
else {
primary = from_wx(get_next_string(tkn));
secondary = from_wx(get_next_string(tkn));
primary = p.next_color();
secondary = p.next_color();
// Read and discard tertiary color
get_next_string(tkn);
// Skip tertiary color
p.skip_token();
// Read shadow/outline color
outline = from_wx(get_next_string(tkn));
outline = p.next_color();
shadow = outline;
}
bold = !!get_next_int(tkn);
italic = !!get_next_int(tkn);
bold = !!p.next_int();
italic = !!p.next_int();
if (version != 0) {
underline = !!get_next_int(tkn);
strikeout = !!get_next_int(tkn);
underline = !!p.next_int();
strikeout = !!p.next_int();
scalex = get_next_double(tkn);
scaley = get_next_double(tkn);
spacing = get_next_double(tkn);
angle = get_next_double(tkn);
scalex = p.next_double();
scaley = p.next_double();
spacing = p.next_double();
angle = p.next_double();
}
else {
// SSA defaults
@ -136,42 +183,33 @@ AssStyle::AssStyle(wxString rawData, int version) {
angle = 0.0;
}
borderstyle = get_next_int(tkn);
outline_w = get_next_double(tkn);
shadow_w = get_next_double(tkn);
alignment = get_next_int(tkn);
borderstyle = p.next_int();
outline_w = p.next_double();
shadow_w = p.next_double();
alignment = p.next_int();
if (version == 0)
alignment = SsaToAss(alignment);
// Read left margin
Margin[0] = mid(0, get_next_int(tkn), 9999);
// Read right margin
Margin[1] = mid(0, get_next_int(tkn), 9999);
// Read vertical margin
Margin[2] = mid(0, get_next_int(tkn), 9999);
Margin[0] = mid(0, p.next_int(), 9999);
Margin[1] = mid(0, p.next_int(), 9999);
Margin[2] = mid(0, p.next_int(), 9999);
// Skip alpha level
if (version == 0)
get_next_string(tkn);
p.skip_token();
// Read encoding
encoding = get_next_int(tkn);
if (tkn.HasMoreTokens())
throw SubtitleFormatParseError("Malformed style: too many fields", 0);
encoding = p.next_int();
UpdateData();
}
void AssStyle::UpdateData() {
name.Replace(",", ";");
font.Replace(",", ";");
replace(name.begin(), name.end(), ',', ';');
replace(font.begin(), font.end(), ',', ';');
data = wxString::Format("Style: %s,%s,%g,%s,%s,%s,%s,%d,%d,%d,%d,%g,%g,%g,%g,%d,%g,%g,%i,%i,%i,%i,%i",
name, font, fontsize,
to_wx(name), to_wx(font), fontsize,
primary.GetAssStyleFormatted(),
secondary.GetAssStyleFormatted(),
outline.GetAssStyleFormatted(),
@ -185,7 +223,7 @@ void AssStyle::UpdateData() {
wxString AssStyle::GetSSAText() const {
return wxString::Format("Style: %s,%s,%g,%s,%s,0,%s,%d,%d,%d,%g,%g,%d,%d,%d,%d,0,%i",
name, font, fontsize,
to_wx(name), to_wx(font), fontsize,
primary.GetSsaFormatted(),
secondary.GetSsaFormatted(),
shadow.GetSsaFormatted(),

View File

@ -32,20 +32,19 @@
/// @ingroup subs_storage
///
#include <array>
#include <wx/colour.h>
#include "ass_entry.h"
#include <libaegisub/color.h>
#include <array>
#include <wx/arrstr.h>
class AssStyle : public AssEntry {
wxString data;
public:
wxString name; ///< Name of the style; must be case-insensitively unique within a file despite being case-sensitive
wxString font; ///< Font face name
std::string name; ///< Name of the style; must be case-insensitively unique within a file despite being case-sensitive
std::string font; ///< Font face name
double fontsize; ///< Font size
agi::Color primary; ///< Default text color
@ -76,7 +75,7 @@ public:
static void GetEncodings(wxArrayString &encodingStrings);
AssStyle();
AssStyle(wxString data, int version=1);
AssStyle(wxString const& data, int version=1);
const wxString GetEntryData() const override { return data; }
wxString GetSSAText() const override;

View File

@ -36,14 +36,15 @@
#include "ass_style_storage.h"
#include <functional>
#include "ass_style.h"
#include "standard_paths.h"
#include "text_file_reader.h"
#include "text_file_writer.h"
#include "utils.h"
#include <boost/algorithm/string/predicate.hpp>
#include <functional>
AssStyleStorage::~AssStyleStorage() {
delete_clear(style);
}
@ -92,16 +93,16 @@ void AssStyleStorage::Delete(int idx) {
style.erase(style.begin() + idx);
}
wxArrayString AssStyleStorage::GetNames() {
wxArrayString names;
std::vector<std::string> AssStyleStorage::GetNames() {
std::vector<std::string> names;
for (const AssStyle *cur : style)
names.Add(cur->name);
names.emplace_back(cur->name);
return names;
}
AssStyle *AssStyleStorage::GetStyle(wxString const& name) {
AssStyle *AssStyleStorage::GetStyle(std::string const& name) {
for (AssStyle *cur : style) {
if (cur->name.CmpNoCase(name) == 0)
if (boost::iequals(cur->name, name))
return cur;
}
return 0;

View File

@ -33,8 +33,10 @@
///
#include <deque>
#include <string>
#include <vector>
#include <wx/arrstr.h>
#include <wx/string.h>
class AssStyle;
@ -57,7 +59,7 @@ public:
size_t size() const { return style.size(); }
/// Get the names of all styles in this storage
wxArrayString GetNames();
std::vector<std::string> GetNames();
/// Delete all styles in this storage
void Clear();
@ -68,7 +70,7 @@ public:
/// Get the style with the given name
/// @param name Case-insensitive style name
/// @return Style or nullptr if the requested style is not found
AssStyle *GetStyle(wxString const& name);
AssStyle *GetStyle(std::string const& name);
/// Save stored styles to a file
void Save() const;

View File

@ -289,7 +289,7 @@ void AudioTimingControllerKaraoke::Revert() {
for (auto it = kara->begin(); it != kara->end(); ++it) {
if (it != kara->begin())
markers.emplace_back(it->start_time, &separator_pen, AudioMarker::Feet_None);
labels.emplace_back(it->text, TimeRange(it->start_time, it->start_time + it->duration));
labels.emplace_back(to_wx(it->text), TimeRange(it->start_time, it->start_time + it->duration));
}
AnnounceUpdatedPrimaryRange();

View File

@ -40,6 +40,8 @@
#include <tchar.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <libaegisub/charset_conv_win.h>
#endif
#include <wx/button.h>
@ -97,7 +99,7 @@ namespace Automation4 {
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = ANTIALIASED_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
wcsncpy(lf.lfFaceName, style->font.wc_str(), 32);
wcsncpy(lf.lfFaceName, agi::charset::ConvertW(style->font).c_str(), 32);
HFONT thefont = CreateFontIndirect(&lf);
if (!thefont) return false;

View File

@ -69,6 +69,10 @@ namespace {
lua_pushstring(L, value.utf8_str());
}
void push_value(lua_State *L, std::string const& value) {
lua_pushstring(L, value.c_str());
}
void push_value(lua_State *L, const char *value) {
lua_pushstring(L, value);
}
@ -302,8 +306,8 @@ namespace Automation4 {
else if (lclass == "style") {
AssStyle *sty = new AssStyle;
result = sty;
sty->name = get_wxstring_field(L, "name", "style");
sty->font = get_wxstring_field(L, "fontname", "style");
sty->name = get_string_field(L, "name", "style");
sty->font = get_string_field(L, "fontname", "style");
sty->fontsize = get_double_field(L, "fontsize", "style");
sty->primary = get_string_field(L, "color1", "style");
sty->secondary = get_string_field(L, "color2", "style");

View File

@ -280,7 +280,7 @@ void commit_text(agi::Context const * const c, wxString const& desc, int sel_sta
void toggle_override_tag(const agi::Context *c, bool (AssStyle::*field), const char *tag, wxString const& undo_msg) {
AssDialogue *const line = c->selectionController->GetActiveLine();
AssStyle const* const style = c->ass->GetStyle(line->Style);
AssStyle const* const style = c->ass->GetStyle(from_wx(line->Style));
bool state = style ? style->*field : AssStyle().*field;
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
@ -299,7 +299,7 @@ void toggle_override_tag(const agi::Context *c, bool (AssStyle::*field), const c
void show_color_picker(const agi::Context *c, agi::Color (AssStyle::*field), const char *tag, const char *alt) {
AssDialogue *const line = c->selectionController->GetActiveLine();
AssStyle const* const style = c->ass->GetStyle(line->Style);
AssStyle const* const style = c->ass->GetStyle(from_wx(line->Style));
agi::Color color = (style ? style->*field : AssStyle().*field);
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
@ -421,7 +421,7 @@ struct edit_font : public Command {
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
const int blockn = block_at_pos(line->Text, c->textSelectionController->GetInsertionPoint());
const AssStyle *style = c->ass->GetStyle(line->Style);
const AssStyle *style = c->ass->GetStyle(from_wx(line->Style));
const AssStyle default_style;
if (!style)
style = &default_style;

View File

@ -639,7 +639,7 @@ DialogKanjiTimer::DialogKanjiTimer(agi::Context *c)
Interpolate = new wxCheckBox(this,-1,_("Attempt to &interpolate kanji."),wxDefaultPosition,wxDefaultSize,wxALIGN_LEFT);
Interpolate->SetValue(OPT_GET("Tool/Kanji Timer/Interpolation")->GetBool());
wxArrayString styles = subs->GetStyles();
wxArrayString styles = to_wx(subs->GetStyles());
SourceStyle = new wxComboBox(this, -1, "", wxDefaultPosition, wxSize(160, -1), styles, wxCB_READONLY);
DestStyle = new wxComboBox(this, -1, "", wxDefaultPosition, wxSize(160, -1), styles, wxCB_READONLY);

View File

@ -69,15 +69,15 @@ class StyleRenamer {
agi::Context *c;
bool found_any;
bool do_replace;
wxString source_name;
wxString new_name;
std::string source_name;
std::string new_name;
/// Process a single override parameter to check if it's \r with this style name
static void ProcessTag(std::string const& tag, AssOverrideParameter* param, void *userData) {
StyleRenamer *self = static_cast<StyleRenamer*>(userData);
if (tag == "\\r" && param->GetType() == VARDATA_TEXT && to_wx(param->Get<std::string>()) == self->source_name) {
if (tag == "\\r" && param->GetType() == VARDATA_TEXT && param->Get<std::string>() == self->source_name) {
if (self->do_replace)
param->Set(from_wx(self->new_name));
param->Set(self->new_name);
else
self->found_any = true;
}
@ -87,10 +87,13 @@ class StyleRenamer {
found_any = false;
do_replace = replace;
wxString wx_old(to_wx(source_name));
wxString wx_new(to_wx(new_name));
for (auto diag : c->ass->Line | agi::of_type<AssDialogue>()) {
if (diag->Style == source_name) {
if (diag->Style == wx_old) {
if (replace)
diag->Style = new_name;
diag->Style = wx_new;
else
found_any = true;
}
@ -106,7 +109,7 @@ class StyleRenamer {
}
public:
StyleRenamer(agi::Context *c, wxString const& source_name, wxString const& new_name)
StyleRenamer(agi::Context *c, std::string const& source_name, std::string const& new_name)
: c(c)
, found_any(false)
, do_replace(false)
@ -140,7 +143,7 @@ static wxTextCtrl *num_text_ctrl(wxWindow *parent, double value, wxSize size = w
return new wxTextCtrl(parent, -1, "", wxDefaultPosition, size, 0, NumValidator(value));
}
DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store, wxString const& new_name)
DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store, std::string const& new_name)
: wxDialog (parent, -1, _("Style Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, c(c)
, is_new(false)
@ -181,8 +184,8 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
wxSizer *PreviewBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Preview"));
// Create controls
StyleName = new wxTextCtrl(this, -1, style->name);
FontName = new wxComboBox(this, -1, style->font, wxDefaultPosition, wxSize(150, -1), 0, 0, wxCB_DROPDOWN);
StyleName = new wxTextCtrl(this, -1, to_wx(style->name));
FontName = new wxComboBox(this, -1, to_wx(style->font), wxDefaultPosition, wxSize(150, -1), 0, 0, wxCB_DROPDOWN);
FontSize = num_text_ctrl(this, style->fontsize, wxSize(50, -1));
BoxBold = new wxCheckBox(this, -1, _("&Bold"));
BoxItalic = new wxCheckBox(this, -1, _("&Italic"));
@ -240,7 +243,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
// Fill font face list box
FontName->Freeze();
FontName->Append(fontList);
FontName->SetValue(style->font);
FontName->SetValue(to_wx(style->font));
FontName->Thaw();
// Set encoding value
@ -410,32 +413,29 @@ DialogStyleEditor::~DialogStyleEditor() {
delete style;
}
wxString DialogStyleEditor::GetStyleName() const {
std::string DialogStyleEditor::GetStyleName() const {
return style->name;
}
void DialogStyleEditor::Apply(bool apply, bool close) {
if (apply) {
wxString newStyleName = StyleName->GetValue();
std::string new_name = from_wx(StyleName->GetValue());
// Get list of existing styles
wxArrayString styles = store ? store->GetNames() : c->ass->GetStyles();
std::vector<std::string> styles = store ? store->GetNames() : c->ass->GetStyles();
// Check if style name is unique
for (auto const& style_name : styles) {
if (newStyleName.CmpNoCase(style_name) == 0) {
if ((store && store->GetStyle(style_name) != style) || (!store && c->ass->GetStyle(style_name) != style)) {
wxMessageBox("There is already a style with this name. Please choose another name.", "Style name conflict.", wxOK | wxICON_ERROR | wxCENTER);
return;
}
}
AssStyle *existing = store ? store->GetStyle(new_name) : c->ass->GetStyle(new_name);
if (existing && existing != style) {
wxMessageBox(_("There is already a style with this name. Please choose another name."), _("Style name conflict"), wxOK | wxICON_ERROR | wxCENTER);
return;
}
// Style name change
bool did_rename = false;
if (work->name != newStyleName) {
if (work->name != new_name) {
if (!store && !is_new) {
StyleRenamer renamer(c, work->name, newStyleName);
StyleRenamer renamer(c, work->name, new_name);
if (renamer.NeedsReplace()) {
// See if user wants to update style name through script
int answer = wxMessageBox(
@ -452,7 +452,7 @@ void DialogStyleEditor::Apply(bool apply, bool close) {
}
}
work->name = newStyleName;
work->name = new_name;
}
UpdateWorkStyle();
@ -482,7 +482,7 @@ void DialogStyleEditor::Apply(bool apply, bool close) {
/// @brief Update work style
void DialogStyleEditor::UpdateWorkStyle() {
work->font = FontName->GetValue();
work->font = from_wx(FontName->GetValue());
FontSize->GetValue().ToDouble(&(work->fontsize));
ScaleX->GetValue().ToDouble(&(work->scalex));

View File

@ -106,8 +106,8 @@ class DialogStyleEditor : public wxDialog {
void OnSetColor(int n, wxCommandEvent& evt);
public:
DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store = 0, wxString const& new_name = "");
DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store = 0, std::string const& new_name = "");
~DialogStyleEditor();
wxString GetStyleName() const;
std::string GetStyleName() const;
};

View File

@ -110,11 +110,11 @@ wxSizer *make_edit_buttons(wxWindow *parent, wxString move_label, wxButton **mov
}
template<class Func>
wxString unique_name(Func name_checker, wxString const& source_name) {
std::string unique_name(Func name_checker, std::string const& source_name) {
if (name_checker(source_name)) {
wxString name = wxString::Format(_("%s - Copy"), source_name);
std::string name = from_wx(wxString::Format(_("%s - Copy"), to_wx(source_name)));
for (int i = 2; name_checker(name); ++i)
name = wxString::Format(_("%s - Copy (%d)"), source_name, i);
name = from_wx(wxString::Format(_("%s - Copy (%d)"), to_wx(source_name), i));
return name;
}
return source_name;
@ -275,7 +275,7 @@ void DialogStyleManager::LoadCurrentStyles(int commit_type) {
styleMap.clear();
for (auto style : c->ass->Line | agi::of_type<AssStyle>()) {
CurrentList->Append(style->name);
CurrentList->Append(to_wx(style->name));
styleMap.push_back(style);
}
}
@ -304,8 +304,7 @@ void DialogStyleManager::UpdateStorage() {
Store.Save();
StorageList->Clear();
for (auto style : Store)
StorageList->Append(style->name);
StorageList->Append(to_wx(Store.GetNames()));
UpdateButtons();
}
@ -406,8 +405,8 @@ void DialogStyleManager::OnCopyToStorage() {
for (int i = 0; i < n; i++) {
wxString styleName = CurrentList->GetString(selections[i]);
if (AssStyle *style = Store.GetStyle(styleName)) {
if (wxYES == wxMessageBox(wxString::Format(_("There is already a style with the name \"%s\" in the current storage. Overwrite?"),styleName), _("Style name collision."), wxYES_NO)) {
if (AssStyle *style = Store.GetStyle(from_wx(styleName))) {
if (wxYES == wxMessageBox(wxString::Format(_("There is already a style with the name \"%s\" in the current storage. Overwrite?"),styleName), _("Style name collision"), wxYES_NO)) {
*style = *styleMap.at(selections[i]);
copied.push_back(styleName);
}
@ -432,19 +431,14 @@ void DialogStyleManager::OnCopyToCurrent() {
copied.reserve(n);
for (int i = 0; i < n; i++) {
wxString styleName = StorageList->GetString(selections[i]);
bool addStyle = true;
for (auto style = styleMap.begin(); style != styleMap.end(); ++style) {
if ((*style)->name.CmpNoCase(styleName) == 0) {
addStyle = false;
if (wxYES == wxMessageBox(wxString::Format(_("There is already a style with the name \"%s\" in the current script. Overwrite?"), styleName), _("Style name collision"), wxYES_NO)) {
**style = *Store[selections[i]];
copied.push_back(styleName);
}
break;
if (AssStyle *style = c->ass->GetStyle(from_wx(styleName))) {
if (wxYES == wxMessageBox(wxString::Format(_("There is already a style with the name \"%s\" in the current script. Overwrite?"), styleName), _("Style name collision"), wxYES_NO)) {
*style = *Store[selections[i]];
copied.push_back(styleName);
}
}
if (addStyle) {
else {
c->ass->InsertLine(new AssStyle(*Store[selections[i]]));
copied.push_back(styleName);
}
@ -488,15 +482,15 @@ void DialogStyleManager::PasteToStorage() {
std::bind(&AssStyleStorage::push_back, &Store, _1));
UpdateStorage();
StorageList->SetStringSelection(Store.back()->name);
StorageList->SetStringSelection(to_wx(Store.back()->name));
UpdateButtons();
}
void DialogStyleManager::ShowStorageEditor(AssStyle *style, wxString const& new_name) {
void DialogStyleManager::ShowStorageEditor(AssStyle *style, std::string const& new_name) {
DialogStyleEditor editor(this, style, c, &Store, new_name);
if (editor.ShowModal()) {
UpdateStorage();
StorageList->SetStringSelection(editor.GetStyleName());
StorageList->SetStringSelection(to_wx(editor.GetStyleName()));
UpdateButtons();
}
}
@ -530,11 +524,11 @@ void DialogStyleManager::OnStorageDelete() {
}
}
void DialogStyleManager::ShowCurrentEditor(AssStyle *style, wxString const& new_name) {
void DialogStyleManager::ShowCurrentEditor(AssStyle *style, std::string const& new_name) {
DialogStyleEditor editor(this, style, c, 0, new_name);
if (editor.ShowModal()) {
CurrentList->DeselectAll();
CurrentList->SetStringSelection(editor.GetStyleName());
CurrentList->SetStringSelection(to_wx(editor.GetStyleName()));
UpdateButtons();
}
}
@ -590,7 +584,7 @@ void DialogStyleManager::OnCurrentImport() {
}
// Get styles
wxArrayString styles = temp.GetStyles();
std::vector<std::string> styles = temp.GetStyles();
if (styles.empty()) {
wxMessageBox(_("The selected file has no available styles."), _("Error Importing Styles"));
return;
@ -598,35 +592,28 @@ void DialogStyleManager::OnCurrentImport() {
// Get selection
wxArrayInt selections;
int res = GetSelectedChoices(this, selections, _("Choose styles to import:"), _("Import Styles"), styles);
int res = GetSelectedChoices(this, selections, _("Choose styles to import:"), _("Import Styles"), to_wx(styles));
if (res == -1 || selections.empty()) return;
bool modified = false;
// Loop through selection
for (auto const& sel : selections) {
// Check if there is already a style with that name
int test = CurrentList->FindString(styles[sel], false);
if (test != wxNOT_FOUND) {
if (AssStyle *existing = c->ass->GetStyle(styles[sel])) {
int answer = wxMessageBox(
wxString::Format(_("There is already a style with the name \"%s\" in the current script. Overwrite?"), styles[sel]),
_("Style name collision"),
wxYES_NO);
if (answer == wxYES) {
// Overwrite
modified = true;
// The result of GetString is used rather than the name
// itself to deal with that AssFile::GetStyle is
// case-sensitive, but style names are case insensitive
*c->ass->GetStyle(CurrentList->GetString(test)) = *temp.GetStyle(styles[sel]);
*existing = *temp.GetStyle(styles[sel]);
}
continue;
}
// Copy
modified = true;
AssStyle *tempStyle = new AssStyle;
*tempStyle = *temp.GetStyle(styles[sel]);
c->ass->InsertLine(tempStyle);
c->ass->InsertLine(temp.GetStyle(styles[sel])->Clone());
}
// Update

View File

@ -107,12 +107,12 @@ class DialogStyleManager : public wxDialog {
/// Open the style editor for the given style on the script
/// @param style Style to edit, or nullptr for new
/// @param new_name Default new name for copies
void ShowCurrentEditor(AssStyle *style, wxString const& new_name = "");
void ShowCurrentEditor(AssStyle *style, std::string const& new_name = "");
/// Open the style editor for the given style in the storage
/// @param style Style to edit, or nullptr for new
/// @param new_name Default new name for copies
void ShowStorageEditor(AssStyle *style, wxString const& new_name = "");
void ShowStorageEditor(AssStyle *style, std::string const& new_name = "");
/// Save the storage and update the view after a change
void UpdateStorage();

View File

@ -32,6 +32,7 @@
#include "ass_style.h"
#include "audio_controller.h"
#include "command/command.h"
#include "compat.h"
#include "help_button.h"
#include "libresrc/libresrc.h"
#include "persist_location.h"
@ -70,7 +71,7 @@ DialogStyling::DialogStyling(agi::Context *context)
{
wxSizer *styles_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Styles available"));
style_list = new wxListBox(this, -1, wxDefaultPosition, wxSize(150, 180), context->ass->GetStyles());
style_list = new wxListBox(this, -1, wxDefaultPosition, wxSize(150, 180), to_wx(context->ass->GetStyles()));
styles_box->Add(style_list, 1, wxEXPAND, 0);
bottom_sizer->Add(styles_box, 1, wxEXPAND | wxRIGHT, 5);
}
@ -169,7 +170,7 @@ void DialogStyling::OnActiveLineChanged(AssDialogue *new_line) {
}
void DialogStyling::Commit(bool next) {
if (!c->ass->GetStyle(style_name->GetValue())) return;
if (!c->ass->GetStyle(from_wx(style_name->GetValue()))) return;
active_line->Style = style_name->GetValue();
c->ass->Commit(_("styling assistant"), AssFile::COMMIT_DIAG_META);
@ -183,7 +184,7 @@ void DialogStyling::OnActivate(wxActivateEvent &) {
play_video->Enable(c->videoController->IsLoaded());
play_audio->Enable(c->audioController->IsAudioOpen());
style_list->Set(c->ass->GetStyles());
style_list->Set(to_wx(c->ass->GetStyles()));
if (auto_seek->IsChecked())
c->videoController->JumpToTime(active_line->Start);

View File

@ -53,6 +53,7 @@
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_time.h"
#include "compat.h"
#include "help_button.h"
#include "include/aegisub/context.h"
#include "libresrc/libresrc.h"
@ -117,7 +118,7 @@ DialogTimingProcessor::DialogTimingProcessor(agi::Context *c)
// Styles box
wxSizer *LeftSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Apply to styles"));
StyleList = new wxCheckListBox(this, -1, wxDefaultPosition, wxSize(150,150), c->ass->GetStyles());
StyleList = new wxCheckListBox(this, -1, wxDefaultPosition, wxSize(150,150), to_wx(c->ass->GetStyles()));
StyleList->SetToolTip(_("Select styles to process. Unchecked ones will be ignored."));
wxButton *all = new wxButton(this,-1,_("&All"));

View File

@ -37,10 +37,12 @@
#include "export_fixstyle.h"
#include <algorithm>
#include <boost/algorithm/string/case_conv.hpp>
#include <functional>
#include "ass_file.h"
#include "ass_dialogue.h"
#include "compat.h"
#include <libaegisub/of_type_adaptor.h>
@ -50,12 +52,12 @@ AssFixStylesFilter::AssFixStylesFilter()
}
void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *) {
wxArrayString styles = subs->GetStyles();
for_each(styles.begin(), styles.end(), std::mem_fun_ref(&wxString::MakeLower));
styles.Sort();
std::vector<std::string> styles = subs->GetStyles();
for_each(begin(styles), end(styles), [](std::string& str) { boost::to_lower(str); });
sort(begin(styles), end(styles));
for (auto diag : subs->Line | agi::of_type<AssDialogue>()) {
if (!std::binary_search(styles.begin(), styles.end(), diag->Style.get().Lower()))
if (!binary_search(begin(styles), end(styles), from_wx(diag->Style.get().Lower())))
diag->Style = "Default";
}
}

View File

@ -49,7 +49,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
if (line->Comment) return;
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
StyleInfo style = styles[line->Style];
StyleInfo style = styles[from_wx(line->Style)];
StyleInfo initial = style;
bool overriden = false;
@ -60,7 +60,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
std::string const& name = tag.Name;
if (name == "\\r") {
style = styles[to_wx(tag.Params[0].Get(from_wx(line->Style)))];
style = styles[tag.Params[0].Get(from_wx(line->Style))];
overriden = false;
}
else if (name == "\\b") {
@ -72,7 +72,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
overriden = true;
}
else if (name == "\\fn") {
style.facename = to_wx(tag.Params[0].Get(from_wx(initial.facename)));
style.facename = tag.Params[0].Get(initial.facename);
overriden = true;
}
}

View File

@ -51,7 +51,7 @@ public:
/// @param italic Italic?
/// @param characters Characters in this style
/// @return Path to the matching font file(s), or empty if not found
virtual CollectionResult GetFontPaths(wxString const& facename, int bold, bool italic, std::set<wxUniChar> const& characters) = 0;
virtual CollectionResult GetFontPaths(std::string const& facename, int bold, bool italic, std::set<wxUniChar> const& characters) = 0;
};
/// @class FontCollector
@ -59,7 +59,7 @@ public:
class FontCollector {
/// All data needed to find the font file used to render text
struct StyleInfo {
wxString facename;
std::string facename;
int bold;
bool italic;
bool operator<(StyleInfo const& rgt) const;
@ -67,9 +67,9 @@ class FontCollector {
/// Data about where each style is used
struct UsageData {
std::set<wxUniChar> chars; ///< Characters used in this style which glyphs will be needed for
std::set<int> lines; ///< Lines on which this style is used via overrides
std::set<wxString> styles; ///< ASS styles which use this style
std::set<wxUniChar> chars; ///< Characters used in this style which glyphs will be needed for
std::set<int> lines; ///< Lines on which this style is used via overrides
std::set<std::string> styles; ///< ASS styles which use this style
};
/// Message callback provider by caller
@ -80,7 +80,7 @@ class FontCollector {
/// The set of all glyphs used in the file
std::map<StyleInfo, UsageData> used_styles;
/// Style name -> ASS style definition
std::map<wxString, StyleInfo> styles;
std::map<std::string, StyleInfo> styles;
/// Paths to found required font files
std::set<wxString> results;
/// Number of fonts which could not be found

View File

@ -88,10 +88,10 @@ FontConfigFontFileLister::FontConfigFontFileLister(FontCollectorStatusCallback c
FcConfigBuildFonts(config);
}
FontFileLister::CollectionResult FontConfigFontFileLister::GetFontPaths(wxString const& facename, int bold, bool italic, std::set<wxUniChar> const& characters) {
FontFileLister::CollectionResult FontConfigFontFileLister::GetFontPaths(std::string const& facename, int bold, bool italic, std::set<wxUniChar> const& characters) {
CollectionResult ret;
std::string family = from_wx(facename);
std::string family(facename);
if (family[0] == '@')
family.erase(0, 1);
boost::to_lower(family);

View File

@ -44,7 +44,7 @@ public:
/// @param cb Callback for status logging
FontConfigFontFileLister(FontCollectorStatusCallback cb);
CollectionResult GetFontPaths(wxString const& facename, int bold, bool italic, std::set<wxUniChar> const& characters);
CollectionResult GetFontPaths(std::string const& facename, int bold, bool italic, std::set<wxUniChar> const& characters);
};
#endif

View File

@ -265,7 +265,7 @@ void SubsEditBox::OnCommit(int type) {
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_STYLES) {
wxString style = style_box->GetValue();
style_box->Clear();
style_box->Append(c->ass->GetStyles());
style_box->Append(to_wx(c->ass->GetStyles()));
style_box->Select(style_box->FindString(style));
}

View File

@ -400,7 +400,7 @@ namespace
imline.time_out -= 1;
// convert alignment from style
AssStyle *style = copy.GetStyle(line->Style);
AssStyle *style = copy.GetStyle(from_wx(line->Style));
if (!style)
style = &default_style;

View File

@ -42,6 +42,7 @@
#include "ass_file.h"
#include "ass_style.h"
#include "ass_time.h"
#include "compat.h"
#include "text_file_writer.h"
#include <libaegisub/of_type_adaptor.h>
@ -98,7 +99,7 @@ wxString TranStationSubtitleFormat::ConvertLine(AssFile *file, AssDialogue *curr
int valign = 0;
const char *halign = " "; // default is centered
const char *type = "N"; // no special style
if (AssStyle *style = file->GetStyle(current->Style)) {
if (AssStyle *style = file->GetStyle(from_wx(current->Style))) {
if (style->alignment >= 4) valign = 4;
if (style->alignment >= 7) valign = 9;
if (style->alignment == 1 || style->alignment == 4 || style->alignment == 7) halign = "L";

View File

@ -388,7 +388,7 @@ Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) {
memcpy(margin, diag->Margin, sizeof margin);
int align = 2;
if (AssStyle *style = c->ass->GetStyle(diag->Style)) {
if (AssStyle *style = c->ass->GetStyle(from_wx(diag->Style))) {
align = style->alignment;
for (int i = 0; i < 3; i++) {
if (margin[i] == 0)
@ -453,7 +453,7 @@ bool VisualToolBase::GetLineMove(AssDialogue *diag, Vector2D &p1, Vector2D &p2,
void VisualToolBase::GetLineRotation(AssDialogue *diag, float &rx, float &ry, float &rz) {
rx = ry = rz = 0.f;
if (AssStyle *style = c->ass->GetStyle(diag->Style))
if (AssStyle *style = c->ass->GetStyle(from_wx(diag->Style)))
rz = style->angle;
boost::ptr_vector<AssDialogueBlock> blocks(diag->ParseTags());
@ -471,7 +471,7 @@ void VisualToolBase::GetLineRotation(AssDialogue *diag, float &rx, float &ry, fl
void VisualToolBase::GetLineScale(AssDialogue *diag, Vector2D &scale) {
float x = 100.f, y = 100.f;
if (AssStyle *style = c->ass->GetStyle(diag->Style)) {
if (AssStyle *style = c->ass->GetStyle(from_wx(diag->Style))) {
x = style->scalex;
y = style->scaley;
}