Calculate the exact size of the symbols image before creating it and pasting it into the card image.

This commit is contained in:
2025-07-13 01:24:59 -05:00
parent a0c4ae822b
commit 8c15f06c55

View File

@@ -47,21 +47,27 @@ class Images ():
class SymbolDrawer ():
def __init__ (self, size, direction="ltr"):
self.direction = direction
self.image = Image.new("RGBA", size)
self.symbols = []
self.symbol_pos = (0, 0)
self.size = (0, 0)
def add_symbol (self, symbol):
if isinstance(symbol, str):
symbol = symbols[symbol]
self.image.paste(symbol, self.symbol_pos)
self.symbols.append((symbol, self.symbol_pos))
if self.direction == "ltr":
self.symbol_pos = (self.symbol_pos[0] + symbol.width, self.symbol_pos[1])
self.size = (self.symbol_pos[0], max(symbol.height, self.size[1]))
elif self.direction == "ttb":
self.symbol_pos = (self.symbol_pos[0], self.symbol_pos[1] + symbol.height)
self.size = (max(symbol.width, self.size[0]), self.symbol_pos[1])
def draw_onto (self, target_image, dest):
target_image.alpha_composite(self.image, dest)
image = Image.new("RGBA", self.size)
for symbol in self.symbols:
image.paste(symbol[0], symbol[1])
target_image.alpha_composite(image, dest)
images = Images(IMAGES_DIRECTORY)
symbols = Images(SYMBOLS_DIRECTORY)
@@ -79,6 +85,9 @@ class Field ():
def has (self, rule_name):
return rule_name in self.style_rules
def __getattr__ (self, rule_name):
return self.get(rule_name)
def __resolve (self, rule):
try:
return resolve_style_rule(rule, self.value, self.card)