1 | // Copyright (C) 2018 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "bmshape_p.h" |
5 | |
6 | #include <QJsonArray> |
7 | #include <QJsonObject> |
8 | #include <QLoggingCategory> |
9 | |
10 | #include "bmgroup_p.h" |
11 | #include "bmfill_p.h" |
12 | #include "bmgfill_p.h" |
13 | #include "bmstroke_p.h" |
14 | #include "bmrect_p.h" |
15 | #include "bmellipse_p.h" |
16 | #include "bmround_p.h" |
17 | #include "bmtrimpath_p.h" |
18 | #include "bmshapetransform_p.h" |
19 | #include "bmfreeformshape_p.h" |
20 | #include "bmrepeater_p.h" |
21 | #include "bmconstants_p.h" |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | BMShape::BMShape(const BMShape &other) |
26 | : BMBase(other) |
27 | { |
28 | m_direction = other.m_direction; |
29 | m_path = other.m_path; |
30 | m_appliedTrim = other.m_appliedTrim; |
31 | } |
32 | |
33 | BMBase *BMShape::clone() const |
34 | { |
35 | return new BMShape(*this); |
36 | } |
37 | |
38 | BMShape *BMShape::construct(QJsonObject definition, const QVersionNumber &version, BMBase *parent) |
39 | { |
40 | qCDebug(lcLottieQtBodymovinParser) << "BMShape::construct()" ; |
41 | |
42 | BMShape *shape = nullptr; |
43 | const QByteArray type = definition.value(key: QLatin1String("ty" )).toString().toLatin1(); |
44 | |
45 | if (Q_UNLIKELY(type.size() != 2)) { |
46 | qCWarning(lcLottieQtBodymovinParser) << "Unsupported shape type:" |
47 | << type; |
48 | return shape; |
49 | } |
50 | |
51 | #define BM_SHAPE_TAG(c1, c2) int((quint32(c1)<<8) | quint32(c2)) |
52 | |
53 | int typeToBuild = BM_SHAPE_TAG(type[0], type[1]); |
54 | |
55 | switch (typeToBuild) { |
56 | case BM_SHAPE_TAG('g', 'r'): |
57 | { |
58 | qCDebug(lcLottieQtBodymovinParser) << "Parse group" ; |
59 | shape = new BMGroup(definition, version, parent); |
60 | shape->setType(BM_SHAPE_GROUP_IX); |
61 | break; |
62 | } |
63 | case BM_SHAPE_TAG('r', 'c'): |
64 | { |
65 | qCDebug(lcLottieQtBodymovinParser) << "Parse m_rect" ; |
66 | shape = new BMRect(definition, version, parent); |
67 | shape->setType(BM_SHAPE_RECT_IX); |
68 | break; |
69 | } |
70 | case BM_SHAPE_TAG('f', 'l'): |
71 | { |
72 | qCDebug(lcLottieQtBodymovinParser) << "Parse fill" ; |
73 | shape = new BMFill(definition, version, parent); |
74 | shape->setType(BM_SHAPE_FILL_IX); |
75 | break; |
76 | } |
77 | case BM_SHAPE_TAG('g', 'f'): |
78 | { |
79 | qCDebug(lcLottieQtBodymovinParser) << "Parse group fill" ; |
80 | shape = new BMGFill(definition, version, parent); |
81 | shape->setType(BM_SHAPE_GFILL_IX); |
82 | break; |
83 | } |
84 | case BM_SHAPE_TAG('s', 't'): |
85 | { |
86 | qCDebug(lcLottieQtBodymovinParser) << "Parse stroke" ; |
87 | shape = new BMStroke(definition, version, parent); |
88 | shape->setType(BM_SHAPE_STROKE_IX); |
89 | break; |
90 | } |
91 | case BM_SHAPE_TAG('t', 'r'): |
92 | { |
93 | qCDebug(lcLottieQtBodymovinParser) << "Parse shape transform" ; |
94 | shape = new BMShapeTransform(definition, version, parent); |
95 | shape->setType(BM_SHAPE_TRANS_IX); |
96 | break; |
97 | } |
98 | case BM_SHAPE_TAG('e', 'l'): |
99 | { |
100 | qCDebug(lcLottieQtBodymovinParser) << "Parse ellipse" ; |
101 | shape = new BMEllipse(definition, version, parent); |
102 | shape->setType(BM_SHAPE_ELLIPSE_IX); |
103 | break; |
104 | } |
105 | case BM_SHAPE_TAG('r', 'd'): |
106 | { |
107 | qCDebug(lcLottieQtBodymovinParser) << "Parse round" ; |
108 | shape = new BMRound(definition, version, parent); |
109 | shape->setType(BM_SHAPE_ROUND_IX); |
110 | break; |
111 | } |
112 | case BM_SHAPE_TAG('s', 'h'): |
113 | { |
114 | qCDebug(lcLottieQtBodymovinParser) << "Parse shape" ; |
115 | shape = new BMFreeFormShape(definition, version, parent); |
116 | shape->setType(BM_SHAPE_SHAPE_IX); |
117 | break; |
118 | } |
119 | case BM_SHAPE_TAG('t', 'm'): |
120 | { |
121 | qCDebug(lcLottieQtBodymovinParser) << "Parse trim path" ; |
122 | shape = new BMTrimPath(definition, version, parent); |
123 | shape->setType(BM_SHAPE_TRIM_IX); |
124 | break; |
125 | } |
126 | case BM_SHAPE_TAG('r', 'p'): |
127 | { |
128 | qCDebug(lcLottieQtBodymovinParser) << "Parse trim path" ; |
129 | shape = new BMRepeater(definition, version, parent); |
130 | shape->setType(BM_SHAPE_REPEATER_IX); |
131 | break; |
132 | } |
133 | case BM_SHAPE_TAG('g', 's'): // ### BM_SHAPE_GSTROKE_IX |
134 | case BM_SHAPE_TAG('s', 'r'): // ### BM_SHAPE_STAR_IX |
135 | // fall through |
136 | default: |
137 | qCWarning(lcLottieQtBodymovinParser) << "Unsupported shape type:" |
138 | << type; |
139 | } |
140 | |
141 | #undef BM_SHAPE_TAG |
142 | |
143 | return shape; |
144 | } |
145 | |
146 | bool BMShape::acceptsTrim() const |
147 | { |
148 | return false; |
149 | } |
150 | |
151 | void BMShape::applyTrim(const BMTrimPath &trimmer) |
152 | { |
153 | if (trimmer.simultaneous()) |
154 | m_path = trimmer.trim(path: m_path); |
155 | } |
156 | |
157 | int BMShape::direction() const |
158 | { |
159 | return m_direction; |
160 | } |
161 | |
162 | const QPainterPath &BMShape::path() const |
163 | { |
164 | return m_path; |
165 | } |
166 | |
167 | QT_END_NAMESPACE |
168 | |