Some more completelly untested attachment-related code

Originally committed to SVN as r439.
This commit is contained in:
Rodrigo Braz Monteiro 2006-06-30 21:59:20 +00:00
parent 9c12480c7f
commit 60b87000e5
4 changed files with 138 additions and 5 deletions

View File

@ -42,6 +42,7 @@
///////////////
// Constructor
AssAttachment::AssAttachment() {
data = boost::shared_ptr<AttachData> (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() {
}

View File

@ -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<void> data;
boost::shared_ptr<AttachData> data;
public:
wxString filename;
const void *GetData();
void AddData(wxString data);
void Finish();
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }
AssEntry *Clone();

View File

@ -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<AssAttachment*> (base);
}
return NULL;
}
//////////////////////
// Get SSA conversion
wxString AssEntry::GetSSAText() {

View File

@ -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<data.Length();i++) {
if (data[i] < 33 || data[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;
}