#include<vector>
#include<memory>
#include<unordered_map>
-#include <algorithm>
+#include <cmath>
#include"vpoint.h"
#include"vrect.h"
#include"vinterpolator.h"
class LottieShapeData
{
public:
- void reserve(int size) {
+ void reserve(size_t size) {
mPoints.reserve(mPoints.size() + size);
}
void toPath(VPath& path) {
if (mPoints.empty()) return;
- int size = mPoints.size();
- const VPointF *points = mPoints.data();
+ auto size = mPoints.size();
+ auto points = mPoints.data();
/* reserve exact memory requirement at once
* ptSize = size + 1(size + close)
* elmSize = size/3 cubic + 1 move + 1 close
*/
path.reserve(size + 1 , size/3 + 2);
path.moveTo(points[0]);
- for (int i = 1 ; i < size; i+=3) {
+ for (size_t i = 1 ; i < size; i+=3) {
path.cubicTo(points[i], points[i+1], points[i+2]);
}
if (mClosed)
path.close();
}
public:
- std::vector<VPointF> mPoints;
- bool mClosed = false; /* "c" */
+ std::vector<VPointF> mPoints;
+ bool mClosed = false; /* "c" */
};
* Time streach factor is already applied to the layers inFrame and outFrame.
* @TODO need to find out if timestreatch also affects the in and out frame of the
* child layers or not. */
- return frameNo / mTimeStreatch;
+ return int(frameNo / mTimeStreatch);
}
class LOTFillData : public LOTData
Intersect,
Difference
};
- float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;}
+ float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0f;}
bool isStatic() const {return mIsStatic;}
public:
LOTAnimatable<LottieShapeData> mShape;
};
LOTPolystarData():LOTPath(LOTData::Type::Polystar){}
public:
- LOTPolystarData::PolyType mType{PolyType::Polygon};
+ LOTPolystarData::PolyType mPolyType{PolyType::Polygon};
LOTAnimatable<VPointF> mPos;
LOTAnimatable<float> mPointCount{0};
LOTAnimatable<float> mInnerRadius{0};
Segment segment(int frameNo) const {
float start = mStart.value(frameNo)/100.0f;
float end = mEnd.value(frameNo)/100.0f;
- float offset = fmod(mOffset.value(frameNo), 360.0f)/ 360.0f;
+ float offset = std::fmod(mOffset.value(frameNo), 360.0f)/ 360.0f;
- float diff = fabs(start - end);
+ float diff = std::abs(start - end);
if (vCompare(diff, 0.0f)) return Segment(0, 0);
if (vCompare(diff, 1.0f)) return Segment(0, 1);
v_.SetInt64(i);
return true;
}
- bool Uint64(uint64_t u)
+ bool Uint64(int64_t u)
{
st_ = kHasNumber;
v_.SetUint64(u);
protected:
explicit LookaheadParserHandler(char *str);
- void ParseNext();
protected:
enum LookaheadParsingState {
static const int parseFlags = kParseDefaultFlags | kParseInsituFlag;
};
-class LottieParserImpl : protected LookaheadParserHandler {
+class LottieParserImpl : public LookaheadParserHandler {
public:
LottieParserImpl(char *str, const char *dir_path)
: LookaheadParserHandler(str), mDirPath(dir_path)
{
+ ParseNext();
}
-
+ void ParseNext();
public:
bool EnterObject();
bool EnterArray();
void SkipArray();
void SkipValue();
Value *PeekValue();
- int PeekType(); // returns a rapidjson::Type, or -1 for no value (at end of
- // object/array)
-
+ int PeekType() const;
bool IsValid() { return st_ != kError; }
void Skip(const char *key);
: v_(), st_(kInit), r_(), ss_(str)
{
r_.IterativeParseInit();
- ParseNext();
}
-void LookaheadParserHandler::ParseNext()
+void LottieParserImpl::ParseNext()
{
if (r_.HasParseError()) {
st_ = kError;
// #ifdef DEBUG_PARSER
// vDebug<<"Object: Exiting nested loop";
// #endif
- return 0;
+ return nullptr;
}
if (st_ != kExitingObject) {
RAPIDJSON_ASSERT(false);
st_ = kError;
- return 0;
+ return nullptr;
}
ParseNext();
- return 0;
+ return nullptr;
}
bool LottieParserImpl::NextArrayValue()
if (st_ != kHasString) {
st_ = kError;
RAPIDJSON_ASSERT(false);
- return 0;
+ return nullptr;
}
const char *result = v_.GetString();
return &v_;
}
- return 0;
+ return nullptr;
}
-int LottieParserImpl::PeekType()
+// returns a rapidjson::Type, or -1 for no value (at end of
+// object/array)
+int LottieParserImpl::PeekType() const
{
if (st_ >= kHasNull && st_ <= kHasKey) {
return v_.GetType();
25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
-std::string b64decode(const void *data, const size_t len)
+std::string b64decode(const char *data, const size_t len)
{
- unsigned char *p = (unsigned char *)data;
+ auto p = reinterpret_cast<const unsigned char *>(data);
int pad = len > 0 && (len % 4 || p[len - 1] == '=');
const size_t L = ((len + 3) / 4 - pad) * 4;
std::string str(L / 4 * 3 + pad, '\0');
LottieColor LottieParserImpl::toColor(const char *str)
{
LottieColor color;
- int len = strlen(str);
+ auto len = strlen(str);
// some resource has empty color string
// return a default color for those cases.
char tmp[3] = {'\0', '\0', '\0'};
tmp[0] = str[1];
tmp[1] = str[2];
- color.r = std::strtol(tmp, NULL, 16) / 255.0;
+ color.r = std::strtol(tmp, nullptr, 16) / 255.0f;
tmp[0] = str[3];
tmp[1] = str[4];
- color.g = std::strtol(tmp, NULL, 16) / 255.0;
+ color.g = std::strtol(tmp, nullptr, 16) / 255.0f;
tmp[0] = str[5];
tmp[1] = str[6];
- color.b = std::strtol(tmp, NULL, 16) / 255.0;
+ color.b = std::strtol(tmp, nullptr, 16) / 255.0f;
return color;
}
parseProperty(obj->mRotation);
} else if (0 == strcmp(key, "sy")) {
int starType = GetInt();
- if (starType == 1) obj->mType = LOTPolystarData::PolyType::Star;
- if (starType == 2) obj->mType = LOTPolystarData::PolyType::Polygon;
+ if (starType == 1) obj->mPolyType = LOTPolystarData::PolyType::Star;
+ if (starType == 2) obj->mPolyType = LOTPolystarData::PolyType::Polygon;
} else if (0 == strcmp(key, "d")) {
obj->mDirection = GetInt();
} else if (0 == strcmp(key, "hd")) {
vCritical << "The Shape data are corrupted";
points = std::vector<VPointF>();
} else {
- int size = vertices.size();
+ auto size = vertices.size();
points.reserve(3 * size + 4);
points.push_back(vertices[0]);
- for (int i = 1; i < size; i++) {
+ for (size_t i = 1; i < size; i++) {
points.push_back(vertices[i - 1] +
outPoint[i - 1]); // CP1 = start + outTangent
points.push_back(vertices[i] +
}
}
-#if LOTTIE_DUMP_TREE_SUPPORT
+#ifdef LOTTIE_DUMP_TREE_SUPPORT
class LOTDataInspector {
public:
#endif
-LottieParser::~LottieParser()
-{
- delete d;
-}
-
+LottieParser::~LottieParser() = default;
LottieParser::LottieParser(char *str, const char *dir_path)
- : d(new LottieParserImpl(str, dir_path))
+ : d(std::make_unique<LottieParserImpl>(str, dir_path))
{
d->parseComposition();
}