Пример #1
0
            internal static AnimatableShapeValue NewInstance(JsonObject json, LottieComposition composition)
            {
                var result = AnimatableValueParser <ShapeData> .NewInstance(json, composition.DpScale, composition, ShapeData.Factory.Instance).ParseJson();

                return(new AnimatableShapeValue(result.Keyframes, result.InitialValue));
            }
        private static LottieResult <LottieComposition> FromZipStreamSyncInternal(ZipArchive inputStream, string cacheKey)
        {
            LottieComposition             composition = null;
            Dictionary <string, SKBitmap> images      = new Dictionary <string, SKBitmap>();

            try
            {
                foreach (ZipArchiveEntry entry in inputStream.Entries)
                {
                    if (entry.FullName.Contains("__MACOSX"))
                    {
                        continue;
                    }
                    else if (entry.FullName.Contains(".json"))
                    {
                        composition = FromJsonInputStreamSync(entry.Open(), cacheKey, false).Value;
                    }
                    else if (entry.FullName.Contains(".png"))
                    {
                        string[] splitName = entry.FullName.Split('/');
                        string   name      = splitName[splitName.Length - 1];
                        using (var stream = entry.Open())
                        {
                            var bitmap = SKBitmap.Decode(stream);
                            images[name] = bitmap;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            catch (IOException e)
            {
                return(new LottieResult <LottieComposition>(e));
            }

            if (composition == null)
            {
                return(new LottieResult <LottieComposition>(new ArgumentException("Unable to parse composition")));
            }

            foreach (var e in images)
            {
                LottieImageAsset imageAsset = FindImageAssetForFileName(composition, e.Key);
                if (imageAsset != null)
                {
                    imageAsset.Bitmap = e.Value;
                }
            }

            // Ensure that all bitmaps have been set.
            foreach (var entry in composition.Images)
            {
                if (entry.Value.Bitmap == null)
                {
                    return(new LottieResult <LottieComposition>(new ArgumentException("There is no image for " + entry.Value.FileName)));
                }
            }

            LottieCompositionCache.Instance.Put(cacheKey, composition);
            return(new LottieResult <LottieComposition>(composition));
        }
Пример #3
0
            internal static GradientStroke NewInstance(JsonObject json, LottieComposition composition)
            {
                var name      = json.GetNamedString("nm");
                var jsonColor = json.GetNamedObject("g", null);

                if (jsonColor != null && jsonColor.ContainsKey("k"))
                {
                    jsonColor = jsonColor.GetNamedObject("k");
                }
                AnimatableGradientColorValue color = null;

                if (jsonColor != null)
                {
                    color = AnimatableGradientColorValue.Factory.NewInstance(jsonColor, composition);
                }

                var jsonOpacity = json.GetNamedObject("o", null);
                AnimatableIntegerValue opacity = null;

                if (jsonOpacity != null)
                {
                    opacity = AnimatableIntegerValue.Factory.NewInstance(jsonOpacity, composition);
                }

                var gradientTypeInt = (int)json.GetNamedNumber("t", 1);
                var gradientType    = gradientTypeInt == 1 ? GradientType.Linear : GradientType.Radial;

                var jsonStartPoint = json.GetNamedObject("s", null);
                AnimatablePointValue startPoint = null;

                if (jsonStartPoint != null)
                {
                    startPoint = AnimatablePointValue.Factory.NewInstance(jsonStartPoint, composition);
                }

                var jsonEndPoint = json.GetNamedObject("e", null);
                AnimatablePointValue endPoint = null;

                if (jsonEndPoint != null)
                {
                    endPoint = AnimatablePointValue.Factory.NewInstance(jsonEndPoint, composition);
                }
                var width = AnimatableFloatValue.Factory.NewInstance(json.GetNamedObject("w"), composition);


                var capType  = (ShapeStroke.LineCapType)(int)(json.GetNamedNumber("lc") - 1);
                var joinType = (ShapeStroke.LineJoinType)(int)(json.GetNamedNumber("lj") - 1);

                AnimatableFloatValue         offset          = null;
                IList <AnimatableFloatValue> lineDashPattern = new List <AnimatableFloatValue>();

                if (json.ContainsKey("d"))
                {
                    var dashesJson = json.GetNamedArray("d");
                    for (var i = 0; i < dashesJson.Count; i++)
                    {
                        var dashJson = dashesJson[i].GetObject();
                        var n        = dashJson.GetNamedString("n");
                        if (n.Equals("o"))
                        {
                            var value = dashJson.GetNamedObject("v");
                            offset = AnimatableFloatValue.Factory.NewInstance(value, composition);
                        }
                        else if (n.Equals("d") || n.Equals("g"))
                        {
                            var value = dashJson.GetNamedObject("v");
                            lineDashPattern.Add(AnimatableFloatValue.Factory.NewInstance(value, composition));
                        }
                    }
                    if (lineDashPattern.Count == 1)
                    {
                        // If there is only 1 value then it is assumed to be equal parts on and off.
                        lineDashPattern.Add(lineDashPattern[0]);
                    }
                }

                return(new GradientStroke(name, gradientType, color, opacity, startPoint, endPoint, width, capType, joinType, lineDashPattern, offset));
            }
Пример #4
0
 internal static RectangleShape NewInstance(JsonObject json, LottieComposition composition)
 {
     return(new RectangleShape(json.GetNamedString("nm"), AnimatablePathValue.CreateAnimatablePathOrSplitDimensionPath(json.GetNamedObject("p"), composition), AnimatablePointValue.Factory.NewInstance(json.GetNamedObject("s"), composition), AnimatableFloatValue.Factory.NewInstance(json.GetNamedObject("r"), composition)));
 }
Пример #5
0
            internal static ShapePath NewInstance(JsonObject json, LottieComposition composition)
            {
                var animatableShapeValue = AnimatableShapeValue.Factory.NewInstance(json.GetNamedObject("ks"), composition);

                return(new ShapePath(json.GetNamedString("nm"), (int)json.GetNamedNumber("ind"), animatableShapeValue));
            }