text referencing others
This commit is contained in:
+14
-4
@@ -63,10 +63,19 @@ def load_item(i, item):
|
||||
raw_texts = utils.read_key(item, "texts", meme.texts, types=[dict], is_list=True)
|
||||
if "texts" in item:
|
||||
meme.texts = []
|
||||
c = 1
|
||||
for j in range(len(raw_texts)):
|
||||
raw_text = raw_texts[j]
|
||||
try:
|
||||
meme.texts += [load_text(j, raw_text)]
|
||||
text = load_text(c, raw_text)
|
||||
if text.text_ref is None:
|
||||
c += 1
|
||||
elif text.text_ref < 0 or text.text_ref >= len(meme.texts):
|
||||
logger.warning(f"Item '{item_id}'({i}) / Text {j}: invalid text reference {text.text_ref}")
|
||||
continue
|
||||
else:
|
||||
text.text = meme.texts[text.text_ref].text
|
||||
meme.texts += [text]
|
||||
except TypeError as e:
|
||||
logger.warning(f"Item '{item_id}'({i}) / Text {j}: {e}")
|
||||
for text in meme.texts:
|
||||
@@ -89,11 +98,11 @@ def load_item(i, item):
|
||||
logger.warning(f"Item '{item_id}'({i}): {e}")
|
||||
|
||||
|
||||
def load_text(j, raw_text, text=None):
|
||||
def load_text(c, raw_text, text=None):
|
||||
"""
|
||||
TODO
|
||||
|
||||
:param (int) j:
|
||||
:param (int) c:
|
||||
:param (dict) raw_text:
|
||||
:param (Text|None) text:
|
||||
:raises TypeError:
|
||||
@@ -101,10 +110,11 @@ def load_text(j, raw_text, text=None):
|
||||
:return:
|
||||
"""
|
||||
if text is None:
|
||||
text = Text(f"text {j + 1}")
|
||||
text = Text(f"text {c}")
|
||||
text.font = utils.read_key_safe(raw_text, "font", text.font, types=[str])
|
||||
text.x_range = utils.read_key_safe(raw_text, "x_range", types=[float, int], is_list=True, is_list_size=2)
|
||||
text.y_range = utils.read_key_safe(raw_text, "y_range", types=[float, int], is_list=True, is_list_size=2)
|
||||
text.text_ref = utils.read_key_safe(raw_text, "text_ref", types=[int])
|
||||
text.angle = utils.read_key_safe(raw_text, "angle", types=[float, int])
|
||||
text.font_size = utils.read_key_safe(raw_text, "font_size", text.font_size, types=[float, int])
|
||||
text.fill = utils.read_key_safe(raw_text, "fill", text.fill, types=[int], is_list=True, is_list_size=3)
|
||||
|
||||
@@ -39,11 +39,16 @@ def compute(*args, left_wmark_text=None, debug=False):
|
||||
logger.warning(f"Meme template '{meme_id}' not found")
|
||||
return None
|
||||
if len(args) > 1:
|
||||
c = 0
|
||||
for i in range(len(meme.texts)):
|
||||
if i < len(args) - 1:
|
||||
meme.texts[i].text = args[i + 1]
|
||||
if meme.texts[i].text_ref is None:
|
||||
if i < len(args) - 1:
|
||||
meme.texts[i].text = args[c + 1]
|
||||
else:
|
||||
meme.texts[i].text = ""
|
||||
c += 1
|
||||
else:
|
||||
meme.texts[i].text = ""
|
||||
meme.texts[i].text = meme.texts[meme.texts[i].text_ref].text
|
||||
meme.texts += [right_wmark]
|
||||
if left_wmark_text is not None:
|
||||
left_wmark.text = left_wmark_text
|
||||
|
||||
@@ -55,6 +55,7 @@ class Text:
|
||||
|
||||
def __init__(self, text=None):
|
||||
self.text = text
|
||||
self.text_ref = None
|
||||
|
||||
self.x_range = (0, 1)
|
||||
self.y_range = (0, 1)
|
||||
|
||||
Reference in New Issue
Block a user