2006-01-16 22:02:54 +01:00
|
|
|
// Copyright (c) 2005, 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-01-16 22:02:54 +01:00
|
|
|
#include "ass_entry.h"
|
2012-12-11 00:32:36 +01:00
|
|
|
#include "ass_override.h"
|
2014-07-06 16:28:58 +02:00
|
|
|
|
|
|
|
#include <libaegisub/ass/time.h>
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2014-03-04 17:32:29 +01:00
|
|
|
#include <array>
|
2012-12-04 23:35:59 +01:00
|
|
|
#include <boost/flyweight.hpp>
|
2012-12-02 19:24:49 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2013-06-13 00:54:19 +02:00
|
|
|
enum class AssBlockType {
|
|
|
|
PLAIN,
|
|
|
|
COMMENT,
|
|
|
|
OVERRIDE,
|
|
|
|
DRAWING
|
2006-01-16 22:02:54 +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
|
|
|
/// @class AssDialogueBlock
|
|
|
|
/// @brief AssDialogue Blocks
|
|
|
|
///
|
|
|
|
/// A block is each group in the text field of an AssDialogue
|
2009-07-30 05:36:53 +02:00
|
|
|
/// @verbatim
|
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
|
|
|
/// Yes, I {\i1}am{\i0} here.
|
|
|
|
///
|
|
|
|
/// Gets split in five blocks:
|
|
|
|
/// "Yes, I " (Plain)
|
2009-07-30 05:36:53 +02:00
|
|
|
/// "\\i1" (Override)
|
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
|
|
|
/// "am" (Plain)
|
2009-07-30 05:36:53 +02:00
|
|
|
/// "\\i0" (Override)
|
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
|
|
|
/// " here." (Plain)
|
|
|
|
///
|
|
|
|
/// Also note how {}s are discarded.
|
2011-12-26 23:21:08 +01:00
|
|
|
/// Override blocks are further divided in AssOverrideTags.
|
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
|
|
|
///
|
|
|
|
/// The GetText() method generates a new value for the "text" field from
|
|
|
|
/// the other fields in the specific class, and returns the new value.
|
2009-07-30 05:36:53 +02:00
|
|
|
/// @endverbatim
|
2006-01-16 22:02:54 +01:00
|
|
|
class AssDialogueBlock {
|
2011-12-26 23:21:08 +01:00
|
|
|
protected:
|
|
|
|
/// Text of this block
|
2012-12-30 00:53:56 +01:00
|
|
|
std::string text;
|
2011-12-26 23:21:08 +01:00
|
|
|
public:
|
2013-11-21 18:13:36 +01:00
|
|
|
AssDialogueBlock(std::string text) : text(std::move(text)) { }
|
2014-04-25 19:01:07 +02:00
|
|
|
virtual ~AssDialogueBlock() = default;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-10-12 03:52:36 +02:00
|
|
|
virtual AssBlockType GetType() const = 0;
|
2012-12-30 00:53:56 +01:00
|
|
|
virtual std::string GetText() { return text; }
|
2006-01-16 22:02:54 +01:00
|
|
|
};
|
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class AssDialogueBlockPlain final : public AssDialogueBlock {
|
2006-01-16 22:02:54 +01:00
|
|
|
public:
|
2012-11-03 05:24:11 +01:00
|
|
|
using AssDialogueBlock::text;
|
2013-06-13 00:54:19 +02:00
|
|
|
AssBlockType GetType() const override { return AssBlockType::PLAIN; }
|
2012-12-30 00:53:56 +01:00
|
|
|
AssDialogueBlockPlain(std::string const& text = std::string()) : AssDialogueBlock(text) { }
|
2006-01-16 22:02:54 +01:00
|
|
|
};
|
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class AssDialogueBlockComment final : public AssDialogueBlock {
|
2012-12-30 18:04:43 +01:00
|
|
|
public:
|
2013-06-13 00:54:19 +02:00
|
|
|
AssBlockType GetType() const override { return AssBlockType::COMMENT; }
|
2012-12-30 18:04:43 +01:00
|
|
|
AssDialogueBlockComment(std::string const& text = std::string()) : AssDialogueBlock("{" + text + "}") { }
|
|
|
|
};
|
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class AssDialogueBlockDrawing final : public AssDialogueBlock {
|
2006-01-16 22:02:54 +01:00
|
|
|
public:
|
2013-07-05 01:28:43 +02:00
|
|
|
using AssDialogueBlock::text;
|
2006-01-16 22:02:54 +01:00
|
|
|
int Scale;
|
|
|
|
|
2013-06-13 00:54:19 +02:00
|
|
|
AssBlockType GetType() const override { return AssBlockType::DRAWING; }
|
2012-12-30 00:53:56 +01:00
|
|
|
AssDialogueBlockDrawing(std::string const& text, int scale) : AssDialogueBlock(text), Scale(scale) { }
|
2006-01-16 22:02:54 +01:00
|
|
|
};
|
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class AssDialogueBlockOverride final : public AssDialogueBlock {
|
2006-01-16 22:02:54 +01:00
|
|
|
public:
|
2012-12-30 00:53:56 +01:00
|
|
|
AssDialogueBlockOverride(std::string const& text = std::string()) : AssDialogueBlock(text) { }
|
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-12-11 00:32:36 +01:00
|
|
|
std::vector<AssOverrideTag> Tags;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2013-06-13 00:54:19 +02:00
|
|
|
AssBlockType GetType() const override { return AssBlockType::OVERRIDE; }
|
2012-12-30 00:53:56 +01:00
|
|
|
std::string GetText() override;
|
2012-10-10 15:45:36 +02:00
|
|
|
void ParseTags();
|
2012-12-30 00:53:56 +01:00
|
|
|
void AddTag(std::string const& tag);
|
2009-08-01 05:27:13 +02:00
|
|
|
|
|
|
|
/// Type of callback function passed to ProcessParameters
|
2012-12-30 00:53:56 +01:00
|
|
|
typedef void (*ProcessParametersCallback)(std::string const&, AssOverrideParameter *, void *);
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @brief Process parameters via callback
|
2012-12-02 21:36:11 +01:00
|
|
|
/// @param callback The callback function to call per tag parameter
|
2009-08-01 05:27:13 +02:00
|
|
|
/// @param userData User data to pass to callback function
|
2012-12-02 21:36:11 +01:00
|
|
|
void ProcessParameters(ProcessParametersCallback callback, void *userData);
|
2006-01-16 22:02:54 +01:00
|
|
|
};
|
|
|
|
|
2014-03-04 17:32:29 +01:00
|
|
|
struct AssDialogueBase {
|
2012-11-03 05:06:37 +01:00
|
|
|
/// Unique ID of this line. Copies of the line for Undo/Redo purposes
|
|
|
|
/// preserve the unique ID, so that the equivalent lines can be found in
|
|
|
|
/// the different versions of the file.
|
2014-03-04 17:32:29 +01:00
|
|
|
int Id;
|
2012-11-03 05:06:37 +01:00
|
|
|
|
2014-03-31 16:41:57 +02:00
|
|
|
int Row = -1;
|
|
|
|
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Is this a comment line?
|
2013-12-12 01:29:48 +01:00
|
|
|
bool Comment = false;
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Layer number
|
2013-12-12 01:29:48 +01:00
|
|
|
int Layer = 0;
|
2012-10-10 16:04:44 +02:00
|
|
|
/// Margins: 0 = Left, 1 = Right, 2 = Top (Vertical)
|
2014-11-23 14:24:29 +01:00
|
|
|
std::array<int, 3> Margin = std::array<int, 3>{{ 0, 0, 0 }};
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Starting time
|
2014-07-06 16:28:58 +02:00
|
|
|
agi::Time Start = 0;
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Ending time
|
2014-07-06 16:28:58 +02:00
|
|
|
agi::Time End = 5000;
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Style name
|
2014-11-23 14:24:29 +01:00
|
|
|
boost::flyweight<std::string> Style = boost::flyweight<std::string>("Default");
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Actor name
|
2013-01-04 16:01:50 +01:00
|
|
|
boost::flyweight<std::string> Actor;
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Effect name
|
2013-01-04 16:01:50 +01:00
|
|
|
boost::flyweight<std::string> Effect;
|
2014-04-22 19:21:00 +02:00
|
|
|
/// IDs of extradata entries for line
|
|
|
|
boost::flyweight<std::vector<uint32_t>> ExtradataIds;
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Raw text data
|
2013-01-04 16:01:50 +01:00
|
|
|
boost::flyweight<std::string> Text;
|
2014-03-04 17:32:29 +01:00
|
|
|
};
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class AssDialogue final : public AssEntry, public AssDialogueBase, public AssEntryListHook {
|
2014-03-04 17:32:29 +01:00
|
|
|
/// @brief Parse raw ASS data into everything else
|
|
|
|
/// @param data ASS line
|
|
|
|
void Parse(std::string const& data);
|
|
|
|
public:
|
2013-06-13 00:54:19 +02:00
|
|
|
AssEntryGroup Group() const override { return AssEntryGroup::DIALOGUE; }
|
2006-02-27 03:23:50 +01:00
|
|
|
|
2012-03-29 01:58:50 +02:00
|
|
|
/// Parse text as ASS and return block information
|
2014-04-14 19:58:46 +02:00
|
|
|
std::vector<std::unique_ptr<AssDialogueBlock>> ParseTags() const;
|
2007-04-14 17:26:46 +02:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
/// Strip all ASS tags from the text
|
|
|
|
void StripTags();
|
|
|
|
/// Strip a specific ASS tag from the text
|
|
|
|
/// Get text without tags
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string GetStrippedText() const;
|
2010-06-24 03:24:43 +02:00
|
|
|
|
2012-12-02 19:24:49 +01:00
|
|
|
/// Update the text of the line from parsed blocks
|
2014-04-14 19:58:46 +02:00
|
|
|
void UpdateText(std::vector<std::unique_ptr<AssDialogueBlock>>& blocks);
|
2014-04-29 18:33:22 +02:00
|
|
|
std::string GetEntryData() const;
|
2010-06-24 03:24:43 +02:00
|
|
|
|
|
|
|
/// Does this line collide with the passed line?
|
2012-03-20 01:39:10 +01:00
|
|
|
bool CollidesWith(const AssDialogue *target) const;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
AssDialogue();
|
2010-06-22 02:03:11 +02:00
|
|
|
AssDialogue(AssDialogue const&);
|
2014-03-04 17:32:29 +01:00
|
|
|
AssDialogue(AssDialogueBase const&);
|
2013-01-04 16:01:50 +01:00
|
|
|
AssDialogue(std::string const& data);
|
2006-01-16 22:02:54 +01:00
|
|
|
~AssDialogue();
|
|
|
|
};
|
2014-04-22 19:21:00 +02:00
|
|
|
|