File indexing completed on 2025-01-19 03:59:52

0001 from .base import LottieObject, LottieProp, LottieEnum
0002 from .properties import Value, MultiDimensional
0003 from ..nvector import NVector
0004 from .helpers import Transform
0005 
0006 
0007 ## @ingroup Lottie
0008 ## @ingroup LottieCheck
0009 class MaskedPath(LottieObject):
0010     _props = [
0011         LottieProp("mask", "m", float),
0012         LottieProp("f", "f", Value),
0013         LottieProp("l", "l", Value),
0014         LottieProp("r", "r", float),
0015     ]
0016 
0017     def __init__(self):
0018         ## Type?
0019         self.mask = None
0020         ## First?
0021         self.f = None
0022         ## Last?
0023         self.l = None
0024         ## ??
0025         self.r = None
0026 
0027 
0028 ## @ingroup Lottie
0029 ## @ingroup LottieCheck
0030 class TextAnimatorDataProperty(Transform):
0031     _props = [
0032         LottieProp("rx", "rx", Value),
0033         LottieProp("ry", "ry", Value),
0034         LottieProp("stroke_width", "sw", Value),
0035         LottieProp("stroke_color", "sc", MultiDimensional),
0036         LottieProp("fill_color", "fc", MultiDimensional),
0037         LottieProp("fh", "fh", Value),
0038         LottieProp("fs", "fs", Value),
0039         LottieProp("fb", "fb", Value),
0040         LottieProp("tracking", "t", Value),
0041         LottieProp("scale", "s", MultiDimensional),
0042     ]
0043 
0044     def __init__(self):
0045         super().__init__()
0046         ## Angle?
0047         self.rx = Value()
0048         ## Angle?
0049         self.ry = Value()
0050         ## Stroke width
0051         self.stroke_width = Value()
0052         ## Stroke color
0053         self.stroke_color = MultiDimensional()
0054         ## Fill color
0055         self.fill_color = MultiDimensional()
0056         self.fh = Value()
0057         ## 0-100?
0058         self.fs = Value()
0059         ## 0-100?
0060         self.fb = Value()
0061         ## Tracking
0062         self.tracking = Value()
0063 
0064 
0065 ## @ingroup Lottie
0066 ## @ingroup LottieCheck
0067 class TextMoreOptions(LottieObject):
0068     _props = [
0069         LottieProp("alignment", "a", MultiDimensional),
0070         LottieProp("g", "g", float),
0071     ]
0072 
0073     def __init__(self):
0074         self.alignment = MultiDimensional(NVector(0, 0))
0075         self.g = None
0076 
0077 
0078 ## @ingroup Lottie
0079 class TextJustify(LottieEnum):
0080     Left = 0
0081     Right = 1
0082     Center = 2
0083 
0084 
0085 ## @ingroup Lottie
0086 class TextDocument(LottieObject):
0087     """!
0088     @see http://docs.aenhancers.com/other/textdocument/
0089     """
0090     _props = [
0091         LottieProp("font_family", "f", str),
0092         LottieProp("color", "fc", NVector),
0093         LottieProp("font_size", "s", float),
0094         LottieProp("line_height", "lh", float),
0095         LottieProp("wrap_size", "sz", NVector),
0096         LottieProp("text", "t", str),
0097         LottieProp("justify", "j", TextJustify),
0098         # ls?
0099     ]
0100 
0101     def __init__(self, text="", font_size=10, color=None, font_family=""):
0102         self.font_family = font_family
0103         ## Text color
0104         self.color = color or NVector(0, 0, 0)
0105         ## Line height when wrapping
0106         self.line_height = None
0107         ## Text alignment
0108         self.justify = TextJustify.Left
0109         ## Size of the box containing the text
0110         self.wrap_size = None
0111         ## Text
0112         self.text = text
0113         ## Font Size
0114         self.font_size = font_size
0115 
0116 
0117 ## @ingroup Lottie
0118 class TextDataKeyframe(LottieObject):
0119     _props = [
0120         LottieProp("start", "s", TextDocument),
0121         LottieProp("time", "t", float),
0122     ]
0123 
0124     def __init__(self, time=0, start=None):
0125         ## Start value of keyframe segment.
0126         self.start = start
0127         ## Start time of keyframe segment.
0128         self.time = time
0129 
0130 
0131 ## @ingroup Lottie
0132 class TextData(LottieObject):
0133     _props = [
0134         LottieProp("keyframes", "k", TextDataKeyframe, True),
0135     ]
0136 
0137     def __init__(self):
0138         self.keyframes = []
0139 
0140     def get_value(self, time):
0141         for kf in self.keyframes:
0142             if kf.time >= time:
0143                 return kf.start
0144         return None
0145 
0146 
0147 ## @ingroup Lottie
0148 class TextAnimatorData(LottieObject):
0149     _props = [
0150         LottieProp("properties", "a", TextAnimatorDataProperty, True),
0151         LottieProp("data", "d", TextData, False),
0152         LottieProp("more_options", "m", TextMoreOptions, False),
0153         LottieProp("masked_path", "p", MaskedPath),
0154     ]
0155 
0156     def __init__(self):
0157         self.properties = []
0158         self.data = TextData()
0159         self.more_options = TextMoreOptions()
0160         self.masked_path = MaskedPath()
0161 
0162     def add_keyframe(self, time, item):
0163         self.data.keyframes.append(TextDataKeyframe(time, item))
0164 
0165     def get_value(self, time):
0166         return self.data.get_value(time)
0167 
0168 
0169 ## @ingroup Lottie
0170 class FontPathOrigin(LottieEnum):
0171     CssUrl = 1
0172     ScriptUrl = 2
0173     FontUrl = 3
0174 
0175 
0176 ## @ingroup Lottie
0177 class Font(LottieObject):
0178     _props = [
0179         LottieProp("ascent", "ascent", float),
0180         LottieProp("font_family", "fFamily", str),
0181         LottieProp("name", "fName", str),
0182         LottieProp("font_style", "fStyle", str),
0183         LottieProp("path", "fPath", str),
0184         LottieProp("weight", "fWeight", str),
0185         LottieProp("origin", "origin", FontPathOrigin),
0186     ]
0187 
0188     def __init__(self, font_family="sans", font_style="Regular", name=None):
0189         self.ascent = None
0190         self.font_family = font_family
0191         self.font_style = font_style
0192         self.name = name or "%s-%s" % (font_family, font_style)
0193         self.path = None
0194         self.weight = None
0195         self.origin = None
0196 
0197 
0198 ## @ingroup Lottie
0199 class FontList(LottieObject):
0200     _props = [
0201         LottieProp("list", "list", Font, True),
0202     ]
0203 
0204     def __init__(self):
0205         self.list = []
0206 
0207     def append(self, font):
0208         self.list.append(font)