6 from ..parsers.tgs
import parse_tgs
7 from ..objects.base
import ObjectVisitor
8 from ..objects.animation
import Animation
9 from ..objects
import layers
10 from ..objects
import shapes
11 from ..objects
import helpers
21 def __init__(self, message, target, severity=Severity.Warning):
27 if isinstance(self.
targettarget, str):
29 if getattr(self.
targettarget,
"name",
""):
30 return self.
targettarget.name
31 return self.
targettarget.__class__.__name__
34 return "%s: on %s: %s" % (
46 def _check(self, expr, message, target, severity=Severity.Warning):
47 if severity.value >= self.
severityseverity.value
and not expr:
51 return self.
check_sizecheck_size(os.path.getsize(filename))
57 "Invalid size (%.1fk), should be less than 64k" % size_k,
66 except json.decoder.JSONDecodeError
as e:
69 "Invalid JSON: %s" % e,
75 for cls
in inspect.getmro(object.__class__):
76 callback =
"_visit_%s" % cls.__name__.lower()
77 if hasattr(self, callback):
78 getattr(self, callback)(object)
80 def _visit_animation(self, o: Animation):
82 o.frame_rate
in {30, 60},
83 "Invalid framerate %s, should be 30 or 60" % o.frame_rate,
89 "Invalid width %s, should be 512" % o.width,
95 "Invalid height %s, should be 512" % o.height,
100 (o.out_point-o.in_point) <= 180,
101 "Too many frames (%s), should be less than 180" % (o.out_point-o.in_point),
106 def _visit_layer(self, o: layers.Layer):
108 not o.has_masks
and not o.masks,
109 "Masks are not officially supported",
115 "Effects are not supported",
120 not o.threedimensional,
121 "3D layers are not supported",
126 not isinstance(o, layers.TextLayer),
127 "Text layers are not supported",
132 not isinstance(o, layers.ImageLayer),
133 "Image layers are not supported",
139 "Auto-orient layers are not supported",
144 o.matte_mode
in {
None, layers.MatteMode.Normal},
145 "Mattes are not supported",
150 def _visit_precomplayer(self, o: layers.PreCompLayer):
152 o.time_remapping
is None,
153 "Time remapping is not supported",
158 def _visit_merge(self, o: shapes.Merge):
161 "Merge paths are not supported",
166 def _visit_transform(self, o: helpers.Transform):
169 not o.skew.animated
and o.skew.value == 0
171 "Skew transforms are not supported",
176 def _visit_gradientstroke(self, o: shapes.GradientStroke):
179 "Gradient strokes are not officially supported",
184 def _visit_star(self, o: shapes.Star):
187 "Star Shapes are not officially supported",
192 def _visit_repeater(self, o: shapes.Repeater):
195 "Repeaters are not officially supported",
def __init__(self, message, target, severity=Severity.Warning)
def _check(self, expr, message, target, severity=Severity.Warning)
def check_file(self, filename)
def check_size(self, bytes, filename="file")
def check_file_size(self, filename)
def __init__(self, severity=Severity.Note)
def parse_tgs(filename, encoding="utf-8")
Reads both tgs and lottie files.