diff --git a/src/Lib/Ass/AssFactory.cc b/src/Lib/Ass/AssFactory.cc index d034e0d948414b0d8accd6ca26bcea47915310f1..db96607f5945ccc43828c8620047968f671902ff 100644 --- a/src/Lib/Ass/AssFactory.cc +++ b/src/Lib/Ass/AssFactory.cc @@ -74,24 +74,31 @@ AssFactory::initFromStorage() noexcept bool AssFactory::checkValidity() const noexcept { - if (assInfo.isEmpty()) + if (assInfo.isEmpty()) { + qCritical() << "Empty info section"; return false; + } // Check for fields that must be integers - bool ok = false; SectionContent::const_iterator it = assInfo.begin(); const SectionContent::const_iterator end = assInfo.end(); while (it != end) { - if (intTypeFields.contains(it.key()) && (it.value().toInt(&ok), !ok)) + bool ok = false; + if (intTypeFields.contains(it.key()) && (it.value().toInt(&ok), !ok)) { + qCritical() << it.key() << "is not an integer:" << it.value(); return false; + } ++it; } // Check for fixed values fields for (const auto &fixedValues : checkedValues) { if (const auto &first = fixedValues.first; - assInfo.contains(first) && assInfo[first] != fixedValues.second) + assInfo.contains(first) && assInfo[first] != fixedValues.second) { + qCritical() << "Invalid" << first << "as it should be equal to" << fixedValues.second + << "but was" << assInfo[first]; return false; + } } return true; diff --git a/src/Lib/Ass/AssFactory.hh b/src/Lib/Ass/AssFactory.hh index b30189c82c2be7b7e0d88b95320497500c604a19..62c0941d33dfecd412229a8c8b6eb67fde99acc4 100644 --- a/src/Lib/Ass/AssFactory.hh +++ b/src/Lib/Ass/AssFactory.hh @@ -48,7 +48,7 @@ private: static inline const QList<QPair<QString, QString>> checkedValues = { { "ScriptType", "v4.00+" }, { "WrapStyle", "0" }, - { "YCbCr Matrix", "TV.601" }, + // { "YCbCr Matrix", "TV.601" }, { "ScaledBorderAndShadow", "yes" } }; diff --git a/src/Lib/Ass/Style.cc b/src/Lib/Ass/Style.cc index 2652769b3adf5721d11a884fe8cd7a2d6f1babe0..a51696353a4958d92f412d83f074cf1dfa3eab86 100644 --- a/src/Lib/Ass/Style.cc +++ b/src/Lib/Ass/Style.cc @@ -1,6 +1,8 @@ #include "Style.hh" #include <stdexcept> +#include <QJsonDocument> +#include <QJsonObject> using namespace Vivy::Ass; @@ -50,7 +52,7 @@ Style::Style(const QString &styleString) if (!styleString.startsWith(lineHeader)) throw std::runtime_error(("invalid style line header: " + styleString).toStdString()); - const QString lineContent = styleString.mid(styleString.indexOf(": ")); + const QString lineContent = styleString.mid(styleString.indexOf(": ") + 2 /* strlen ": " */); const QStringList content = lineContent.split(",", Qt::KeepEmptyParts, Qt::CaseInsensitive); if (content.size() != StyleIndex::PastLastCode) @@ -166,3 +168,46 @@ Color::fromString(const QString &colorString) noexcept return QColor(red, green, blue, alpha); } + +QString +Style::getElementName() const noexcept +{ + return styleName; +} + +QJsonDocument +Style::getProperties() const noexcept +{ + QJsonDocument ret; + + QJsonObject styleFont{ + { "Font name", fontName }, { "Font size", fontSize }, { "Bold", bold }, + { "Italic", italic }, { "Underline", underline }, { "Strike Out", strikeOut }, + }; + + QJsonObject styleFontProperties{ + { "Scale X", static_cast<const double>(scaleX) }, + { "Scale Y", static_cast<const double>(scaleY) }, + { "Spacing", static_cast<const double>(spacing) }, + { "Angle", static_cast<const double>(angle) }, + { "Border Style", static_cast<const double>(borderStyle) }, + { "Outline", static_cast<const double>(outline) }, + { "Shadow", static_cast<const double>(shadow) }, + }; + + QJsonObject styleMargins{ + { "Left", marginL }, + { "Right", marginR }, + { "Vertical", marginV }, + }; + + QJsonObject object{ { "Name", styleName }, + { "Font", styleFont }, + { "Font properties", styleFontProperties }, + { "Margin", styleMargins }, + { "Alignement", alignment }, + { "Encoding", encoding } }; + + ret.setObject(object); + return ret; +} diff --git a/src/Lib/Ass/Style.hh b/src/Lib/Ass/Style.hh index 21ca04d27a99099562cbfef7f923fc68d19c16e1..c8803692baab8c658377d778c8295a0cc2067c15 100644 --- a/src/Lib/Ass/Style.hh +++ b/src/Lib/Ass/Style.hh @@ -5,6 +5,7 @@ #include <QVector> #include <QtGlobal> #include <QColor> +#include <QObject> namespace Vivy::Ass { @@ -41,6 +42,9 @@ public: Style &operator=(const Style &) = delete; ~Style() noexcept = default; + QString getElementName() 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); diff --git a/src/Lib/Document/CRTPSubDocument.cc b/src/Lib/Document/CRTPSubDocument.cc index d6ac414b607200268e9d6a2b7a9755fd6d59a6ce..a5493d26381c97157055046887aee5a993c32a2e 100644 --- a/src/Lib/Document/CRTPSubDocument.cc +++ b/src/Lib/Document/CRTPSubDocument.cc @@ -119,6 +119,11 @@ AssSubDocument::getProperties() const noexcept { QJsonDocument ret; QJsonObject object; + + for (const Ass::StylePtr &style : styles) { + object.insert(style->getElementName(), style->getProperties().object()); + } + ret.setObject(object); return ret; } diff --git a/src/Lib/Document/CRTPSubDocument.hh b/src/Lib/Document/CRTPSubDocument.hh index f89b26f65e235f3c3b3fd72a22510c7afd7cebdd..f8be95a08a8e8a6e0db9223b5597cdc81ab90945 100644 --- a/src/Lib/Document/CRTPSubDocument.hh +++ b/src/Lib/Document/CRTPSubDocument.hh @@ -41,7 +41,7 @@ public: try { ret->initFromPath(path); // May throw } catch (const std::runtime_error &e) { - qDebug() << "Failed to init document from file" << path; + qDebug().nospace() << "Failed to init document from file " << path << ": " << e.what(); ret.reset(); }