forked from mia/Aegisub
Early file attachment code (note that they are NOT saved back to the file, so they are essentially lost)
Originally committed to SVN as r440.
This commit is contained in:
parent
60b87000e5
commit
f2645de0c7
4 changed files with 64 additions and 12 deletions
|
@ -41,7 +41,8 @@
|
|||
|
||||
///////////////
|
||||
// Constructor
|
||||
AssAttachment::AssAttachment() {
|
||||
AssAttachment::AssAttachment(wxString name) {
|
||||
filename = name;
|
||||
data = boost::shared_ptr<AttachData> (new AttachData);
|
||||
}
|
||||
|
||||
|
@ -56,10 +57,9 @@ AssAttachment::~AssAttachment() {
|
|||
// Clone
|
||||
AssEntry *AssAttachment::Clone() {
|
||||
// New object
|
||||
AssAttachment *clone = new AssAttachment;
|
||||
AssAttachment *clone = new AssAttachment(filename);
|
||||
|
||||
// Copy fields
|
||||
clone->filename = filename;
|
||||
clone->data = data;
|
||||
|
||||
// Return
|
||||
|
@ -93,31 +93,73 @@ void AssAttachment::Finish() {
|
|||
///////////////
|
||||
// Constructor
|
||||
AttachData::AttachData() {
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
|
||||
//////////////
|
||||
// Destructor
|
||||
AttachData::~AttachData() {
|
||||
delete data;
|
||||
}
|
||||
|
||||
|
||||
////////////
|
||||
// Get data
|
||||
const void *AttachData::GetData() {
|
||||
return (void*) data;
|
||||
return (void*) &data[0];
|
||||
}
|
||||
|
||||
|
||||
////////////
|
||||
// Add data
|
||||
void AttachData::AddData(wxString data) {
|
||||
buffer += data;
|
||||
}
|
||||
|
||||
|
||||
//////////
|
||||
// Finish
|
||||
void AttachData::Finish() {
|
||||
// Source and dest buffers
|
||||
unsigned char src[4];
|
||||
unsigned char dst[3];
|
||||
int bufPos = 0;
|
||||
bool ok = true;
|
||||
|
||||
// Read buffer
|
||||
while (ok) {
|
||||
// Find characters left
|
||||
int left = buffer.Length() - bufPos;
|
||||
int nbytes;
|
||||
|
||||
// At least four, proceed normally
|
||||
if (left >= 4) {
|
||||
// Move 4 bytes from buffer to src
|
||||
for (int i=0;i<4;i++) {
|
||||
src[i] = (unsigned char) buffer[bufPos] - 33;
|
||||
bufPos++;
|
||||
}
|
||||
ok = true;
|
||||
nbytes = 3;
|
||||
}
|
||||
|
||||
// Zero, end
|
||||
else if (left == 0) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Convert the 4 bytes from source to 3 in dst
|
||||
dst[0] = (src[0] << 2) | (src[1] >> 4);
|
||||
dst[1] = ((src[1] & 0xF) << 4) | (src[2] >> 2);
|
||||
dst[2] = ((src[2] & 0x3) << 6) | (src[3]);
|
||||
|
||||
// Push into vector
|
||||
size_t size = data.size();
|
||||
data.resize(size+nbytes);
|
||||
for (int i=0;i<nbytes;i++) data[size+i] = dst[i];
|
||||
}
|
||||
|
||||
// Clear buffer
|
||||
buffer.Clear();
|
||||
buffer.Shrink();
|
||||
}
|
||||
|
|
|
@ -41,13 +41,15 @@
|
|||
// Headers
|
||||
#include "ass_entry.h"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include <vector>
|
||||
|
||||
|
||||
///////////////////
|
||||
// Attachment data
|
||||
class AttachData {
|
||||
private:
|
||||
char *data;
|
||||
std::vector<unsigned char> data;
|
||||
wxString buffer;
|
||||
|
||||
public:
|
||||
AttachData();
|
||||
|
@ -75,6 +77,6 @@ public:
|
|||
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }
|
||||
AssEntry *Clone();
|
||||
|
||||
AssAttachment();
|
||||
AssAttachment(wxString name);
|
||||
~AssAttachment();
|
||||
};
|
||||
|
|
|
@ -271,9 +271,9 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) {
|
|||
}
|
||||
|
||||
// Attachment
|
||||
else if (group == _T("[Fonts]")) {
|
||||
else if (group == _T("[Fonts]") || group == _T("[Graphics]")) {
|
||||
// Check if it's valid data
|
||||
bool validData = true;
|
||||
bool validData = data.Length() > 0;
|
||||
for (size_t i=0;i<data.Length();i++) {
|
||||
if (data[i] < 33 || data[i] >= 97) validData = false;
|
||||
}
|
||||
|
@ -295,7 +295,11 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) {
|
|||
// Valid data
|
||||
if (validData) {
|
||||
// Create attachment if needed
|
||||
if (!attach) attach = new AssAttachment;
|
||||
if (!attach) {
|
||||
attach = new AssAttachment(data.Mid(10));
|
||||
attach->StartMS = lasttime;
|
||||
attach->group = group;
|
||||
}
|
||||
|
||||
// Insert data
|
||||
attach->AddData(data);
|
||||
|
|
|
@ -61,9 +61,10 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
|
|||
// Parse file
|
||||
wxString curgroup;
|
||||
int lasttime = -1;
|
||||
wxString wxbuffer;
|
||||
while (file.HasMoreLines()) {
|
||||
// Reads line
|
||||
wxString wxbuffer = file.ReadLineFromFile();
|
||||
wxbuffer = file.ReadLineFromFile();
|
||||
|
||||
// Convert v4 styles to v4+ styles
|
||||
if (wxbuffer.Lower() == _T("[v4 styles]")) {
|
||||
|
@ -88,6 +89,9 @@ void ASSSubtitleFormat::ReadFile(wxString filename,wxString encoding) {
|
|||
throw wxString(_T("Error processing line: ")) + wxbuffer;
|
||||
}
|
||||
}
|
||||
|
||||
// Add one last empty line in case it didn't end with one
|
||||
if (!wxbuffer.IsEmpty()) AddLine(_T(""),curgroup,lasttime,IsSSA);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue