Example #1
0
        /// <summary>
        /// Creates a <see cref="LayerTranslator"/> for the given Lottie layer.
        /// </summary>
        /// <returns>The <see cref="LayerTranslator"/> that will translate the
        /// given Lottie layer to a Shape or a Visual.</returns>
        static LayerTranslator CreateTranslatorForLayer(CompositionContext context, Layer layer)
        {
            if (layer.Is3d)
            {
                context.Issues.ThreeDLayerIsNotSupported();
            }

            if (layer.BlendMode != BlendMode.Normal)
            {
                context.Issues.BlendModeNotNormal(layer.Name, layer.BlendMode.ToString());
            }

            if (layer.TimeStretch != 1)
            {
                context.Issues.TimeStretchIsNotSupported();
            }

            if (layer.IsHidden)
            {
                return(null);
            }

            switch (layer.Type)
            {
            case Layer.LayerType.Image:
                return(Images.CreateImageLayerTranslator(context.CreateLayerContext((ImageLayer)layer)));

            case Layer.LayerType.Null:
                // Null layers only exist to hold transforms when declared as parents of other layers.
                return(null);

            case Layer.LayerType.PreComp:
                return(PreComps.CreatePreCompLayerTranslator(context.CreateLayerContext((PreCompLayer)layer)));

            case Layer.LayerType.Shape:
                return(Shapes.CreateShapeLayerTranslator(context.CreateLayerContext((ShapeLayer)layer)));

            case Layer.LayerType.Solid:
                return(SolidLayers.CreateSolidLayerTranslator(context.CreateLayerContext((SolidLayer)layer)));

            case Layer.LayerType.Text:
                return(TextLayers.CreateTextLayerTranslator(context.CreateLayerContext((TextLayer)layer)));

            default:
                throw new InvalidOperationException();
            }
        }
Example #2
0
        static LayerTranslator?CreateTranslatorForLayer(CompositionContext context, Layer layer)
        {
            if (layer.IsHidden)
            {
                // Hidden layers don't need to be translated. Get out before checking
                // for any issues - we always render hidden layers correctly (by not
                // showing them) so they have no issues.
                return(null);
            }

            if (layer.InPoint >= layer.OutPoint)
            {
                // We currently don't support layers with InPoint after the OutPoint. In most
                // cases this would describe a layer that isn't visible, but if TimeStretch
                // is negative it is a layer that plays in reverse, so it is valid to have
                // the InPoint after the OutPoint.
                return(null);
            }

            if (layer.Is3d)
            {
                context.Issues.ThreeDLayerIsNotSupported();
            }

            if (layer.BlendMode != BlendMode.Normal)
            {
                context.Issues.BlendModeNotNormal(layer.Name, layer.BlendMode.ToString());
            }

            if (layer.TimeStretch != 1)
            {
                context.Issues.TimeStretchIsNotSupported();
            }

            return(layer.Type switch
            {
                Layer.LayerType.Image => Images.CreateImageLayerTranslator(context.CreateLayerContext((ImageLayer)layer)),

                // Null layers only exist to hold transforms when declared as parents of other layers.
                Layer.LayerType.Null => null,
                Layer.LayerType.PreComp => PreComps.CreatePreCompLayerTranslator(context.CreateLayerContext((PreCompLayer)layer)),
                Layer.LayerType.Shape => Shapes.CreateShapeLayerTranslator(context.CreateLayerContext((ShapeLayer)layer)),
                Layer.LayerType.Solid => SolidLayers.CreateSolidLayerTranslator(context.CreateLayerContext((SolidLayer)layer)),
                Layer.LayerType.Text => TextLayers.CreateTextLayerTranslator(context.CreateLayerContext((TextLayer)layer)),
                _ => throw new InvalidOperationException(),
            });