forked from mia/Aegisub
Override CanSave in the SRT format to allow supported override tags
Originally committed to SVN as r6627.
This commit is contained in:
parent
d49e59653f
commit
a76fb7c432
2 changed files with 44 additions and 1 deletions
|
@ -36,17 +36,20 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "subtitle_format_srt.h"
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
#include <wx/regex.h>
|
#include <wx/regex.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "ass_attachment.h"
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_override.h"
|
#include "ass_override.h"
|
||||||
#include "ass_style.h"
|
#include "ass_style.h"
|
||||||
#include "colorspace.h"
|
#include "colorspace.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "subtitle_format_srt.h"
|
#include "utils.h"
|
||||||
#include "text_file_reader.h"
|
#include "text_file_reader.h"
|
||||||
#include "text_file_writer.h"
|
#include "text_file_writer.h"
|
||||||
|
|
||||||
|
@ -516,6 +519,42 @@ void SRTSubtitleFormat::WriteFile(const AssFile *src, wxString const& filename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SRTSubtitleFormat::CanSave(const AssFile *file) const {
|
||||||
|
wxString supported_tags[] = { "\\b", "\\i", "\\s", "\\u" };
|
||||||
|
|
||||||
|
AssStyle defstyle;
|
||||||
|
for (std::list<AssEntry*>::const_iterator cur = file->Line.begin(); cur != file->Line.end(); ++cur) {
|
||||||
|
// Check style, if anything non-default is found, return false
|
||||||
|
if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(*cur)) {
|
||||||
|
if (curstyle->GetEntryData() != defstyle.GetEntryData())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for attachments, if any is found, return false
|
||||||
|
if (dynamic_cast<const AssAttachment*>(*cur)) return false;
|
||||||
|
|
||||||
|
// Check dialogue
|
||||||
|
if (const AssDialogue *curdiag = dynamic_cast<const AssDialogue*>(*cur)) {
|
||||||
|
std::vector<AssDialogueBlock*> blocks = curdiag->ParseTags();
|
||||||
|
for (size_t i = 0; i < blocks.size(); ++i) {
|
||||||
|
AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(blocks[i]);
|
||||||
|
if (!ovr) continue;
|
||||||
|
|
||||||
|
// Verify that all overrides used are supported
|
||||||
|
for (size_t j = 0; j < ovr->Tags.size(); ++j) {
|
||||||
|
if (!std::binary_search(supported_tags, supported_tags + 4, ovr->Tags[j]->Name)) {
|
||||||
|
delete_clear(blocks);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete_clear(blocks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
wxString SRTSubtitleFormat::ConvertTags(AssDialogue *diag) const {
|
wxString SRTSubtitleFormat::ConvertTags(AssDialogue *diag) const {
|
||||||
wxString final;
|
wxString final;
|
||||||
std::map<char, bool> tag_states;
|
std::map<char, bool> tag_states;
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
|
|
||||||
#include "subtitle_format.h"
|
#include "subtitle_format.h"
|
||||||
|
|
||||||
|
class AssDialogue;
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
/// @class SRTSubtitleFormat
|
/// @class SRTSubtitleFormat
|
||||||
/// @brief DOCME
|
/// @brief DOCME
|
||||||
|
@ -48,6 +50,8 @@ public:
|
||||||
wxArrayString GetReadWildcards() const;
|
wxArrayString GetReadWildcards() const;
|
||||||
wxArrayString GetWriteWildcards() const;
|
wxArrayString GetWriteWildcards() const;
|
||||||
|
|
||||||
|
bool CanSave(const AssFile *file) const;
|
||||||
|
|
||||||
void ReadFile(AssFile *target, wxString const& filename, wxString const& forceEncoding) const;
|
void ReadFile(AssFile *target, wxString const& filename, wxString const& forceEncoding) const;
|
||||||
void WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding) const;
|
void WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue