private LottieComposition CreateComposition(int startFrame, int endFrame)
        {
            var composition = new LottieComposition();

            composition.Init(new Rect(), startFrame, endFrame, 1000, new List <Layer>(),
                             new Dictionary <long, Layer>(0), new Dictionary <string, List <Layer> >(0),
                             new Dictionary <string, LottieImageAsset>(0), new Dictionary <int, FontCharacter>(0),
                             new Dictionary <string, Font>(0));
            return(composition);
        }
示例#2
0
        public LottieValueAnimatorUnitTest()
        {
            LottieComposition composition = new LottieComposition();

            composition.Init(new Rect(), 0, 1000, 1000, new List <Layer>(),
                             new Dictionary <long, Layer>(0), new Dictionary <string, List <Layer> >(0),
                             new Dictionary <string, LottieImageAsset>(0), new Dictionary <int, FontCharacter>(0),
                             new Dictionary <string, Font>(0));
            _mockAnimator = new Mock <TestLottieValueAnimator>
            {
                CallBase = true,
            };
            _animator             = _mockAnimator.Object;
            _animator.Composition = composition;

            isDone = false;
        }
        public static LottieComposition Parse(JsonReader reader)
        {
            var   scale      = Utils.Utils.DpScale();
            float startFrame = 0f;
            float endFrame   = 0f;
            float frameRate  = 0f;
            Dictionary <long, Layer> layerMap = new Dictionary <long, Layer>();
            List <Layer>             layers   = new List <Layer>();
            int width  = 0;
            int height = 0;
            Dictionary <string, List <Layer> >    precomps   = new Dictionary <string, List <Layer> >();
            Dictionary <string, LottieImageAsset> images     = new Dictionary <string, LottieImageAsset>();
            Dictionary <string, Font>             fonts      = new Dictionary <string, Font>();
            Dictionary <int, FontCharacter>       characters = new Dictionary <int, FontCharacter>();
            var composition = new LottieComposition();

            reader.BeginObject();
            while (reader.HasNext())
            {
                switch (reader.NextName())
                {
                case "w":
                    width = reader.NextInt();
                    break;

                case "h":
                    height = reader.NextInt();
                    break;

                case "ip":
                    startFrame = reader.NextDouble();
                    break;

                case "op":
                    endFrame = reader.NextDouble() - 0.01f;
                    break;

                case "fr":
                    frameRate = reader.NextDouble();
                    break;

                case "v":
                    var version      = reader.NextString();
                    var versions     = Regex.Split(version, "\\.");
                    var majorVersion = int.Parse(versions[0]);
                    var minorVersion = int.Parse(versions[1]);
                    var patchVersion = int.Parse(versions[2]);
                    if (!Utils.Utils.IsAtLeastVersion(majorVersion, minorVersion, patchVersion, 4, 4, 0))
                    {
                        composition.AddWarning("Lottie only supports bodymovin >= 4.4.0");
                    }
                    break;

                case "layers":
                    ParseLayers(reader, composition, layers, layerMap);
                    break;

                case "assets":
                    ParseAssets(reader, composition, precomps, images);
                    break;

                case "fonts":
                    ParseFonts(reader, fonts);
                    break;

                case "chars":
                    ParseChars(reader, composition, characters);
                    break;

                default:
                    reader.SkipValue();
                    break;
                }
            }
            reader.EndObject();

            int  scaledWidth  = (int)(width * scale);
            int  scaledHeight = (int)(height * scale);
            Rect bounds       = new Rect(0, 0, scaledWidth, scaledHeight);

            composition.Init(bounds, startFrame, endFrame, frameRate, layers, layerMap, precomps, images, characters, fonts);

            return(composition);
        }