示例#1
0
        internal static Mask Parse(JsonReader reader, LottieComposition composition)
        {
            var maskMode = Mask.MaskMode.MaskModeAdd;
            AnimatableShapeValue   maskPath = null;
            AnimatableIntegerValue opacity  = null;

            reader.BeginObject();
            while (reader.HasNext())
            {
                var mode = reader.NextName();
                switch (mode)
                {
                case "mode":
                    switch (reader.NextString())
                    {
                    case "a":
                        maskMode = Mask.MaskMode.MaskModeAdd;
                        break;

                    case "s":
                        maskMode = Mask.MaskMode.MaskModeSubtract;
                        break;

                    case "i":
                        composition.AddWarning(
                            "Animation contains intersect masks. They are not supported but will be treated like add masks.");
                        maskMode = Mask.MaskMode.MaskModeIntersect;
                        break;

                    default:
                        Debug.WriteLine($"Unknown mask mode {mode}. Defaulting to Add.", LottieLog.Tag);
                        maskMode = Mask.MaskMode.MaskModeAdd;
                        break;
                    }

                    break;

                case "pt":
                    maskPath = AnimatableValueParser.ParseShapeData(reader, composition);
                    break;

                case "o":
                    opacity = AnimatableValueParser.ParseInteger(reader, composition);
                    break;

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

            reader.EndObject();

            return(new Mask(maskMode, maskPath, opacity));
        }
        internal static ShapeFill Parse(JsonReader reader, LottieComposition composition)
        {
            AnimatableColorValue color     = null;
            bool fillEnabled               = false;
            AnimatableIntegerValue opacity = null;
            string name        = null;
            int    fillTypeInt = 1;

            bool hidden = false;

            while (reader.HasNext())
            {
                switch (reader.NextName())
                {
                case "nm":
                    name = reader.NextString();
                    break;

                case "c":
                    color = AnimatableValueParser.ParseColor(reader, composition);
                    break;

                case "o":
                    opacity = AnimatableValueParser.ParseInteger(reader, composition);
                    break;

                case "fillEnabled":
                    fillEnabled = reader.NextBoolean();
                    break;

                case "r":
                    fillTypeInt = reader.NextInt();
                    break;

                case "hd":
                    hidden = reader.NextBoolean();
                    break;

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

            var fillType = fillTypeInt == 1 ? SKPathFillType.Winding : SKPathFillType.EvenOdd;

            return(new ShapeFill(name, fillEnabled, fillType, color, opacity, hidden));
        }
示例#3
0
        internal static ShapeStroke Parse(JsonReader reader, LottieComposition composition)
        {
            string name = null;
            AnimatableColorValue   color   = null;
            AnimatableFloatValue   width   = null;
            AnimatableIntegerValue opacity = null;

            ShapeStroke.LineCapType  capType  = ShapeStroke.LineCapType.Unknown;
            ShapeStroke.LineJoinType joinType = ShapeStroke.LineJoinType.Round;
            AnimatableFloatValue     offset   = null;
            float miterLimit = 0f;

            List <AnimatableFloatValue> lineDashPattern = new List <AnimatableFloatValue>();


            bool hidden = false;

            while (reader.HasNext())
            {
                switch (reader.NextName())
                {
                case "nm":
                    name = reader.NextString();
                    break;

                case "c":
                    color = AnimatableValueParser.ParseColor(reader, composition);
                    break;

                case "w":
                    width = AnimatableValueParser.ParseFloat(reader, composition);
                    break;

                case "o":
                    opacity = AnimatableValueParser.ParseInteger(reader, composition);
                    break;

                case "lc":
                    capType = (ShapeStroke.LineCapType)(reader.NextInt() - 1);
                    break;

                case "lj":
                    joinType = (ShapeStroke.LineJoinType)(reader.NextInt() - 1);
                    break;

                case "ml":
                    miterLimit = reader.NextDouble();
                    break;

                case "d":
                    reader.BeginArray();
                    while (reader.HasNext())
                    {
                        String n = null;
                        AnimatableFloatValue val = null;

                        reader.BeginObject();
                        while (reader.HasNext())
                        {
                            switch (reader.NextName())
                            {
                            case "n":
                                n = reader.NextString();
                                break;

                            case "v":
                                val = AnimatableValueParser.ParseFloat(reader, composition);
                                break;

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

                        switch (n)
                        {
                        case "o":
                            offset = val;
                            break;

                        case "d":
                        case "g":
                            lineDashPattern.Add(val);
                            break;
                        }
                    }
                    reader.EndArray();

                    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]);
                    }
                    break;

                case "hd":
                    hidden = reader.NextBoolean();
                    break;

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

            return(new ShapeStroke(name, offset, lineDashPattern, color, opacity, width, capType, joinType, miterLimit, hidden));
        }
        internal static GradientStroke Parse(JsonReader reader, LottieComposition composition)
        {
            string name = null;
            AnimatableGradientColorValue color   = null;
            AnimatableIntegerValue       opacity = null;
            var gradientType = GradientType.Linear;
            AnimatablePointValue startPoint = null;
            AnimatablePointValue endPoint   = null;
            AnimatableFloatValue width      = null;
            var capType  = ShapeStroke.LineCapType.Unknown;
            var joinType = ShapeStroke.LineJoinType.Round;
            AnimatableFloatValue offset = null;
            var miterLimit = 0f;

            var lineDashPattern = new List <AnimatableFloatValue>();

            while (reader.HasNext())
            {
                switch (reader.NextName())
                {
                case "nm":
                    name = reader.NextString();
                    break;

                case "g":
                    var points = -1;
                    reader.BeginObject();
                    while (reader.HasNext())
                    {
                        switch (reader.NextName())
                        {
                        case "p":
                            points = reader.NextInt();
                            break;

                        case "k":
                            color = AnimatableValueParser.ParseGradientColor(reader, composition, points);
                            break;

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

                    reader.EndObject();
                    break;

                case "o":
                    opacity = AnimatableValueParser.ParseInteger(reader, composition);
                    break;

                case "t":
                    gradientType = reader.NextInt() == 1 ? GradientType.Linear : GradientType.Radial;
                    break;

                case "s":
                    startPoint = AnimatableValueParser.ParsePoint(reader, composition);
                    break;

                case "e":
                    endPoint = AnimatableValueParser.ParsePoint(reader, composition);
                    break;

                case "w":
                    width = AnimatableValueParser.ParseFloat(reader, composition);
                    break;

                case "lc":
                    capType = (ShapeStroke.LineCapType)(reader.NextInt() - 1);
                    break;

                case "lj":
                    joinType = (ShapeStroke.LineJoinType)(reader.NextInt() - 1);
                    break;

                case "ml":
                    miterLimit = reader.NextDouble();
                    break;

                case "d":
                    reader.BeginArray();
                    while (reader.HasNext())
                    {
                        string n = null;
                        AnimatableFloatValue val = null;
                        reader.BeginObject();
                        while (reader.HasNext())
                        {
                            switch (reader.NextName())
                            {
                            case "n":
                                n = reader.NextString();
                                break;

                            case "v":
                                val = AnimatableValueParser.ParseFloat(reader, composition);
                                break;

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

                        reader.EndObject();

                        if (n.Equals("o"))
                        {
                            offset = val;
                        }
                        else if (n.Equals("d") || n.Equals("g"))
                        {
                            lineDashPattern.Add(val);
                        }
                    }

                    reader.EndArray();
                    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]);
                    }
                    break;

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

            return(new GradientStroke(
                       name, gradientType, color, opacity, startPoint, endPoint, width, capType, joinType,
                       miterLimit, lineDashPattern, offset));
        }
        public static AnimatableTransform Parse(JsonReader reader, LottieComposition composition)
        {
            AnimatablePathValue anchorPoint = null;
            IAnimatableValue <Vector2?, Vector2?> position = null;
            AnimatableScaleValue   scale        = null;
            AnimatableFloatValue   rotation     = null;
            AnimatableIntegerValue opacity      = null;
            AnimatableFloatValue   startOpacity = null;
            AnimatableFloatValue   endOpacity   = null;

            bool isObject = reader.Peek() == JsonToken.StartObject;

            if (isObject)
            {
                reader.BeginObject();
            }
            while (reader.HasNext())
            {
                switch (reader.NextName())
                {
                case "a":
                    reader.BeginObject();
                    while (reader.HasNext())
                    {
                        if (reader.NextName().Equals("k"))
                        {
                            anchorPoint = AnimatablePathValueParser.Parse(reader, composition);
                        }
                        else
                        {
                            reader.SkipValue();
                        }
                    }
                    reader.EndObject();
                    break;

                case "p":
                    position = AnimatablePathValueParser.ParseSplitPath(reader, composition);
                    break;

                case "s":
                    scale = AnimatableValueParser.ParseScale(reader, composition);
                    break;

                case "rz":
                    composition.AddWarning("Lottie doesn't support 3D layers.");
                    rotation = AnimatableValueParser.ParseFloat(reader, composition, false);
                    break;

                case "r":
                    rotation = AnimatableValueParser.ParseFloat(reader, composition, false);
                    break;

                case "o":
                    opacity = AnimatableValueParser.ParseInteger(reader, composition);
                    break;

                case "so":
                    startOpacity = AnimatableValueParser.ParseFloat(reader, composition, false);
                    break;

                case "eo":
                    endOpacity = AnimatableValueParser.ParseFloat(reader, composition, false);
                    break;

                default:
                    reader.SkipValue();
                    break;
                }
            }
            if (isObject)
            {
                reader.EndObject();
            }

            if (anchorPoint == null)
            {
                // Cameras don't have an anchor point property. Although we don't support them, at least
                // we won't crash.
                Debug.WriteLine("Layer has no transform property. You may be using an unsupported layer type such as a camera.", LottieLog.Tag);
                anchorPoint = new AnimatablePathValue();
            }

            if (scale == null)
            {
                // Somehow some community animations don't have scale in the transform.
                scale = new AnimatableScaleValue(new ScaleXy(1f, 1f));
            }

            if (opacity == null)
            {
                // Repeaters have start/end opacity instead of opacity
                opacity = new AnimatableIntegerValue();
            }

            return(new AnimatableTransform(
                       anchorPoint, position, scale, rotation, opacity, startOpacity, endOpacity));
        }
示例#6
0
        internal static GradientFill Parse(JsonReader reader, LottieComposition composition)
        {
            string name = null;
            AnimatableGradientColorValue color   = null;
            AnimatableIntegerValue       opacity = null;
            var gradientType = GradientType.Linear;
            AnimatablePointValue startPoint = null;
            AnimatablePointValue endPoint   = null;
            var fillType = PathFillType.EvenOdd;

            while (reader.HasNext())
            {
                switch (reader.NextName())
                {
                case "nm":
                    name = reader.NextString();
                    break;

                case "g":
                    var points = -1;
                    reader.BeginObject();
                    while (reader.HasNext())
                    {
                        switch (reader.NextName())
                        {
                        case "p":
                            points = reader.NextInt();
                            break;

                        case "k":
                            color = AnimatableValueParser.ParseGradientColor(reader, composition, points);
                            break;

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

                    reader.EndObject();
                    break;

                case "o":
                    opacity = AnimatableValueParser.ParseInteger(reader, composition);
                    break;

                case "t":
                    gradientType = reader.NextInt() == 1 ? GradientType.Linear : GradientType.Radial;
                    break;

                case "s":
                    startPoint = AnimatableValueParser.ParsePoint(reader, composition);
                    break;

                case "e":
                    endPoint = AnimatableValueParser.ParsePoint(reader, composition);
                    break;

                case "r":
                    fillType = reader.NextInt() == 1 ? PathFillType.Winding : PathFillType.EvenOdd;
                    break;

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

            return(new GradientFill(
                       name, gradientType, fillType, color, opacity, startPoint, endPoint, null, null));
        }