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/
|
|
|
|
|
|
|
|
/// @file ass_dialogue.h
|
|
|
|
/// @see ass_dialogue.cpp
|
|
|
|
/// @ingroup subs_storage
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
#include "ass_entry.h"
|
2012-12-11 00:32:36 +01:00
|
|
|
#include "ass_override.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "ass_time.h"
|
|
|
|
|
2012-10-26 16:33:50 +02:00
|
|
|
#include <libaegisub/exception.h>
|
|
|
|
|
2012-12-04 23:35:59 +01:00
|
|
|
#include <boost/flyweight.hpp>
|
2012-12-02 19:24:49 +01:00
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
|
|
|
#include <vector>
|
|
|
|
|
2012-10-12 03:52:36 +02:00
|
|
|
enum AssBlockType {
|
2006-01-16 22:02:54 +01:00
|
|
|
BLOCK_BASE,
|
|
|
|
BLOCK_PLAIN,
|
2012-12-30 18:04:43 +01:00
|
|
|
BLOCK_COMMENT,
|
2006-01-16 22:02:54 +01:00
|
|
|
BLOCK_OVERRIDE,
|
|
|
|
BLOCK_DRAWING
|
|
|
|
};
|
|
|
|
|
2012-12-04 23:35:59 +01:00
|
|
|
std::size_t hash_value(wxString const& s);
|
|
|
|
|
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:
|
2012-12-30 00:53:56 +01:00
|
|
|
AssDialogueBlock(std::string const& text) : text(text) { }
|
2010-06-24 03:24:43 +02:00
|
|
|
virtual ~AssDialogueBlock() { }
|
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
|
|
|
};
|
|
|
|
|
|
|
|
class AssDialogueBlockPlain : public AssDialogueBlock {
|
|
|
|
public:
|
2012-11-26 15:57:58 +01:00
|
|
|
AssBlockType GetType() const override { return BLOCK_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
|
|
|
};
|
|
|
|
|
2012-12-30 18:04:43 +01:00
|
|
|
class AssDialogueBlockComment : public AssDialogueBlock {
|
|
|
|
public:
|
|
|
|
AssBlockType GetType() const override { return BLOCK_COMMENT; }
|
|
|
|
AssDialogueBlockComment(std::string const& text = std::string()) : AssDialogueBlock("{" + text + "}") { }
|
|
|
|
};
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
class AssDialogueBlockDrawing : public AssDialogueBlock {
|
|
|
|
public:
|
|
|
|
int Scale;
|
|
|
|
|
2012-11-26 15:57:58 +01:00
|
|
|
AssBlockType GetType() const override { return BLOCK_DRAWING; }
|
2012-12-30 00:53:56 +01:00
|
|
|
AssDialogueBlockDrawing(std::string const& text, int scale) : AssDialogueBlock(text), Scale(scale) { }
|
2007-10-18 04:47:13 +02:00
|
|
|
void TransformCoords(int trans_x,int trans_y,double mult_x,double mult_y);
|
2006-01-16 22:02:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class AssDialogueBlockOverride : public AssDialogueBlock {
|
|
|
|
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
|
|
|
|
2012-11-26 15:57:58 +01:00
|
|
|
AssBlockType GetType() const override { return BLOCK_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
|
|
|
};
|
|
|
|
|
|
|
|
class AssDialogue : public AssEntry {
|
2010-07-08 09:14:55 +02:00
|
|
|
wxString GetData(bool ssa) const;
|
2006-01-16 22:02:54 +01:00
|
|
|
public:
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Is this a comment line?
|
|
|
|
bool Comment;
|
|
|
|
/// Layer number
|
|
|
|
int Layer;
|
2012-10-10 16:04:44 +02:00
|
|
|
/// Margins: 0 = Left, 1 = Right, 2 = Top (Vertical)
|
|
|
|
int Margin[3];
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Starting time
|
|
|
|
AssTime Start;
|
|
|
|
/// Ending time
|
|
|
|
AssTime End;
|
|
|
|
/// Style name
|
2012-12-04 23:35:59 +01:00
|
|
|
boost::flyweight<wxString> Style;
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Actor name
|
2012-12-04 23:35:59 +01:00
|
|
|
boost::flyweight<wxString> Actor;
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Effect name
|
2012-12-04 23:35:59 +01:00
|
|
|
boost::flyweight<wxString> Effect;
|
2010-05-19 02:44:44 +02:00
|
|
|
/// Raw text data
|
2012-12-04 23:35:59 +01:00
|
|
|
boost::flyweight<wxString> Text;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-11-26 15:57:58 +01:00
|
|
|
AssEntryGroup Group() const override { return ENTRY_DIALOGUE; }
|
2006-02-27 03:23:50 +01:00
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
/// @brief Parse raw ASS data into everything else
|
|
|
|
/// @param data ASS line
|
|
|
|
/// @return Did it successfully parse?
|
2012-10-10 16:04:44 +02:00
|
|
|
bool Parse(wxString const& data);
|
2012-03-29 01:58:50 +02:00
|
|
|
|
|
|
|
/// Parse text as ASS and return block information
|
2012-12-02 19:24:49 +01:00
|
|
|
std::auto_ptr<boost::ptr_vector<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
|
|
|
|
wxString GetStrippedText() const;
|
|
|
|
|
2012-12-02 19:24:49 +01:00
|
|
|
/// Update the text of the line from parsed blocks
|
|
|
|
void UpdateText(boost::ptr_vector<AssDialogueBlock>& blocks);
|
2012-11-26 15:57:58 +01:00
|
|
|
const wxString GetEntryData() const override;
|
2010-06-24 03:24:43 +02:00
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
template<int which>
|
2012-10-05 04:10:20 +02:00
|
|
|
void SetMarginString(wxString const& value) { SetMarginString(value, which);}
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @brief Set a margin
|
2010-06-24 03:24:43 +02:00
|
|
|
/// @param value New value of the margin
|
2012-10-10 16:04:44 +02:00
|
|
|
/// @param which 0 = left, 1 = right, 2 = vertical
|
2012-10-05 04:10:20 +02:00
|
|
|
void SetMarginString(wxString const& value, int which);
|
2010-06-24 03:24:43 +02:00
|
|
|
/// @brief Get a margin
|
2012-10-10 16:04:44 +02:00
|
|
|
/// @param which 0 = left, 1 = right, 2 = vertical
|
2012-12-02 16:55:38 +01:00
|
|
|
wxString GetMarginString(int which) const;
|
2010-06-24 03:24:43 +02:00
|
|
|
/// Get the line as SSA rather than ASS
|
2012-11-26 15:57:58 +01:00
|
|
|
wxString GetSSAText() const override;
|
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
|
|
|
|
2009-06-07 02:22:36 +02:00
|
|
|
AssEntry *Clone() const;
|
2006-02-27 10:07:08 +01:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
AssDialogue();
|
2010-06-22 02:03:11 +02:00
|
|
|
AssDialogue(AssDialogue const&);
|
2012-10-10 16:04:44 +02:00
|
|
|
AssDialogue(wxString const& data);
|
2006-01-16 22:02:54 +01:00
|
|
|
~AssDialogue();
|
|
|
|
};
|
2012-10-26 16:33:50 +02:00
|
|
|
|
|
|
|
class InvalidMarginIdError : public agi::InternalError {
|
|
|
|
public:
|
|
|
|
InvalidMarginIdError() : InternalError("Invalid margin id", 0) { }
|
|
|
|
const char *GetName() const { return "internal_error/invalid_margin_id"; }
|
|
|
|
};
|