python-lottie  0.6.11+devcecd248
A framework to work with lottie files and telegram animated stickers (tgs)
stripper.py
Go to the documentation of this file.
1 from ..objects.base import LottieObject, ObjectVisitor
2 from ..objects.bezier import Bezier
3 from ..objects.helpers import Transform
4 from ..nvector import NVector
5 
6 
8  def __init__(self, float_round, remove_attributes={}):
9  self.float_round = float_round
10  self.remove_attributes = remove_attributes
11 
12  def round(self, fl):
13  return round(fl, self.float_round)
14 
15  def nvector(self, value):
16  value.components = list(map(self.round, value.components))
17  return value
18 
19  def visit_property(self, object, property, value):
20  if isinstance(value, Bezier):
21  for l in ["vertices", "in_tangents", "out_tangents"]:
22  setattr(value, l, [self.nvector(NVector(p.x, p.y)) for p in getattr(value, l)])
23  elif property.lottie in self.remove_attributes:
24  property.set(object, None)
25  elif isinstance(value, float):
26  property.set(object, round(value, 3))
27  elif isinstance(value, NVector):
28  self.nvector(value)
29 
30 
32  def visit(self, object):
33  if isinstance(object, Transform):
34  self.transform_unset(object, "anchor_point", NVector(0, 0))
35  self.transform_unset(object, "position", NVector(0, 0))
36  #self.transform_unset(object, "scale", NVector(100, 100))
37  self.transform_unset(object, "rotation", 0)
38  #self.transform_unset(object, "opacity", 100)
39  self.transform_unset(object, "skew", 0)
40  self.transform_unset(object, "skew_axis", 0)
41 
42  def transform_unset(self, object, prop_name, value):
43  prop = getattr(object, prop_name)
44  if prop and not prop.animated and prop.value == value:
45  setattr(object, prop_name, None)
46 
47 
48 heavy_strip = TransformStip(3, {"ind", "ix", "nm", "mn"})
49 float_strip = Strip(3)
lottie.utils.stripper.Strip.float_round
float_round
Definition: stripper.py:9
lottie.objects.base.ObjectVisitor
Definition: base.py:365
lottie.utils.stripper.Strip.nvector
def nvector(self, value)
Definition: stripper.py:15
lottie.utils.stripper.Strip.remove_attributes
remove_attributes
Definition: stripper.py:10
lottie.utils.stripper.Strip.__init__
def __init__(self, float_round, remove_attributes={})
Definition: stripper.py:8
lottie.utils.stripper.Strip.round
def round(self, fl)
Definition: stripper.py:12
lottie.utils.stripper.TransformStip.transform_unset
def transform_unset(self, object, prop_name, value)
Definition: stripper.py:42
lottie.utils.stripper.TransformStip
Definition: stripper.py:31
lottie.utils.stripper.Strip.visit_property
def visit_property(self, object, property, value)
Definition: stripper.py:19
lottie.utils.stripper.TransformStip.visit
def visit(self, object)
Definition: stripper.py:32
lottie.utils.stripper.Strip
Definition: stripper.py:7
lottie.nvector.NVector
Definition: nvector.py:9