def BodyText(image, text, color, flavor_text_size=0, font=None): # Replacement of keywords with symbols for keyword in RulesDict: if keyword in text: text = text.replace(keyword, RulesDict[keyword]) text = FixUnicode(text) if font is None: font = fonts["Body"] anchor = Anchors["Body"] leading = -1 # Get the size of the body text as (w,h) body_text_size = PIL_Helper.GetTextBlockSize(text, fonts["Body"], textmaxwidth) # If the height of the body text plus the height of the flavor text # doesn't fit in on the card in the normal position, move the body text up if body_text_size[1] + flavor_text_size[1] > TextHeightThresholds[0]: anchor = Anchors["BodyShiftedUp"] # If they still don't fit, makes the body text smaller if body_text_size[1] + flavor_text_size[1] > TextHeightThresholds[1]: font = fonts["BodySmall"] body_text_size = PIL_Helper.GetTextBlockSize(text, font, textmaxwidth) # If they still don't fit, make it smaller again. They're probably # the changeling cards if body_text_size[1] + flavor_text_size[1] > TextHeightThresholds[1]: font = fonts["BodyChangeling"] leading = -3 Anchors["BodyShiftedUp"] PIL_Helper.AddText(image=image, text=text, font=font, fill=color, anchor=anchor, halign="center", max_width=textmaxwidth, leading_offset=leading)
def BarText(image, text, color): bar_text_size = PIL_Helper.GetTextBlockSize(text, fonts["Bar"], textmaxwidth) if bar_text_size[0] > BarTextThreshold[0]: font = fonts["BarSmall"] else: font = fonts["Bar"] PIL_Helper.AddText(image=image, text=text, font=font, fill=color, anchor=Anchors["Bar"], halign="right")