2006-02-26 23:45:34 +01:00
|
|
|
// Copyright (c) 2006, 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.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-02-26 23:45:34 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file subtitle_format.h
|
|
|
|
/// @see subtitle_format.cpp
|
|
|
|
/// @ingroup subtitle_io
|
|
|
|
///
|
2006-02-26 23:45:34 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#ifndef AGI_PRE
|
2006-02-26 23:45:34 +01:00
|
|
|
#include <list>
|
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#include <wx/arrstr.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#endif
|
|
|
|
|
2010-06-20 21:04:58 +02:00
|
|
|
#include <libaegisub/exception.h>
|
|
|
|
|
2006-02-26 23:45:34 +01:00
|
|
|
class AssEntry;
|
2012-01-08 02:34:30 +01:00
|
|
|
class AssFile;
|
2012-03-29 21:04:36 +02:00
|
|
|
namespace agi { namespace vfr { class Framerate; } }
|
2006-02-26 23:45:34 +01:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// DOCME
|
|
|
|
/// @class SubtitleFormat
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
|
|
|
/// DOCME
|
2006-02-27 22:57:10 +01:00
|
|
|
class SubtitleFormat {
|
2011-09-28 21:44:53 +02:00
|
|
|
wxString name;
|
2006-02-27 22:57:10 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Get this format's wildcards for a load dialog
|
|
|
|
virtual wxArrayString GetReadWildcards() const { return wxArrayString(); }
|
|
|
|
/// Get this format's wildcards for a save dialog
|
|
|
|
virtual wxArrayString GetWriteWildcards() const { return wxArrayString(); }
|
2006-02-27 22:57:10 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// List of loaded subtitle formats
|
2006-02-27 22:57:10 +01:00
|
|
|
static std::list<SubtitleFormat*> formats;
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2012-03-29 21:05:26 +02:00
|
|
|
public:
|
2012-01-26 21:08:38 +01:00
|
|
|
typedef std::list<AssEntry*> LineList;
|
|
|
|
|
2011-11-25 20:28:19 +01:00
|
|
|
/// Strip override tags
|
2012-03-29 21:05:26 +02:00
|
|
|
static void StripTags(LineList &lines);
|
2011-11-25 20:28:19 +01:00
|
|
|
/// Convert newlines to the specified character(s)
|
|
|
|
/// @param lineEnd newline character(s)
|
2011-09-28 21:44:53 +02:00
|
|
|
/// @param mergeLineBreaks Should multiple consecutive line breaks be merged into one?
|
2012-03-29 21:05:26 +02:00
|
|
|
static void ConvertNewlines(LineList &lines, wxString const& newline, bool mergeLineBreaks = true);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Remove All commented and empty lines
|
2012-03-29 21:05:26 +02:00
|
|
|
static void StripComments(LineList &lines);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Remove everything but the dialogue lines
|
2012-03-29 21:05:26 +02:00
|
|
|
static void StripNonDialogue(LineList &lines);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// @brief Split and merge lines so there are no overlapping lines
|
|
|
|
///
|
|
|
|
/// Algorithm described at http://devel.aegisub.org/wiki/Technical/SplitMerge
|
2012-03-29 21:05:26 +02:00
|
|
|
static void RecombineOverlaps(LineList &lines);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Merge sequential identical lines
|
2012-03-29 21:05:26 +02:00
|
|
|
static void MergeIdentical(LineList &lines);
|
2012-01-26 21:08:38 +01:00
|
|
|
|
2012-03-29 21:04:36 +02:00
|
|
|
/// Prompt the user for a frame rate to use
|
|
|
|
/// @param allow_vfr Include video frame rate as an option even if it's vfr
|
|
|
|
/// @param show_smpte Show SMPTE drop frame option
|
2012-03-29 21:05:26 +02:00
|
|
|
static agi::vfr::Framerate AskForFPS(bool allow_vfr, bool show_smpte);
|
2006-02-26 23:45:34 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Constructor
|
|
|
|
/// @param Subtitle format name
|
|
|
|
/// @note Automatically registers the format
|
|
|
|
SubtitleFormat(wxString const& name);
|
|
|
|
/// Destructor
|
|
|
|
/// @note Automatically unregisters the format
|
2006-02-27 22:57:10 +01:00
|
|
|
virtual ~SubtitleFormat();
|
2006-12-26 19:26:13 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Get this format's name
|
|
|
|
wxString GetName() const { return name; }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// @brief Check if the given file can be read by this format
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2012-03-29 01:58:40 +02:00
|
|
|
/// Default implementation simply checks if the file's extension is in the
|
2011-09-28 21:44:53 +02:00
|
|
|
/// format's wildcard list
|
|
|
|
virtual bool CanReadFile(wxString const& filename) const;
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// @brief Check if the given file can be written by this format
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2012-03-29 01:58:40 +02:00
|
|
|
/// Default implementation simply checks if the file's extension is in the
|
2011-09-28 21:44:53 +02:00
|
|
|
/// format's wildcard list
|
|
|
|
virtual bool CanWriteFile(wxString const& filename) const;
|
|
|
|
|
2012-03-29 01:58:40 +02:00
|
|
|
/// @brief Check if the given subtitles can be losslessly written by this format
|
|
|
|
///
|
|
|
|
/// Default implementation rejects files with attachments, non-default
|
|
|
|
/// styles, and any overrides
|
|
|
|
virtual bool CanSave(const AssFile *file) const;
|
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Load a subtitle file
|
2012-01-26 21:08:38 +01:00
|
|
|
/// @param[out] target Destination to read lines into
|
2011-09-28 21:44:53 +02:00
|
|
|
/// @param filename File to load
|
|
|
|
/// @param forceEncoding Encoding to use or empty string for default
|
2012-01-26 21:08:38 +01:00
|
|
|
virtual void ReadFile(AssFile *target, wxString const& filename, wxString const& forceEncoding="") const { }
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
/// Save a subtitle file
|
2012-01-26 21:08:38 +01:00
|
|
|
/// @param src Data to write
|
2011-09-28 21:44:53 +02:00
|
|
|
/// @param filename File to write to
|
|
|
|
/// @param forceEncoding Encoding to use or empty string for default
|
2012-01-26 21:08:38 +01:00
|
|
|
virtual void WriteFile(const AssFile *src, wxString const& filename, wxString const& encoding="") const { }
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
/// Get the wildcards for a save or load dialog
|
|
|
|
/// @param mode 0: load 1: save
|
|
|
|
static wxString GetWildcards(int mode);
|
2006-02-27 22:57:10 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Get a subtitle format that can read the given file or NULL if none can
|
2012-01-26 21:08:38 +01:00
|
|
|
static const SubtitleFormat *GetReader(wxString const& filename);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Get a subtitle format that can write the given file or NULL if none can
|
2012-01-26 21:08:38 +01:00
|
|
|
static const SubtitleFormat *GetWriter(wxString const& filename);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Initialize subtitle formats
|
2006-02-27 22:57:10 +01:00
|
|
|
static void LoadFormats();
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Deinitialize subtitle formats
|
2006-02-27 22:57:10 +01:00
|
|
|
static void DestroyFormats();
|
2006-02-26 23:45:34 +01:00
|
|
|
};
|
2009-07-29 07:43:02 +02:00
|
|
|
|
2010-06-20 21:04:58 +02:00
|
|
|
DEFINE_SIMPLE_EXCEPTION(SubtitleFormatParseError, agi::InvalidInputException, "subtitle_io/parse/generic")
|