python-lottie  0.6.11+deva0e77a1
A framework to work with lottie files and telegram animated stickers (tgs)
text.py
Go to the documentation of this file.
1 from .base import LottieObject, LottieProp, LottieEnum
2 from .properties import Value, MultiDimensional, ColorValue, Color
3 from ..nvector import NVector
4 from .helpers import Transform
5 from .shapes import ShapeElement
6 
7 
8 ## @ingroup Lottie
9 ## @ingroup LottieCheck
11  _props = [
12  LottieProp("mask", "m", float),
13  LottieProp("f", "f", Value),
14  LottieProp("l", "l", Value),
15  LottieProp("r", "r", float),
16  ]
17 
18  def __init__(self):
19  ## Type?
20  self.maskmask = None
21  ## First?
22  self.ff = None
23  ## Last?
24  self.ll = None
25  ## ??
26  self.rr = None
27 
28 
29 ## @ingroup Lottie
30 ## @ingroup LottieCheck
32  _props = [
33  LottieProp("rotate_x", "rx", Value),
34  LottieProp("rotate_y", "ry", Value),
35  LottieProp("stroke_width", "sw", Value),
36  LottieProp("stroke_color", "sc", ColorValue),
37  LottieProp("fill_color", "fc", ColorValue),
38  LottieProp("fill_hue", "fh", Value),
39  LottieProp("fill_saturation", "fs", Value),
40  LottieProp("fill_brightness", "fb", Value),
41  LottieProp("tracking", "t", Value),
42  LottieProp("scale", "s", MultiDimensional),
43  ]
44 
45  def __init__(self):
46  super().__init__()
47  ## Angle?
48  self.rxrx = Value()
49  ## Angle?
50  self.ryry = Value()
51  ## Stroke width
52  self.stroke_widthstroke_width = Value()
53  ## Stroke color
54  self.stroke_colorstroke_color = MultiDimensional()
55  ## Fill color
56  self.fill_colorfill_color = MultiDimensional()
57  ## Hue
58  self.fill_huefill_hue = Value()
59  ## Saturation 0-100
60  self.fill_saturationfill_saturation = Value()
61  ## Brightness 0-100
62  self.fill_brightnessfill_brightness = Value()
63  ## Tracking
64  self.trackingtracking = Value()
65 
66 
67 ## @ingroup Lottie
69  Characters = 1
70  Word = 2
71  Line = 3
72  All = 4
73 
74  @classmethod
75  def default(cls):
76  return cls.CharactersCharacters
77 
78 
79 ## @ingroup Lottie
80 ## @ingroup LottieCheck
82  _props = [
83  LottieProp("alignment", "a", MultiDimensional),
84  LottieProp("grouping", "g", TextGrouping),
85  ]
86 
87  def __init__(self):
88  self.alignmentalignment = MultiDimensional(NVector(0, 0))
89  self.groupinggrouping = TextGrouping.default()
90 
91 
92 ## @ingroup Lottie
94  Left = 0
95  Right = 1
96  Center = 2
97  JustifyWithLastLineLeft = 3
98  JustifyWithLastLineRight = 4
99  JustifyWithLastLineCenter = 5
100  JustifyWithLastLineFull = 6
101 
102 
103 #ingroup Lottie
105  Regular = 0
106  AllCaps = 1
107  SmallCaps = 2
108 
109 
110 ## @ingroup Lottie
112  """!
113  @see http://docs.aenhancers.com/other/textdocument/
114 
115  Note that for multi-line text, lines are separated by \\r
116  """
117  _props = [
118  LottieProp("font_family", "f", str),
119  LottieProp("color", "fc", Color),
120  LottieProp("font_size", "s", float),
121  LottieProp("line_height", "lh", float),
122  LottieProp("wrap_size", "sz", NVector),
123  LottieProp("text", "t", str),
124  LottieProp("justify", "j", TextJustify),
125  LottieProp("text_caps", "ca", TextCaps, False),
126  LottieProp("tracking", "tr", float, False),
127  ]
128 
129  def __init__(self, text="", font_size=10, color=None, font_family=""):
130  self.font_familyfont_family = font_family
131  ## Text color
132  self.colorcolor = color or Color(0, 0, 0)
133  ## Line height when wrapping
134  self.line_heightline_height = None
135  ## Text alignment
136  self.justifyjustify = TextJustify.Left
137  ## Size of the box containing the text
138  self.wrap_sizewrap_size = None
139  ## Text
140  self.texttext = text
141  ## Font Size
142  self.font_sizefont_size = font_size
143  ## Text caps
144  self.text_capstext_caps = None
145  ## Text Tracking
146  self.trackingtracking = None
147 
148 
149 ## @ingroup Lottie
151  _props = [
152  LottieProp("start", "s", TextDocument),
153  LottieProp("time", "t", float),
154  ]
155 
156  def __init__(self, time=0, start=None):
157  ## Start value of keyframe segment.
158  self.startstart = start
159  ## Start time of keyframe segment.
160  self.timetime = time
161 
162 
163 ## @ingroup Lottie
165  _props = [
166  LottieProp("keyframes", "k", TextDataKeyframe, True),
167  ]
168 
169  def __init__(self):
170  self.keyframeskeyframes = []
171 
172  def get_value(self, time):
173  for kf in self.keyframeskeyframes:
174  if kf.time >= time:
175  return kf.start
176  return None
177 
178 
179 ## @ingroup Lottie
181  _props = [
182  LottieProp("properties", "a", TextAnimatorDataProperty, True),
183  LottieProp("data", "d", TextData, False),
184  LottieProp("more_options", "m", TextMoreOptions, False),
185  LottieProp("masked_path", "p", MaskedPath),
186  ]
187 
188  def __init__(self):
189  self.propertiesproperties = []
190  self.datadata = TextData()
191  self.more_optionsmore_options = TextMoreOptions()
192  self.masked_pathmasked_path = MaskedPath()
193 
194  def add_keyframe(self, time, item):
195  self.datadata.keyframes.append(TextDataKeyframe(time, item))
196 
197  def get_value(self, time):
198  return self.datadata.get_value(time)
199 
200 
201 ## @ingroup Lottie
203  Local = 0
204  CssUrl = 1
205  ScriptUrl = 2
206  FontUrl = 3
207 
208 
209 ## @ingroup Lottie
211  _props = [
212  LottieProp("ascent", "ascent", float),
213  LottieProp("font_family", "fFamily", str),
214  LottieProp("name", "fName", str),
215  LottieProp("font_style", "fStyle", str),
216  LottieProp("path", "fPath", str),
217  LottieProp("weight", "fWeight", str),
218  LottieProp("origin", "origin", FontPathOrigin),
219  LottieProp("css_class", "fClass", str),
220  ]
221 
222  def __init__(self, font_family="sans", font_style="Regular", name=None):
223  self.ascentascent = None
224  self.font_familyfont_family = font_family
225  self.font_stylefont_style = font_style
226  self.namename = name or "%s-%s" % (font_family, font_style)
227  self.pathpath = None
228  self.weightweight = None
229  self.originorigin = None
230  self.css_classcss_class = None
231 
232 
233 ## @ingroup Lottie
235  _props = [
236  LottieProp("list", "list", Font, True),
237  ]
238 
239  def __init__(self):
240  self.listlist = []
241 
242  def append(self, font):
243  self.listlist.append(font)
244 
245 
246 ## @ingroup Lottie
248  """!
249  Character shapes
250  """
251  _props = [
252  LottieProp("shapes", "shapes", ShapeElement, True),
253  ]
254 
255  def __init__(self):
256  self.shapesshapes = []
257 
258 
259 ## @ingroup Lottie
261  """!
262  Defines character shapes to avoid loading system fonts
263  """
264  _props = [
265  LottieProp("character", "ch", str, False),
266  LottieProp("font_family", "fFamily", str, False),
267  LottieProp("font_size", "size", float, False),
268  LottieProp("font_style", "style", str, False),
269  LottieProp("width", "w", float, False),
270  LottieProp("data", "data", CharacterData, False),
271  ]
272 
273  def __init__(self):
274  ## Character Value
275  self.charactercharacter = ""
276  ## Character Font Family
277  self.font_familyfont_family = ""
278  ## Character Font Size
279  self.font_sizefont_size = 0
280  ## Character Font Style
281  self.font_stylefont_style = "" # Regular
282  ## Character Width
283  self.widthwidth = 0
284  ## Character Data
285  self.datadata = CharacterData()
286 
287  @property
288  def shapes(self):
289  return self.datadata.shapes
Base class for enum-like types in the Lottie JSON structure.
Definition: base.py:42
Base class for mapping Python classes into Lottie JSON objects.
Definition: base.py:225
Lottie <-> Python property mapper.
Definition: base.py:88
An animatable property that holds a NVector.
Definition: properties.py:471
An animatable property that holds a float.
Definition: properties.py:708
Defines character shapes to avoid loading system fonts.
Definition: text.py:260
character
Character Value.
Definition: text.py:275
font_size
Character Font Size.
Definition: text.py:279
def __init__(self)
Definition: text.py:273
font_style
Character Font Style.
Definition: text.py:281
data
Character Data.
Definition: text.py:285
font_family
Character Font Family.
Definition: text.py:277
width
Character Width.
Definition: text.py:283
def append(self, font)
Definition: text.py:242
def __init__(self, font_family="sans", font_style="Regular", name=None)
Definition: text.py:222
def add_keyframe(self, time, item)
Definition: text.py:194
time
Start time of keyframe segment.
Definition: text.py:160
def __init__(self, time=0, start=None)
Definition: text.py:156
start
Start value of keyframe segment.
Definition: text.py:158
def get_value(self, time)
Definition: text.py:172
wrap_size
Size of the box containing the text.
Definition: text.py:138
def __init__(self, text="", font_size=10, color=None, font_family="")
Definition: text.py:129
justify
Text alignment.
Definition: text.py:136
line_height
Line height when wrapping.
Definition: text.py:134