mirror of https://github.com/odrling/Aegisub
Attachments seem to work for mod3 files
Originally committed to SVN as r441.
This commit is contained in:
parent
f2645de0c7
commit
fe43cb641d
|
@ -69,7 +69,7 @@ AssEntry *AssAttachment::Clone() {
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
// Get data
|
// Get data
|
||||||
const void *AssAttachment::GetData() {
|
const DataVec &AssAttachment::GetData() {
|
||||||
return data->GetData();
|
return data->GetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,55 @@ void AssAttachment::Finish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////
|
||||||
|
// Get encoded data to write on file
|
||||||
|
const wxString AssAttachment::GetEntryData() {
|
||||||
|
// Get data
|
||||||
|
const DataVec &dat = data->GetData();
|
||||||
|
int pos = 0;
|
||||||
|
int size = dat.size();
|
||||||
|
int written = 0;
|
||||||
|
unsigned char src[3];
|
||||||
|
unsigned char dst[4];
|
||||||
|
|
||||||
|
// Write header
|
||||||
|
wxString entryData;
|
||||||
|
if (group == _T("[Fonts]")) entryData = _T("fontname: ");
|
||||||
|
else entryData = _T("filename: ");
|
||||||
|
entryData += filename + _T("\r\n");
|
||||||
|
|
||||||
|
// Read three bytes
|
||||||
|
while (pos+3 <= size) {
|
||||||
|
// Read source
|
||||||
|
src[0] = dat[pos];
|
||||||
|
src[1] = dat[pos+1];
|
||||||
|
src[2] = dat[pos+2];
|
||||||
|
pos += 3;
|
||||||
|
|
||||||
|
// Codify
|
||||||
|
dst[0] = src[0] >> 2;
|
||||||
|
dst[1] = ((src[0] & 0x3) << 4) | ((src[1] & 0xF0) >> 4);
|
||||||
|
dst[2] = ((src[1] & 0xF) << 2) | ((src[2] & 0xC0) >> 6);
|
||||||
|
dst[3] = src[2] & 0x3F;
|
||||||
|
|
||||||
|
// Convert to text
|
||||||
|
for (int i=0;i<4;i++) {
|
||||||
|
entryData += wxChar(dst[i]+33);
|
||||||
|
written++;
|
||||||
|
|
||||||
|
// Line break
|
||||||
|
if (written == 80) {
|
||||||
|
written = 0;
|
||||||
|
entryData += _T("\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return entryData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////// Attachment //////////////////
|
/////////////////// Attachment //////////////////
|
||||||
///////////////
|
///////////////
|
||||||
|
@ -104,8 +153,8 @@ AttachData::~AttachData() {
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
// Get data
|
// Get data
|
||||||
const void *AttachData::GetData() {
|
const DataVec &AttachData::GetData() {
|
||||||
return (void*) &data[0];
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,18 +44,23 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
///////////
|
||||||
|
// Typedef
|
||||||
|
typedef std::vector<unsigned char> DataVec;
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// Attachment data
|
// Attachment data
|
||||||
class AttachData {
|
class AttachData {
|
||||||
private:
|
private:
|
||||||
std::vector<unsigned char> data;
|
DataVec data;
|
||||||
wxString buffer;
|
wxString buffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AttachData();
|
AttachData();
|
||||||
~AttachData();
|
~AttachData();
|
||||||
|
|
||||||
const void *GetData();
|
const DataVec &GetData();
|
||||||
void AddData(wxString data);
|
void AddData(wxString data);
|
||||||
void Finish();
|
void Finish();
|
||||||
};
|
};
|
||||||
|
@ -69,11 +74,12 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxString filename;
|
wxString filename;
|
||||||
const void *GetData();
|
const DataVec &GetData();
|
||||||
|
|
||||||
void AddData(wxString data);
|
void AddData(wxString data);
|
||||||
void Finish();
|
void Finish();
|
||||||
|
|
||||||
|
const wxString GetEntryData();
|
||||||
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }
|
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }
|
||||||
AssEntry *Clone();
|
AssEntry *Clone();
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ wxString AssEntry::GetSSAText() {
|
||||||
if (group.Lower() == _T("[events]")) return wxString(_T("Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"));
|
if (group.Lower() == _T("[events]")) return wxString(_T("Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"));
|
||||||
if (group.Lower() == _T("[v4+ styles]")) return wxString(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding"));
|
if (group.Lower() == _T("[v4+ styles]")) return wxString(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding"));
|
||||||
}
|
}
|
||||||
return data;
|
return GetEntryData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -273,13 +273,14 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) {
|
||||||
// Attachment
|
// Attachment
|
||||||
else if (group == _T("[Fonts]") || group == _T("[Graphics]")) {
|
else if (group == _T("[Fonts]") || group == _T("[Graphics]")) {
|
||||||
// Check if it's valid data
|
// Check if it's valid data
|
||||||
bool validData = data.Length() > 0;
|
size_t dataLen = data.Length();
|
||||||
for (size_t i=0;i<data.Length();i++) {
|
bool validData = (dataLen > 0) && (dataLen <= 80);
|
||||||
|
for (size_t i=0;i<dataLen;i++) {
|
||||||
if (data[i] < 33 || data[i] >= 97) validData = false;
|
if (data[i] < 33 || data[i] >= 97) validData = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the filename line?
|
// Is the filename line?
|
||||||
bool isFilename = data.Left(10) == _T("filename: ");
|
bool isFilename = (data.Left(10) == _T("fontname: ") && group == _T("[Fonts]")) || (data.Left(10) == _T("filename: ") && group == _T("[Graphics]"));
|
||||||
|
|
||||||
// The attachment file is static, since it is built through several calls to this
|
// The attachment file is static, since it is built through several calls to this
|
||||||
// After it's done building, it's reset to NULL
|
// After it's done building, it's reset to NULL
|
||||||
|
@ -292,15 +293,16 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) {
|
||||||
attach = NULL;
|
attach = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid data
|
|
||||||
if (validData) {
|
|
||||||
// Create attachment if needed
|
// Create attachment if needed
|
||||||
if (!attach) {
|
if (isFilename) {
|
||||||
attach = new AssAttachment(data.Mid(10));
|
attach = new AssAttachment(data.Mid(10));
|
||||||
attach->StartMS = lasttime;
|
attach->StartMS = lasttime;
|
||||||
attach->group = group;
|
attach->group = group;
|
||||||
|
return lasttime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Valid data?
|
||||||
|
if (validData) {
|
||||||
// Insert data
|
// Insert data
|
||||||
attach->AddData(data);
|
attach->AddData(data);
|
||||||
|
|
||||||
|
@ -310,6 +312,9 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) {
|
||||||
entry = attach;
|
entry = attach;
|
||||||
attach = NULL;
|
attach = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not done
|
||||||
|
else return lasttime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue