diff --git a/core/ass_attachment.cpp b/core/ass_attachment.cpp index de4b805ca..a262d88ce 100644 --- a/core/ass_attachment.cpp +++ b/core/ass_attachment.cpp @@ -41,7 +41,8 @@ /////////////// // Constructor -AssAttachment::AssAttachment() { +AssAttachment::AssAttachment(wxString name) { + filename = name; data = boost::shared_ptr (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 /////////////////// // Attachment data class AttachData { private: - char *data; + std::vector data; + wxString buffer; public: AttachData(); @@ -75,6 +77,6 @@ public: ASS_EntryType GetType() { return ENTRY_ATTACHMENT; } AssEntry *Clone(); - AssAttachment(); + AssAttachment(wxString name); ~AssAttachment(); }; diff --git a/core/ass_file.cpp b/core/ass_file.cpp index 81ab6d969..08c3294ec 100644 --- a/core/ass_file.cpp +++ b/core/ass_file.cpp @@ -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= 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); diff --git a/core/subtitle_format_ass.cpp b/core/subtitle_format_ass.cpp index fb1695aab..62a917bca 100644 --- a/core/subtitle_format_ass.cpp +++ b/core/subtitle_format_ass.cpp @@ -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); }