Attachments seem to work for mod3 files

Originally committed to SVN as r441.
This commit is contained in:
Rodrigo Braz Monteiro 2006-06-30 23:37:30 +00:00
parent f2645de0c7
commit fe43cb641d
4 changed files with 78 additions and 18 deletions

View File

@ -69,7 +69,7 @@ AssEntry *AssAttachment::Clone() {
////////////
// Get data
const void *AssAttachment::GetData() {
const DataVec &AssAttachment::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 //////////////////
///////////////
@ -104,8 +153,8 @@ AttachData::~AttachData() {
////////////
// Get data
const void *AttachData::GetData() {
return (void*) &data[0];
const DataVec &AttachData::GetData() {
return data;
}

View File

@ -44,18 +44,23 @@
#include <vector>
///////////
// Typedef
typedef std::vector<unsigned char> DataVec;
///////////////////
// Attachment data
class AttachData {
private:
std::vector<unsigned char> data;
DataVec data;
wxString buffer;
public:
AttachData();
~AttachData();
const void *GetData();
const DataVec &GetData();
void AddData(wxString data);
void Finish();
};
@ -69,11 +74,12 @@ private:
public:
wxString filename;
const void *GetData();
const DataVec &GetData();
void AddData(wxString data);
void Finish();
const wxString GetEntryData();
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }
AssEntry *Clone();

View File

@ -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("[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();
}

View File

@ -273,13 +273,14 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) {
// Attachment
else if (group == _T("[Fonts]") || group == _T("[Graphics]")) {
// Check if it's valid data
bool validData = data.Length() > 0;
for (size_t i=0;i<data.Length();i++) {
size_t dataLen = data.Length();
bool validData = (dataLen > 0) && (dataLen <= 80);
for (size_t i=0;i<dataLen;i++) {
if (data[i] < 33 || data[i] >= 97) validData = false;
}
// 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
// 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;
}
// Valid data
if (validData) {
// Create attachment if needed
if (!attach) {
if (isFilename) {
attach = new AssAttachment(data.Mid(10));
attach->StartMS = lasttime;
attach->group = group;
return lasttime;
}
// Valid data?
if (validData) {
// Insert data
attach->AddData(data);
@ -310,6 +312,9 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) {
entry = attach;
attach = NULL;
}
// Not done
else return lasttime;
}
}