mirror of https://github.com/odrling/Aegisub
Partially de-wxify AssStyle
This commit is contained in:
parent
d49758edbf
commit
3ec82952f8
|
@ -36,6 +36,7 @@
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -350,16 +351,16 @@ void AssFile::GetResolution(int &sw,int &sh) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxArrayString AssFile::GetStyles() const {
|
std::vector<std::string> AssFile::GetStyles() const {
|
||||||
wxArrayString styles;
|
std::vector<std::string> styles;
|
||||||
for (auto style : Line | agi::of_type<AssStyle>())
|
for (auto style : Line | agi::of_type<AssStyle>())
|
||||||
styles.push_back(style->name);
|
styles.push_back(style->name);
|
||||||
return styles;
|
return styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssStyle *AssFile::GetStyle(wxString const& name) {
|
AssStyle *AssFile::GetStyle(std::string const& name) {
|
||||||
for (auto style : Line | agi::of_type<AssStyle>()) {
|
for (auto style : Line | agi::of_type<AssStyle>()) {
|
||||||
if (style->name == name)
|
if (boost::iequals(style->name, name))
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -37,8 +37,6 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <wx/arrstr.h>
|
|
||||||
|
|
||||||
#include <libaegisub/signal.h>
|
#include <libaegisub/signal.h>
|
||||||
|
|
||||||
#include "ass_entry.h"
|
#include "ass_entry.h"
|
||||||
|
@ -98,11 +96,11 @@ public:
|
||||||
/// Attach a file to the ass file
|
/// Attach a file to the ass file
|
||||||
void InsertAttachment(wxString filename);
|
void InsertAttachment(wxString filename);
|
||||||
/// Get the names of all of the styles available
|
/// Get the names of all of the styles available
|
||||||
wxArrayString GetStyles() const;
|
std::vector<std::string> GetStyles() const;
|
||||||
/// @brief Get a style by name
|
/// @brief Get a style by name
|
||||||
/// @param name Style name
|
/// @param name Style name
|
||||||
/// @return Pointer to style or nullptr
|
/// @return Pointer to style or nullptr
|
||||||
AssStyle *GetStyle(wxString const& name);
|
AssStyle *GetStyle(std::string const& name);
|
||||||
|
|
||||||
void swap(AssFile &) throw();
|
void swap(AssFile &) throw();
|
||||||
|
|
||||||
|
|
|
@ -34,16 +34,19 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <cctype>
|
|
||||||
|
|
||||||
#include <wx/intl.h>
|
|
||||||
#include <wx/tokenzr.h>
|
|
||||||
|
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "subtitle_format.h"
|
#include "subtitle_format.h"
|
||||||
#include "utils.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()
|
AssStyle::AssStyle()
|
||||||
: name("Default")
|
: name("Default")
|
||||||
, font("Arial")
|
, font("Arial")
|
||||||
|
@ -69,61 +72,105 @@ AssStyle::AssStyle()
|
||||||
UpdateData();
|
UpdateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
static wxString get_next_string(wxStringTokenizer &tok) {
|
namespace {
|
||||||
if (!tok.HasMoreTokens()) throw SubtitleFormatParseError("Malformed style: not enough fields", 0);
|
class parser {
|
||||||
return tok.GetNextToken();
|
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) {
|
AssStyle::AssStyle(wxString const& rawData, int version) {
|
||||||
long temp;
|
parser p(from_wx(rawData));
|
||||||
if (!get_next_string(tok).ToLong(&temp))
|
|
||||||
throw SubtitleFormatParseError("Malformed style: could not parse int field", 0);
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double get_next_double(wxStringTokenizer &tok) {
|
name = p.next_str();
|
||||||
double temp;
|
font = p.next_str();
|
||||||
if (!get_next_string(tok).ToDouble(&temp))
|
fontsize = p.next_double();
|
||||||
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);
|
|
||||||
|
|
||||||
if (version != 0) {
|
if (version != 0) {
|
||||||
primary = from_wx(get_next_string(tkn));
|
primary = p.next_color();
|
||||||
secondary = from_wx(get_next_string(tkn));
|
secondary = p.next_color();
|
||||||
outline = from_wx(get_next_string(tkn));
|
outline = p.next_color();
|
||||||
shadow = from_wx(get_next_string(tkn));
|
shadow = p.next_color();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
primary = from_wx(get_next_string(tkn));
|
primary = p.next_color();
|
||||||
secondary = from_wx(get_next_string(tkn));
|
secondary = p.next_color();
|
||||||
|
|
||||||
// Read and discard tertiary color
|
// Skip tertiary color
|
||||||
get_next_string(tkn);
|
p.skip_token();
|
||||||
|
|
||||||
// Read shadow/outline color
|
// Read shadow/outline color
|
||||||
outline = from_wx(get_next_string(tkn));
|
outline = p.next_color();
|
||||||
shadow = outline;
|
shadow = outline;
|
||||||
}
|
}
|
||||||
|
|
||||||
bold = !!get_next_int(tkn);
|
bold = !!p.next_int();
|
||||||
italic = !!get_next_int(tkn);
|
italic = !!p.next_int();
|
||||||
|
|
||||||
if (version != 0) {
|
if (version != 0) {
|
||||||
underline = !!get_next_int(tkn);
|
underline = !!p.next_int();
|
||||||
strikeout = !!get_next_int(tkn);
|
strikeout = !!p.next_int();
|
||||||
|
|
||||||
scalex = get_next_double(tkn);
|
scalex = p.next_double();
|
||||||
scaley = get_next_double(tkn);
|
scaley = p.next_double();
|
||||||
spacing = get_next_double(tkn);
|
spacing = p.next_double();
|
||||||
angle = get_next_double(tkn);
|
angle = p.next_double();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// SSA defaults
|
// SSA defaults
|
||||||
|
@ -136,42 +183,33 @@ AssStyle::AssStyle(wxString rawData, int version) {
|
||||||
angle = 0.0;
|
angle = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
borderstyle = get_next_int(tkn);
|
borderstyle = p.next_int();
|
||||||
outline_w = get_next_double(tkn);
|
outline_w = p.next_double();
|
||||||
shadow_w = get_next_double(tkn);
|
shadow_w = p.next_double();
|
||||||
alignment = get_next_int(tkn);
|
alignment = p.next_int();
|
||||||
|
|
||||||
if (version == 0)
|
if (version == 0)
|
||||||
alignment = SsaToAss(alignment);
|
alignment = SsaToAss(alignment);
|
||||||
|
|
||||||
// Read left margin
|
Margin[0] = mid(0, p.next_int(), 9999);
|
||||||
Margin[0] = mid(0, get_next_int(tkn), 9999);
|
Margin[1] = mid(0, p.next_int(), 9999);
|
||||||
|
Margin[2] = mid(0, p.next_int(), 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);
|
|
||||||
|
|
||||||
// Skip alpha level
|
// Skip alpha level
|
||||||
if (version == 0)
|
if (version == 0)
|
||||||
get_next_string(tkn);
|
p.skip_token();
|
||||||
|
|
||||||
// Read encoding
|
encoding = p.next_int();
|
||||||
encoding = get_next_int(tkn);
|
|
||||||
|
|
||||||
if (tkn.HasMoreTokens())
|
|
||||||
throw SubtitleFormatParseError("Malformed style: too many fields", 0);
|
|
||||||
|
|
||||||
UpdateData();
|
UpdateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssStyle::UpdateData() {
|
void AssStyle::UpdateData() {
|
||||||
name.Replace(",", ";");
|
replace(name.begin(), name.end(), ',', ';');
|
||||||
font.Replace(",", ";");
|
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",
|
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(),
|
primary.GetAssStyleFormatted(),
|
||||||
secondary.GetAssStyleFormatted(),
|
secondary.GetAssStyleFormatted(),
|
||||||
outline.GetAssStyleFormatted(),
|
outline.GetAssStyleFormatted(),
|
||||||
|
@ -185,7 +223,7 @@ void AssStyle::UpdateData() {
|
||||||
|
|
||||||
wxString AssStyle::GetSSAText() const {
|
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",
|
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(),
|
primary.GetSsaFormatted(),
|
||||||
secondary.GetSsaFormatted(),
|
secondary.GetSsaFormatted(),
|
||||||
shadow.GetSsaFormatted(),
|
shadow.GetSsaFormatted(),
|
||||||
|
|
|
@ -32,20 +32,19 @@
|
||||||
/// @ingroup subs_storage
|
/// @ingroup subs_storage
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
#include <wx/colour.h>
|
|
||||||
|
|
||||||
#include "ass_entry.h"
|
#include "ass_entry.h"
|
||||||
|
|
||||||
#include <libaegisub/color.h>
|
#include <libaegisub/color.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <wx/arrstr.h>
|
||||||
|
|
||||||
class AssStyle : public AssEntry {
|
class AssStyle : public AssEntry {
|
||||||
wxString data;
|
wxString data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxString name; ///< Name of the style; must be case-insensitively unique within a file despite being case-sensitive
|
std::string name; ///< Name of the style; must be case-insensitively unique within a file despite being case-sensitive
|
||||||
wxString font; ///< Font face name
|
std::string font; ///< Font face name
|
||||||
double fontsize; ///< Font size
|
double fontsize; ///< Font size
|
||||||
|
|
||||||
agi::Color primary; ///< Default text color
|
agi::Color primary; ///< Default text color
|
||||||
|
@ -76,7 +75,7 @@ public:
|
||||||
static void GetEncodings(wxArrayString &encodingStrings);
|
static void GetEncodings(wxArrayString &encodingStrings);
|
||||||
|
|
||||||
AssStyle();
|
AssStyle();
|
||||||
AssStyle(wxString data, int version=1);
|
AssStyle(wxString const& data, int version=1);
|
||||||
|
|
||||||
const wxString GetEntryData() const override { return data; }
|
const wxString GetEntryData() const override { return data; }
|
||||||
wxString GetSSAText() const override;
|
wxString GetSSAText() const override;
|
||||||
|
|
|
@ -36,14 +36,15 @@
|
||||||
|
|
||||||
#include "ass_style_storage.h"
|
#include "ass_style_storage.h"
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
#include "standard_paths.h"
|
#include "standard_paths.h"
|
||||||
#include "text_file_reader.h"
|
#include "text_file_reader.h"
|
||||||
#include "text_file_writer.h"
|
#include "text_file_writer.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
AssStyleStorage::~AssStyleStorage() {
|
AssStyleStorage::~AssStyleStorage() {
|
||||||
delete_clear(style);
|
delete_clear(style);
|
||||||
}
|
}
|
||||||
|
@ -92,16 +93,16 @@ void AssStyleStorage::Delete(int idx) {
|
||||||
style.erase(style.begin() + idx);
|
style.erase(style.begin() + idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxArrayString AssStyleStorage::GetNames() {
|
std::vector<std::string> AssStyleStorage::GetNames() {
|
||||||
wxArrayString names;
|
std::vector<std::string> names;
|
||||||
for (const AssStyle *cur : style)
|
for (const AssStyle *cur : style)
|
||||||
names.Add(cur->name);
|
names.emplace_back(cur->name);
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssStyle *AssStyleStorage::GetStyle(wxString const& name) {
|
AssStyle *AssStyleStorage::GetStyle(std::string const& name) {
|
||||||
for (AssStyle *cur : style) {
|
for (AssStyle *cur : style) {
|
||||||
if (cur->name.CmpNoCase(name) == 0)
|
if (boost::iequals(cur->name, name))
|
||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -33,8 +33,10 @@
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <wx/arrstr.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
class AssStyle;
|
class AssStyle;
|
||||||
|
|
||||||
|
@ -57,7 +59,7 @@ public:
|
||||||
size_t size() const { return style.size(); }
|
size_t size() const { return style.size(); }
|
||||||
|
|
||||||
/// Get the names of all styles in this storage
|
/// Get the names of all styles in this storage
|
||||||
wxArrayString GetNames();
|
std::vector<std::string> GetNames();
|
||||||
|
|
||||||
/// Delete all styles in this storage
|
/// Delete all styles in this storage
|
||||||
void Clear();
|
void Clear();
|
||||||
|
@ -68,7 +70,7 @@ public:
|
||||||
/// Get the style with the given name
|
/// Get the style with the given name
|
||||||
/// @param name Case-insensitive style name
|
/// @param name Case-insensitive style name
|
||||||
/// @return Style or nullptr if the requested style is not found
|
/// @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
|
/// Save stored styles to a file
|
||||||
void Save() const;
|
void Save() const;
|
||||||
|
|
|
@ -289,7 +289,7 @@ void AudioTimingControllerKaraoke::Revert() {
|
||||||
for (auto it = kara->begin(); it != kara->end(); ++it) {
|
for (auto it = kara->begin(); it != kara->end(); ++it) {
|
||||||
if (it != kara->begin())
|
if (it != kara->begin())
|
||||||
markers.emplace_back(it->start_time, &separator_pen, AudioMarker::Feet_None);
|
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();
|
AnnounceUpdatedPrimaryRange();
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <libaegisub/charset_conv_win.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <wx/button.h>
|
#include <wx/button.h>
|
||||||
|
@ -97,7 +99,7 @@ namespace Automation4 {
|
||||||
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
||||||
lf.lfQuality = ANTIALIASED_QUALITY;
|
lf.lfQuality = ANTIALIASED_QUALITY;
|
||||||
lf.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
|
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);
|
HFONT thefont = CreateFontIndirect(&lf);
|
||||||
if (!thefont) return false;
|
if (!thefont) return false;
|
||||||
|
|
|
@ -69,6 +69,10 @@ namespace {
|
||||||
lua_pushstring(L, value.utf8_str());
|
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) {
|
void push_value(lua_State *L, const char *value) {
|
||||||
lua_pushstring(L, value);
|
lua_pushstring(L, value);
|
||||||
}
|
}
|
||||||
|
@ -302,8 +306,8 @@ namespace Automation4 {
|
||||||
else if (lclass == "style") {
|
else if (lclass == "style") {
|
||||||
AssStyle *sty = new AssStyle;
|
AssStyle *sty = new AssStyle;
|
||||||
result = sty;
|
result = sty;
|
||||||
sty->name = get_wxstring_field(L, "name", "style");
|
sty->name = get_string_field(L, "name", "style");
|
||||||
sty->font = get_wxstring_field(L, "fontname", "style");
|
sty->font = get_string_field(L, "fontname", "style");
|
||||||
sty->fontsize = get_double_field(L, "fontsize", "style");
|
sty->fontsize = get_double_field(L, "fontsize", "style");
|
||||||
sty->primary = get_string_field(L, "color1", "style");
|
sty->primary = get_string_field(L, "color1", "style");
|
||||||
sty->secondary = get_string_field(L, "color2", "style");
|
sty->secondary = get_string_field(L, "color2", "style");
|
||||||
|
|
|
@ -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) {
|
void toggle_override_tag(const agi::Context *c, bool (AssStyle::*field), const char *tag, wxString const& undo_msg) {
|
||||||
AssDialogue *const line = c->selectionController->GetActiveLine();
|
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;
|
bool state = style ? style->*field : AssStyle().*field;
|
||||||
|
|
||||||
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
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) {
|
void show_color_picker(const agi::Context *c, agi::Color (AssStyle::*field), const char *tag, const char *alt) {
|
||||||
AssDialogue *const line = c->selectionController->GetActiveLine();
|
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);
|
agi::Color color = (style ? style->*field : AssStyle().*field);
|
||||||
|
|
||||||
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
||||||
|
@ -421,7 +421,7 @@ struct edit_font : public Command {
|
||||||
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
||||||
const int blockn = block_at_pos(line->Text, c->textSelectionController->GetInsertionPoint());
|
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;
|
const AssStyle default_style;
|
||||||
if (!style)
|
if (!style)
|
||||||
style = &default_style;
|
style = &default_style;
|
||||||
|
|
|
@ -639,7 +639,7 @@ DialogKanjiTimer::DialogKanjiTimer(agi::Context *c)
|
||||||
Interpolate = new wxCheckBox(this,-1,_("Attempt to &interpolate kanji."),wxDefaultPosition,wxDefaultSize,wxALIGN_LEFT);
|
Interpolate = new wxCheckBox(this,-1,_("Attempt to &interpolate kanji."),wxDefaultPosition,wxDefaultSize,wxALIGN_LEFT);
|
||||||
Interpolate->SetValue(OPT_GET("Tool/Kanji Timer/Interpolation")->GetBool());
|
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);
|
SourceStyle = new wxComboBox(this, -1, "", wxDefaultPosition, wxSize(160, -1), styles, wxCB_READONLY);
|
||||||
DestStyle = new wxComboBox(this, -1, "", wxDefaultPosition, wxSize(160, -1), styles, wxCB_READONLY);
|
DestStyle = new wxComboBox(this, -1, "", wxDefaultPosition, wxSize(160, -1), styles, wxCB_READONLY);
|
||||||
|
|
||||||
|
|
|
@ -69,15 +69,15 @@ class StyleRenamer {
|
||||||
agi::Context *c;
|
agi::Context *c;
|
||||||
bool found_any;
|
bool found_any;
|
||||||
bool do_replace;
|
bool do_replace;
|
||||||
wxString source_name;
|
std::string source_name;
|
||||||
wxString new_name;
|
std::string new_name;
|
||||||
|
|
||||||
/// Process a single override parameter to check if it's \r with this style 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) {
|
static void ProcessTag(std::string const& tag, AssOverrideParameter* param, void *userData) {
|
||||||
StyleRenamer *self = static_cast<StyleRenamer*>(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)
|
if (self->do_replace)
|
||||||
param->Set(from_wx(self->new_name));
|
param->Set(self->new_name);
|
||||||
else
|
else
|
||||||
self->found_any = true;
|
self->found_any = true;
|
||||||
}
|
}
|
||||||
|
@ -87,10 +87,13 @@ class StyleRenamer {
|
||||||
found_any = false;
|
found_any = false;
|
||||||
do_replace = replace;
|
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>()) {
|
for (auto diag : c->ass->Line | agi::of_type<AssDialogue>()) {
|
||||||
if (diag->Style == source_name) {
|
if (diag->Style == wx_old) {
|
||||||
if (replace)
|
if (replace)
|
||||||
diag->Style = new_name;
|
diag->Style = wx_new;
|
||||||
else
|
else
|
||||||
found_any = true;
|
found_any = true;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +109,7 @@ class StyleRenamer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
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)
|
: c(c)
|
||||||
, found_any(false)
|
, found_any(false)
|
||||||
, do_replace(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));
|
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)
|
: wxDialog (parent, -1, _("Style Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||||
, c(c)
|
, c(c)
|
||||||
, is_new(false)
|
, is_new(false)
|
||||||
|
@ -181,8 +184,8 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
|
||||||
wxSizer *PreviewBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Preview"));
|
wxSizer *PreviewBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Preview"));
|
||||||
|
|
||||||
// Create controls
|
// Create controls
|
||||||
StyleName = new wxTextCtrl(this, -1, style->name);
|
StyleName = new wxTextCtrl(this, -1, to_wx(style->name));
|
||||||
FontName = new wxComboBox(this, -1, style->font, wxDefaultPosition, wxSize(150, -1), 0, 0, wxCB_DROPDOWN);
|
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));
|
FontSize = num_text_ctrl(this, style->fontsize, wxSize(50, -1));
|
||||||
BoxBold = new wxCheckBox(this, -1, _("&Bold"));
|
BoxBold = new wxCheckBox(this, -1, _("&Bold"));
|
||||||
BoxItalic = new wxCheckBox(this, -1, _("&Italic"));
|
BoxItalic = new wxCheckBox(this, -1, _("&Italic"));
|
||||||
|
@ -240,7 +243,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
|
||||||
// Fill font face list box
|
// Fill font face list box
|
||||||
FontName->Freeze();
|
FontName->Freeze();
|
||||||
FontName->Append(fontList);
|
FontName->Append(fontList);
|
||||||
FontName->SetValue(style->font);
|
FontName->SetValue(to_wx(style->font));
|
||||||
FontName->Thaw();
|
FontName->Thaw();
|
||||||
|
|
||||||
// Set encoding value
|
// Set encoding value
|
||||||
|
@ -410,32 +413,29 @@ DialogStyleEditor::~DialogStyleEditor() {
|
||||||
delete style;
|
delete style;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString DialogStyleEditor::GetStyleName() const {
|
std::string DialogStyleEditor::GetStyleName() const {
|
||||||
return style->name;
|
return style->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogStyleEditor::Apply(bool apply, bool close) {
|
void DialogStyleEditor::Apply(bool apply, bool close) {
|
||||||
if (apply) {
|
if (apply) {
|
||||||
wxString newStyleName = StyleName->GetValue();
|
std::string new_name = from_wx(StyleName->GetValue());
|
||||||
|
|
||||||
// Get list of existing styles
|
// 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
|
// Check if style name is unique
|
||||||
for (auto const& style_name : styles) {
|
AssStyle *existing = store ? store->GetStyle(new_name) : c->ass->GetStyle(new_name);
|
||||||
if (newStyleName.CmpNoCase(style_name) == 0) {
|
if (existing && existing != style) {
|
||||||
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);
|
||||||
wxMessageBox("There is already a style with this name. Please choose another name.", "Style name conflict.", wxOK | wxICON_ERROR | wxCENTER);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Style name change
|
// Style name change
|
||||||
bool did_rename = false;
|
bool did_rename = false;
|
||||||
if (work->name != newStyleName) {
|
if (work->name != new_name) {
|
||||||
if (!store && !is_new) {
|
if (!store && !is_new) {
|
||||||
StyleRenamer renamer(c, work->name, newStyleName);
|
StyleRenamer renamer(c, work->name, new_name);
|
||||||
if (renamer.NeedsReplace()) {
|
if (renamer.NeedsReplace()) {
|
||||||
// See if user wants to update style name through script
|
// See if user wants to update style name through script
|
||||||
int answer = wxMessageBox(
|
int answer = wxMessageBox(
|
||||||
|
@ -452,7 +452,7 @@ void DialogStyleEditor::Apply(bool apply, bool close) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
work->name = newStyleName;
|
work->name = new_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateWorkStyle();
|
UpdateWorkStyle();
|
||||||
|
@ -482,7 +482,7 @@ void DialogStyleEditor::Apply(bool apply, bool close) {
|
||||||
|
|
||||||
/// @brief Update work style
|
/// @brief Update work style
|
||||||
void DialogStyleEditor::UpdateWorkStyle() {
|
void DialogStyleEditor::UpdateWorkStyle() {
|
||||||
work->font = FontName->GetValue();
|
work->font = from_wx(FontName->GetValue());
|
||||||
FontSize->GetValue().ToDouble(&(work->fontsize));
|
FontSize->GetValue().ToDouble(&(work->fontsize));
|
||||||
|
|
||||||
ScaleX->GetValue().ToDouble(&(work->scalex));
|
ScaleX->GetValue().ToDouble(&(work->scalex));
|
||||||
|
|
|
@ -106,8 +106,8 @@ class DialogStyleEditor : public wxDialog {
|
||||||
void OnSetColor(int n, wxCommandEvent& evt);
|
void OnSetColor(int n, wxCommandEvent& evt);
|
||||||
|
|
||||||
public:
|
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();
|
~DialogStyleEditor();
|
||||||
|
|
||||||
wxString GetStyleName() const;
|
std::string GetStyleName() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -110,11 +110,11 @@ wxSizer *make_edit_buttons(wxWindow *parent, wxString move_label, wxButton **mov
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Func>
|
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)) {
|
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)
|
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 name;
|
||||||
}
|
}
|
||||||
return source_name;
|
return source_name;
|
||||||
|
@ -275,7 +275,7 @@ void DialogStyleManager::LoadCurrentStyles(int commit_type) {
|
||||||
styleMap.clear();
|
styleMap.clear();
|
||||||
|
|
||||||
for (auto style : c->ass->Line | agi::of_type<AssStyle>()) {
|
for (auto style : c->ass->Line | agi::of_type<AssStyle>()) {
|
||||||
CurrentList->Append(style->name);
|
CurrentList->Append(to_wx(style->name));
|
||||||
styleMap.push_back(style);
|
styleMap.push_back(style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,8 +304,7 @@ void DialogStyleManager::UpdateStorage() {
|
||||||
Store.Save();
|
Store.Save();
|
||||||
|
|
||||||
StorageList->Clear();
|
StorageList->Clear();
|
||||||
for (auto style : Store)
|
StorageList->Append(to_wx(Store.GetNames()));
|
||||||
StorageList->Append(style->name);
|
|
||||||
|
|
||||||
UpdateButtons();
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
|
@ -406,8 +405,8 @@ void DialogStyleManager::OnCopyToStorage() {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
wxString styleName = CurrentList->GetString(selections[i]);
|
wxString styleName = CurrentList->GetString(selections[i]);
|
||||||
|
|
||||||
if (AssStyle *style = Store.GetStyle(styleName)) {
|
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)) {
|
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]);
|
*style = *styleMap.at(selections[i]);
|
||||||
copied.push_back(styleName);
|
copied.push_back(styleName);
|
||||||
}
|
}
|
||||||
|
@ -432,19 +431,14 @@ void DialogStyleManager::OnCopyToCurrent() {
|
||||||
copied.reserve(n);
|
copied.reserve(n);
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
wxString styleName = StorageList->GetString(selections[i]);
|
wxString styleName = StorageList->GetString(selections[i]);
|
||||||
bool addStyle = true;
|
|
||||||
|
|
||||||
for (auto style = styleMap.begin(); style != styleMap.end(); ++style) {
|
if (AssStyle *style = c->ass->GetStyle(from_wx(styleName))) {
|
||||||
if ((*style)->name.CmpNoCase(styleName) == 0) {
|
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)) {
|
||||||
addStyle = false;
|
*style = *Store[selections[i]];
|
||||||
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)) {
|
copied.push_back(styleName);
|
||||||
**style = *Store[selections[i]];
|
|
||||||
copied.push_back(styleName);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (addStyle) {
|
else {
|
||||||
c->ass->InsertLine(new AssStyle(*Store[selections[i]]));
|
c->ass->InsertLine(new AssStyle(*Store[selections[i]]));
|
||||||
copied.push_back(styleName);
|
copied.push_back(styleName);
|
||||||
}
|
}
|
||||||
|
@ -488,15 +482,15 @@ void DialogStyleManager::PasteToStorage() {
|
||||||
std::bind(&AssStyleStorage::push_back, &Store, _1));
|
std::bind(&AssStyleStorage::push_back, &Store, _1));
|
||||||
|
|
||||||
UpdateStorage();
|
UpdateStorage();
|
||||||
StorageList->SetStringSelection(Store.back()->name);
|
StorageList->SetStringSelection(to_wx(Store.back()->name));
|
||||||
UpdateButtons();
|
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);
|
DialogStyleEditor editor(this, style, c, &Store, new_name);
|
||||||
if (editor.ShowModal()) {
|
if (editor.ShowModal()) {
|
||||||
UpdateStorage();
|
UpdateStorage();
|
||||||
StorageList->SetStringSelection(editor.GetStyleName());
|
StorageList->SetStringSelection(to_wx(editor.GetStyleName()));
|
||||||
UpdateButtons();
|
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);
|
DialogStyleEditor editor(this, style, c, 0, new_name);
|
||||||
if (editor.ShowModal()) {
|
if (editor.ShowModal()) {
|
||||||
CurrentList->DeselectAll();
|
CurrentList->DeselectAll();
|
||||||
CurrentList->SetStringSelection(editor.GetStyleName());
|
CurrentList->SetStringSelection(to_wx(editor.GetStyleName()));
|
||||||
UpdateButtons();
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -590,7 +584,7 @@ void DialogStyleManager::OnCurrentImport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get styles
|
// Get styles
|
||||||
wxArrayString styles = temp.GetStyles();
|
std::vector<std::string> styles = temp.GetStyles();
|
||||||
if (styles.empty()) {
|
if (styles.empty()) {
|
||||||
wxMessageBox(_("The selected file has no available styles."), _("Error Importing Styles"));
|
wxMessageBox(_("The selected file has no available styles."), _("Error Importing Styles"));
|
||||||
return;
|
return;
|
||||||
|
@ -598,35 +592,28 @@ void DialogStyleManager::OnCurrentImport() {
|
||||||
|
|
||||||
// Get selection
|
// Get selection
|
||||||
wxArrayInt selections;
|
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;
|
if (res == -1 || selections.empty()) return;
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
|
|
||||||
// Loop through selection
|
// Loop through selection
|
||||||
for (auto const& sel : selections) {
|
for (auto const& sel : selections) {
|
||||||
// Check if there is already a style with that name
|
// Check if there is already a style with that name
|
||||||
int test = CurrentList->FindString(styles[sel], false);
|
if (AssStyle *existing = c->ass->GetStyle(styles[sel])) {
|
||||||
if (test != wxNOT_FOUND) {
|
|
||||||
int answer = wxMessageBox(
|
int answer = wxMessageBox(
|
||||||
wxString::Format(_("There is already a style with the name \"%s\" in the current script. Overwrite?"), styles[sel]),
|
wxString::Format(_("There is already a style with the name \"%s\" in the current script. Overwrite?"), styles[sel]),
|
||||||
_("Style name collision"),
|
_("Style name collision"),
|
||||||
wxYES_NO);
|
wxYES_NO);
|
||||||
if (answer == wxYES) {
|
if (answer == wxYES) {
|
||||||
// Overwrite
|
|
||||||
modified = true;
|
modified = true;
|
||||||
// The result of GetString is used rather than the name
|
*existing = *temp.GetStyle(styles[sel]);
|
||||||
// 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]);
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy
|
// Copy
|
||||||
modified = true;
|
modified = true;
|
||||||
AssStyle *tempStyle = new AssStyle;
|
c->ass->InsertLine(temp.GetStyle(styles[sel])->Clone());
|
||||||
*tempStyle = *temp.GetStyle(styles[sel]);
|
|
||||||
c->ass->InsertLine(tempStyle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
|
|
|
@ -107,12 +107,12 @@ class DialogStyleManager : public wxDialog {
|
||||||
/// Open the style editor for the given style on the script
|
/// Open the style editor for the given style on the script
|
||||||
/// @param style Style to edit, or nullptr for new
|
/// @param style Style to edit, or nullptr for new
|
||||||
/// @param new_name Default new name for copies
|
/// @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
|
/// Open the style editor for the given style in the storage
|
||||||
/// @param style Style to edit, or nullptr for new
|
/// @param style Style to edit, or nullptr for new
|
||||||
/// @param new_name Default new name for copies
|
/// @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
|
/// Save the storage and update the view after a change
|
||||||
void UpdateStorage();
|
void UpdateStorage();
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
#include "audio_controller.h"
|
#include "audio_controller.h"
|
||||||
#include "command/command.h"
|
#include "command/command.h"
|
||||||
|
#include "compat.h"
|
||||||
#include "help_button.h"
|
#include "help_button.h"
|
||||||
#include "libresrc/libresrc.h"
|
#include "libresrc/libresrc.h"
|
||||||
#include "persist_location.h"
|
#include "persist_location.h"
|
||||||
|
@ -70,7 +71,7 @@ DialogStyling::DialogStyling(agi::Context *context)
|
||||||
|
|
||||||
{
|
{
|
||||||
wxSizer *styles_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Styles available"));
|
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);
|
styles_box->Add(style_list, 1, wxEXPAND, 0);
|
||||||
bottom_sizer->Add(styles_box, 1, wxEXPAND | wxRIGHT, 5);
|
bottom_sizer->Add(styles_box, 1, wxEXPAND | wxRIGHT, 5);
|
||||||
}
|
}
|
||||||
|
@ -169,7 +170,7 @@ void DialogStyling::OnActiveLineChanged(AssDialogue *new_line) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogStyling::Commit(bool next) {
|
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();
|
active_line->Style = style_name->GetValue();
|
||||||
c->ass->Commit(_("styling assistant"), AssFile::COMMIT_DIAG_META);
|
c->ass->Commit(_("styling assistant"), AssFile::COMMIT_DIAG_META);
|
||||||
|
@ -183,7 +184,7 @@ void DialogStyling::OnActivate(wxActivateEvent &) {
|
||||||
play_video->Enable(c->videoController->IsLoaded());
|
play_video->Enable(c->videoController->IsLoaded());
|
||||||
play_audio->Enable(c->audioController->IsAudioOpen());
|
play_audio->Enable(c->audioController->IsAudioOpen());
|
||||||
|
|
||||||
style_list->Set(c->ass->GetStyles());
|
style_list->Set(to_wx(c->ass->GetStyles()));
|
||||||
|
|
||||||
if (auto_seek->IsChecked())
|
if (auto_seek->IsChecked())
|
||||||
c->videoController->JumpToTime(active_line->Start);
|
c->videoController->JumpToTime(active_line->Start);
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_time.h"
|
#include "ass_time.h"
|
||||||
|
#include "compat.h"
|
||||||
#include "help_button.h"
|
#include "help_button.h"
|
||||||
#include "include/aegisub/context.h"
|
#include "include/aegisub/context.h"
|
||||||
#include "libresrc/libresrc.h"
|
#include "libresrc/libresrc.h"
|
||||||
|
@ -117,7 +118,7 @@ DialogTimingProcessor::DialogTimingProcessor(agi::Context *c)
|
||||||
|
|
||||||
// Styles box
|
// Styles box
|
||||||
wxSizer *LeftSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Apply to styles"));
|
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."));
|
StyleList->SetToolTip(_("Select styles to process. Unchecked ones will be ignored."));
|
||||||
|
|
||||||
wxButton *all = new wxButton(this,-1,_("&All"));
|
wxButton *all = new wxButton(this,-1,_("&All"));
|
||||||
|
|
|
@ -37,10 +37,12 @@
|
||||||
#include "export_fixstyle.h"
|
#include "export_fixstyle.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
#include <libaegisub/of_type_adaptor.h>
|
#include <libaegisub/of_type_adaptor.h>
|
||||||
|
|
||||||
|
@ -50,12 +52,12 @@ AssFixStylesFilter::AssFixStylesFilter()
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *) {
|
void AssFixStylesFilter::ProcessSubs(AssFile *subs, wxWindow *) {
|
||||||
wxArrayString styles = subs->GetStyles();
|
std::vector<std::string> styles = subs->GetStyles();
|
||||||
for_each(styles.begin(), styles.end(), std::mem_fun_ref(&wxString::MakeLower));
|
for_each(begin(styles), end(styles), [](std::string& str) { boost::to_lower(str); });
|
||||||
styles.Sort();
|
sort(begin(styles), end(styles));
|
||||||
|
|
||||||
for (auto diag : subs->Line | agi::of_type<AssDialogue>()) {
|
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";
|
diag->Style = "Default";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
|
||||||
if (line->Comment) return;
|
if (line->Comment) return;
|
||||||
|
|
||||||
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
|
||||||
StyleInfo style = styles[line->Style];
|
StyleInfo style = styles[from_wx(line->Style)];
|
||||||
StyleInfo initial = style;
|
StyleInfo initial = style;
|
||||||
|
|
||||||
bool overriden = false;
|
bool overriden = false;
|
||||||
|
@ -60,7 +60,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
|
||||||
std::string const& name = tag.Name;
|
std::string const& name = tag.Name;
|
||||||
|
|
||||||
if (name == "\\r") {
|
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;
|
overriden = false;
|
||||||
}
|
}
|
||||||
else if (name == "\\b") {
|
else if (name == "\\b") {
|
||||||
|
@ -72,7 +72,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
|
||||||
overriden = true;
|
overriden = true;
|
||||||
}
|
}
|
||||||
else if (name == "\\fn") {
|
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;
|
overriden = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ public:
|
||||||
/// @param italic Italic?
|
/// @param italic Italic?
|
||||||
/// @param characters Characters in this style
|
/// @param characters Characters in this style
|
||||||
/// @return Path to the matching font file(s), or empty if not found
|
/// @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
|
/// @class FontCollector
|
||||||
|
@ -59,7 +59,7 @@ public:
|
||||||
class FontCollector {
|
class FontCollector {
|
||||||
/// All data needed to find the font file used to render text
|
/// All data needed to find the font file used to render text
|
||||||
struct StyleInfo {
|
struct StyleInfo {
|
||||||
wxString facename;
|
std::string facename;
|
||||||
int bold;
|
int bold;
|
||||||
bool italic;
|
bool italic;
|
||||||
bool operator<(StyleInfo const& rgt) const;
|
bool operator<(StyleInfo const& rgt) const;
|
||||||
|
@ -67,9 +67,9 @@ class FontCollector {
|
||||||
|
|
||||||
/// Data about where each style is used
|
/// Data about where each style is used
|
||||||
struct UsageData {
|
struct UsageData {
|
||||||
std::set<wxUniChar> chars; ///< Characters used in this style which glyphs will be needed for
|
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<int> lines; ///< Lines on which this style is used via overrides
|
||||||
std::set<wxString> styles; ///< ASS styles which use this style
|
std::set<std::string> styles; ///< ASS styles which use this style
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Message callback provider by caller
|
/// Message callback provider by caller
|
||||||
|
@ -80,7 +80,7 @@ class FontCollector {
|
||||||
/// The set of all glyphs used in the file
|
/// The set of all glyphs used in the file
|
||||||
std::map<StyleInfo, UsageData> used_styles;
|
std::map<StyleInfo, UsageData> used_styles;
|
||||||
/// Style name -> ASS style definition
|
/// Style name -> ASS style definition
|
||||||
std::map<wxString, StyleInfo> styles;
|
std::map<std::string, StyleInfo> styles;
|
||||||
/// Paths to found required font files
|
/// Paths to found required font files
|
||||||
std::set<wxString> results;
|
std::set<wxString> results;
|
||||||
/// Number of fonts which could not be found
|
/// Number of fonts which could not be found
|
||||||
|
|
|
@ -88,10 +88,10 @@ FontConfigFontFileLister::FontConfigFontFileLister(FontCollectorStatusCallback c
|
||||||
FcConfigBuildFonts(config);
|
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;
|
CollectionResult ret;
|
||||||
|
|
||||||
std::string family = from_wx(facename);
|
std::string family(facename);
|
||||||
if (family[0] == '@')
|
if (family[0] == '@')
|
||||||
family.erase(0, 1);
|
family.erase(0, 1);
|
||||||
boost::to_lower(family);
|
boost::to_lower(family);
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
/// @param cb Callback for status logging
|
/// @param cb Callback for status logging
|
||||||
FontConfigFontFileLister(FontCollectorStatusCallback cb);
|
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
|
#endif
|
||||||
|
|
|
@ -265,7 +265,7 @@ void SubsEditBox::OnCommit(int type) {
|
||||||
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_STYLES) {
|
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_STYLES) {
|
||||||
wxString style = style_box->GetValue();
|
wxString style = style_box->GetValue();
|
||||||
style_box->Clear();
|
style_box->Clear();
|
||||||
style_box->Append(c->ass->GetStyles());
|
style_box->Append(to_wx(c->ass->GetStyles()));
|
||||||
style_box->Select(style_box->FindString(style));
|
style_box->Select(style_box->FindString(style));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -400,7 +400,7 @@ namespace
|
||||||
imline.time_out -= 1;
|
imline.time_out -= 1;
|
||||||
|
|
||||||
// convert alignment from style
|
// convert alignment from style
|
||||||
AssStyle *style = copy.GetStyle(line->Style);
|
AssStyle *style = copy.GetStyle(from_wx(line->Style));
|
||||||
if (!style)
|
if (!style)
|
||||||
style = &default_style;
|
style = &default_style;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
#include "ass_time.h"
|
#include "ass_time.h"
|
||||||
|
#include "compat.h"
|
||||||
#include "text_file_writer.h"
|
#include "text_file_writer.h"
|
||||||
|
|
||||||
#include <libaegisub/of_type_adaptor.h>
|
#include <libaegisub/of_type_adaptor.h>
|
||||||
|
@ -98,7 +99,7 @@ wxString TranStationSubtitleFormat::ConvertLine(AssFile *file, AssDialogue *curr
|
||||||
int valign = 0;
|
int valign = 0;
|
||||||
const char *halign = " "; // default is centered
|
const char *halign = " "; // default is centered
|
||||||
const char *type = "N"; // no special style
|
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 >= 4) valign = 4;
|
||||||
if (style->alignment >= 7) valign = 9;
|
if (style->alignment >= 7) valign = 9;
|
||||||
if (style->alignment == 1 || style->alignment == 4 || style->alignment == 7) halign = "L";
|
if (style->alignment == 1 || style->alignment == 4 || style->alignment == 7) halign = "L";
|
||||||
|
|
|
@ -388,7 +388,7 @@ Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) {
|
||||||
memcpy(margin, diag->Margin, sizeof margin);
|
memcpy(margin, diag->Margin, sizeof margin);
|
||||||
int align = 2;
|
int align = 2;
|
||||||
|
|
||||||
if (AssStyle *style = c->ass->GetStyle(diag->Style)) {
|
if (AssStyle *style = c->ass->GetStyle(from_wx(diag->Style))) {
|
||||||
align = style->alignment;
|
align = style->alignment;
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
if (margin[i] == 0)
|
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) {
|
void VisualToolBase::GetLineRotation(AssDialogue *diag, float &rx, float &ry, float &rz) {
|
||||||
rx = ry = rz = 0.f;
|
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;
|
rz = style->angle;
|
||||||
|
|
||||||
boost::ptr_vector<AssDialogueBlock> blocks(diag->ParseTags());
|
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) {
|
void VisualToolBase::GetLineScale(AssDialogue *diag, Vector2D &scale) {
|
||||||
float x = 100.f, y = 100.f;
|
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;
|
x = style->scalex;
|
||||||
y = style->scaley;
|
y = style->scaley;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue