From 3ec82952f87a71f9550157d0fb8123ec2a4c93cf Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 29 Dec 2012 16:32:36 -0800 Subject: [PATCH] Partially de-wxify AssStyle --- aegisub/src/ass_file.cpp | 9 +- aegisub/src/ass_file.h | 6 +- aegisub/src/ass_style.cpp | 170 ++++++++++++-------- aegisub/src/ass_style.h | 13 +- aegisub/src/ass_style_storage.cpp | 15 +- aegisub/src/ass_style_storage.h | 8 +- aegisub/src/audio_timing_karaoke.cpp | 2 +- aegisub/src/auto4_base.cpp | 4 +- aegisub/src/auto4_lua_assfile.cpp | 8 +- aegisub/src/command/edit.cpp | 6 +- aegisub/src/dialog_kara_timing_copy.cpp | 2 +- aegisub/src/dialog_style_editor.cpp | 50 +++--- aegisub/src/dialog_style_editor.h | 4 +- aegisub/src/dialog_style_manager.cpp | 57 +++---- aegisub/src/dialog_style_manager.h | 4 +- aegisub/src/dialog_styling_assistant.cpp | 7 +- aegisub/src/dialog_timing_processor.cpp | 3 +- aegisub/src/export_fixstyle.cpp | 10 +- aegisub/src/font_file_lister.cpp | 6 +- aegisub/src/font_file_lister.h | 12 +- aegisub/src/font_file_lister_fontconfig.cpp | 4 +- aegisub/src/font_file_lister_fontconfig.h | 2 +- aegisub/src/subs_edit_box.cpp | 2 +- aegisub/src/subtitle_format_ebu3264.cpp | 2 +- aegisub/src/subtitle_format_transtation.cpp | 3 +- aegisub/src/visual_tool.cpp | 6 +- 26 files changed, 226 insertions(+), 189 deletions(-) diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index ad47ea8dd..eba59cc7e 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -36,6 +36,7 @@ #include "ass_file.h" #include +#include #include #include #include @@ -350,16 +351,16 @@ void AssFile::GetResolution(int &sw,int &sh) const { } } -wxArrayString AssFile::GetStyles() const { - wxArrayString styles; +std::vector AssFile::GetStyles() const { + std::vector styles; for (auto style : Line | agi::of_type()) 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()) { - if (style->name == name) + if (boost::iequals(style->name, name)) return style; } return nullptr; diff --git a/aegisub/src/ass_file.h b/aegisub/src/ass_file.h index 165126148..c56528122 100644 --- a/aegisub/src/ass_file.h +++ b/aegisub/src/ass_file.h @@ -37,8 +37,6 @@ #include #include -#include - #include #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 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(); diff --git a/aegisub/src/ass_style.cpp b/aegisub/src/ass_style.cpp index 939ea60c0..e9b99e2db 100644 --- a/aegisub/src/ass_style.cpp +++ b/aegisub/src/ass_style.cpp @@ -34,16 +34,19 @@ #include "config.h" -#include - -#include -#include - #include "ass_style.h" #include "compat.h" #include "subtitle_format.h" #include "utils.h" +#include +#include +#include +#include +#include + +#include + 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 string_range; + string_range str; + std::vector 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(next_tok()); + } + catch (boost::bad_lexical_cast const&) { + throw SubtitleFormatParseError("Malformed style: bad int field", 0); + } + } + + double next_double() { + try { + return boost::lexical_cast(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(), diff --git a/aegisub/src/ass_style.h b/aegisub/src/ass_style.h index bb5c14a5c..2c3e9a8db 100644 --- a/aegisub/src/ass_style.h +++ b/aegisub/src/ass_style.h @@ -32,20 +32,19 @@ /// @ingroup subs_storage /// -#include - -#include - #include "ass_entry.h" #include +#include +#include + 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; diff --git a/aegisub/src/ass_style_storage.cpp b/aegisub/src/ass_style_storage.cpp index 94929938c..ac0da6853 100644 --- a/aegisub/src/ass_style_storage.cpp +++ b/aegisub/src/ass_style_storage.cpp @@ -36,14 +36,15 @@ #include "ass_style_storage.h" -#include - #include "ass_style.h" #include "standard_paths.h" #include "text_file_reader.h" #include "text_file_writer.h" #include "utils.h" +#include +#include + 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 AssStyleStorage::GetNames() { + std::vector 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; diff --git a/aegisub/src/ass_style_storage.h b/aegisub/src/ass_style_storage.h index b2d45b6d2..1015e2665 100644 --- a/aegisub/src/ass_style_storage.h +++ b/aegisub/src/ass_style_storage.h @@ -33,8 +33,10 @@ /// #include +#include +#include -#include +#include 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 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; diff --git a/aegisub/src/audio_timing_karaoke.cpp b/aegisub/src/audio_timing_karaoke.cpp index 7280ad2fa..5b3b725ea 100644 --- a/aegisub/src/audio_timing_karaoke.cpp +++ b/aegisub/src/audio_timing_karaoke.cpp @@ -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(); diff --git a/aegisub/src/auto4_base.cpp b/aegisub/src/auto4_base.cpp index 7118d673f..01d5fa341 100644 --- a/aegisub/src/auto4_base.cpp +++ b/aegisub/src/auto4_base.cpp @@ -40,6 +40,8 @@ #include #define WIN32_LEAN_AND_MEAN #include + +#include #endif #include @@ -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; diff --git a/aegisub/src/auto4_lua_assfile.cpp b/aegisub/src/auto4_lua_assfile.cpp index 5060ba569..d73823bdc 100644 --- a/aegisub/src/auto4_lua_assfile.cpp +++ b/aegisub/src/auto4_lua_assfile.cpp @@ -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"); diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index 5ef391ef4..c0396590a 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -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 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 blocks(line->ParseTags()); @@ -421,7 +421,7 @@ struct edit_font : public Command { boost::ptr_vector 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; diff --git a/aegisub/src/dialog_kara_timing_copy.cpp b/aegisub/src/dialog_kara_timing_copy.cpp index fe0b21e28..5a8d24583 100644 --- a/aegisub/src/dialog_kara_timing_copy.cpp +++ b/aegisub/src/dialog_kara_timing_copy.cpp @@ -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); diff --git a/aegisub/src/dialog_style_editor.cpp b/aegisub/src/dialog_style_editor.cpp index 88331ade1..71f50036e 100644 --- a/aegisub/src/dialog_style_editor.cpp +++ b/aegisub/src/dialog_style_editor.cpp @@ -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(userData); - if (tag == "\\r" && param->GetType() == VARDATA_TEXT && to_wx(param->Get()) == self->source_name) { + if (tag == "\\r" && param->GetType() == VARDATA_TEXT && param->Get() == 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()) { - 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 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)); diff --git a/aegisub/src/dialog_style_editor.h b/aegisub/src/dialog_style_editor.h index c2e39c515..991183b0e 100644 --- a/aegisub/src/dialog_style_editor.h +++ b/aegisub/src/dialog_style_editor.h @@ -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; }; diff --git a/aegisub/src/dialog_style_manager.cpp b/aegisub/src/dialog_style_manager.cpp index 895de47ef..84bc3e64f 100644 --- a/aegisub/src/dialog_style_manager.cpp +++ b/aegisub/src/dialog_style_manager.cpp @@ -110,11 +110,11 @@ wxSizer *make_edit_buttons(wxWindow *parent, wxString move_label, wxButton **mov } template -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()) { - 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 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 diff --git a/aegisub/src/dialog_style_manager.h b/aegisub/src/dialog_style_manager.h index 01ff184ed..b38f63e01 100644 --- a/aegisub/src/dialog_style_manager.h +++ b/aegisub/src/dialog_style_manager.h @@ -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(); diff --git a/aegisub/src/dialog_styling_assistant.cpp b/aegisub/src/dialog_styling_assistant.cpp index 7442840a8..1eb03cc97 100644 --- a/aegisub/src/dialog_styling_assistant.cpp +++ b/aegisub/src/dialog_styling_assistant.cpp @@ -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); diff --git a/aegisub/src/dialog_timing_processor.cpp b/aegisub/src/dialog_timing_processor.cpp index ca6f6df06..4f0fbcef0 100644 --- a/aegisub/src/dialog_timing_processor.cpp +++ b/aegisub/src/dialog_timing_processor.cpp @@ -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")); diff --git a/aegisub/src/export_fixstyle.cpp b/aegisub/src/export_fixstyle.cpp index bb129947d..ccdcc7c74 100644 --- a/aegisub/src/export_fixstyle.cpp +++ b/aegisub/src/export_fixstyle.cpp @@ -37,10 +37,12 @@ #include "export_fixstyle.h" #include +#include #include #include "ass_file.h" #include "ass_dialogue.h" +#include "compat.h" #include @@ -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 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()) { - 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"; } } diff --git a/aegisub/src/font_file_lister.cpp b/aegisub/src/font_file_lister.cpp index 1d4357edf..d206867b8 100644 --- a/aegisub/src/font_file_lister.cpp +++ b/aegisub/src/font_file_lister.cpp @@ -49,7 +49,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { if (line->Comment) return; boost::ptr_vector 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; } } diff --git a/aegisub/src/font_file_lister.h b/aegisub/src/font_file_lister.h index ef1c41449..8156a9699 100644 --- a/aegisub/src/font_file_lister.h +++ b/aegisub/src/font_file_lister.h @@ -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 const& characters) = 0; + virtual CollectionResult GetFontPaths(std::string const& facename, int bold, bool italic, std::set 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 chars; ///< Characters used in this style which glyphs will be needed for - std::set lines; ///< Lines on which this style is used via overrides - std::set styles; ///< ASS styles which use this style + std::set chars; ///< Characters used in this style which glyphs will be needed for + std::set lines; ///< Lines on which this style is used via overrides + std::set 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 used_styles; /// Style name -> ASS style definition - std::map styles; + std::map styles; /// Paths to found required font files std::set results; /// Number of fonts which could not be found diff --git a/aegisub/src/font_file_lister_fontconfig.cpp b/aegisub/src/font_file_lister_fontconfig.cpp index da0f7e385..4755c5480 100644 --- a/aegisub/src/font_file_lister_fontconfig.cpp +++ b/aegisub/src/font_file_lister_fontconfig.cpp @@ -88,10 +88,10 @@ FontConfigFontFileLister::FontConfigFontFileLister(FontCollectorStatusCallback c FcConfigBuildFonts(config); } -FontFileLister::CollectionResult FontConfigFontFileLister::GetFontPaths(wxString const& facename, int bold, bool italic, std::set const& characters) { +FontFileLister::CollectionResult FontConfigFontFileLister::GetFontPaths(std::string const& facename, int bold, bool italic, std::set 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); diff --git a/aegisub/src/font_file_lister_fontconfig.h b/aegisub/src/font_file_lister_fontconfig.h index 6ac59aa90..360990ceb 100644 --- a/aegisub/src/font_file_lister_fontconfig.h +++ b/aegisub/src/font_file_lister_fontconfig.h @@ -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 const& characters); + CollectionResult GetFontPaths(std::string const& facename, int bold, bool italic, std::set const& characters); }; #endif diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index bb84736f9..fd156ffb2 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -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)); } diff --git a/aegisub/src/subtitle_format_ebu3264.cpp b/aegisub/src/subtitle_format_ebu3264.cpp index 2cca600be..f54de07c1 100644 --- a/aegisub/src/subtitle_format_ebu3264.cpp +++ b/aegisub/src/subtitle_format_ebu3264.cpp @@ -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; diff --git a/aegisub/src/subtitle_format_transtation.cpp b/aegisub/src/subtitle_format_transtation.cpp index 9bec2e137..732fee172 100644 --- a/aegisub/src/subtitle_format_transtation.cpp +++ b/aegisub/src/subtitle_format_transtation.cpp @@ -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 @@ -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"; diff --git a/aegisub/src/visual_tool.cpp b/aegisub/src/visual_tool.cpp index 96214d6cd..45483e833 100644 --- a/aegisub/src/visual_tool.cpp +++ b/aegisub/src/visual_tool.cpp @@ -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 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; }