| 1 |
// Copyright (C) 2018 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include <QCoreApplication> |
| 5 |
#include <QJsonDocument> |
| 6 |
#include <QJsonObject> |
| 7 |
#include <QJsonArray> |
| 8 |
#include <QFile> |
| 9 |
|
| 10 |
#include <QtLottie/private/qlottiebase_p.h> |
| 11 |
#include <QtLottie/private/qlottielayer_p.h> |
| 12 |
|
| 13 |
using namespace Qt::StringLiterals; |
| 14 |
|
| 15 |
int main(int argc, char *argv[]) |
| 16 |
{ |
| 17 |
QCoreApplication a(argc, argv); |
| 18 |
|
| 19 |
if (argc < 2) { |
| 20 |
printf("Filename missing\n"); |
| 21 |
return -1; |
| 22 |
} |
| 23 |
|
| 24 |
QFile sourceFile(argv[1]); |
| 25 |
|
| 26 |
if (!sourceFile.open(QIODevice::ReadOnly)) { |
| 27 |
fprintf(stderr, "Cannot open file\n"); |
| 28 |
return -1; |
| 29 |
} |
| 30 |
|
| 31 |
QByteArray json = sourceFile.readAll(); |
| 32 |
|
| 33 |
QJsonDocument doc = QJsonDocument::fromJson(json); |
| 34 |
QJsonObject rootObj = doc.object(); |
| 35 |
|
| 36 |
if (rootObj.empty()) { |
| 37 |
fprintf(stderr, "Json document not found\n"); |
| 38 |
return -1; |
| 39 |
} |
| 40 |
|
| 41 |
if (rootObj.value(QLatin1String("assets")).toArray().count()) |
| 42 |
qWarning() << "assets not supported"; |
| 43 |
|
| 44 |
if (rootObj.value(QLatin1String("chars")).toArray().count()) |
| 45 |
qWarning() << "chars not supported"; |
| 46 |
|
| 47 |
if (rootObj.value(QLatin1String("markers")).toArray().count()) |
| 48 |
qWarning() << "markers not supported"; |
| 49 |
|
| 50 |
QMap<QString, QJsonObject> assets; |
| 51 |
QJsonArray jsonLayers = rootObj.value(QLatin1String("layers")).toArray(); |
| 52 |
QJsonArray jsonAssets = rootObj.value(QLatin1String("assets")).toArray(); |
| 53 |
QJsonArray::const_iterator jsonAssetsIt = jsonAssets.constBegin(); |
| 54 |
while (jsonAssetsIt != jsonAssets.constEnd()) { |
| 55 |
QJsonObject jsonAsset = (*jsonAssetsIt).toObject(); |
| 56 |
|
| 57 |
jsonAsset.insert(QLatin1String("fileSource"), QJsonValue::fromVariant(sourceFile.fileName())); |
| 58 |
QString id = jsonAsset.value(QLatin1String("id")).toString(); |
| 59 |
assets.insert(id, jsonAsset); |
| 60 |
jsonAssetsIt++; |
| 61 |
} |
| 62 |
QJsonArray::const_iterator jsonLayerIt = jsonLayers.constBegin(); |
| 63 |
while (jsonLayerIt != jsonLayers.constEnd()) { |
| 64 |
QJsonObject jsonLayer = (*jsonLayerIt).toObject(); |
| 65 |
QLottieLayer *layer = QLottieLayer::construct(jsonLayer, assets); |
| 66 |
if (layer) |
| 67 |
delete layer; |
| 68 |
jsonLayerIt++; |
| 69 |
} |
| 70 |
} |