diff --git a/src/lottie/lottieanimation.cpp b/src/lottie/lottieanimation.cpp index 2ff5dc49f7..18f07c1386 100644 --- a/src/lottie/lottieanimation.cpp +++ b/src/lottie/lottieanimation.cpp @@ -367,14 +367,9 @@ void Animation::setValue(Point_Type, Property prop, const std::string &keypath, d->setValue(keypath, LOTVariant(prop, value)); } +Animation::~Animation() = default; Animation::Animation() : d(std::make_unique()) {} -/* - * this is only to supress build fail - * because unique_ptr expects the destructor in the same translation unit. - */ -Animation::~Animation() {} - Surface::Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine) : mBuffer(buffer), diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index 173d77ec2f..831392d56b 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -1253,7 +1253,7 @@ void LOTPolystarItem::updatePath(VPath &path, int frameNo) path.reset(); VMatrix m; - if (mData->mType == LOTPolystarData::PolyType::Star) { + if (mData->mPolyType == LOTPolystarData::PolyType::Star) { path.addPolystar(points, innerRadius, outerRadius, innerRoundness, outerRoundness, 0.0, 0.0, 0.0, mData->direction()); } else { diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 87d23fe1cc..32edc92c35 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include"vpoint.h" #include"vrect.h" #include"vinterpolator.h" @@ -102,7 +102,7 @@ inline const LottieColor operator*(float m, const LottieColor &c) class LottieShapeData { public: - void reserve(int size) { + void reserve(size_t size) { mPoints.reserve(mPoints.size() + size); } void toPath(VPath& path) { @@ -110,23 +110,23 @@ public: 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 mPoints; - bool mClosed = false; /* "c" */ + std::vector mPoints; + bool mClosed = false; /* "c" */ }; @@ -617,7 +617,7 @@ inline int LOTLayerData::timeRemap(int frameNo) const * 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 @@ -797,7 +797,7 @@ public: 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 mShape; @@ -835,7 +835,7 @@ public: }; LOTPolystarData():LOTPath(LOTData::Type::Polystar){} public: - LOTPolystarData::PolyType mType{PolyType::Polygon}; + LOTPolystarData::PolyType mPolyType{PolyType::Polygon}; LOTAnimatable mPos; LOTAnimatable mPointCount{0}; LOTAnimatable mInnerRadius{0}; @@ -867,9 +867,9 @@ public: 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); diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 21a44d93dd..2fa32ebd15 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -95,7 +95,7 @@ public: v_.SetInt64(i); return true; } - bool Uint64(uint64_t u) + bool Uint64(int64_t u) { st_ = kHasNumber; v_.SetUint64(u); @@ -143,7 +143,6 @@ public: protected: explicit LookaheadParserHandler(char *str); - void ParseNext(); protected: enum LookaheadParsingState { @@ -168,13 +167,14 @@ protected: 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(); @@ -190,9 +190,7 @@ public: 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); @@ -280,10 +278,9 @@ LookaheadParserHandler::LookaheadParserHandler(char *str) : v_(), st_(kInit), r_(), ss_(str) { r_.IterativeParseInit(); - ParseNext(); } -void LookaheadParserHandler::ParseNext() +void LottieParserImpl::ParseNext() { if (r_.HasParseError()) { st_ = kError; @@ -338,17 +335,17 @@ const char *LottieParserImpl::NextObjectKey() // #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() @@ -431,7 +428,7 @@ const char *LottieParserImpl::GetString() if (st_ != kHasString) { st_ = kError; RAPIDJSON_ASSERT(false); - return 0; + return nullptr; } const char *result = v_.GetString(); @@ -476,10 +473,12 @@ Value *LottieParserImpl::PeekValue() 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(); @@ -621,9 +620,9 @@ static constexpr const unsigned char B64index[256] = { 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(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'); @@ -764,7 +763,7 @@ void LottieParserImpl::parseLayers(LOTCompositionData *comp) 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. @@ -776,15 +775,15 @@ LottieColor LottieParserImpl::toColor(const char *str) 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; } @@ -1233,8 +1232,8 @@ std::shared_ptr LottieParserImpl::parsePolystarObject() 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")) { @@ -1813,10 +1812,10 @@ void LottieParserImpl::getValue(LottieShapeData &obj) vCritical << "The Shape data are corrupted"; points = std::vector(); } 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] + @@ -2060,7 +2059,7 @@ void LottieParserImpl::parseProperty(LOTAnimatable &obj) } } -#if LOTTIE_DUMP_TREE_SUPPORT +#ifdef LOTTIE_DUMP_TREE_SUPPORT class LOTDataInspector { public: @@ -2243,13 +2242,9 @@ 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(str, dir_path)) { d->parseComposition(); } diff --git a/src/lottie/lottieparser.h b/src/lottie/lottieparser.h index 21e5ae8a43..35a84173bc 100644 --- a/src/lottie/lottieparser.h +++ b/src/lottie/lottieparser.h @@ -20,6 +20,7 @@ #define LOTTIEPARSER_H #include "lottiemodel.h" +#include class LottieParserImpl; class LottieParser { @@ -28,7 +29,7 @@ public: LottieParser(char* str, const char *dir_path); std::shared_ptr model(); private: - LottieParserImpl *d; + std::unique_ptr d; }; #endif // LOTTIEPARSER_H diff --git a/src/vector/vraster.cpp b/src/vector/vraster.cpp index 3f24e3dd70..1f9c1bb851 100644 --- a/src/vector/vraster.cpp +++ b/src/vector/vraster.cpp @@ -467,7 +467,7 @@ public: class RleTaskScheduler { public: - FTOutline outlineRef; + FTOutline outlineRef{}; SW_FT_Stroker stroker; public: