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

ASS: Create parts of the lines from the ASS

parent f2baee99
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
...@@ -27,7 +27,27 @@ Line::Line(AssFactory *const factory, const QString &lineString) ...@@ -27,7 +27,27 @@ Line::Line(AssFactory *const factory, const QString &lineString)
throw std::runtime_error(("invalid event line header: " + lineString).toStdString()); throw std::runtime_error(("invalid event line header: " + lineString).toStdString());
const QString lineContent = lineString.mid(lineString.indexOf(": ") + 2 /* strlen ": " */); const QString lineContent = lineString.mid(lineString.indexOf(": ") + 2 /* strlen ": " */);
const QStringList content = lineContent.split(",", Qt::KeepEmptyParts, Qt::CaseInsensitive); const QStringList contentList = lineContent.split(",", Qt::KeepEmptyParts, Qt::CaseInsensitive);
if (contentList.size() != LineIndex::PastLastCode)
throw std::runtime_error(("invalid number of items " + QString::number(content.size()) +
" instead of " + QString::number(PastLastCode) +
" for line: " + lineContent)
.toStdString());
layer = Utils::decodeLineToInteger(contentList[LineIndex::Layer], "Layer is not an integer");
effect = contentList[LineIndex::Effect];
nameOrActor = contentList[LineIndex::Name];
styleProperties.marginL =
Utils::decodeLineToInteger(contentList[LineIndex::MarginL], "MarginL is not an integer");
styleProperties.marginR =
Utils::decodeLineToInteger(contentList[LineIndex::MarginR], "MarginR is not an integer");
styleProperties.marginV =
Utils::decodeLineToInteger(contentList[LineIndex::MarginV], "MarginV is not an integer");
const QString style = contentList[LineIndex::Style];
if (!assFactory->hasStyle(style))
throw std::runtime_error(("Invalid or not declared style name: " + style).toStdString());
} }
void void
......
...@@ -14,9 +14,12 @@ class Line { ...@@ -14,9 +14,12 @@ class Line {
private: private:
quint64 start{ 0 }; quint64 start{ 0 };
quint64 end{ 0 }; quint64 end{ 0 };
int layer{ 0 };
QVector<Syl> content{}; QVector<Syl> content{};
StyleProperties styleProperties; StyleProperties styleProperties{};
QString effect{};
QString nameOrActor{};
AssFactory *const assFactory; AssFactory *const assFactory;
......
...@@ -65,70 +65,49 @@ Style::Style(const QString &styleString) ...@@ -65,70 +65,49 @@ Style::Style(const QString &styleString)
styleName = content[StyleIndex::Name]; styleName = content[StyleIndex::Name];
fontName = content[StyleIndex::FontName]; fontName = content[StyleIndex::FontName];
fontSize = decodeLineToInteger(content[StyleIndex::FontSize], "FontSize is not an integer"); fontSize =
Utils::decodeLineToInteger(content[StyleIndex::FontSize], "FontSize is not an integer");
primaryColor = Color::fromString(content[StyleIndex::ColorPrimary]); primaryColor = Color::fromString(content[StyleIndex::ColorPrimary]);
secondaryColor = Color::fromString(content[StyleIndex::ColorSecondary]); secondaryColor = Color::fromString(content[StyleIndex::ColorSecondary]);
outlineColor = Color::fromString(content[StyleIndex::ColorOutline]); outlineColor = Color::fromString(content[StyleIndex::ColorOutline]);
backColor = Color::fromString(content[StyleIndex::ColorBack]); backColor = Color::fromString(content[StyleIndex::ColorBack]);
bold = decodeLineToBoolean(content[StyleIndex::Bold], "Bold is not a boolean"); bold = Utils::decodeLineToBoolean(content[StyleIndex::Bold], "Bold is not a boolean");
italic = decodeLineToBoolean(content[StyleIndex::Italic], "Italic is not a boolean"); italic = Utils::decodeLineToBoolean(content[StyleIndex::Italic], "Italic is not a boolean");
underline = decodeLineToBoolean(content[StyleIndex::Underline], "Underline is not a boolean"); underline =
strikeOut = decodeLineToBoolean(content[StyleIndex::StrikeOut], "StrikeOut is not a boolean"); Utils::decodeLineToBoolean(content[StyleIndex::Underline], "Underline is not a boolean");
strikeOut =
scaleX = decodeLineToFloating(content[StyleIndex::ScaleX], "ScaleX is not a floating"); Utils::decodeLineToBoolean(content[StyleIndex::StrikeOut], "StrikeOut is not a boolean");
scaleY = decodeLineToFloating(content[StyleIndex::ScaleY], "ScaleY is not a floating");
spacing = decodeLineToFloating(content[StyleIndex::ScaleY], "Spacing is not a floating"); scaleX = Utils::decodeLineToFloating(content[StyleIndex::ScaleX], "ScaleX is not a floating");
angle = decodeLineToFloating(content[StyleIndex::Angle], "Angle is not a floating"); scaleY = Utils::decodeLineToFloating(content[StyleIndex::ScaleY], "ScaleY is not a floating");
borderStyle = spacing = Utils::decodeLineToFloating(content[StyleIndex::ScaleY], "Spacing is not a floating");
decodeLineToFloating(content[StyleIndex::BorderStyle], "BorderStyle is not a floating"); angle = Utils::decodeLineToFloating(content[StyleIndex::Angle], "Angle is not a floating");
outline = decodeLineToFloating(content[StyleIndex::Outline], "Outline is not a floating"); borderStyle = Utils::decodeLineToFloating(content[StyleIndex::BorderStyle],
shadow = decodeLineToFloating(content[StyleIndex::Shadow], "Shadow is not a floating"); "BorderStyle is not a floating");
outline =
Utils::decodeLineToFloating(content[StyleIndex::Outline], "Outline is not a floating");
shadow = Utils::decodeLineToFloating(content[StyleIndex::Shadow], "Shadow is not a floating");
alignment = alignment =
decodeLineToInteger(content[StyleIndex::Alignement], "Alignement is not an integer"); Utils::decodeLineToInteger(content[StyleIndex::Alignement], "Alignement is not an integer");
if (alignment < 1 || alignment > 9) if (alignment < 1 || alignment > 9)
throw std::runtime_error( throw std::runtime_error(
("invalid line content: Alignement must be between 1 and 9 included, it was " + ("invalid line content: Alignement must be between 1 and 9 included, it was " +
QString::number(alignment)) QString::number(alignment))
.toStdString()); .toStdString());
marginL = decodeLineToInteger(content[StyleIndex::MarginL], "MarginL is not an integer"); marginL = Utils::decodeLineToInteger(content[StyleIndex::MarginL], "MarginL is not an integer");
marginR = decodeLineToInteger(content[StyleIndex::MarginR], "MarginR is not an integer"); marginR = Utils::decodeLineToInteger(content[StyleIndex::MarginR], "MarginR is not an integer");
marginV = decodeLineToInteger(content[StyleIndex::MarginV], "MarginV is not an integer"); marginV = Utils::decodeLineToInteger(content[StyleIndex::MarginV], "MarginV is not an integer");
encoding = decodeLineToInteger(content[StyleIndex::Encoding], "Encoding is not an integer"); encoding =
Utils::decodeLineToInteger(content[StyleIndex::Encoding], "Encoding is not an integer");
if (encoding != 1) if (encoding != 1)
qWarning() << "Encoding is not '1' in the ASS Style"; qWarning() << "Encoding is not '1' in the ASS Style";
} }
bool
Style::decodeLineToBoolean(const QString &item, const QString &error)
{
return decodeLineToInteger(item, error) >= 1;
}
int
Style::decodeLineToInteger(const QString &item, const QString &error)
{
bool conversion = false;
int ret = item.toInt(&conversion);
if (!conversion)
throw std::runtime_error(("invalid line content: " + error).toStdString());
return ret;
}
float
Style::decodeLineToFloating(const QString &item, const QString &error)
{
bool conversion = false;
float ret = item.toFloat(&conversion);
if (!conversion)
throw std::runtime_error(("invalid line content: " + error).toStdString());
return ret;
}
QString QString
Color::toString(const QColor &c) noexcept Color::toString(const QColor &c) noexcept
{ {
......
...@@ -45,11 +45,6 @@ public: ...@@ -45,11 +45,6 @@ public:
QString getElementName() const noexcept; QString getElementName() const noexcept;
QJsonDocument getProperties() const noexcept; QJsonDocument getProperties() const noexcept;
private:
static bool decodeLineToBoolean(const QString &item, const QString &error);
static int decodeLineToInteger(const QString &item, const QString &error);
static float decodeLineToFloating(const QString &item, const QString &error);
}; };
} }
......
...@@ -14,7 +14,7 @@ struct StyleProperties final { ...@@ -14,7 +14,7 @@ struct StyleProperties final {
QColor primaryColor{ Color::defaultValue }, secondaryColor{ Color::defaultValue }, QColor primaryColor{ Color::defaultValue }, secondaryColor{ Color::defaultValue },
outlineColor{ Color::defaultValue }, backColor{ Color::defaultValue }; outlineColor{ Color::defaultValue }, backColor{ Color::defaultValue };
QString fontName; // Can override the font's name QString fontName{}; // Can override the font's name
int fontSize{}; // The font size != the font scaling int fontSize{}; // The font size != the font scaling
bool bold{ false }, italic{ false }, underline{ false }, strikeOut{ false }; bool bold{ false }, italic{ false }, underline{ false }, strikeOut{ false };
......
...@@ -24,3 +24,29 @@ Utils::detectDocumentType(const QFileInfo &file, DocumentType *type) ...@@ -24,3 +24,29 @@ Utils::detectDocumentType(const QFileInfo &file, DocumentType *type)
return false; return false;
} }
bool
Utils::decodeLineToBoolean(const QString &item, const QString &error)
{
return Utils::decodeLineToInteger(item, error) >= 1;
}
int
Utils::decodeLineToInteger(const QString &item, const QString &error)
{
bool conversion = false;
int ret = item.toInt(&conversion);
if (!conversion)
throw std::runtime_error(("invalid line content: " + error).toStdString());
return ret;
}
float
Utils::decodeLineToFloating(const QString &item, const QString &error)
{
bool conversion = false;
float ret = item.toFloat(&conversion);
if (!conversion)
throw std::runtime_error(("invalid line content: " + error).toStdString());
return ret;
}
...@@ -85,6 +85,9 @@ toUnderlying(E e) noexcept ...@@ -85,6 +85,9 @@ toUnderlying(E e) noexcept
} }
bool detectDocumentType(const QFileInfo &, DocumentType *); bool detectDocumentType(const QFileInfo &, DocumentType *);
bool decodeLineToBoolean(const QString &item, const QString &error);
int decodeLineToInteger(const QString &item, const QString &error);
float decodeLineToFloating(const QString &item, const QString &error);
} }
namespace Vivy namespace Vivy
......
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