Skip to content
Extraits de code Groupes Projets
Vérifiée Valider b51e05ba rédigé par Kubat's avatar Kubat
Parcourir les fichiers

ASS: Build the Syl in the Line object, and remove the no more used Char class

parent a6eca143
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!7Add the ASS sub document and the ASS tree
#ifndef VIVY_ASS_ASS_H
#define VIVY_ASS_ASS_H
#include "Char.hh"
#include "Line.hh"
#include "Syl.hh"
#include "Style.hh"
......
#include "Char.hh"
#include "Syl.hh"
using namespace Vivy::Ass;
Char::Char(Syl *const syl, const QChar /*unused*/)
: parentLine(syl->parentLine)
, parentSyl(syl)
{
}
#ifndef VIVY_ASS_CHAR_H
#define VIVY_ASS_CHAR_H
#include <QChar>
#include <QtGlobal>
#include "StyleProperties.hh"
namespace Vivy::Ass
{
class Line;
class Syl;
class Char {
private:
QChar content{};
StyleProperties styleProperties;
quint64 dur{ 0 };
public:
Line *const parentLine;
Syl *const parentSyl;
public:
// Copy constructor
explicit Char(const Char &) = default;
explicit Char(Syl *const, const QChar);
Char &operator=(const Char &) = delete;
~Char() noexcept = default;
};
}
#endif // VIVY_ASS_CHAR_H
......@@ -59,6 +59,30 @@ Line::Line(AssFactory *const factory, const QString &lineString)
___contentAsText = contentList.join("");
}
void
Line::initSylFromString(const QString &line) noexcept
{
// Matches syllabes like: `{\toto}{\alpha&HFF}content`
QRegExp re("(?:{[^}]*})+[^{]*", Qt::CaseInsensitive, QRegExp::RegExp);
int pos = 0;
try {
while ((pos = re.indexIn(line, pos)) != -1) {
content.append(Syl(this, re.cap(1)));
pos += re.matchedLength();
}
} catch (const std::runtime_error &e) {
qCritical() << "Failed to init syllabes with line:" << line;
qCritical() << "Fallback to all line is one syllabe";
pos = 0;
}
if (pos == 0) {
content.clear();
content.append(Syl(this, line, Syl::ConstructMode::Raw));
}
}
void
Line::setStart(quint64 s) noexcept
{
......@@ -74,3 +98,15 @@ Line::setEnd(quint64 s) noexcept
if (start > s)
start = s;
}
quint64
Line::getDuration() const noexcept
{
return end - start;
}
StyleProperties
Line::getStyleProperties() const noexcept
{
return styleProperties;
}
......@@ -36,6 +36,12 @@ public:
void setStart(quint64 s) noexcept;
void setEnd(quint64 s) noexcept;
quint64 getDuration() const noexcept;
StyleProperties getStyleProperties() const noexcept;
private:
void initSylFromString(const QString &) noexcept;
};
}
......
#include "Syl.hh"
#include "Line.hh"
using namespace Vivy::Ass;
Syl::Syl(Line *const line, const QString & /*unused*/)
: parentLine(line)
Syl::Syl(Line *const line, const QString &lineString, ConstructMode mode) noexcept
: content(lineString)
, styleProperties(line->getStyleProperties())
, dur(line->getDuration())
, parentLine(line)
{
// Will override the `content`, but will be heavy anyway
if (mode == ConstructMode::ReadAssTags) {
}
}
#ifndef VIVY_SYL_H
#define VIVY_SYL_H
#include "Char.hh"
#include "StyleProperties.hh"
#include <QString>
#include <QVector>
......@@ -13,7 +12,7 @@ class Line;
class Syl final {
private:
QVector<Char> content;
QString content;
StyleProperties styleProperties;
quint64 dur{ 0 };
......@@ -21,8 +20,14 @@ public:
Line *const parentLine;
public:
explicit Syl(const Syl &) = default;
explicit Syl(Line *const, const QString &);
enum class ConstructMode {
Raw, // Don't read ASS tags
ReadAssTags, // Read ass tags
};
explicit Syl(const Syl &) noexcept = default;
explicit Syl(Line *const, const QString &,
ConstructMode mode = ConstructMode::ReadAssTags) noexcept;
Syl &operator=(const Syl &) = delete;
~Syl() noexcept = default;
......
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