python-lottie  0.6.11+deved4e6c7
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_roundfloat_round = float_round
10  self.remove_attributesremove_attributes = remove_attributes
11 
12  def round(self, fl):
13  return round(fl, self.float_roundfloat_round)
14 
15  def nvector(self, value):
16  value.components = list(map(self.roundround, 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.nvectornvector(NVector(p.x, p.y)) for p in getattr(value, l)])
23  elif property.lottie in self.remove_attributesremove_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.nvectornvector(value)
29 
30 
32  def visit(self, object):
33  if isinstance(object, Transform):
34  self.transform_unsettransform_unset(object, "anchor_point", NVector(0, 0))
35  self.transform_unsettransform_unset(object, "position", NVector(0, 0))
36  #self.transform_unset(object, "scale", NVector(100, 100))
37  self.transform_unsettransform_unset(object, "rotation", 0)
38  #self.transform_unset(object, "opacity", 100)
39  self.transform_unsettransform_unset(object, "skew", 0)
40  self.transform_unsettransform_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)
def __init__(self, float_round, remove_attributes={})
Definition: stripper.py:8
def visit_property(self, object, property, value)
Definition: stripper.py:19
def nvector(self, value)
Definition: stripper.py:15
def transform_unset(self, object, prop_name, value)
Definition: stripper.py:42