Skip to content
Extraits de code Groupes Projets
Valider 5e16567e rédigé par Rodrigo Braz Monteiro's avatar Rodrigo Braz Monteiro
Parcourir les fichiers

Some more work on the subs library.

Originally committed to SVN as r1968.
parent 6246c399
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -183,6 +183,14 @@
RelativePath=".\include\aegilib\format.h"
>
</File>
<File
RelativePath=".\include\aegilib\format_handler.h"
>
</File>
<File
RelativePath=".\include\aegilib\format_manager.h"
>
</File>
<File
RelativePath=".\include\aegilib\manipulator.h"
>
......@@ -235,6 +243,10 @@
RelativePath=".\src\exception.cpp"
>
</File>
<File
RelativePath=".\src\format_manager.cpp"
>
</File>
<File
RelativePath=".\src\prec.cpp"
>
......@@ -261,6 +273,18 @@
>
</File>
</Filter>
<Filter
Name="Formats"
>
<File
RelativePath=".\src\formats\format_ass.cpp"
>
</File>
<File
RelativePath=".\src\formats\format_ass.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
......
......@@ -40,5 +40,7 @@
#include "notification.h"
#include "aegistring.h"
#include "format.h"
#include "format_handler.h"
#include "format_manager.h"
#include "manipulator.h"
#include "exception.h"
......@@ -35,9 +35,12 @@
#pragma once
#include <wx/string.h>
namespace Aegilib {
// Define the string type used throughout this library
typedef std::basic_string<wchar_t> String;
//typedef std::basic_string<wchar_t> String;
typedef wxString String;
};
......@@ -39,15 +39,16 @@
namespace Aegilib {
// Prototypes
class FormatHandler;
class Model;
// Format interface
class Format {
public:
virtual ~Format();
virtual ~Format() {}
virtual String GetName() const = 0;
virtual String GetExtensionWildcard() const = 0;
virtual const FormatHandler& GetHandler() const = 0;
virtual String GetExtension() const = 0;
virtual FormatHandler* GetHandler(const Model &model) const = 0;
virtual bool CanStoreText() const { return false; }
virtual bool CanStoreImages() const { return false; }
......
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/AEGILIB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#pragma once
#include "aegistring.h"
namespace Aegilib {
// Format handler interface
class FormatHandler {
public:
virtual ~FormatHandler() {}
virtual void Load(wxInputStream &file,const String encoding) = 0;
};
};
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/AEGILIB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#pragma once
#include "format.h"
namespace Aegilib {
// Format manager class
class FormatManager {
private:
static std::vector<const Format*> formats;
FormatManager() {}
public:
static void AddFormat(const Format *format);
static void InitializeFormats();
static void ClearFormats();
static int GetFormatCount();
static const Format* GetFormatByIndex(const int index);
static const Format* GetFormatFromFilename(const String &filename);
static const Format* GetFormatFromName(const String &name);
};
};
......@@ -35,6 +35,7 @@
#pragma once
#include <list>
#include <wx/stream.h>
#include "manipulator.h"
#include "file.h"
......@@ -65,13 +66,13 @@ namespace Aegilib {
const Format& GetFormat() const;
void AddListener(View *listener);
void LoadFile(FileReader &file,Format *format=NULL);
void SaveFile(FileWriter &file,Format *format=NULL);
void LoadFile(wxInputStream &input,const Format *format=NULL,const String encoding=L"");
void SaveFile(wxOutputStream &output,const Format *format=NULL,const String encoding=L"UTF-8");
bool CanUndo(String owner=L"") const;
bool CanRedo(String owner=L"") const;
bool Undo(String owner=L"");
bool Redo(String owner=L"");
bool CanUndo(const String owner=L"") const;
bool CanRedo(const String owner=L"") const;
bool Undo(const String owner=L"");
bool Redo(const String owner=L"");
};
};
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/AEGILIB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#include "format_manager.h"
#include "formats/format_ass.h"
#include <wx/string.h>
using namespace Aegilib;
////////
// List
std::vector<const Format*> FormatManager::formats;
////////////////
// Add a format
void FormatManager::AddFormat(const Format *format)
{
formats.push_back(format);
}
///////////////////////////////////
// Initialzie all built-in formats
void FormatManager::InitializeFormats()
{
formats.push_back(new FormatASS);
}
///////////////////////
// Removes all formats
void FormatManager::ClearFormats()
{
formats.clear();
}
/////////////////////
// Number of formats
int FormatManager::GetFormatCount()
{
return (int) formats.size();
}
////////////
// By index
const Format* FormatManager::GetFormatByIndex(const int index)
{
try {
return formats.at(index);
}
catch (...) {
return NULL;
}
}
///////////////
// By filename
const Format* FormatManager::GetFormatFromFilename(const String &filename)
{
size_t len = formats.size();
for (size_t i=0;i<len;i++) {
if (filename.EndsWith(formats[i]->GetExtension())) return formats[i];
}
return NULL;
}
//////////////////
// By format name
const Format* FormatManager::GetFormatFromName(const String &name)
{
size_t len = formats.size();
for (size_t i=0;i<len;i++) {
if (name == formats[i]->GetName()) return formats[i];
}
return NULL;
}
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/AEGILIB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#include "model.h"
#include "format_ass.h"
using namespace Aegilib;
///////////////
// Constructor
FormatHandlerASS::FormatHandlerASS(const Model &model)
{
(void) model;
}
//////////////
// Destructor
FormatHandlerASS::~FormatHandlerASS()
{
}
///////////////
// Load a file
void FormatHandlerASS::Load(wxInputStream &file,const String encoding)
{
(void) file;
(void) encoding;
}
// Copyright (c) 2008, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB/AEGILIB
//
// Website: http://www.aegisub.net
// Contact: mailto:amz@aegisub.net
//
#pragma once
#include "format.h"
#include "format_handler.h"
namespace Aegilib {
// Prototypes
class Model;
// Advanced Substation Alpha format handler
class FormatHandlerASS : public FormatHandler {
public:
FormatHandlerASS(const Model &model);
~FormatHandlerASS();
void Load(wxInputStream &file,const String encoding);
};
// Advanced Substation Alpha format
class FormatASS : public Format {
public:
String GetName() const { return L"Advanced Substation Alpha"; }
String GetExtension() const { return L".ass"; }
FormatHandler* GetHandler(const Model &model) const { return new FormatHandlerASS(model); }
bool CanStoreText() const { return true; }
bool CanUseTime() const { return true; }
bool HasStyles() const { return true; }
bool HasMargins() const { return true; }
bool HasActors() const { return true; }
};
};
......@@ -86,26 +86,34 @@ Manipulator Model::CreateAntiManipulator(const Manipulator &src)
///////////////
// Load a file
void Model::LoadFile(FileReader &file,Format *format)
void Model::LoadFile(wxInputStream &input,const Format *format,const String encoding)
{
// Detect format
// Autodetect format
if (format == NULL) {
// TODO
}
// No format found
throw Exception(Exception::No_Format_Handler);
}
// Get handler
FormatHandler *handler = format->GetHandler(*this);
if (!handler) throw Exception(Exception::No_Format_Handler);
// Load
(void) file;
handler->Load(input,encoding);
// Clean up
delete handler;
}
//////////////////
// Save to a file
void Model::SaveFile(FileWriter &file,Format *format)
void Model::SaveFile(wxOutputStream &output,const Format *format,const String encoding)
{
(void) file;
(void) output;
(void) format;
(void) encoding;
// TODO
}
......@@ -34,6 +34,7 @@
//
#include <aegilib/aegilib.h>
#include <wx/wfstream.h>
#include <iostream>
#include "text_file_reader.h"
#include "text_file_writer.h"
......@@ -44,12 +45,18 @@ int main () {
cout << "Aegilib test program by amz.\n\n";
try {
// Set up the lib
FormatManager::InitializeFormats();
// Subtitles model
Model subs;
// Load subtitles
cout << "Loading file... ";
subs.LoadFile(TextFileReader(L"subs_in.ass"));
String filename = L"subs_in.ass";
const Format *handler = FormatManager::GetFormatFromFilename(filename);
subs.LoadFile(wxFileInputStream(filename),handler);
cout << "Done.\n";
// Modify subtitles
......@@ -58,6 +65,13 @@ int main () {
// Save subtitles
cout << "Saving file... ";
subs.SaveFile(TextFileWriter(L"subs_out.ass"));
filename = L"subs_out.ass";
handler = FormatManager::GetFormatFromFilename(filename);
subs.SaveFile(wxFileOutputStream(filename),handler);
cout << "Done.\n";
}
catch (Exception &e) {
cout << "\n\nException: " << e.GetMessage().mb_str(wxConvUTF8) << endl << endl;
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter