diff --git a/core/ass_attachment.cpp b/core/ass_attachment.cpp index 03694335f..de4b805ca 100644 --- a/core/ass_attachment.cpp +++ b/core/ass_attachment.cpp @@ -42,6 +42,7 @@ /////////////// // Constructor AssAttachment::AssAttachment() { + data = boost::shared_ptr (new AttachData); } @@ -54,7 +55,14 @@ AssAttachment::~AssAttachment() { ///////// // Clone AssEntry *AssAttachment::Clone() { + // New object AssAttachment *clone = new AssAttachment; + + // Copy fields + clone->filename = filename; + clone->data = data; + + // Return return clone; } @@ -62,5 +70,54 @@ AssEntry *AssAttachment::Clone() { //////////// // Get data const void *AssAttachment::GetData() { - return data.get(); + return data->GetData(); +} + + +///////////////// +// Add more data +void AssAttachment::AddData(wxString _data) { + data->AddData(_data); +} + + +////////////////////// +// Finish adding data +void AssAttachment::Finish() { + data->Finish(); +} + + + +/////////////////// Attachment ////////////////// +/////////////// +// Constructor +AttachData::AttachData() { + data = NULL; +} + + +////////////// +// Destructor +AttachData::~AttachData() { + delete data; +} + + +//////////// +// Get data +const void *AttachData::GetData() { + return (void*) data; +} + + +//////////// +// Add data +void AttachData::AddData(wxString data) { +} + + +////////// +// Finish +void AttachData::Finish() { } diff --git a/core/ass_attachment.h b/core/ass_attachment.h index 6cf7cce9f..4440f5495 100644 --- a/core/ass_attachment.h +++ b/core/ass_attachment.h @@ -43,17 +43,35 @@ #include "boost/shared_ptr.hpp" +/////////////////// +// Attachment data +class AttachData { +private: + char *data; + +public: + AttachData(); + ~AttachData(); + + const void *GetData(); + void AddData(wxString data); + void Finish(); +}; + + ////////////////////////////// // Class to store attachments class AssAttachment : public AssEntry { private: - int refCount; - boost::shared_ptr data; + boost::shared_ptr data; public: wxString filename; const void *GetData(); + void AddData(wxString data); + void Finish(); + ASS_EntryType GetType() { return ENTRY_ATTACHMENT; } AssEntry *Clone(); diff --git a/core/ass_entry.cpp b/core/ass_entry.cpp index d71392378..b9a2fb0f5 100644 --- a/core/ass_entry.cpp +++ b/core/ass_entry.cpp @@ -38,6 +38,7 @@ // Headers #include "ass_dialogue.h" #include "ass_style.h" +#include "ass_attachment.h" #include "ass_entry.h" @@ -89,6 +90,17 @@ AssStyle *AssEntry::GetAsStyle(AssEntry *base) { } +/////////////////////////////////////////////////////////////////// +// Returns an entry as attachment if possible, else, returns NULL +AssAttachment *AssEntry::GetAsAttachment(AssEntry *base) { + if (!base) return NULL; + if (base->GetType() == ENTRY_ATTACHMENT) { + return static_cast (base); + } + return NULL; +} + + ////////////////////// // Get SSA conversion wxString AssEntry::GetSSAText() { diff --git a/core/ass_file.cpp b/core/ass_file.cpp index 02757cd37..81ab6d969 100644 --- a/core/ass_file.cpp +++ b/core/ass_file.cpp @@ -41,6 +41,7 @@ #include "ass_file.h" #include "ass_dialogue.h" #include "ass_style.h" +#include "ass_attachment.h" #include "ass_override.h" #include "ass_exporter.h" #include "vfr.h" @@ -269,13 +270,55 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) { } } - // Comment in script info + // Attachment + else if (group == _T("[Fonts]")) { + // Check if it's valid data + bool validData = true; + for (size_t i=0;i= 97) validData = false; + } + + // Is the filename line? + bool isFilename = data.Left(10) == _T("filename: "); + + // The attachment file is static, since it is built through several calls to this + // After it's done building, it's reset to NULL + static AssAttachment *attach = NULL; + + // Attachment exists, and data is over + if (attach && (!validData || isFilename)) { + attach->Finish(); + Line.push_back(attach); + attach = NULL; + } + + // Valid data + if (validData) { + // Create attachment if needed + if (!attach) attach = new AssAttachment; + + // Insert data + attach->AddData(data); + + // Done building + if (data.Length() < 80) { + attach->Finish(); + entry = attach; + attach = NULL; + } + } + } + + // Script info else if (group == _T("[Script Info]")) { + // Comment if (data.Left(1) == _T(";")) { // Skip stupid comments added by other programs - // Of course, we add our own in place... + // Of course, we'll add our own in place later... ;) return lasttime; } + + // Version if (data.Left(11) == _T("ScriptType:")) { wxString version = data.Mid(11); version.Trim(true); @@ -290,6 +333,8 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) { IsSSA = trueSSA; } } + + // Everything entry = new AssEntry(data); entry->StartMS = lasttime; entry->group = group; @@ -302,6 +347,7 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) { entry->group = group; } + // Insert the line Line.push_back(entry); return lasttime; }