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
|
|
|
#pragma once
|
|
|
|
|
2010-06-20 21:04:58 +02:00
|
|
|
#include <libaegisub/exception.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs_fwd.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2010-06-20 21:04:58 +02:00
|
|
|
|
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
|
|
|
|
2006-02-27 22:57:10 +01:00
|
|
|
class SubtitleFormat {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string 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
|
2013-12-12 00:11:06 +01:00
|
|
|
virtual std::vector<std::string> GetReadWildcards() const { return {}; }
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Get this format's wildcards for a save dialog
|
2013-12-12 00:11:06 +01:00
|
|
|
virtual std::vector<std::string> GetWriteWildcards() const { return {}; }
|
2006-02-27 22:57:10 +01:00
|
|
|
|
2012-03-29 21:05:26 +02:00
|
|
|
public:
|
2011-11-25 20:28:19 +01:00
|
|
|
/// Strip override tags
|
2012-10-12 19:16:39 +02:00
|
|
|
static void StripTags(AssFile &file);
|
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?
|
2013-01-04 16:01:50 +01:00
|
|
|
static void ConvertNewlines(AssFile &file, std::string const& newline, bool mergeLineBreaks = true);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Remove All commented and empty lines
|
2012-10-12 19:16:39 +02:00
|
|
|
static void StripComments(AssFile &file);
|
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-10-12 19:16:39 +02:00
|
|
|
static void RecombineOverlaps(AssFile &file);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Merge sequential identical lines
|
2012-10-12 19:16:39 +02:00
|
|
|
static void MergeIdentical(AssFile &file);
|
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
|
2014-03-26 16:14:08 +01:00
|
|
|
static agi::vfr::Framerate AskForFPS(bool allow_vfr, bool show_smpte, agi::vfr::Framerate const& fps);
|
2006-02-26 23:45:34 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Constructor
|
|
|
|
/// @param Subtitle format name
|
2013-11-21 18:13:36 +01:00
|
|
|
SubtitleFormat(std::string name);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Destructor
|
2014-04-25 19:01:07 +02:00
|
|
|
virtual ~SubtitleFormat() = default;
|
2006-12-26 19:26:13 +01:00
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Get this format's name
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string const& 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
|
2013-10-05 15:58:15 +02:00
|
|
|
virtual bool CanReadFile(agi::fs::path const& filename, std::string const& encoding) 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
|
2013-01-04 16:01:50 +01:00
|
|
|
virtual bool CanWriteFile(agi::fs::path const& filename) const;
|
2011-09-28 21:44:53 +02:00
|
|
|
|
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
|
2013-06-09 16:53:07 +02:00
|
|
|
/// @param encoding Encoding to use. May be ignored by the reader.
|
2014-03-26 16:14:08 +01:00
|
|
|
virtual void ReadFile(AssFile *target, agi::fs::path const& filename, agi::vfr::Framerate const& fps, std::string const& encoding) 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
|
2014-03-26 16:14:08 +01:00
|
|
|
virtual void WriteFile(const AssFile *src, agi::fs::path const& filename, agi::vfr::Framerate const& fps, std::string const& encoding="") const { }
|
2011-09-28 21:44:53 +02:00
|
|
|
|
2014-09-19 20:47:34 +02:00
|
|
|
/// Export a subtitle file
|
|
|
|
///
|
|
|
|
/// This is used when saving via Export As..., for subtitle formats which
|
|
|
|
/// want to distinguish between exporting a final version of a script and
|
|
|
|
/// saving a project.
|
|
|
|
virtual void ExportFile(const AssFile *src, agi::fs::path const& filename, agi::vfr::Framerate const& fps, std::string const& encoding="") const {
|
|
|
|
WriteFile(src, filename, fps, encoding);
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Get the wildcards for a save or load dialog
|
|
|
|
/// @param mode 0: load 1: save
|
2013-01-04 16:01:50 +01:00
|
|
|
static std::string GetWildcards(int mode);
|
2006-02-27 22:57:10 +01:00
|
|
|
|
2012-11-13 17:51:01 +01:00
|
|
|
/// Get a subtitle format that can read the given file or nullptr if none can
|
2013-10-05 15:58:15 +02:00
|
|
|
static const SubtitleFormat *GetReader(agi::fs::path const& filename, std::string const& encoding);
|
2012-11-13 17:51:01 +01:00
|
|
|
/// Get a subtitle format that can write the given file or nullptr if none can
|
2013-01-04 16:01:50 +01:00
|
|
|
static const SubtitleFormat *GetWriter(agi::fs::path const& filename);
|
2011-09-28 21:44:53 +02:00
|
|
|
/// Initialize subtitle formats
|
2006-02-27 22:57:10 +01:00
|
|
|
static void LoadFormats();
|
2006-02-26 23:45:34 +01:00
|
|
|
};
|
2009-07-29 07:43:02 +02:00
|
|
|
|
2014-05-29 14:57:27 +02:00
|
|
|
DEFINE_EXCEPTION(SubtitleFormatParseError, agi::InvalidInputException);
|
|
|
|
DEFINE_EXCEPTION(UnknownSubtitleFormatError, agi::InvalidInputException);
|